@@ -615,7 +615,7 @@ discard block |
||
| 615 | 615 | * @param string $dt_frmt string representation of date format defaults to WP settings |
| 616 | 616 | * @param string $conjunction conjunction junction what's your function ? |
| 617 | 617 | * this string joins the start date with the end date ie: Jan 01 "to" Dec 31 |
| 618 | - * @return mixed string on success, FALSE on fail |
|
| 618 | + * @return string string on success, FALSE on fail |
|
| 619 | 619 | * @throws ReflectionException |
| 620 | 620 | * @throws InvalidArgumentException |
| 621 | 621 | * @throws InvalidInterfaceException |
@@ -723,7 +723,7 @@ discard block |
||
| 723 | 723 | * @param string $tm_format string representation of time format defaults to 'g:i a' |
| 724 | 724 | * @param string $conjunction conjunction junction what's your function ? |
| 725 | 725 | * this string joins the start date with the end date ie: Jan 01 "to" Dec 31 |
| 726 | - * @return mixed string on success, FALSE on fail |
|
| 726 | + * @return string string on success, FALSE on fail |
|
| 727 | 727 | * @throws ReflectionException |
| 728 | 728 | * @throws InvalidArgumentException |
| 729 | 729 | * @throws InvalidInterfaceException |
@@ -1077,7 +1077,7 @@ discard block |
||
| 1077 | 1077 | * before any were sold |
| 1078 | 1078 | * |
| 1079 | 1079 | * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
| 1080 | - * @return int |
|
| 1080 | + * @return double |
|
| 1081 | 1081 | * @throws ReflectionException |
| 1082 | 1082 | * @throws InvalidArgumentException |
| 1083 | 1083 | * @throws InvalidInterfaceException |
@@ -13,1412 +13,1412 @@ |
||
| 13 | 13 | class EE_Datetime extends EE_Soft_Delete_Base_Class |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * constant used by get_active_status, indicates datetime has no more available spaces |
|
| 18 | - */ |
|
| 19 | - const sold_out = 'DTS'; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * constant used by get_active_status, indicating datetime is still active (even is not over, can be registered-for) |
|
| 23 | - */ |
|
| 24 | - const active = 'DTA'; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * constant used by get_active_status, indicating the datetime cannot be used for registrations yet, but has not |
|
| 28 | - * expired |
|
| 29 | - */ |
|
| 30 | - const upcoming = 'DTU'; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Datetime is postponed |
|
| 34 | - */ |
|
| 35 | - const postponed = 'DTP'; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Datetime is cancelled |
|
| 39 | - */ |
|
| 40 | - const cancelled = 'DTC'; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * constant used by get_active_status, indicates datetime has expired (event is over) |
|
| 44 | - */ |
|
| 45 | - const expired = 'DTE'; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * constant used in various places indicating that an event is INACTIVE (not yet ready to be published) |
|
| 49 | - */ |
|
| 50 | - const inactive = 'DTI'; |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @param array $props_n_values incoming values |
|
| 55 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be used.) |
|
| 56 | - * @param array $date_formats incoming date_formats in an array where the first value is the date_format |
|
| 57 | - * and the second value is the time format |
|
| 58 | - * @return EE_Datetime |
|
| 59 | - * @throws ReflectionException |
|
| 60 | - * @throws InvalidArgumentException |
|
| 61 | - * @throws InvalidInterfaceException |
|
| 62 | - * @throws InvalidDataTypeException |
|
| 63 | - * @throws EE_Error |
|
| 64 | - */ |
|
| 65 | - public static function new_instance($props_n_values = array(), $timezone = '', $date_formats = array()) |
|
| 66 | - { |
|
| 67 | - $has_object = parent::_check_for_object( |
|
| 68 | - $props_n_values, |
|
| 69 | - __CLASS__, |
|
| 70 | - $timezone, |
|
| 71 | - $date_formats |
|
| 72 | - ); |
|
| 73 | - return $has_object |
|
| 74 | - ? $has_object |
|
| 75 | - : new self($props_n_values, false, $timezone, $date_formats); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @param array $props_n_values incoming values from the database |
|
| 81 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 82 | - * the website will be used. |
|
| 83 | - * @return EE_Datetime |
|
| 84 | - * @throws ReflectionException |
|
| 85 | - * @throws InvalidArgumentException |
|
| 86 | - * @throws InvalidInterfaceException |
|
| 87 | - * @throws InvalidDataTypeException |
|
| 88 | - * @throws EE_Error |
|
| 89 | - */ |
|
| 90 | - public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
| 91 | - { |
|
| 92 | - return new self($props_n_values, true, $timezone); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @param $name |
|
| 98 | - * @throws ReflectionException |
|
| 99 | - * @throws InvalidArgumentException |
|
| 100 | - * @throws InvalidInterfaceException |
|
| 101 | - * @throws InvalidDataTypeException |
|
| 102 | - * @throws EE_Error |
|
| 103 | - */ |
|
| 104 | - public function set_name($name) |
|
| 105 | - { |
|
| 106 | - $this->set('DTT_name', $name); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * @param $description |
|
| 112 | - * @throws ReflectionException |
|
| 113 | - * @throws InvalidArgumentException |
|
| 114 | - * @throws InvalidInterfaceException |
|
| 115 | - * @throws InvalidDataTypeException |
|
| 116 | - * @throws EE_Error |
|
| 117 | - */ |
|
| 118 | - public function set_description($description) |
|
| 119 | - { |
|
| 120 | - $this->set('DTT_description', $description); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Set event start date |
|
| 126 | - * set the start date for an event |
|
| 127 | - * |
|
| 128 | - * @param string $date a string representation of the event's date ex: Dec. 25, 2025 or 12-25-2025 |
|
| 129 | - * @throws ReflectionException |
|
| 130 | - * @throws InvalidArgumentException |
|
| 131 | - * @throws InvalidInterfaceException |
|
| 132 | - * @throws InvalidDataTypeException |
|
| 133 | - * @throws EE_Error |
|
| 134 | - */ |
|
| 135 | - public function set_start_date($date) |
|
| 136 | - { |
|
| 137 | - $this->_set_date_for($date, 'DTT_EVT_start'); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Set event start time |
|
| 143 | - * set the start time for an event |
|
| 144 | - * |
|
| 145 | - * @param string $time a string representation of the event time ex: 9am or 7:30 PM |
|
| 146 | - * @throws ReflectionException |
|
| 147 | - * @throws InvalidArgumentException |
|
| 148 | - * @throws InvalidInterfaceException |
|
| 149 | - * @throws InvalidDataTypeException |
|
| 150 | - * @throws EE_Error |
|
| 151 | - */ |
|
| 152 | - public function set_start_time($time) |
|
| 153 | - { |
|
| 154 | - $this->_set_time_for($time, 'DTT_EVT_start'); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Set event end date |
|
| 160 | - * set the end date for an event |
|
| 161 | - * |
|
| 162 | - * @param string $date a string representation of the event's date ex: Dec. 25, 2025 or 12-25-2025 |
|
| 163 | - * @throws ReflectionException |
|
| 164 | - * @throws InvalidArgumentException |
|
| 165 | - * @throws InvalidInterfaceException |
|
| 166 | - * @throws InvalidDataTypeException |
|
| 167 | - * @throws EE_Error |
|
| 168 | - */ |
|
| 169 | - public function set_end_date($date) |
|
| 170 | - { |
|
| 171 | - $this->_set_date_for($date, 'DTT_EVT_end'); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Set event end time |
|
| 177 | - * set the end time for an event |
|
| 178 | - * |
|
| 179 | - * @param string $time a string representation of the event time ex: 9am or 7:30 PM |
|
| 180 | - * @throws ReflectionException |
|
| 181 | - * @throws InvalidArgumentException |
|
| 182 | - * @throws InvalidInterfaceException |
|
| 183 | - * @throws InvalidDataTypeException |
|
| 184 | - * @throws EE_Error |
|
| 185 | - */ |
|
| 186 | - public function set_end_time($time) |
|
| 187 | - { |
|
| 188 | - $this->_set_time_for($time, 'DTT_EVT_end'); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * Set registration limit |
|
| 194 | - * set the maximum number of attendees that can be registered for this datetime slot |
|
| 195 | - * |
|
| 196 | - * @param int $reg_limit |
|
| 197 | - * @throws ReflectionException |
|
| 198 | - * @throws InvalidArgumentException |
|
| 199 | - * @throws InvalidInterfaceException |
|
| 200 | - * @throws InvalidDataTypeException |
|
| 201 | - * @throws EE_Error |
|
| 202 | - */ |
|
| 203 | - public function set_reg_limit($reg_limit) |
|
| 204 | - { |
|
| 205 | - $this->set('DTT_reg_limit', $reg_limit); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * get the number of tickets sold for this datetime slot |
|
| 211 | - * |
|
| 212 | - * @return mixed int on success, FALSE on fail |
|
| 213 | - * @throws ReflectionException |
|
| 214 | - * @throws InvalidArgumentException |
|
| 215 | - * @throws InvalidInterfaceException |
|
| 216 | - * @throws InvalidDataTypeException |
|
| 217 | - * @throws EE_Error |
|
| 218 | - */ |
|
| 219 | - public function sold() |
|
| 220 | - { |
|
| 221 | - return $this->get_raw('DTT_sold'); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * @param int $sold |
|
| 227 | - * @throws ReflectionException |
|
| 228 | - * @throws InvalidArgumentException |
|
| 229 | - * @throws InvalidInterfaceException |
|
| 230 | - * @throws InvalidDataTypeException |
|
| 231 | - * @throws EE_Error |
|
| 232 | - */ |
|
| 233 | - public function set_sold($sold) |
|
| 234 | - { |
|
| 235 | - // sold can not go below zero |
|
| 236 | - $sold = max(0, $sold); |
|
| 237 | - $this->set('DTT_sold', $sold); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * Increments sold by amount passed by $qty, and persists it immediately to the database. |
|
| 243 | - * Simultaneously decreases the reserved count, unless $also_decrease_reserved is false. |
|
| 244 | - * |
|
| 245 | - * @param int $qty |
|
| 246 | - * @param boolean $also_decrease_reserved |
|
| 247 | - * @return boolean indicating success |
|
| 248 | - * @throws ReflectionException |
|
| 249 | - * @throws InvalidArgumentException |
|
| 250 | - * @throws InvalidInterfaceException |
|
| 251 | - * @throws InvalidDataTypeException |
|
| 252 | - * @throws EE_Error |
|
| 253 | - */ |
|
| 254 | - public function increaseSold($qty = 1, $also_decrease_reserved = true) |
|
| 255 | - { |
|
| 256 | - $qty = absint($qty); |
|
| 257 | - if ($also_decrease_reserved) { |
|
| 258 | - $success = $this->adjustNumericFieldsInDb( |
|
| 259 | - [ |
|
| 260 | - 'DTT_reserved' => $qty * -1, |
|
| 261 | - 'DTT_sold' => $qty |
|
| 262 | - ] |
|
| 263 | - ); |
|
| 264 | - } else { |
|
| 265 | - $success = $this->adjustNumericFieldsInDb( |
|
| 266 | - [ |
|
| 267 | - 'DTT_sold' => $qty |
|
| 268 | - ] |
|
| 269 | - ); |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - do_action( |
|
| 273 | - 'AHEE__EE_Datetime__increase_sold', |
|
| 274 | - $this, |
|
| 275 | - $qty, |
|
| 276 | - $this->sold(), |
|
| 277 | - $success |
|
| 278 | - ); |
|
| 279 | - return $success; |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * Decrements (subtracts) sold amount passed by $qty directly in the DB and on the model object. (Ie, no need |
|
| 285 | - * to save afterwards.) |
|
| 286 | - * |
|
| 287 | - * @param int $qty |
|
| 288 | - * @return boolean indicating success |
|
| 289 | - * @throws ReflectionException |
|
| 290 | - * @throws InvalidArgumentException |
|
| 291 | - * @throws InvalidInterfaceException |
|
| 292 | - * @throws InvalidDataTypeException |
|
| 293 | - * @throws EE_Error |
|
| 294 | - */ |
|
| 295 | - public function decreaseSold($qty = 1) |
|
| 296 | - { |
|
| 297 | - $qty = absint($qty); |
|
| 298 | - $success = $this->adjustNumericFieldsInDb( |
|
| 299 | - [ |
|
| 300 | - 'DTT_sold' => $qty * -1 |
|
| 301 | - ] |
|
| 302 | - ); |
|
| 303 | - do_action( |
|
| 304 | - 'AHEE__EE_Datetime__decrease_sold', |
|
| 305 | - $this, |
|
| 306 | - $qty, |
|
| 307 | - $this->sold(), |
|
| 308 | - $success |
|
| 309 | - ); |
|
| 310 | - return $success; |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - |
|
| 314 | - /** |
|
| 315 | - * Gets qty of reserved tickets for this datetime |
|
| 316 | - * |
|
| 317 | - * @return int |
|
| 318 | - * @throws ReflectionException |
|
| 319 | - * @throws InvalidArgumentException |
|
| 320 | - * @throws InvalidInterfaceException |
|
| 321 | - * @throws InvalidDataTypeException |
|
| 322 | - * @throws EE_Error |
|
| 323 | - */ |
|
| 324 | - public function reserved() |
|
| 325 | - { |
|
| 326 | - return $this->get_raw('DTT_reserved'); |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * Sets qty of reserved tickets for this datetime |
|
| 332 | - * |
|
| 333 | - * @param int $reserved |
|
| 334 | - * @throws ReflectionException |
|
| 335 | - * @throws InvalidArgumentException |
|
| 336 | - * @throws InvalidInterfaceException |
|
| 337 | - * @throws InvalidDataTypeException |
|
| 338 | - * @throws EE_Error |
|
| 339 | - */ |
|
| 340 | - public function set_reserved($reserved) |
|
| 341 | - { |
|
| 342 | - // reserved can not go below zero |
|
| 343 | - $reserved = max(0, (int) $reserved); |
|
| 344 | - $this->set('DTT_reserved', $reserved); |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - |
|
| 348 | - /** |
|
| 349 | - * Increments reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 350 | - * |
|
| 351 | - * @param int $qty |
|
| 352 | - * @return boolean indicating success |
|
| 353 | - * @throws ReflectionException |
|
| 354 | - * @throws InvalidArgumentException |
|
| 355 | - * @throws InvalidInterfaceException |
|
| 356 | - * @throws InvalidDataTypeException |
|
| 357 | - * @throws EE_Error |
|
| 358 | - */ |
|
| 359 | - public function increaseReserved($qty = 1) |
|
| 360 | - { |
|
| 361 | - $qty = absint($qty); |
|
| 362 | - $success = $this->incrementFieldConditionallyInDb( |
|
| 363 | - 'DTT_reserved', |
|
| 364 | - 'DTT_sold', |
|
| 365 | - 'DTT_reg_limit', |
|
| 366 | - $qty |
|
| 367 | - ); |
|
| 368 | - do_action( |
|
| 369 | - 'AHEE__EE_Datetime__increase_reserved', |
|
| 370 | - $this, |
|
| 371 | - $qty, |
|
| 372 | - $this->reserved(), |
|
| 373 | - $success |
|
| 374 | - ); |
|
| 375 | - return $success; |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - |
|
| 379 | - /** |
|
| 380 | - * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 381 | - * |
|
| 382 | - * @param int $qty |
|
| 383 | - * @return boolean indicating success |
|
| 384 | - * @throws ReflectionException |
|
| 385 | - * @throws InvalidArgumentException |
|
| 386 | - * @throws InvalidInterfaceException |
|
| 387 | - * @throws InvalidDataTypeException |
|
| 388 | - * @throws EE_Error |
|
| 389 | - */ |
|
| 390 | - public function decreaseReserved($qty = 1) |
|
| 391 | - { |
|
| 392 | - $qty = absint($qty); |
|
| 393 | - $success = $this->adjustNumericFieldsInDb( |
|
| 394 | - [ |
|
| 395 | - 'DTT_reserved' => $qty * -1 |
|
| 396 | - ] |
|
| 397 | - ); |
|
| 398 | - do_action( |
|
| 399 | - 'AHEE__EE_Datetime__decrease_reserved', |
|
| 400 | - $this, |
|
| 401 | - $qty, |
|
| 402 | - $this->reserved(), |
|
| 403 | - $success |
|
| 404 | - ); |
|
| 405 | - return $success; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * total sold and reserved tickets |
|
| 411 | - * |
|
| 412 | - * @return int |
|
| 413 | - * @throws ReflectionException |
|
| 414 | - * @throws InvalidArgumentException |
|
| 415 | - * @throws InvalidInterfaceException |
|
| 416 | - * @throws InvalidDataTypeException |
|
| 417 | - * @throws EE_Error |
|
| 418 | - */ |
|
| 419 | - public function sold_and_reserved() |
|
| 420 | - { |
|
| 421 | - return $this->sold() + $this->reserved(); |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - |
|
| 425 | - /** |
|
| 426 | - * returns the datetime name |
|
| 427 | - * |
|
| 428 | - * @return string |
|
| 429 | - * @throws ReflectionException |
|
| 430 | - * @throws InvalidArgumentException |
|
| 431 | - * @throws InvalidInterfaceException |
|
| 432 | - * @throws InvalidDataTypeException |
|
| 433 | - * @throws EE_Error |
|
| 434 | - */ |
|
| 435 | - public function name() |
|
| 436 | - { |
|
| 437 | - return $this->get('DTT_name'); |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - |
|
| 441 | - /** |
|
| 442 | - * returns the datetime description |
|
| 443 | - * |
|
| 444 | - * @return string |
|
| 445 | - * @throws ReflectionException |
|
| 446 | - * @throws InvalidArgumentException |
|
| 447 | - * @throws InvalidInterfaceException |
|
| 448 | - * @throws InvalidDataTypeException |
|
| 449 | - * @throws EE_Error |
|
| 450 | - */ |
|
| 451 | - public function description() |
|
| 452 | - { |
|
| 453 | - return $this->get('DTT_description'); |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - |
|
| 457 | - /** |
|
| 458 | - * This helper simply returns whether the event_datetime for the current datetime is a primary datetime |
|
| 459 | - * |
|
| 460 | - * @return boolean TRUE if is primary, FALSE if not. |
|
| 461 | - * @throws ReflectionException |
|
| 462 | - * @throws InvalidArgumentException |
|
| 463 | - * @throws InvalidInterfaceException |
|
| 464 | - * @throws InvalidDataTypeException |
|
| 465 | - * @throws EE_Error |
|
| 466 | - */ |
|
| 467 | - public function is_primary() |
|
| 468 | - { |
|
| 469 | - return $this->get('DTT_is_primary'); |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - |
|
| 473 | - /** |
|
| 474 | - * This helper simply returns the order for the datetime |
|
| 475 | - * |
|
| 476 | - * @return int The order of the datetime for this event. |
|
| 477 | - * @throws ReflectionException |
|
| 478 | - * @throws InvalidArgumentException |
|
| 479 | - * @throws InvalidInterfaceException |
|
| 480 | - * @throws InvalidDataTypeException |
|
| 481 | - * @throws EE_Error |
|
| 482 | - */ |
|
| 483 | - public function order() |
|
| 484 | - { |
|
| 485 | - return $this->get('DTT_order'); |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - |
|
| 489 | - /** |
|
| 490 | - * This helper simply returns the parent id for the datetime |
|
| 491 | - * |
|
| 492 | - * @return int |
|
| 493 | - * @throws ReflectionException |
|
| 494 | - * @throws InvalidArgumentException |
|
| 495 | - * @throws InvalidInterfaceException |
|
| 496 | - * @throws InvalidDataTypeException |
|
| 497 | - * @throws EE_Error |
|
| 498 | - */ |
|
| 499 | - public function parent() |
|
| 500 | - { |
|
| 501 | - return $this->get('DTT_parent'); |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - |
|
| 505 | - /** |
|
| 506 | - * show date and/or time |
|
| 507 | - * |
|
| 508 | - * @param string $date_or_time whether to display a date or time or both |
|
| 509 | - * @param string $start_or_end whether to display start or end datetimes |
|
| 510 | - * @param string $dt_frmt |
|
| 511 | - * @param string $tm_frmt |
|
| 512 | - * @param bool $echo whether we echo or return (note echoing uses "pretty" formats, |
|
| 513 | - * otherwise we use the standard formats) |
|
| 514 | - * @return string|bool string on success, FALSE on fail |
|
| 515 | - * @throws ReflectionException |
|
| 516 | - * @throws InvalidArgumentException |
|
| 517 | - * @throws InvalidInterfaceException |
|
| 518 | - * @throws InvalidDataTypeException |
|
| 519 | - * @throws EE_Error |
|
| 520 | - */ |
|
| 521 | - private function _show_datetime( |
|
| 522 | - $date_or_time = null, |
|
| 523 | - $start_or_end = 'start', |
|
| 524 | - $dt_frmt = '', |
|
| 525 | - $tm_frmt = '', |
|
| 526 | - $echo = false |
|
| 527 | - ) { |
|
| 528 | - $field_name = "DTT_EVT_{$start_or_end}"; |
|
| 529 | - $dtt = $this->_get_datetime( |
|
| 530 | - $field_name, |
|
| 531 | - $dt_frmt, |
|
| 532 | - $tm_frmt, |
|
| 533 | - $date_or_time, |
|
| 534 | - $echo |
|
| 535 | - ); |
|
| 536 | - if (! $echo) { |
|
| 537 | - return $dtt; |
|
| 538 | - } |
|
| 539 | - return ''; |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - |
|
| 543 | - /** |
|
| 544 | - * get event start date. Provide either the date format, or NULL to re-use the |
|
| 545 | - * last-used format, or '' to use the default date format |
|
| 546 | - * |
|
| 547 | - * @param string $dt_frmt string representation of date format defaults to 'F j, Y' |
|
| 548 | - * @return mixed string on success, FALSE on fail |
|
| 549 | - * @throws ReflectionException |
|
| 550 | - * @throws InvalidArgumentException |
|
| 551 | - * @throws InvalidInterfaceException |
|
| 552 | - * @throws InvalidDataTypeException |
|
| 553 | - * @throws EE_Error |
|
| 554 | - */ |
|
| 555 | - public function start_date($dt_frmt = '') |
|
| 556 | - { |
|
| 557 | - return $this->_show_datetime('D', 'start', $dt_frmt); |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - |
|
| 561 | - /** |
|
| 562 | - * Echoes start_date() |
|
| 563 | - * |
|
| 564 | - * @param string $dt_frmt |
|
| 565 | - * @throws ReflectionException |
|
| 566 | - * @throws InvalidArgumentException |
|
| 567 | - * @throws InvalidInterfaceException |
|
| 568 | - * @throws InvalidDataTypeException |
|
| 569 | - * @throws EE_Error |
|
| 570 | - */ |
|
| 571 | - public function e_start_date($dt_frmt = '') |
|
| 572 | - { |
|
| 573 | - $this->_show_datetime('D', 'start', $dt_frmt, null, true); |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * get end date. Provide either the date format, or NULL to re-use the |
|
| 579 | - * last-used format, or '' to use the default date format |
|
| 580 | - * |
|
| 581 | - * @param string $dt_frmt string representation of date format defaults to 'F j, Y' |
|
| 582 | - * @return mixed string on success, FALSE on fail |
|
| 583 | - * @throws ReflectionException |
|
| 584 | - * @throws InvalidArgumentException |
|
| 585 | - * @throws InvalidInterfaceException |
|
| 586 | - * @throws InvalidDataTypeException |
|
| 587 | - * @throws EE_Error |
|
| 588 | - */ |
|
| 589 | - public function end_date($dt_frmt = '') |
|
| 590 | - { |
|
| 591 | - return $this->_show_datetime('D', 'end', $dt_frmt); |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - |
|
| 595 | - /** |
|
| 596 | - * Echoes the end date. See end_date() |
|
| 597 | - * |
|
| 598 | - * @param string $dt_frmt |
|
| 599 | - * @throws ReflectionException |
|
| 600 | - * @throws InvalidArgumentException |
|
| 601 | - * @throws InvalidInterfaceException |
|
| 602 | - * @throws InvalidDataTypeException |
|
| 603 | - * @throws EE_Error |
|
| 604 | - */ |
|
| 605 | - public function e_end_date($dt_frmt = '') |
|
| 606 | - { |
|
| 607 | - $this->_show_datetime('D', 'end', $dt_frmt, null, true); |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - |
|
| 611 | - /** |
|
| 612 | - * get date_range - meaning the start AND end date |
|
| 613 | - * |
|
| 614 | - * @access public |
|
| 615 | - * @param string $dt_frmt string representation of date format defaults to WP settings |
|
| 616 | - * @param string $conjunction conjunction junction what's your function ? |
|
| 617 | - * this string joins the start date with the end date ie: Jan 01 "to" Dec 31 |
|
| 618 | - * @return mixed string on success, FALSE on fail |
|
| 619 | - * @throws ReflectionException |
|
| 620 | - * @throws InvalidArgumentException |
|
| 621 | - * @throws InvalidInterfaceException |
|
| 622 | - * @throws InvalidDataTypeException |
|
| 623 | - * @throws EE_Error |
|
| 624 | - */ |
|
| 625 | - public function date_range($dt_frmt = '', $conjunction = ' - ') |
|
| 626 | - { |
|
| 627 | - $dt_frmt = ! empty($dt_frmt) ? $dt_frmt : $this->_dt_frmt; |
|
| 628 | - $start = str_replace( |
|
| 629 | - ' ', |
|
| 630 | - ' ', |
|
| 631 | - $this->get_i18n_datetime('DTT_EVT_start', $dt_frmt) |
|
| 632 | - ); |
|
| 633 | - $end = str_replace( |
|
| 634 | - ' ', |
|
| 635 | - ' ', |
|
| 636 | - $this->get_i18n_datetime('DTT_EVT_end', $dt_frmt) |
|
| 637 | - ); |
|
| 638 | - return $start !== $end ? $start . $conjunction . $end : $start; |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - |
|
| 642 | - /** |
|
| 643 | - * @param string $dt_frmt |
|
| 644 | - * @param string $conjunction |
|
| 645 | - * @throws ReflectionException |
|
| 646 | - * @throws InvalidArgumentException |
|
| 647 | - * @throws InvalidInterfaceException |
|
| 648 | - * @throws InvalidDataTypeException |
|
| 649 | - * @throws EE_Error |
|
| 650 | - */ |
|
| 651 | - public function e_date_range($dt_frmt = '', $conjunction = ' - ') |
|
| 652 | - { |
|
| 653 | - echo $this->date_range($dt_frmt, $conjunction); |
|
| 654 | - } |
|
| 655 | - |
|
| 656 | - |
|
| 657 | - /** |
|
| 658 | - * get start time |
|
| 659 | - * |
|
| 660 | - * @param string $tm_format - string representation of time format defaults to 'g:i a' |
|
| 661 | - * @return mixed string on success, FALSE on fail |
|
| 662 | - * @throws ReflectionException |
|
| 663 | - * @throws InvalidArgumentException |
|
| 664 | - * @throws InvalidInterfaceException |
|
| 665 | - * @throws InvalidDataTypeException |
|
| 666 | - * @throws EE_Error |
|
| 667 | - */ |
|
| 668 | - public function start_time($tm_format = '') |
|
| 669 | - { |
|
| 670 | - return $this->_show_datetime('T', 'start', null, $tm_format); |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - |
|
| 674 | - /** |
|
| 675 | - * @param string $tm_format |
|
| 676 | - * @throws ReflectionException |
|
| 677 | - * @throws InvalidArgumentException |
|
| 678 | - * @throws InvalidInterfaceException |
|
| 679 | - * @throws InvalidDataTypeException |
|
| 680 | - * @throws EE_Error |
|
| 681 | - */ |
|
| 682 | - public function e_start_time($tm_format = '') |
|
| 683 | - { |
|
| 684 | - $this->_show_datetime('T', 'start', null, $tm_format, true); |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - |
|
| 688 | - /** |
|
| 689 | - * get end time |
|
| 690 | - * |
|
| 691 | - * @param string $tm_format string representation of time format defaults to 'g:i a' |
|
| 692 | - * @return mixed string on success, FALSE on fail |
|
| 693 | - * @throws ReflectionException |
|
| 694 | - * @throws InvalidArgumentException |
|
| 695 | - * @throws InvalidInterfaceException |
|
| 696 | - * @throws InvalidDataTypeException |
|
| 697 | - * @throws EE_Error |
|
| 698 | - */ |
|
| 699 | - public function end_time($tm_format = '') |
|
| 700 | - { |
|
| 701 | - return $this->_show_datetime('T', 'end', null, $tm_format); |
|
| 702 | - } |
|
| 703 | - |
|
| 704 | - |
|
| 705 | - /** |
|
| 706 | - * @param string $tm_format |
|
| 707 | - * @throws ReflectionException |
|
| 708 | - * @throws InvalidArgumentException |
|
| 709 | - * @throws InvalidInterfaceException |
|
| 710 | - * @throws InvalidDataTypeException |
|
| 711 | - * @throws EE_Error |
|
| 712 | - */ |
|
| 713 | - public function e_end_time($tm_format = '') |
|
| 714 | - { |
|
| 715 | - $this->_show_datetime('T', 'end', null, $tm_format, true); |
|
| 716 | - } |
|
| 717 | - |
|
| 718 | - |
|
| 719 | - /** |
|
| 720 | - * get time_range |
|
| 721 | - * |
|
| 722 | - * @access public |
|
| 723 | - * @param string $tm_format string representation of time format defaults to 'g:i a' |
|
| 724 | - * @param string $conjunction conjunction junction what's your function ? |
|
| 725 | - * this string joins the start date with the end date ie: Jan 01 "to" Dec 31 |
|
| 726 | - * @return mixed string on success, FALSE on fail |
|
| 727 | - * @throws ReflectionException |
|
| 728 | - * @throws InvalidArgumentException |
|
| 729 | - * @throws InvalidInterfaceException |
|
| 730 | - * @throws InvalidDataTypeException |
|
| 731 | - * @throws EE_Error |
|
| 732 | - */ |
|
| 733 | - public function time_range($tm_format = '', $conjunction = ' - ') |
|
| 734 | - { |
|
| 735 | - $tm_format = ! empty($tm_format) ? $tm_format : $this->_tm_frmt; |
|
| 736 | - $start = str_replace( |
|
| 737 | - ' ', |
|
| 738 | - ' ', |
|
| 739 | - $this->get_i18n_datetime('DTT_EVT_start', $tm_format) |
|
| 740 | - ); |
|
| 741 | - $end = str_replace( |
|
| 742 | - ' ', |
|
| 743 | - ' ', |
|
| 744 | - $this->get_i18n_datetime('DTT_EVT_end', $tm_format) |
|
| 745 | - ); |
|
| 746 | - return $start !== $end ? $start . $conjunction . $end : $start; |
|
| 747 | - } |
|
| 748 | - |
|
| 749 | - |
|
| 750 | - /** |
|
| 751 | - * @param string $tm_format |
|
| 752 | - * @param string $conjunction |
|
| 753 | - * @throws ReflectionException |
|
| 754 | - * @throws InvalidArgumentException |
|
| 755 | - * @throws InvalidInterfaceException |
|
| 756 | - * @throws InvalidDataTypeException |
|
| 757 | - * @throws EE_Error |
|
| 758 | - */ |
|
| 759 | - public function e_time_range($tm_format = '', $conjunction = ' - ') |
|
| 760 | - { |
|
| 761 | - echo $this->time_range($tm_format, $conjunction); |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - |
|
| 765 | - /** |
|
| 766 | - * This returns a range representation of the date and times. |
|
| 767 | - * Output is dependent on the difference (or similarity) between DTT_EVT_start and DTT_EVT_end. |
|
| 768 | - * Also, the return value is localized. |
|
| 769 | - * |
|
| 770 | - * @param string $dt_format |
|
| 771 | - * @param string $tm_format |
|
| 772 | - * @param string $conjunction used between two different dates or times. |
|
| 773 | - * ex: Dec 1{$conjunction}}Dec 6, or 2pm{$conjunction}3pm |
|
| 774 | - * @param string $separator used between the date and time formats. |
|
| 775 | - * ex: Dec 1, 2016{$separator}2pm |
|
| 776 | - * @return string |
|
| 777 | - * @throws ReflectionException |
|
| 778 | - * @throws InvalidArgumentException |
|
| 779 | - * @throws InvalidInterfaceException |
|
| 780 | - * @throws InvalidDataTypeException |
|
| 781 | - * @throws EE_Error |
|
| 782 | - */ |
|
| 783 | - public function date_and_time_range( |
|
| 784 | - $dt_format = '', |
|
| 785 | - $tm_format = '', |
|
| 786 | - $conjunction = ' - ', |
|
| 787 | - $separator = ' ' |
|
| 788 | - ) { |
|
| 789 | - $dt_format = ! empty($dt_format) ? $dt_format : $this->_dt_frmt; |
|
| 790 | - $tm_format = ! empty($tm_format) ? $tm_format : $this->_tm_frmt; |
|
| 791 | - $full_format = $dt_format . $separator . $tm_format; |
|
| 792 | - // the range output depends on various conditions |
|
| 793 | - switch (true) { |
|
| 794 | - // start date timestamp and end date timestamp are the same. |
|
| 795 | - case ($this->get_raw('DTT_EVT_start') === $this->get_raw('DTT_EVT_end')): |
|
| 796 | - $output = $this->get_i18n_datetime('DTT_EVT_start', $full_format); |
|
| 797 | - break; |
|
| 798 | - // start and end date are the same but times are different |
|
| 799 | - case ($this->start_date() === $this->end_date()): |
|
| 800 | - $output = $this->get_i18n_datetime('DTT_EVT_start', $full_format) |
|
| 801 | - . $conjunction |
|
| 802 | - . $this->get_i18n_datetime('DTT_EVT_end', $tm_format); |
|
| 803 | - break; |
|
| 804 | - // all other conditions |
|
| 805 | - default: |
|
| 806 | - $output = $this->get_i18n_datetime('DTT_EVT_start', $full_format) |
|
| 807 | - . $conjunction |
|
| 808 | - . $this->get_i18n_datetime('DTT_EVT_end', $full_format); |
|
| 809 | - break; |
|
| 810 | - } |
|
| 811 | - return $output; |
|
| 812 | - } |
|
| 813 | - |
|
| 814 | - |
|
| 815 | - /** |
|
| 816 | - * This echos the results of date and time range. |
|
| 817 | - * |
|
| 818 | - * @see date_and_time_range() for more details on purpose. |
|
| 819 | - * @param string $dt_format |
|
| 820 | - * @param string $tm_format |
|
| 821 | - * @param string $conjunction |
|
| 822 | - * @return void |
|
| 823 | - * @throws ReflectionException |
|
| 824 | - * @throws InvalidArgumentException |
|
| 825 | - * @throws InvalidInterfaceException |
|
| 826 | - * @throws InvalidDataTypeException |
|
| 827 | - * @throws EE_Error |
|
| 828 | - */ |
|
| 829 | - public function e_date_and_time_range($dt_format = '', $tm_format = '', $conjunction = ' - ') |
|
| 830 | - { |
|
| 831 | - echo $this->date_and_time_range($dt_format, $tm_format, $conjunction); |
|
| 832 | - } |
|
| 833 | - |
|
| 834 | - |
|
| 835 | - /** |
|
| 836 | - * get start date and start time |
|
| 837 | - * |
|
| 838 | - * @param string $dt_format - string representation of date format defaults to 'F j, Y' |
|
| 839 | - * @param string $tm_format - string representation of time format defaults to 'g:i a' |
|
| 840 | - * @return mixed string on success, FALSE on fail |
|
| 841 | - * @throws ReflectionException |
|
| 842 | - * @throws InvalidArgumentException |
|
| 843 | - * @throws InvalidInterfaceException |
|
| 844 | - * @throws InvalidDataTypeException |
|
| 845 | - * @throws EE_Error |
|
| 846 | - */ |
|
| 847 | - public function start_date_and_time($dt_format = '', $tm_format = '') |
|
| 848 | - { |
|
| 849 | - return $this->_show_datetime('', 'start', $dt_format, $tm_format); |
|
| 850 | - } |
|
| 851 | - |
|
| 852 | - |
|
| 853 | - /** |
|
| 854 | - * @param string $dt_frmt |
|
| 855 | - * @param string $tm_format |
|
| 856 | - * @throws ReflectionException |
|
| 857 | - * @throws InvalidArgumentException |
|
| 858 | - * @throws InvalidInterfaceException |
|
| 859 | - * @throws InvalidDataTypeException |
|
| 860 | - * @throws EE_Error |
|
| 861 | - */ |
|
| 862 | - public function e_start_date_and_time($dt_frmt = '', $tm_format = '') |
|
| 863 | - { |
|
| 864 | - $this->_show_datetime('', 'start', $dt_frmt, $tm_format, true); |
|
| 865 | - } |
|
| 866 | - |
|
| 867 | - |
|
| 868 | - /** |
|
| 869 | - * Shows the length of the event (start to end time). |
|
| 870 | - * Can be shown in 'seconds','minutes','hours', or 'days'. |
|
| 871 | - * By default, rounds up. (So if you use 'days', and then event |
|
| 872 | - * only occurs for 1 hour, it will return 1 day). |
|
| 873 | - * |
|
| 874 | - * @param string $units 'seconds','minutes','hours','days' |
|
| 875 | - * @param bool $round_up |
|
| 876 | - * @return float|int|mixed |
|
| 877 | - * @throws ReflectionException |
|
| 878 | - * @throws InvalidArgumentException |
|
| 879 | - * @throws InvalidInterfaceException |
|
| 880 | - * @throws InvalidDataTypeException |
|
| 881 | - * @throws EE_Error |
|
| 882 | - */ |
|
| 883 | - public function length($units = 'seconds', $round_up = false) |
|
| 884 | - { |
|
| 885 | - $start = $this->get_raw('DTT_EVT_start'); |
|
| 886 | - $end = $this->get_raw('DTT_EVT_end'); |
|
| 887 | - $length_in_units = $end - $start; |
|
| 888 | - switch ($units) { |
|
| 889 | - // NOTE: We purposefully don't use "break;" in order to chain the divisions |
|
| 890 | - /** @noinspection PhpMissingBreakStatementInspection */ |
|
| 891 | - // phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment |
|
| 892 | - case 'days': |
|
| 893 | - $length_in_units /= 24; |
|
| 894 | - /** @noinspection PhpMissingBreakStatementInspection */ |
|
| 895 | - case 'hours': |
|
| 896 | - // fall through is intentional |
|
| 897 | - $length_in_units /= 60; |
|
| 898 | - /** @noinspection PhpMissingBreakStatementInspection */ |
|
| 899 | - case 'minutes': |
|
| 900 | - // fall through is intentional |
|
| 901 | - $length_in_units /= 60; |
|
| 902 | - case 'seconds': |
|
| 903 | - default: |
|
| 904 | - $length_in_units = ceil($length_in_units); |
|
| 905 | - } |
|
| 906 | - // phpcs:enable |
|
| 907 | - if ($round_up) { |
|
| 908 | - $length_in_units = max($length_in_units, 1); |
|
| 909 | - } |
|
| 910 | - return $length_in_units; |
|
| 911 | - } |
|
| 912 | - |
|
| 913 | - |
|
| 914 | - /** |
|
| 915 | - * get end date and time |
|
| 916 | - * |
|
| 917 | - * @param string $dt_frmt - string representation of date format defaults to 'F j, Y' |
|
| 918 | - * @param string $tm_format - string representation of time format defaults to 'g:i a' |
|
| 919 | - * @return mixed string on success, FALSE on fail |
|
| 920 | - * @throws ReflectionException |
|
| 921 | - * @throws InvalidArgumentException |
|
| 922 | - * @throws InvalidInterfaceException |
|
| 923 | - * @throws InvalidDataTypeException |
|
| 924 | - * @throws EE_Error |
|
| 925 | - */ |
|
| 926 | - public function end_date_and_time($dt_frmt = '', $tm_format = '') |
|
| 927 | - { |
|
| 928 | - return $this->_show_datetime('', 'end', $dt_frmt, $tm_format); |
|
| 929 | - } |
|
| 930 | - |
|
| 931 | - |
|
| 932 | - /** |
|
| 933 | - * @param string $dt_frmt |
|
| 934 | - * @param string $tm_format |
|
| 935 | - * @throws ReflectionException |
|
| 936 | - * @throws InvalidArgumentException |
|
| 937 | - * @throws InvalidInterfaceException |
|
| 938 | - * @throws InvalidDataTypeException |
|
| 939 | - * @throws EE_Error |
|
| 940 | - */ |
|
| 941 | - public function e_end_date_and_time($dt_frmt = '', $tm_format = '') |
|
| 942 | - { |
|
| 943 | - $this->_show_datetime('', 'end', $dt_frmt, $tm_format, true); |
|
| 944 | - } |
|
| 945 | - |
|
| 946 | - |
|
| 947 | - /** |
|
| 948 | - * get start timestamp |
|
| 949 | - * |
|
| 950 | - * @return int |
|
| 951 | - * @throws ReflectionException |
|
| 952 | - * @throws InvalidArgumentException |
|
| 953 | - * @throws InvalidInterfaceException |
|
| 954 | - * @throws InvalidDataTypeException |
|
| 955 | - * @throws EE_Error |
|
| 956 | - */ |
|
| 957 | - public function start() |
|
| 958 | - { |
|
| 959 | - return $this->get_raw('DTT_EVT_start'); |
|
| 960 | - } |
|
| 961 | - |
|
| 962 | - |
|
| 963 | - /** |
|
| 964 | - * get end timestamp |
|
| 965 | - * |
|
| 966 | - * @return int |
|
| 967 | - * @throws ReflectionException |
|
| 968 | - * @throws InvalidArgumentException |
|
| 969 | - * @throws InvalidInterfaceException |
|
| 970 | - * @throws InvalidDataTypeException |
|
| 971 | - * @throws EE_Error |
|
| 972 | - */ |
|
| 973 | - public function end() |
|
| 974 | - { |
|
| 975 | - return $this->get_raw('DTT_EVT_end'); |
|
| 976 | - } |
|
| 977 | - |
|
| 978 | - |
|
| 979 | - /** |
|
| 980 | - * get the registration limit for this datetime slot |
|
| 981 | - * |
|
| 982 | - * @return mixed int on success, FALSE on fail |
|
| 983 | - * @throws ReflectionException |
|
| 984 | - * @throws InvalidArgumentException |
|
| 985 | - * @throws InvalidInterfaceException |
|
| 986 | - * @throws InvalidDataTypeException |
|
| 987 | - * @throws EE_Error |
|
| 988 | - */ |
|
| 989 | - public function reg_limit() |
|
| 990 | - { |
|
| 991 | - return $this->get_raw('DTT_reg_limit'); |
|
| 992 | - } |
|
| 993 | - |
|
| 994 | - |
|
| 995 | - /** |
|
| 996 | - * have the tickets sold for this datetime, met or exceed the registration limit ? |
|
| 997 | - * |
|
| 998 | - * @return boolean |
|
| 999 | - * @throws ReflectionException |
|
| 1000 | - * @throws InvalidArgumentException |
|
| 1001 | - * @throws InvalidInterfaceException |
|
| 1002 | - * @throws InvalidDataTypeException |
|
| 1003 | - * @throws EE_Error |
|
| 1004 | - */ |
|
| 1005 | - public function sold_out() |
|
| 1006 | - { |
|
| 1007 | - return $this->reg_limit() > 0 && $this->sold() >= $this->reg_limit(); |
|
| 1008 | - } |
|
| 1009 | - |
|
| 1010 | - |
|
| 1011 | - /** |
|
| 1012 | - * return the total number of spaces remaining at this venue. |
|
| 1013 | - * This only takes the venue's capacity into account, NOT the tickets available for sale |
|
| 1014 | - * |
|
| 1015 | - * @param bool $consider_tickets Whether to consider tickets remaining when determining if there are any spaces left |
|
| 1016 | - * Because if all tickets attached to this datetime have no spaces left, |
|
| 1017 | - * then this datetime IS effectively sold out. |
|
| 1018 | - * However, there are cases where we just want to know the spaces |
|
| 1019 | - * remaining for this particular datetime, hence the flag. |
|
| 1020 | - * @return int |
|
| 1021 | - * @throws ReflectionException |
|
| 1022 | - * @throws InvalidArgumentException |
|
| 1023 | - * @throws InvalidInterfaceException |
|
| 1024 | - * @throws InvalidDataTypeException |
|
| 1025 | - * @throws EE_Error |
|
| 1026 | - */ |
|
| 1027 | - public function spaces_remaining($consider_tickets = false) |
|
| 1028 | - { |
|
| 1029 | - // tickets remaining available for purchase |
|
| 1030 | - // no need for special checks for infinite, because if DTT_reg_limit == EE_INF, then EE_INF - x = EE_INF |
|
| 1031 | - $dtt_remaining = $this->reg_limit() - $this->sold_and_reserved(); |
|
| 1032 | - if (! $consider_tickets) { |
|
| 1033 | - return $dtt_remaining; |
|
| 1034 | - } |
|
| 1035 | - $tickets_remaining = $this->tickets_remaining(); |
|
| 1036 | - return min($dtt_remaining, $tickets_remaining); |
|
| 1037 | - } |
|
| 1038 | - |
|
| 1039 | - |
|
| 1040 | - /** |
|
| 1041 | - * Counts the total tickets available |
|
| 1042 | - * (from all the different types of tickets which are available for this datetime). |
|
| 1043 | - * |
|
| 1044 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1045 | - * @return int |
|
| 1046 | - * @throws ReflectionException |
|
| 1047 | - * @throws InvalidArgumentException |
|
| 1048 | - * @throws InvalidInterfaceException |
|
| 1049 | - * @throws InvalidDataTypeException |
|
| 1050 | - * @throws EE_Error |
|
| 1051 | - */ |
|
| 1052 | - public function tickets_remaining($query_params = array()) |
|
| 1053 | - { |
|
| 1054 | - $sum = 0; |
|
| 1055 | - $tickets = $this->tickets($query_params); |
|
| 1056 | - if (! empty($tickets)) { |
|
| 1057 | - foreach ($tickets as $ticket) { |
|
| 1058 | - if ($ticket instanceof EE_Ticket) { |
|
| 1059 | - // get the actual amount of tickets that can be sold |
|
| 1060 | - $qty = $ticket->qty('saleable'); |
|
| 1061 | - if ($qty === EE_INF) { |
|
| 1062 | - return EE_INF; |
|
| 1063 | - } |
|
| 1064 | - // no negative ticket quantities plz |
|
| 1065 | - if ($qty > 0) { |
|
| 1066 | - $sum += $qty; |
|
| 1067 | - } |
|
| 1068 | - } |
|
| 1069 | - } |
|
| 1070 | - } |
|
| 1071 | - return $sum; |
|
| 1072 | - } |
|
| 1073 | - |
|
| 1074 | - |
|
| 1075 | - /** |
|
| 1076 | - * Gets the count of all the tickets available at this datetime (not ticket types) |
|
| 1077 | - * before any were sold |
|
| 1078 | - * |
|
| 1079 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1080 | - * @return int |
|
| 1081 | - * @throws ReflectionException |
|
| 1082 | - * @throws InvalidArgumentException |
|
| 1083 | - * @throws InvalidInterfaceException |
|
| 1084 | - * @throws InvalidDataTypeException |
|
| 1085 | - * @throws EE_Error |
|
| 1086 | - */ |
|
| 1087 | - public function sum_tickets_initially_available($query_params = array()) |
|
| 1088 | - { |
|
| 1089 | - return $this->sum_related('Ticket', $query_params, 'TKT_qty'); |
|
| 1090 | - } |
|
| 1091 | - |
|
| 1092 | - |
|
| 1093 | - /** |
|
| 1094 | - * Returns the lesser-of-the two: spaces remaining at this datetime, or |
|
| 1095 | - * the total tickets remaining (a sum of the tickets remaining for each ticket type |
|
| 1096 | - * that is available for this datetime). |
|
| 1097 | - * |
|
| 1098 | - * @return int |
|
| 1099 | - * @throws ReflectionException |
|
| 1100 | - * @throws InvalidArgumentException |
|
| 1101 | - * @throws InvalidInterfaceException |
|
| 1102 | - * @throws InvalidDataTypeException |
|
| 1103 | - * @throws EE_Error |
|
| 1104 | - */ |
|
| 1105 | - public function total_tickets_available_at_this_datetime() |
|
| 1106 | - { |
|
| 1107 | - return $this->spaces_remaining(true); |
|
| 1108 | - } |
|
| 1109 | - |
|
| 1110 | - |
|
| 1111 | - /** |
|
| 1112 | - * This simply compares the internal dtt for the given string with NOW |
|
| 1113 | - * and determines if the date is upcoming or not. |
|
| 1114 | - * |
|
| 1115 | - * @access public |
|
| 1116 | - * @return boolean |
|
| 1117 | - * @throws ReflectionException |
|
| 1118 | - * @throws InvalidArgumentException |
|
| 1119 | - * @throws InvalidInterfaceException |
|
| 1120 | - * @throws InvalidDataTypeException |
|
| 1121 | - * @throws EE_Error |
|
| 1122 | - */ |
|
| 1123 | - public function is_upcoming() |
|
| 1124 | - { |
|
| 1125 | - return ($this->get_raw('DTT_EVT_start') > time()); |
|
| 1126 | - } |
|
| 1127 | - |
|
| 1128 | - |
|
| 1129 | - /** |
|
| 1130 | - * This simply compares the internal datetime for the given string with NOW |
|
| 1131 | - * and returns if the date is active (i.e. start and end time) |
|
| 1132 | - * |
|
| 1133 | - * @return boolean |
|
| 1134 | - * @throws ReflectionException |
|
| 1135 | - * @throws InvalidArgumentException |
|
| 1136 | - * @throws InvalidInterfaceException |
|
| 1137 | - * @throws InvalidDataTypeException |
|
| 1138 | - * @throws EE_Error |
|
| 1139 | - */ |
|
| 1140 | - public function is_active() |
|
| 1141 | - { |
|
| 1142 | - return ($this->get_raw('DTT_EVT_start') < time() && $this->get_raw('DTT_EVT_end') > time()); |
|
| 1143 | - } |
|
| 1144 | - |
|
| 1145 | - |
|
| 1146 | - /** |
|
| 1147 | - * This simply compares the internal dtt for the given string with NOW |
|
| 1148 | - * and determines if the date is expired or not. |
|
| 1149 | - * |
|
| 1150 | - * @return boolean |
|
| 1151 | - * @throws ReflectionException |
|
| 1152 | - * @throws InvalidArgumentException |
|
| 1153 | - * @throws InvalidInterfaceException |
|
| 1154 | - * @throws InvalidDataTypeException |
|
| 1155 | - * @throws EE_Error |
|
| 1156 | - */ |
|
| 1157 | - public function is_expired() |
|
| 1158 | - { |
|
| 1159 | - return ($this->get_raw('DTT_EVT_end') < time()); |
|
| 1160 | - } |
|
| 1161 | - |
|
| 1162 | - |
|
| 1163 | - /** |
|
| 1164 | - * This returns the active status for whether an event is active, upcoming, or expired |
|
| 1165 | - * |
|
| 1166 | - * @return int return value will be one of the EE_Datetime status constants. |
|
| 1167 | - * @throws ReflectionException |
|
| 1168 | - * @throws InvalidArgumentException |
|
| 1169 | - * @throws InvalidInterfaceException |
|
| 1170 | - * @throws InvalidDataTypeException |
|
| 1171 | - * @throws EE_Error |
|
| 1172 | - */ |
|
| 1173 | - public function get_active_status() |
|
| 1174 | - { |
|
| 1175 | - $total_tickets_for_this_dtt = $this->total_tickets_available_at_this_datetime(); |
|
| 1176 | - if ($total_tickets_for_this_dtt !== false && $total_tickets_for_this_dtt < 1) { |
|
| 1177 | - return EE_Datetime::sold_out; |
|
| 1178 | - } |
|
| 1179 | - if ($this->is_expired()) { |
|
| 1180 | - return EE_Datetime::expired; |
|
| 1181 | - } |
|
| 1182 | - if ($this->is_upcoming()) { |
|
| 1183 | - return EE_Datetime::upcoming; |
|
| 1184 | - } |
|
| 1185 | - if ($this->is_active()) { |
|
| 1186 | - return EE_Datetime::active; |
|
| 1187 | - } |
|
| 1188 | - return null; |
|
| 1189 | - } |
|
| 1190 | - |
|
| 1191 | - |
|
| 1192 | - /** |
|
| 1193 | - * This returns a nice display name for the datetime that is contingent on the span between the dates and times. |
|
| 1194 | - * |
|
| 1195 | - * @param boolean $use_dtt_name if TRUE then we'll use DTT->name() if its not empty. |
|
| 1196 | - * @return string |
|
| 1197 | - * @throws ReflectionException |
|
| 1198 | - * @throws InvalidArgumentException |
|
| 1199 | - * @throws InvalidInterfaceException |
|
| 1200 | - * @throws InvalidDataTypeException |
|
| 1201 | - * @throws EE_Error |
|
| 1202 | - */ |
|
| 1203 | - public function get_dtt_display_name($use_dtt_name = false) |
|
| 1204 | - { |
|
| 1205 | - if ($use_dtt_name) { |
|
| 1206 | - $dtt_name = $this->name(); |
|
| 1207 | - if (! empty($dtt_name)) { |
|
| 1208 | - return $dtt_name; |
|
| 1209 | - } |
|
| 1210 | - } |
|
| 1211 | - // first condition is to see if the months are different |
|
| 1212 | - if ( |
|
| 1213 | - date('m', $this->get_raw('DTT_EVT_start')) !== date('m', $this->get_raw('DTT_EVT_end')) |
|
| 1214 | - ) { |
|
| 1215 | - $display_date = $this->start_date('M j\, Y g:i a') . ' - ' . $this->end_date('M j\, Y g:i a'); |
|
| 1216 | - // next condition is if its the same month but different day |
|
| 1217 | - } else { |
|
| 1218 | - if ( |
|
| 1219 | - date('m', $this->get_raw('DTT_EVT_start')) === date('m', $this->get_raw('DTT_EVT_end')) |
|
| 1220 | - && date('d', $this->get_raw('DTT_EVT_start')) !== date('d', $this->get_raw('DTT_EVT_end')) |
|
| 1221 | - ) { |
|
| 1222 | - $display_date = $this->start_date('M j\, g:i a') . ' - ' . $this->end_date('M j\, g:i a Y'); |
|
| 1223 | - } else { |
|
| 1224 | - $display_date = $this->start_date('F j\, Y') |
|
| 1225 | - . ' @ ' |
|
| 1226 | - . $this->start_date('g:i a') |
|
| 1227 | - . ' - ' |
|
| 1228 | - . $this->end_date('g:i a'); |
|
| 1229 | - } |
|
| 1230 | - } |
|
| 1231 | - return $display_date; |
|
| 1232 | - } |
|
| 1233 | - |
|
| 1234 | - |
|
| 1235 | - /** |
|
| 1236 | - * Gets all the tickets for this datetime |
|
| 1237 | - * |
|
| 1238 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1239 | - * @return EE_Base_Class[]|EE_Ticket[] |
|
| 1240 | - * @throws ReflectionException |
|
| 1241 | - * @throws InvalidArgumentException |
|
| 1242 | - * @throws InvalidInterfaceException |
|
| 1243 | - * @throws InvalidDataTypeException |
|
| 1244 | - * @throws EE_Error |
|
| 1245 | - */ |
|
| 1246 | - public function tickets($query_params = array()) |
|
| 1247 | - { |
|
| 1248 | - return $this->get_many_related('Ticket', $query_params); |
|
| 1249 | - } |
|
| 1250 | - |
|
| 1251 | - |
|
| 1252 | - /** |
|
| 1253 | - * Gets all the ticket types currently available for purchase |
|
| 1254 | - * |
|
| 1255 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1256 | - * @return EE_Ticket[] |
|
| 1257 | - * @throws ReflectionException |
|
| 1258 | - * @throws InvalidArgumentException |
|
| 1259 | - * @throws InvalidInterfaceException |
|
| 1260 | - * @throws InvalidDataTypeException |
|
| 1261 | - * @throws EE_Error |
|
| 1262 | - */ |
|
| 1263 | - public function ticket_types_available_for_purchase($query_params = array()) |
|
| 1264 | - { |
|
| 1265 | - // first check if datetime is valid |
|
| 1266 | - if ($this->sold_out() || ! ($this->is_upcoming() || $this->is_active())) { |
|
| 1267 | - return array(); |
|
| 1268 | - } |
|
| 1269 | - if (empty($query_params)) { |
|
| 1270 | - $query_params = array( |
|
| 1271 | - array( |
|
| 1272 | - 'TKT_start_date' => array('<=', EEM_Ticket::instance()->current_time_for_query('TKT_start_date')), |
|
| 1273 | - 'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')), |
|
| 1274 | - 'TKT_deleted' => false, |
|
| 1275 | - ), |
|
| 1276 | - ); |
|
| 1277 | - } |
|
| 1278 | - return $this->tickets($query_params); |
|
| 1279 | - } |
|
| 1280 | - |
|
| 1281 | - |
|
| 1282 | - /** |
|
| 1283 | - * @return EE_Base_Class|EE_Event |
|
| 1284 | - * @throws ReflectionException |
|
| 1285 | - * @throws InvalidArgumentException |
|
| 1286 | - * @throws InvalidInterfaceException |
|
| 1287 | - * @throws InvalidDataTypeException |
|
| 1288 | - * @throws EE_Error |
|
| 1289 | - */ |
|
| 1290 | - public function event() |
|
| 1291 | - { |
|
| 1292 | - return $this->get_first_related('Event'); |
|
| 1293 | - } |
|
| 1294 | - |
|
| 1295 | - |
|
| 1296 | - /** |
|
| 1297 | - * Updates the DTT_sold attribute (and saves) based on the number of registrations for this datetime |
|
| 1298 | - * (via the tickets). |
|
| 1299 | - * |
|
| 1300 | - * @return int |
|
| 1301 | - * @throws ReflectionException |
|
| 1302 | - * @throws InvalidArgumentException |
|
| 1303 | - * @throws InvalidInterfaceException |
|
| 1304 | - * @throws InvalidDataTypeException |
|
| 1305 | - * @throws EE_Error |
|
| 1306 | - */ |
|
| 1307 | - public function update_sold() |
|
| 1308 | - { |
|
| 1309 | - $count_regs_for_this_datetime = EEM_Registration::instance()->count( |
|
| 1310 | - array( |
|
| 1311 | - array( |
|
| 1312 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1313 | - 'REG_deleted' => 0, |
|
| 1314 | - 'Ticket.Datetime.DTT_ID' => $this->ID(), |
|
| 1315 | - ), |
|
| 1316 | - ) |
|
| 1317 | - ); |
|
| 1318 | - $this->set_sold($count_regs_for_this_datetime); |
|
| 1319 | - $this->save(); |
|
| 1320 | - return $count_regs_for_this_datetime; |
|
| 1321 | - } |
|
| 1322 | - |
|
| 1323 | - |
|
| 1324 | - /******************************************************************* |
|
| 16 | + /** |
|
| 17 | + * constant used by get_active_status, indicates datetime has no more available spaces |
|
| 18 | + */ |
|
| 19 | + const sold_out = 'DTS'; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * constant used by get_active_status, indicating datetime is still active (even is not over, can be registered-for) |
|
| 23 | + */ |
|
| 24 | + const active = 'DTA'; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * constant used by get_active_status, indicating the datetime cannot be used for registrations yet, but has not |
|
| 28 | + * expired |
|
| 29 | + */ |
|
| 30 | + const upcoming = 'DTU'; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Datetime is postponed |
|
| 34 | + */ |
|
| 35 | + const postponed = 'DTP'; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Datetime is cancelled |
|
| 39 | + */ |
|
| 40 | + const cancelled = 'DTC'; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * constant used by get_active_status, indicates datetime has expired (event is over) |
|
| 44 | + */ |
|
| 45 | + const expired = 'DTE'; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * constant used in various places indicating that an event is INACTIVE (not yet ready to be published) |
|
| 49 | + */ |
|
| 50 | + const inactive = 'DTI'; |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @param array $props_n_values incoming values |
|
| 55 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be used.) |
|
| 56 | + * @param array $date_formats incoming date_formats in an array where the first value is the date_format |
|
| 57 | + * and the second value is the time format |
|
| 58 | + * @return EE_Datetime |
|
| 59 | + * @throws ReflectionException |
|
| 60 | + * @throws InvalidArgumentException |
|
| 61 | + * @throws InvalidInterfaceException |
|
| 62 | + * @throws InvalidDataTypeException |
|
| 63 | + * @throws EE_Error |
|
| 64 | + */ |
|
| 65 | + public static function new_instance($props_n_values = array(), $timezone = '', $date_formats = array()) |
|
| 66 | + { |
|
| 67 | + $has_object = parent::_check_for_object( |
|
| 68 | + $props_n_values, |
|
| 69 | + __CLASS__, |
|
| 70 | + $timezone, |
|
| 71 | + $date_formats |
|
| 72 | + ); |
|
| 73 | + return $has_object |
|
| 74 | + ? $has_object |
|
| 75 | + : new self($props_n_values, false, $timezone, $date_formats); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @param array $props_n_values incoming values from the database |
|
| 81 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 82 | + * the website will be used. |
|
| 83 | + * @return EE_Datetime |
|
| 84 | + * @throws ReflectionException |
|
| 85 | + * @throws InvalidArgumentException |
|
| 86 | + * @throws InvalidInterfaceException |
|
| 87 | + * @throws InvalidDataTypeException |
|
| 88 | + * @throws EE_Error |
|
| 89 | + */ |
|
| 90 | + public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
| 91 | + { |
|
| 92 | + return new self($props_n_values, true, $timezone); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @param $name |
|
| 98 | + * @throws ReflectionException |
|
| 99 | + * @throws InvalidArgumentException |
|
| 100 | + * @throws InvalidInterfaceException |
|
| 101 | + * @throws InvalidDataTypeException |
|
| 102 | + * @throws EE_Error |
|
| 103 | + */ |
|
| 104 | + public function set_name($name) |
|
| 105 | + { |
|
| 106 | + $this->set('DTT_name', $name); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * @param $description |
|
| 112 | + * @throws ReflectionException |
|
| 113 | + * @throws InvalidArgumentException |
|
| 114 | + * @throws InvalidInterfaceException |
|
| 115 | + * @throws InvalidDataTypeException |
|
| 116 | + * @throws EE_Error |
|
| 117 | + */ |
|
| 118 | + public function set_description($description) |
|
| 119 | + { |
|
| 120 | + $this->set('DTT_description', $description); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Set event start date |
|
| 126 | + * set the start date for an event |
|
| 127 | + * |
|
| 128 | + * @param string $date a string representation of the event's date ex: Dec. 25, 2025 or 12-25-2025 |
|
| 129 | + * @throws ReflectionException |
|
| 130 | + * @throws InvalidArgumentException |
|
| 131 | + * @throws InvalidInterfaceException |
|
| 132 | + * @throws InvalidDataTypeException |
|
| 133 | + * @throws EE_Error |
|
| 134 | + */ |
|
| 135 | + public function set_start_date($date) |
|
| 136 | + { |
|
| 137 | + $this->_set_date_for($date, 'DTT_EVT_start'); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Set event start time |
|
| 143 | + * set the start time for an event |
|
| 144 | + * |
|
| 145 | + * @param string $time a string representation of the event time ex: 9am or 7:30 PM |
|
| 146 | + * @throws ReflectionException |
|
| 147 | + * @throws InvalidArgumentException |
|
| 148 | + * @throws InvalidInterfaceException |
|
| 149 | + * @throws InvalidDataTypeException |
|
| 150 | + * @throws EE_Error |
|
| 151 | + */ |
|
| 152 | + public function set_start_time($time) |
|
| 153 | + { |
|
| 154 | + $this->_set_time_for($time, 'DTT_EVT_start'); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Set event end date |
|
| 160 | + * set the end date for an event |
|
| 161 | + * |
|
| 162 | + * @param string $date a string representation of the event's date ex: Dec. 25, 2025 or 12-25-2025 |
|
| 163 | + * @throws ReflectionException |
|
| 164 | + * @throws InvalidArgumentException |
|
| 165 | + * @throws InvalidInterfaceException |
|
| 166 | + * @throws InvalidDataTypeException |
|
| 167 | + * @throws EE_Error |
|
| 168 | + */ |
|
| 169 | + public function set_end_date($date) |
|
| 170 | + { |
|
| 171 | + $this->_set_date_for($date, 'DTT_EVT_end'); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Set event end time |
|
| 177 | + * set the end time for an event |
|
| 178 | + * |
|
| 179 | + * @param string $time a string representation of the event time ex: 9am or 7:30 PM |
|
| 180 | + * @throws ReflectionException |
|
| 181 | + * @throws InvalidArgumentException |
|
| 182 | + * @throws InvalidInterfaceException |
|
| 183 | + * @throws InvalidDataTypeException |
|
| 184 | + * @throws EE_Error |
|
| 185 | + */ |
|
| 186 | + public function set_end_time($time) |
|
| 187 | + { |
|
| 188 | + $this->_set_time_for($time, 'DTT_EVT_end'); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * Set registration limit |
|
| 194 | + * set the maximum number of attendees that can be registered for this datetime slot |
|
| 195 | + * |
|
| 196 | + * @param int $reg_limit |
|
| 197 | + * @throws ReflectionException |
|
| 198 | + * @throws InvalidArgumentException |
|
| 199 | + * @throws InvalidInterfaceException |
|
| 200 | + * @throws InvalidDataTypeException |
|
| 201 | + * @throws EE_Error |
|
| 202 | + */ |
|
| 203 | + public function set_reg_limit($reg_limit) |
|
| 204 | + { |
|
| 205 | + $this->set('DTT_reg_limit', $reg_limit); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * get the number of tickets sold for this datetime slot |
|
| 211 | + * |
|
| 212 | + * @return mixed int on success, FALSE on fail |
|
| 213 | + * @throws ReflectionException |
|
| 214 | + * @throws InvalidArgumentException |
|
| 215 | + * @throws InvalidInterfaceException |
|
| 216 | + * @throws InvalidDataTypeException |
|
| 217 | + * @throws EE_Error |
|
| 218 | + */ |
|
| 219 | + public function sold() |
|
| 220 | + { |
|
| 221 | + return $this->get_raw('DTT_sold'); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * @param int $sold |
|
| 227 | + * @throws ReflectionException |
|
| 228 | + * @throws InvalidArgumentException |
|
| 229 | + * @throws InvalidInterfaceException |
|
| 230 | + * @throws InvalidDataTypeException |
|
| 231 | + * @throws EE_Error |
|
| 232 | + */ |
|
| 233 | + public function set_sold($sold) |
|
| 234 | + { |
|
| 235 | + // sold can not go below zero |
|
| 236 | + $sold = max(0, $sold); |
|
| 237 | + $this->set('DTT_sold', $sold); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * Increments sold by amount passed by $qty, and persists it immediately to the database. |
|
| 243 | + * Simultaneously decreases the reserved count, unless $also_decrease_reserved is false. |
|
| 244 | + * |
|
| 245 | + * @param int $qty |
|
| 246 | + * @param boolean $also_decrease_reserved |
|
| 247 | + * @return boolean indicating success |
|
| 248 | + * @throws ReflectionException |
|
| 249 | + * @throws InvalidArgumentException |
|
| 250 | + * @throws InvalidInterfaceException |
|
| 251 | + * @throws InvalidDataTypeException |
|
| 252 | + * @throws EE_Error |
|
| 253 | + */ |
|
| 254 | + public function increaseSold($qty = 1, $also_decrease_reserved = true) |
|
| 255 | + { |
|
| 256 | + $qty = absint($qty); |
|
| 257 | + if ($also_decrease_reserved) { |
|
| 258 | + $success = $this->adjustNumericFieldsInDb( |
|
| 259 | + [ |
|
| 260 | + 'DTT_reserved' => $qty * -1, |
|
| 261 | + 'DTT_sold' => $qty |
|
| 262 | + ] |
|
| 263 | + ); |
|
| 264 | + } else { |
|
| 265 | + $success = $this->adjustNumericFieldsInDb( |
|
| 266 | + [ |
|
| 267 | + 'DTT_sold' => $qty |
|
| 268 | + ] |
|
| 269 | + ); |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + do_action( |
|
| 273 | + 'AHEE__EE_Datetime__increase_sold', |
|
| 274 | + $this, |
|
| 275 | + $qty, |
|
| 276 | + $this->sold(), |
|
| 277 | + $success |
|
| 278 | + ); |
|
| 279 | + return $success; |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * Decrements (subtracts) sold amount passed by $qty directly in the DB and on the model object. (Ie, no need |
|
| 285 | + * to save afterwards.) |
|
| 286 | + * |
|
| 287 | + * @param int $qty |
|
| 288 | + * @return boolean indicating success |
|
| 289 | + * @throws ReflectionException |
|
| 290 | + * @throws InvalidArgumentException |
|
| 291 | + * @throws InvalidInterfaceException |
|
| 292 | + * @throws InvalidDataTypeException |
|
| 293 | + * @throws EE_Error |
|
| 294 | + */ |
|
| 295 | + public function decreaseSold($qty = 1) |
|
| 296 | + { |
|
| 297 | + $qty = absint($qty); |
|
| 298 | + $success = $this->adjustNumericFieldsInDb( |
|
| 299 | + [ |
|
| 300 | + 'DTT_sold' => $qty * -1 |
|
| 301 | + ] |
|
| 302 | + ); |
|
| 303 | + do_action( |
|
| 304 | + 'AHEE__EE_Datetime__decrease_sold', |
|
| 305 | + $this, |
|
| 306 | + $qty, |
|
| 307 | + $this->sold(), |
|
| 308 | + $success |
|
| 309 | + ); |
|
| 310 | + return $success; |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + |
|
| 314 | + /** |
|
| 315 | + * Gets qty of reserved tickets for this datetime |
|
| 316 | + * |
|
| 317 | + * @return int |
|
| 318 | + * @throws ReflectionException |
|
| 319 | + * @throws InvalidArgumentException |
|
| 320 | + * @throws InvalidInterfaceException |
|
| 321 | + * @throws InvalidDataTypeException |
|
| 322 | + * @throws EE_Error |
|
| 323 | + */ |
|
| 324 | + public function reserved() |
|
| 325 | + { |
|
| 326 | + return $this->get_raw('DTT_reserved'); |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * Sets qty of reserved tickets for this datetime |
|
| 332 | + * |
|
| 333 | + * @param int $reserved |
|
| 334 | + * @throws ReflectionException |
|
| 335 | + * @throws InvalidArgumentException |
|
| 336 | + * @throws InvalidInterfaceException |
|
| 337 | + * @throws InvalidDataTypeException |
|
| 338 | + * @throws EE_Error |
|
| 339 | + */ |
|
| 340 | + public function set_reserved($reserved) |
|
| 341 | + { |
|
| 342 | + // reserved can not go below zero |
|
| 343 | + $reserved = max(0, (int) $reserved); |
|
| 344 | + $this->set('DTT_reserved', $reserved); |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + |
|
| 348 | + /** |
|
| 349 | + * Increments reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 350 | + * |
|
| 351 | + * @param int $qty |
|
| 352 | + * @return boolean indicating success |
|
| 353 | + * @throws ReflectionException |
|
| 354 | + * @throws InvalidArgumentException |
|
| 355 | + * @throws InvalidInterfaceException |
|
| 356 | + * @throws InvalidDataTypeException |
|
| 357 | + * @throws EE_Error |
|
| 358 | + */ |
|
| 359 | + public function increaseReserved($qty = 1) |
|
| 360 | + { |
|
| 361 | + $qty = absint($qty); |
|
| 362 | + $success = $this->incrementFieldConditionallyInDb( |
|
| 363 | + 'DTT_reserved', |
|
| 364 | + 'DTT_sold', |
|
| 365 | + 'DTT_reg_limit', |
|
| 366 | + $qty |
|
| 367 | + ); |
|
| 368 | + do_action( |
|
| 369 | + 'AHEE__EE_Datetime__increase_reserved', |
|
| 370 | + $this, |
|
| 371 | + $qty, |
|
| 372 | + $this->reserved(), |
|
| 373 | + $success |
|
| 374 | + ); |
|
| 375 | + return $success; |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + |
|
| 379 | + /** |
|
| 380 | + * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 381 | + * |
|
| 382 | + * @param int $qty |
|
| 383 | + * @return boolean indicating success |
|
| 384 | + * @throws ReflectionException |
|
| 385 | + * @throws InvalidArgumentException |
|
| 386 | + * @throws InvalidInterfaceException |
|
| 387 | + * @throws InvalidDataTypeException |
|
| 388 | + * @throws EE_Error |
|
| 389 | + */ |
|
| 390 | + public function decreaseReserved($qty = 1) |
|
| 391 | + { |
|
| 392 | + $qty = absint($qty); |
|
| 393 | + $success = $this->adjustNumericFieldsInDb( |
|
| 394 | + [ |
|
| 395 | + 'DTT_reserved' => $qty * -1 |
|
| 396 | + ] |
|
| 397 | + ); |
|
| 398 | + do_action( |
|
| 399 | + 'AHEE__EE_Datetime__decrease_reserved', |
|
| 400 | + $this, |
|
| 401 | + $qty, |
|
| 402 | + $this->reserved(), |
|
| 403 | + $success |
|
| 404 | + ); |
|
| 405 | + return $success; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * total sold and reserved tickets |
|
| 411 | + * |
|
| 412 | + * @return int |
|
| 413 | + * @throws ReflectionException |
|
| 414 | + * @throws InvalidArgumentException |
|
| 415 | + * @throws InvalidInterfaceException |
|
| 416 | + * @throws InvalidDataTypeException |
|
| 417 | + * @throws EE_Error |
|
| 418 | + */ |
|
| 419 | + public function sold_and_reserved() |
|
| 420 | + { |
|
| 421 | + return $this->sold() + $this->reserved(); |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + |
|
| 425 | + /** |
|
| 426 | + * returns the datetime name |
|
| 427 | + * |
|
| 428 | + * @return string |
|
| 429 | + * @throws ReflectionException |
|
| 430 | + * @throws InvalidArgumentException |
|
| 431 | + * @throws InvalidInterfaceException |
|
| 432 | + * @throws InvalidDataTypeException |
|
| 433 | + * @throws EE_Error |
|
| 434 | + */ |
|
| 435 | + public function name() |
|
| 436 | + { |
|
| 437 | + return $this->get('DTT_name'); |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + |
|
| 441 | + /** |
|
| 442 | + * returns the datetime description |
|
| 443 | + * |
|
| 444 | + * @return string |
|
| 445 | + * @throws ReflectionException |
|
| 446 | + * @throws InvalidArgumentException |
|
| 447 | + * @throws InvalidInterfaceException |
|
| 448 | + * @throws InvalidDataTypeException |
|
| 449 | + * @throws EE_Error |
|
| 450 | + */ |
|
| 451 | + public function description() |
|
| 452 | + { |
|
| 453 | + return $this->get('DTT_description'); |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + |
|
| 457 | + /** |
|
| 458 | + * This helper simply returns whether the event_datetime for the current datetime is a primary datetime |
|
| 459 | + * |
|
| 460 | + * @return boolean TRUE if is primary, FALSE if not. |
|
| 461 | + * @throws ReflectionException |
|
| 462 | + * @throws InvalidArgumentException |
|
| 463 | + * @throws InvalidInterfaceException |
|
| 464 | + * @throws InvalidDataTypeException |
|
| 465 | + * @throws EE_Error |
|
| 466 | + */ |
|
| 467 | + public function is_primary() |
|
| 468 | + { |
|
| 469 | + return $this->get('DTT_is_primary'); |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + |
|
| 473 | + /** |
|
| 474 | + * This helper simply returns the order for the datetime |
|
| 475 | + * |
|
| 476 | + * @return int The order of the datetime for this event. |
|
| 477 | + * @throws ReflectionException |
|
| 478 | + * @throws InvalidArgumentException |
|
| 479 | + * @throws InvalidInterfaceException |
|
| 480 | + * @throws InvalidDataTypeException |
|
| 481 | + * @throws EE_Error |
|
| 482 | + */ |
|
| 483 | + public function order() |
|
| 484 | + { |
|
| 485 | + return $this->get('DTT_order'); |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + |
|
| 489 | + /** |
|
| 490 | + * This helper simply returns the parent id for the datetime |
|
| 491 | + * |
|
| 492 | + * @return int |
|
| 493 | + * @throws ReflectionException |
|
| 494 | + * @throws InvalidArgumentException |
|
| 495 | + * @throws InvalidInterfaceException |
|
| 496 | + * @throws InvalidDataTypeException |
|
| 497 | + * @throws EE_Error |
|
| 498 | + */ |
|
| 499 | + public function parent() |
|
| 500 | + { |
|
| 501 | + return $this->get('DTT_parent'); |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + |
|
| 505 | + /** |
|
| 506 | + * show date and/or time |
|
| 507 | + * |
|
| 508 | + * @param string $date_or_time whether to display a date or time or both |
|
| 509 | + * @param string $start_or_end whether to display start or end datetimes |
|
| 510 | + * @param string $dt_frmt |
|
| 511 | + * @param string $tm_frmt |
|
| 512 | + * @param bool $echo whether we echo or return (note echoing uses "pretty" formats, |
|
| 513 | + * otherwise we use the standard formats) |
|
| 514 | + * @return string|bool string on success, FALSE on fail |
|
| 515 | + * @throws ReflectionException |
|
| 516 | + * @throws InvalidArgumentException |
|
| 517 | + * @throws InvalidInterfaceException |
|
| 518 | + * @throws InvalidDataTypeException |
|
| 519 | + * @throws EE_Error |
|
| 520 | + */ |
|
| 521 | + private function _show_datetime( |
|
| 522 | + $date_or_time = null, |
|
| 523 | + $start_or_end = 'start', |
|
| 524 | + $dt_frmt = '', |
|
| 525 | + $tm_frmt = '', |
|
| 526 | + $echo = false |
|
| 527 | + ) { |
|
| 528 | + $field_name = "DTT_EVT_{$start_or_end}"; |
|
| 529 | + $dtt = $this->_get_datetime( |
|
| 530 | + $field_name, |
|
| 531 | + $dt_frmt, |
|
| 532 | + $tm_frmt, |
|
| 533 | + $date_or_time, |
|
| 534 | + $echo |
|
| 535 | + ); |
|
| 536 | + if (! $echo) { |
|
| 537 | + return $dtt; |
|
| 538 | + } |
|
| 539 | + return ''; |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + |
|
| 543 | + /** |
|
| 544 | + * get event start date. Provide either the date format, or NULL to re-use the |
|
| 545 | + * last-used format, or '' to use the default date format |
|
| 546 | + * |
|
| 547 | + * @param string $dt_frmt string representation of date format defaults to 'F j, Y' |
|
| 548 | + * @return mixed string on success, FALSE on fail |
|
| 549 | + * @throws ReflectionException |
|
| 550 | + * @throws InvalidArgumentException |
|
| 551 | + * @throws InvalidInterfaceException |
|
| 552 | + * @throws InvalidDataTypeException |
|
| 553 | + * @throws EE_Error |
|
| 554 | + */ |
|
| 555 | + public function start_date($dt_frmt = '') |
|
| 556 | + { |
|
| 557 | + return $this->_show_datetime('D', 'start', $dt_frmt); |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + |
|
| 561 | + /** |
|
| 562 | + * Echoes start_date() |
|
| 563 | + * |
|
| 564 | + * @param string $dt_frmt |
|
| 565 | + * @throws ReflectionException |
|
| 566 | + * @throws InvalidArgumentException |
|
| 567 | + * @throws InvalidInterfaceException |
|
| 568 | + * @throws InvalidDataTypeException |
|
| 569 | + * @throws EE_Error |
|
| 570 | + */ |
|
| 571 | + public function e_start_date($dt_frmt = '') |
|
| 572 | + { |
|
| 573 | + $this->_show_datetime('D', 'start', $dt_frmt, null, true); |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * get end date. Provide either the date format, or NULL to re-use the |
|
| 579 | + * last-used format, or '' to use the default date format |
|
| 580 | + * |
|
| 581 | + * @param string $dt_frmt string representation of date format defaults to 'F j, Y' |
|
| 582 | + * @return mixed string on success, FALSE on fail |
|
| 583 | + * @throws ReflectionException |
|
| 584 | + * @throws InvalidArgumentException |
|
| 585 | + * @throws InvalidInterfaceException |
|
| 586 | + * @throws InvalidDataTypeException |
|
| 587 | + * @throws EE_Error |
|
| 588 | + */ |
|
| 589 | + public function end_date($dt_frmt = '') |
|
| 590 | + { |
|
| 591 | + return $this->_show_datetime('D', 'end', $dt_frmt); |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + |
|
| 595 | + /** |
|
| 596 | + * Echoes the end date. See end_date() |
|
| 597 | + * |
|
| 598 | + * @param string $dt_frmt |
|
| 599 | + * @throws ReflectionException |
|
| 600 | + * @throws InvalidArgumentException |
|
| 601 | + * @throws InvalidInterfaceException |
|
| 602 | + * @throws InvalidDataTypeException |
|
| 603 | + * @throws EE_Error |
|
| 604 | + */ |
|
| 605 | + public function e_end_date($dt_frmt = '') |
|
| 606 | + { |
|
| 607 | + $this->_show_datetime('D', 'end', $dt_frmt, null, true); |
|
| 608 | + } |
|
| 609 | + |
|
| 610 | + |
|
| 611 | + /** |
|
| 612 | + * get date_range - meaning the start AND end date |
|
| 613 | + * |
|
| 614 | + * @access public |
|
| 615 | + * @param string $dt_frmt string representation of date format defaults to WP settings |
|
| 616 | + * @param string $conjunction conjunction junction what's your function ? |
|
| 617 | + * this string joins the start date with the end date ie: Jan 01 "to" Dec 31 |
|
| 618 | + * @return mixed string on success, FALSE on fail |
|
| 619 | + * @throws ReflectionException |
|
| 620 | + * @throws InvalidArgumentException |
|
| 621 | + * @throws InvalidInterfaceException |
|
| 622 | + * @throws InvalidDataTypeException |
|
| 623 | + * @throws EE_Error |
|
| 624 | + */ |
|
| 625 | + public function date_range($dt_frmt = '', $conjunction = ' - ') |
|
| 626 | + { |
|
| 627 | + $dt_frmt = ! empty($dt_frmt) ? $dt_frmt : $this->_dt_frmt; |
|
| 628 | + $start = str_replace( |
|
| 629 | + ' ', |
|
| 630 | + ' ', |
|
| 631 | + $this->get_i18n_datetime('DTT_EVT_start', $dt_frmt) |
|
| 632 | + ); |
|
| 633 | + $end = str_replace( |
|
| 634 | + ' ', |
|
| 635 | + ' ', |
|
| 636 | + $this->get_i18n_datetime('DTT_EVT_end', $dt_frmt) |
|
| 637 | + ); |
|
| 638 | + return $start !== $end ? $start . $conjunction . $end : $start; |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + |
|
| 642 | + /** |
|
| 643 | + * @param string $dt_frmt |
|
| 644 | + * @param string $conjunction |
|
| 645 | + * @throws ReflectionException |
|
| 646 | + * @throws InvalidArgumentException |
|
| 647 | + * @throws InvalidInterfaceException |
|
| 648 | + * @throws InvalidDataTypeException |
|
| 649 | + * @throws EE_Error |
|
| 650 | + */ |
|
| 651 | + public function e_date_range($dt_frmt = '', $conjunction = ' - ') |
|
| 652 | + { |
|
| 653 | + echo $this->date_range($dt_frmt, $conjunction); |
|
| 654 | + } |
|
| 655 | + |
|
| 656 | + |
|
| 657 | + /** |
|
| 658 | + * get start time |
|
| 659 | + * |
|
| 660 | + * @param string $tm_format - string representation of time format defaults to 'g:i a' |
|
| 661 | + * @return mixed string on success, FALSE on fail |
|
| 662 | + * @throws ReflectionException |
|
| 663 | + * @throws InvalidArgumentException |
|
| 664 | + * @throws InvalidInterfaceException |
|
| 665 | + * @throws InvalidDataTypeException |
|
| 666 | + * @throws EE_Error |
|
| 667 | + */ |
|
| 668 | + public function start_time($tm_format = '') |
|
| 669 | + { |
|
| 670 | + return $this->_show_datetime('T', 'start', null, $tm_format); |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + |
|
| 674 | + /** |
|
| 675 | + * @param string $tm_format |
|
| 676 | + * @throws ReflectionException |
|
| 677 | + * @throws InvalidArgumentException |
|
| 678 | + * @throws InvalidInterfaceException |
|
| 679 | + * @throws InvalidDataTypeException |
|
| 680 | + * @throws EE_Error |
|
| 681 | + */ |
|
| 682 | + public function e_start_time($tm_format = '') |
|
| 683 | + { |
|
| 684 | + $this->_show_datetime('T', 'start', null, $tm_format, true); |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + |
|
| 688 | + /** |
|
| 689 | + * get end time |
|
| 690 | + * |
|
| 691 | + * @param string $tm_format string representation of time format defaults to 'g:i a' |
|
| 692 | + * @return mixed string on success, FALSE on fail |
|
| 693 | + * @throws ReflectionException |
|
| 694 | + * @throws InvalidArgumentException |
|
| 695 | + * @throws InvalidInterfaceException |
|
| 696 | + * @throws InvalidDataTypeException |
|
| 697 | + * @throws EE_Error |
|
| 698 | + */ |
|
| 699 | + public function end_time($tm_format = '') |
|
| 700 | + { |
|
| 701 | + return $this->_show_datetime('T', 'end', null, $tm_format); |
|
| 702 | + } |
|
| 703 | + |
|
| 704 | + |
|
| 705 | + /** |
|
| 706 | + * @param string $tm_format |
|
| 707 | + * @throws ReflectionException |
|
| 708 | + * @throws InvalidArgumentException |
|
| 709 | + * @throws InvalidInterfaceException |
|
| 710 | + * @throws InvalidDataTypeException |
|
| 711 | + * @throws EE_Error |
|
| 712 | + */ |
|
| 713 | + public function e_end_time($tm_format = '') |
|
| 714 | + { |
|
| 715 | + $this->_show_datetime('T', 'end', null, $tm_format, true); |
|
| 716 | + } |
|
| 717 | + |
|
| 718 | + |
|
| 719 | + /** |
|
| 720 | + * get time_range |
|
| 721 | + * |
|
| 722 | + * @access public |
|
| 723 | + * @param string $tm_format string representation of time format defaults to 'g:i a' |
|
| 724 | + * @param string $conjunction conjunction junction what's your function ? |
|
| 725 | + * this string joins the start date with the end date ie: Jan 01 "to" Dec 31 |
|
| 726 | + * @return mixed string on success, FALSE on fail |
|
| 727 | + * @throws ReflectionException |
|
| 728 | + * @throws InvalidArgumentException |
|
| 729 | + * @throws InvalidInterfaceException |
|
| 730 | + * @throws InvalidDataTypeException |
|
| 731 | + * @throws EE_Error |
|
| 732 | + */ |
|
| 733 | + public function time_range($tm_format = '', $conjunction = ' - ') |
|
| 734 | + { |
|
| 735 | + $tm_format = ! empty($tm_format) ? $tm_format : $this->_tm_frmt; |
|
| 736 | + $start = str_replace( |
|
| 737 | + ' ', |
|
| 738 | + ' ', |
|
| 739 | + $this->get_i18n_datetime('DTT_EVT_start', $tm_format) |
|
| 740 | + ); |
|
| 741 | + $end = str_replace( |
|
| 742 | + ' ', |
|
| 743 | + ' ', |
|
| 744 | + $this->get_i18n_datetime('DTT_EVT_end', $tm_format) |
|
| 745 | + ); |
|
| 746 | + return $start !== $end ? $start . $conjunction . $end : $start; |
|
| 747 | + } |
|
| 748 | + |
|
| 749 | + |
|
| 750 | + /** |
|
| 751 | + * @param string $tm_format |
|
| 752 | + * @param string $conjunction |
|
| 753 | + * @throws ReflectionException |
|
| 754 | + * @throws InvalidArgumentException |
|
| 755 | + * @throws InvalidInterfaceException |
|
| 756 | + * @throws InvalidDataTypeException |
|
| 757 | + * @throws EE_Error |
|
| 758 | + */ |
|
| 759 | + public function e_time_range($tm_format = '', $conjunction = ' - ') |
|
| 760 | + { |
|
| 761 | + echo $this->time_range($tm_format, $conjunction); |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + |
|
| 765 | + /** |
|
| 766 | + * This returns a range representation of the date and times. |
|
| 767 | + * Output is dependent on the difference (or similarity) between DTT_EVT_start and DTT_EVT_end. |
|
| 768 | + * Also, the return value is localized. |
|
| 769 | + * |
|
| 770 | + * @param string $dt_format |
|
| 771 | + * @param string $tm_format |
|
| 772 | + * @param string $conjunction used between two different dates or times. |
|
| 773 | + * ex: Dec 1{$conjunction}}Dec 6, or 2pm{$conjunction}3pm |
|
| 774 | + * @param string $separator used between the date and time formats. |
|
| 775 | + * ex: Dec 1, 2016{$separator}2pm |
|
| 776 | + * @return string |
|
| 777 | + * @throws ReflectionException |
|
| 778 | + * @throws InvalidArgumentException |
|
| 779 | + * @throws InvalidInterfaceException |
|
| 780 | + * @throws InvalidDataTypeException |
|
| 781 | + * @throws EE_Error |
|
| 782 | + */ |
|
| 783 | + public function date_and_time_range( |
|
| 784 | + $dt_format = '', |
|
| 785 | + $tm_format = '', |
|
| 786 | + $conjunction = ' - ', |
|
| 787 | + $separator = ' ' |
|
| 788 | + ) { |
|
| 789 | + $dt_format = ! empty($dt_format) ? $dt_format : $this->_dt_frmt; |
|
| 790 | + $tm_format = ! empty($tm_format) ? $tm_format : $this->_tm_frmt; |
|
| 791 | + $full_format = $dt_format . $separator . $tm_format; |
|
| 792 | + // the range output depends on various conditions |
|
| 793 | + switch (true) { |
|
| 794 | + // start date timestamp and end date timestamp are the same. |
|
| 795 | + case ($this->get_raw('DTT_EVT_start') === $this->get_raw('DTT_EVT_end')): |
|
| 796 | + $output = $this->get_i18n_datetime('DTT_EVT_start', $full_format); |
|
| 797 | + break; |
|
| 798 | + // start and end date are the same but times are different |
|
| 799 | + case ($this->start_date() === $this->end_date()): |
|
| 800 | + $output = $this->get_i18n_datetime('DTT_EVT_start', $full_format) |
|
| 801 | + . $conjunction |
|
| 802 | + . $this->get_i18n_datetime('DTT_EVT_end', $tm_format); |
|
| 803 | + break; |
|
| 804 | + // all other conditions |
|
| 805 | + default: |
|
| 806 | + $output = $this->get_i18n_datetime('DTT_EVT_start', $full_format) |
|
| 807 | + . $conjunction |
|
| 808 | + . $this->get_i18n_datetime('DTT_EVT_end', $full_format); |
|
| 809 | + break; |
|
| 810 | + } |
|
| 811 | + return $output; |
|
| 812 | + } |
|
| 813 | + |
|
| 814 | + |
|
| 815 | + /** |
|
| 816 | + * This echos the results of date and time range. |
|
| 817 | + * |
|
| 818 | + * @see date_and_time_range() for more details on purpose. |
|
| 819 | + * @param string $dt_format |
|
| 820 | + * @param string $tm_format |
|
| 821 | + * @param string $conjunction |
|
| 822 | + * @return void |
|
| 823 | + * @throws ReflectionException |
|
| 824 | + * @throws InvalidArgumentException |
|
| 825 | + * @throws InvalidInterfaceException |
|
| 826 | + * @throws InvalidDataTypeException |
|
| 827 | + * @throws EE_Error |
|
| 828 | + */ |
|
| 829 | + public function e_date_and_time_range($dt_format = '', $tm_format = '', $conjunction = ' - ') |
|
| 830 | + { |
|
| 831 | + echo $this->date_and_time_range($dt_format, $tm_format, $conjunction); |
|
| 832 | + } |
|
| 833 | + |
|
| 834 | + |
|
| 835 | + /** |
|
| 836 | + * get start date and start time |
|
| 837 | + * |
|
| 838 | + * @param string $dt_format - string representation of date format defaults to 'F j, Y' |
|
| 839 | + * @param string $tm_format - string representation of time format defaults to 'g:i a' |
|
| 840 | + * @return mixed string on success, FALSE on fail |
|
| 841 | + * @throws ReflectionException |
|
| 842 | + * @throws InvalidArgumentException |
|
| 843 | + * @throws InvalidInterfaceException |
|
| 844 | + * @throws InvalidDataTypeException |
|
| 845 | + * @throws EE_Error |
|
| 846 | + */ |
|
| 847 | + public function start_date_and_time($dt_format = '', $tm_format = '') |
|
| 848 | + { |
|
| 849 | + return $this->_show_datetime('', 'start', $dt_format, $tm_format); |
|
| 850 | + } |
|
| 851 | + |
|
| 852 | + |
|
| 853 | + /** |
|
| 854 | + * @param string $dt_frmt |
|
| 855 | + * @param string $tm_format |
|
| 856 | + * @throws ReflectionException |
|
| 857 | + * @throws InvalidArgumentException |
|
| 858 | + * @throws InvalidInterfaceException |
|
| 859 | + * @throws InvalidDataTypeException |
|
| 860 | + * @throws EE_Error |
|
| 861 | + */ |
|
| 862 | + public function e_start_date_and_time($dt_frmt = '', $tm_format = '') |
|
| 863 | + { |
|
| 864 | + $this->_show_datetime('', 'start', $dt_frmt, $tm_format, true); |
|
| 865 | + } |
|
| 866 | + |
|
| 867 | + |
|
| 868 | + /** |
|
| 869 | + * Shows the length of the event (start to end time). |
|
| 870 | + * Can be shown in 'seconds','minutes','hours', or 'days'. |
|
| 871 | + * By default, rounds up. (So if you use 'days', and then event |
|
| 872 | + * only occurs for 1 hour, it will return 1 day). |
|
| 873 | + * |
|
| 874 | + * @param string $units 'seconds','minutes','hours','days' |
|
| 875 | + * @param bool $round_up |
|
| 876 | + * @return float|int|mixed |
|
| 877 | + * @throws ReflectionException |
|
| 878 | + * @throws InvalidArgumentException |
|
| 879 | + * @throws InvalidInterfaceException |
|
| 880 | + * @throws InvalidDataTypeException |
|
| 881 | + * @throws EE_Error |
|
| 882 | + */ |
|
| 883 | + public function length($units = 'seconds', $round_up = false) |
|
| 884 | + { |
|
| 885 | + $start = $this->get_raw('DTT_EVT_start'); |
|
| 886 | + $end = $this->get_raw('DTT_EVT_end'); |
|
| 887 | + $length_in_units = $end - $start; |
|
| 888 | + switch ($units) { |
|
| 889 | + // NOTE: We purposefully don't use "break;" in order to chain the divisions |
|
| 890 | + /** @noinspection PhpMissingBreakStatementInspection */ |
|
| 891 | + // phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment |
|
| 892 | + case 'days': |
|
| 893 | + $length_in_units /= 24; |
|
| 894 | + /** @noinspection PhpMissingBreakStatementInspection */ |
|
| 895 | + case 'hours': |
|
| 896 | + // fall through is intentional |
|
| 897 | + $length_in_units /= 60; |
|
| 898 | + /** @noinspection PhpMissingBreakStatementInspection */ |
|
| 899 | + case 'minutes': |
|
| 900 | + // fall through is intentional |
|
| 901 | + $length_in_units /= 60; |
|
| 902 | + case 'seconds': |
|
| 903 | + default: |
|
| 904 | + $length_in_units = ceil($length_in_units); |
|
| 905 | + } |
|
| 906 | + // phpcs:enable |
|
| 907 | + if ($round_up) { |
|
| 908 | + $length_in_units = max($length_in_units, 1); |
|
| 909 | + } |
|
| 910 | + return $length_in_units; |
|
| 911 | + } |
|
| 912 | + |
|
| 913 | + |
|
| 914 | + /** |
|
| 915 | + * get end date and time |
|
| 916 | + * |
|
| 917 | + * @param string $dt_frmt - string representation of date format defaults to 'F j, Y' |
|
| 918 | + * @param string $tm_format - string representation of time format defaults to 'g:i a' |
|
| 919 | + * @return mixed string on success, FALSE on fail |
|
| 920 | + * @throws ReflectionException |
|
| 921 | + * @throws InvalidArgumentException |
|
| 922 | + * @throws InvalidInterfaceException |
|
| 923 | + * @throws InvalidDataTypeException |
|
| 924 | + * @throws EE_Error |
|
| 925 | + */ |
|
| 926 | + public function end_date_and_time($dt_frmt = '', $tm_format = '') |
|
| 927 | + { |
|
| 928 | + return $this->_show_datetime('', 'end', $dt_frmt, $tm_format); |
|
| 929 | + } |
|
| 930 | + |
|
| 931 | + |
|
| 932 | + /** |
|
| 933 | + * @param string $dt_frmt |
|
| 934 | + * @param string $tm_format |
|
| 935 | + * @throws ReflectionException |
|
| 936 | + * @throws InvalidArgumentException |
|
| 937 | + * @throws InvalidInterfaceException |
|
| 938 | + * @throws InvalidDataTypeException |
|
| 939 | + * @throws EE_Error |
|
| 940 | + */ |
|
| 941 | + public function e_end_date_and_time($dt_frmt = '', $tm_format = '') |
|
| 942 | + { |
|
| 943 | + $this->_show_datetime('', 'end', $dt_frmt, $tm_format, true); |
|
| 944 | + } |
|
| 945 | + |
|
| 946 | + |
|
| 947 | + /** |
|
| 948 | + * get start timestamp |
|
| 949 | + * |
|
| 950 | + * @return int |
|
| 951 | + * @throws ReflectionException |
|
| 952 | + * @throws InvalidArgumentException |
|
| 953 | + * @throws InvalidInterfaceException |
|
| 954 | + * @throws InvalidDataTypeException |
|
| 955 | + * @throws EE_Error |
|
| 956 | + */ |
|
| 957 | + public function start() |
|
| 958 | + { |
|
| 959 | + return $this->get_raw('DTT_EVT_start'); |
|
| 960 | + } |
|
| 961 | + |
|
| 962 | + |
|
| 963 | + /** |
|
| 964 | + * get end timestamp |
|
| 965 | + * |
|
| 966 | + * @return int |
|
| 967 | + * @throws ReflectionException |
|
| 968 | + * @throws InvalidArgumentException |
|
| 969 | + * @throws InvalidInterfaceException |
|
| 970 | + * @throws InvalidDataTypeException |
|
| 971 | + * @throws EE_Error |
|
| 972 | + */ |
|
| 973 | + public function end() |
|
| 974 | + { |
|
| 975 | + return $this->get_raw('DTT_EVT_end'); |
|
| 976 | + } |
|
| 977 | + |
|
| 978 | + |
|
| 979 | + /** |
|
| 980 | + * get the registration limit for this datetime slot |
|
| 981 | + * |
|
| 982 | + * @return mixed int on success, FALSE on fail |
|
| 983 | + * @throws ReflectionException |
|
| 984 | + * @throws InvalidArgumentException |
|
| 985 | + * @throws InvalidInterfaceException |
|
| 986 | + * @throws InvalidDataTypeException |
|
| 987 | + * @throws EE_Error |
|
| 988 | + */ |
|
| 989 | + public function reg_limit() |
|
| 990 | + { |
|
| 991 | + return $this->get_raw('DTT_reg_limit'); |
|
| 992 | + } |
|
| 993 | + |
|
| 994 | + |
|
| 995 | + /** |
|
| 996 | + * have the tickets sold for this datetime, met or exceed the registration limit ? |
|
| 997 | + * |
|
| 998 | + * @return boolean |
|
| 999 | + * @throws ReflectionException |
|
| 1000 | + * @throws InvalidArgumentException |
|
| 1001 | + * @throws InvalidInterfaceException |
|
| 1002 | + * @throws InvalidDataTypeException |
|
| 1003 | + * @throws EE_Error |
|
| 1004 | + */ |
|
| 1005 | + public function sold_out() |
|
| 1006 | + { |
|
| 1007 | + return $this->reg_limit() > 0 && $this->sold() >= $this->reg_limit(); |
|
| 1008 | + } |
|
| 1009 | + |
|
| 1010 | + |
|
| 1011 | + /** |
|
| 1012 | + * return the total number of spaces remaining at this venue. |
|
| 1013 | + * This only takes the venue's capacity into account, NOT the tickets available for sale |
|
| 1014 | + * |
|
| 1015 | + * @param bool $consider_tickets Whether to consider tickets remaining when determining if there are any spaces left |
|
| 1016 | + * Because if all tickets attached to this datetime have no spaces left, |
|
| 1017 | + * then this datetime IS effectively sold out. |
|
| 1018 | + * However, there are cases where we just want to know the spaces |
|
| 1019 | + * remaining for this particular datetime, hence the flag. |
|
| 1020 | + * @return int |
|
| 1021 | + * @throws ReflectionException |
|
| 1022 | + * @throws InvalidArgumentException |
|
| 1023 | + * @throws InvalidInterfaceException |
|
| 1024 | + * @throws InvalidDataTypeException |
|
| 1025 | + * @throws EE_Error |
|
| 1026 | + */ |
|
| 1027 | + public function spaces_remaining($consider_tickets = false) |
|
| 1028 | + { |
|
| 1029 | + // tickets remaining available for purchase |
|
| 1030 | + // no need for special checks for infinite, because if DTT_reg_limit == EE_INF, then EE_INF - x = EE_INF |
|
| 1031 | + $dtt_remaining = $this->reg_limit() - $this->sold_and_reserved(); |
|
| 1032 | + if (! $consider_tickets) { |
|
| 1033 | + return $dtt_remaining; |
|
| 1034 | + } |
|
| 1035 | + $tickets_remaining = $this->tickets_remaining(); |
|
| 1036 | + return min($dtt_remaining, $tickets_remaining); |
|
| 1037 | + } |
|
| 1038 | + |
|
| 1039 | + |
|
| 1040 | + /** |
|
| 1041 | + * Counts the total tickets available |
|
| 1042 | + * (from all the different types of tickets which are available for this datetime). |
|
| 1043 | + * |
|
| 1044 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1045 | + * @return int |
|
| 1046 | + * @throws ReflectionException |
|
| 1047 | + * @throws InvalidArgumentException |
|
| 1048 | + * @throws InvalidInterfaceException |
|
| 1049 | + * @throws InvalidDataTypeException |
|
| 1050 | + * @throws EE_Error |
|
| 1051 | + */ |
|
| 1052 | + public function tickets_remaining($query_params = array()) |
|
| 1053 | + { |
|
| 1054 | + $sum = 0; |
|
| 1055 | + $tickets = $this->tickets($query_params); |
|
| 1056 | + if (! empty($tickets)) { |
|
| 1057 | + foreach ($tickets as $ticket) { |
|
| 1058 | + if ($ticket instanceof EE_Ticket) { |
|
| 1059 | + // get the actual amount of tickets that can be sold |
|
| 1060 | + $qty = $ticket->qty('saleable'); |
|
| 1061 | + if ($qty === EE_INF) { |
|
| 1062 | + return EE_INF; |
|
| 1063 | + } |
|
| 1064 | + // no negative ticket quantities plz |
|
| 1065 | + if ($qty > 0) { |
|
| 1066 | + $sum += $qty; |
|
| 1067 | + } |
|
| 1068 | + } |
|
| 1069 | + } |
|
| 1070 | + } |
|
| 1071 | + return $sum; |
|
| 1072 | + } |
|
| 1073 | + |
|
| 1074 | + |
|
| 1075 | + /** |
|
| 1076 | + * Gets the count of all the tickets available at this datetime (not ticket types) |
|
| 1077 | + * before any were sold |
|
| 1078 | + * |
|
| 1079 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1080 | + * @return int |
|
| 1081 | + * @throws ReflectionException |
|
| 1082 | + * @throws InvalidArgumentException |
|
| 1083 | + * @throws InvalidInterfaceException |
|
| 1084 | + * @throws InvalidDataTypeException |
|
| 1085 | + * @throws EE_Error |
|
| 1086 | + */ |
|
| 1087 | + public function sum_tickets_initially_available($query_params = array()) |
|
| 1088 | + { |
|
| 1089 | + return $this->sum_related('Ticket', $query_params, 'TKT_qty'); |
|
| 1090 | + } |
|
| 1091 | + |
|
| 1092 | + |
|
| 1093 | + /** |
|
| 1094 | + * Returns the lesser-of-the two: spaces remaining at this datetime, or |
|
| 1095 | + * the total tickets remaining (a sum of the tickets remaining for each ticket type |
|
| 1096 | + * that is available for this datetime). |
|
| 1097 | + * |
|
| 1098 | + * @return int |
|
| 1099 | + * @throws ReflectionException |
|
| 1100 | + * @throws InvalidArgumentException |
|
| 1101 | + * @throws InvalidInterfaceException |
|
| 1102 | + * @throws InvalidDataTypeException |
|
| 1103 | + * @throws EE_Error |
|
| 1104 | + */ |
|
| 1105 | + public function total_tickets_available_at_this_datetime() |
|
| 1106 | + { |
|
| 1107 | + return $this->spaces_remaining(true); |
|
| 1108 | + } |
|
| 1109 | + |
|
| 1110 | + |
|
| 1111 | + /** |
|
| 1112 | + * This simply compares the internal dtt for the given string with NOW |
|
| 1113 | + * and determines if the date is upcoming or not. |
|
| 1114 | + * |
|
| 1115 | + * @access public |
|
| 1116 | + * @return boolean |
|
| 1117 | + * @throws ReflectionException |
|
| 1118 | + * @throws InvalidArgumentException |
|
| 1119 | + * @throws InvalidInterfaceException |
|
| 1120 | + * @throws InvalidDataTypeException |
|
| 1121 | + * @throws EE_Error |
|
| 1122 | + */ |
|
| 1123 | + public function is_upcoming() |
|
| 1124 | + { |
|
| 1125 | + return ($this->get_raw('DTT_EVT_start') > time()); |
|
| 1126 | + } |
|
| 1127 | + |
|
| 1128 | + |
|
| 1129 | + /** |
|
| 1130 | + * This simply compares the internal datetime for the given string with NOW |
|
| 1131 | + * and returns if the date is active (i.e. start and end time) |
|
| 1132 | + * |
|
| 1133 | + * @return boolean |
|
| 1134 | + * @throws ReflectionException |
|
| 1135 | + * @throws InvalidArgumentException |
|
| 1136 | + * @throws InvalidInterfaceException |
|
| 1137 | + * @throws InvalidDataTypeException |
|
| 1138 | + * @throws EE_Error |
|
| 1139 | + */ |
|
| 1140 | + public function is_active() |
|
| 1141 | + { |
|
| 1142 | + return ($this->get_raw('DTT_EVT_start') < time() && $this->get_raw('DTT_EVT_end') > time()); |
|
| 1143 | + } |
|
| 1144 | + |
|
| 1145 | + |
|
| 1146 | + /** |
|
| 1147 | + * This simply compares the internal dtt for the given string with NOW |
|
| 1148 | + * and determines if the date is expired or not. |
|
| 1149 | + * |
|
| 1150 | + * @return boolean |
|
| 1151 | + * @throws ReflectionException |
|
| 1152 | + * @throws InvalidArgumentException |
|
| 1153 | + * @throws InvalidInterfaceException |
|
| 1154 | + * @throws InvalidDataTypeException |
|
| 1155 | + * @throws EE_Error |
|
| 1156 | + */ |
|
| 1157 | + public function is_expired() |
|
| 1158 | + { |
|
| 1159 | + return ($this->get_raw('DTT_EVT_end') < time()); |
|
| 1160 | + } |
|
| 1161 | + |
|
| 1162 | + |
|
| 1163 | + /** |
|
| 1164 | + * This returns the active status for whether an event is active, upcoming, or expired |
|
| 1165 | + * |
|
| 1166 | + * @return int return value will be one of the EE_Datetime status constants. |
|
| 1167 | + * @throws ReflectionException |
|
| 1168 | + * @throws InvalidArgumentException |
|
| 1169 | + * @throws InvalidInterfaceException |
|
| 1170 | + * @throws InvalidDataTypeException |
|
| 1171 | + * @throws EE_Error |
|
| 1172 | + */ |
|
| 1173 | + public function get_active_status() |
|
| 1174 | + { |
|
| 1175 | + $total_tickets_for_this_dtt = $this->total_tickets_available_at_this_datetime(); |
|
| 1176 | + if ($total_tickets_for_this_dtt !== false && $total_tickets_for_this_dtt < 1) { |
|
| 1177 | + return EE_Datetime::sold_out; |
|
| 1178 | + } |
|
| 1179 | + if ($this->is_expired()) { |
|
| 1180 | + return EE_Datetime::expired; |
|
| 1181 | + } |
|
| 1182 | + if ($this->is_upcoming()) { |
|
| 1183 | + return EE_Datetime::upcoming; |
|
| 1184 | + } |
|
| 1185 | + if ($this->is_active()) { |
|
| 1186 | + return EE_Datetime::active; |
|
| 1187 | + } |
|
| 1188 | + return null; |
|
| 1189 | + } |
|
| 1190 | + |
|
| 1191 | + |
|
| 1192 | + /** |
|
| 1193 | + * This returns a nice display name for the datetime that is contingent on the span between the dates and times. |
|
| 1194 | + * |
|
| 1195 | + * @param boolean $use_dtt_name if TRUE then we'll use DTT->name() if its not empty. |
|
| 1196 | + * @return string |
|
| 1197 | + * @throws ReflectionException |
|
| 1198 | + * @throws InvalidArgumentException |
|
| 1199 | + * @throws InvalidInterfaceException |
|
| 1200 | + * @throws InvalidDataTypeException |
|
| 1201 | + * @throws EE_Error |
|
| 1202 | + */ |
|
| 1203 | + public function get_dtt_display_name($use_dtt_name = false) |
|
| 1204 | + { |
|
| 1205 | + if ($use_dtt_name) { |
|
| 1206 | + $dtt_name = $this->name(); |
|
| 1207 | + if (! empty($dtt_name)) { |
|
| 1208 | + return $dtt_name; |
|
| 1209 | + } |
|
| 1210 | + } |
|
| 1211 | + // first condition is to see if the months are different |
|
| 1212 | + if ( |
|
| 1213 | + date('m', $this->get_raw('DTT_EVT_start')) !== date('m', $this->get_raw('DTT_EVT_end')) |
|
| 1214 | + ) { |
|
| 1215 | + $display_date = $this->start_date('M j\, Y g:i a') . ' - ' . $this->end_date('M j\, Y g:i a'); |
|
| 1216 | + // next condition is if its the same month but different day |
|
| 1217 | + } else { |
|
| 1218 | + if ( |
|
| 1219 | + date('m', $this->get_raw('DTT_EVT_start')) === date('m', $this->get_raw('DTT_EVT_end')) |
|
| 1220 | + && date('d', $this->get_raw('DTT_EVT_start')) !== date('d', $this->get_raw('DTT_EVT_end')) |
|
| 1221 | + ) { |
|
| 1222 | + $display_date = $this->start_date('M j\, g:i a') . ' - ' . $this->end_date('M j\, g:i a Y'); |
|
| 1223 | + } else { |
|
| 1224 | + $display_date = $this->start_date('F j\, Y') |
|
| 1225 | + . ' @ ' |
|
| 1226 | + . $this->start_date('g:i a') |
|
| 1227 | + . ' - ' |
|
| 1228 | + . $this->end_date('g:i a'); |
|
| 1229 | + } |
|
| 1230 | + } |
|
| 1231 | + return $display_date; |
|
| 1232 | + } |
|
| 1233 | + |
|
| 1234 | + |
|
| 1235 | + /** |
|
| 1236 | + * Gets all the tickets for this datetime |
|
| 1237 | + * |
|
| 1238 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1239 | + * @return EE_Base_Class[]|EE_Ticket[] |
|
| 1240 | + * @throws ReflectionException |
|
| 1241 | + * @throws InvalidArgumentException |
|
| 1242 | + * @throws InvalidInterfaceException |
|
| 1243 | + * @throws InvalidDataTypeException |
|
| 1244 | + * @throws EE_Error |
|
| 1245 | + */ |
|
| 1246 | + public function tickets($query_params = array()) |
|
| 1247 | + { |
|
| 1248 | + return $this->get_many_related('Ticket', $query_params); |
|
| 1249 | + } |
|
| 1250 | + |
|
| 1251 | + |
|
| 1252 | + /** |
|
| 1253 | + * Gets all the ticket types currently available for purchase |
|
| 1254 | + * |
|
| 1255 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1256 | + * @return EE_Ticket[] |
|
| 1257 | + * @throws ReflectionException |
|
| 1258 | + * @throws InvalidArgumentException |
|
| 1259 | + * @throws InvalidInterfaceException |
|
| 1260 | + * @throws InvalidDataTypeException |
|
| 1261 | + * @throws EE_Error |
|
| 1262 | + */ |
|
| 1263 | + public function ticket_types_available_for_purchase($query_params = array()) |
|
| 1264 | + { |
|
| 1265 | + // first check if datetime is valid |
|
| 1266 | + if ($this->sold_out() || ! ($this->is_upcoming() || $this->is_active())) { |
|
| 1267 | + return array(); |
|
| 1268 | + } |
|
| 1269 | + if (empty($query_params)) { |
|
| 1270 | + $query_params = array( |
|
| 1271 | + array( |
|
| 1272 | + 'TKT_start_date' => array('<=', EEM_Ticket::instance()->current_time_for_query('TKT_start_date')), |
|
| 1273 | + 'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')), |
|
| 1274 | + 'TKT_deleted' => false, |
|
| 1275 | + ), |
|
| 1276 | + ); |
|
| 1277 | + } |
|
| 1278 | + return $this->tickets($query_params); |
|
| 1279 | + } |
|
| 1280 | + |
|
| 1281 | + |
|
| 1282 | + /** |
|
| 1283 | + * @return EE_Base_Class|EE_Event |
|
| 1284 | + * @throws ReflectionException |
|
| 1285 | + * @throws InvalidArgumentException |
|
| 1286 | + * @throws InvalidInterfaceException |
|
| 1287 | + * @throws InvalidDataTypeException |
|
| 1288 | + * @throws EE_Error |
|
| 1289 | + */ |
|
| 1290 | + public function event() |
|
| 1291 | + { |
|
| 1292 | + return $this->get_first_related('Event'); |
|
| 1293 | + } |
|
| 1294 | + |
|
| 1295 | + |
|
| 1296 | + /** |
|
| 1297 | + * Updates the DTT_sold attribute (and saves) based on the number of registrations for this datetime |
|
| 1298 | + * (via the tickets). |
|
| 1299 | + * |
|
| 1300 | + * @return int |
|
| 1301 | + * @throws ReflectionException |
|
| 1302 | + * @throws InvalidArgumentException |
|
| 1303 | + * @throws InvalidInterfaceException |
|
| 1304 | + * @throws InvalidDataTypeException |
|
| 1305 | + * @throws EE_Error |
|
| 1306 | + */ |
|
| 1307 | + public function update_sold() |
|
| 1308 | + { |
|
| 1309 | + $count_regs_for_this_datetime = EEM_Registration::instance()->count( |
|
| 1310 | + array( |
|
| 1311 | + array( |
|
| 1312 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1313 | + 'REG_deleted' => 0, |
|
| 1314 | + 'Ticket.Datetime.DTT_ID' => $this->ID(), |
|
| 1315 | + ), |
|
| 1316 | + ) |
|
| 1317 | + ); |
|
| 1318 | + $this->set_sold($count_regs_for_this_datetime); |
|
| 1319 | + $this->save(); |
|
| 1320 | + return $count_regs_for_this_datetime; |
|
| 1321 | + } |
|
| 1322 | + |
|
| 1323 | + |
|
| 1324 | + /******************************************************************* |
|
| 1325 | 1325 | *********************** DEPRECATED METHODS ********************** |
| 1326 | 1326 | *******************************************************************/ |
| 1327 | 1327 | |
| 1328 | 1328 | |
| 1329 | - /** |
|
| 1330 | - * Increments sold by amount passed by $qty, and persists it immediately to the database. |
|
| 1331 | - * |
|
| 1332 | - * @deprecated 4.9.80.p |
|
| 1333 | - * @param int $qty |
|
| 1334 | - * @return boolean |
|
| 1335 | - * @throws ReflectionException |
|
| 1336 | - * @throws InvalidArgumentException |
|
| 1337 | - * @throws InvalidInterfaceException |
|
| 1338 | - * @throws InvalidDataTypeException |
|
| 1339 | - * @throws EE_Error |
|
| 1340 | - */ |
|
| 1341 | - public function increase_sold($qty = 1) |
|
| 1342 | - { |
|
| 1343 | - EE_Error::doing_it_wrong( |
|
| 1344 | - __FUNCTION__, |
|
| 1345 | - esc_html__('Please use EE_Datetime::increaseSold() instead', 'event_espresso'), |
|
| 1346 | - '4.9.80.p', |
|
| 1347 | - '5.0.0.p' |
|
| 1348 | - ); |
|
| 1349 | - return $this->increaseSold($qty); |
|
| 1350 | - } |
|
| 1351 | - |
|
| 1352 | - |
|
| 1353 | - /** |
|
| 1354 | - * Decrements (subtracts) sold amount passed by $qty directly in the DB and on the model object. (Ie, no need |
|
| 1355 | - * to save afterwards.) |
|
| 1356 | - * |
|
| 1357 | - * @deprecated 4.9.80.p |
|
| 1358 | - * @param int $qty |
|
| 1359 | - * @return boolean |
|
| 1360 | - * @throws ReflectionException |
|
| 1361 | - * @throws InvalidArgumentException |
|
| 1362 | - * @throws InvalidInterfaceException |
|
| 1363 | - * @throws InvalidDataTypeException |
|
| 1364 | - * @throws EE_Error |
|
| 1365 | - */ |
|
| 1366 | - public function decrease_sold($qty = 1) |
|
| 1367 | - { |
|
| 1368 | - EE_Error::doing_it_wrong( |
|
| 1369 | - __FUNCTION__, |
|
| 1370 | - esc_html__('Please use EE_Datetime::decreaseSold() instead', 'event_espresso'), |
|
| 1371 | - '4.9.80.p', |
|
| 1372 | - '5.0.0.p' |
|
| 1373 | - ); |
|
| 1374 | - return $this->decreaseSold($qty); |
|
| 1375 | - } |
|
| 1376 | - |
|
| 1377 | - |
|
| 1378 | - /** |
|
| 1379 | - * Increments reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 1380 | - * |
|
| 1381 | - * @deprecated 4.9.80.p |
|
| 1382 | - * @param int $qty |
|
| 1383 | - * @return boolean indicating success |
|
| 1384 | - * @throws ReflectionException |
|
| 1385 | - * @throws InvalidArgumentException |
|
| 1386 | - * @throws InvalidInterfaceException |
|
| 1387 | - * @throws InvalidDataTypeException |
|
| 1388 | - * @throws EE_Error |
|
| 1389 | - */ |
|
| 1390 | - public function increase_reserved($qty = 1) |
|
| 1391 | - { |
|
| 1392 | - EE_Error::doing_it_wrong( |
|
| 1393 | - __FUNCTION__, |
|
| 1394 | - esc_html__('Please use EE_Datetime::increaseReserved() instead', 'event_espresso'), |
|
| 1395 | - '4.9.80.p', |
|
| 1396 | - '5.0.0.p' |
|
| 1397 | - ); |
|
| 1398 | - return $this->increaseReserved($qty); |
|
| 1399 | - } |
|
| 1400 | - |
|
| 1401 | - |
|
| 1402 | - /** |
|
| 1403 | - * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 1404 | - * |
|
| 1405 | - * @deprecated 4.9.80.p |
|
| 1406 | - * @param int $qty |
|
| 1407 | - * @return boolean |
|
| 1408 | - * @throws ReflectionException |
|
| 1409 | - * @throws InvalidArgumentException |
|
| 1410 | - * @throws InvalidInterfaceException |
|
| 1411 | - * @throws InvalidDataTypeException |
|
| 1412 | - * @throws EE_Error |
|
| 1413 | - */ |
|
| 1414 | - public function decrease_reserved($qty = 1) |
|
| 1415 | - { |
|
| 1416 | - EE_Error::doing_it_wrong( |
|
| 1417 | - __FUNCTION__, |
|
| 1418 | - esc_html__('Please use EE_Datetime::decreaseReserved() instead', 'event_espresso'), |
|
| 1419 | - '4.9.80.p', |
|
| 1420 | - '5.0.0.p' |
|
| 1421 | - ); |
|
| 1422 | - return $this->decreaseReserved($qty); |
|
| 1423 | - } |
|
| 1329 | + /** |
|
| 1330 | + * Increments sold by amount passed by $qty, and persists it immediately to the database. |
|
| 1331 | + * |
|
| 1332 | + * @deprecated 4.9.80.p |
|
| 1333 | + * @param int $qty |
|
| 1334 | + * @return boolean |
|
| 1335 | + * @throws ReflectionException |
|
| 1336 | + * @throws InvalidArgumentException |
|
| 1337 | + * @throws InvalidInterfaceException |
|
| 1338 | + * @throws InvalidDataTypeException |
|
| 1339 | + * @throws EE_Error |
|
| 1340 | + */ |
|
| 1341 | + public function increase_sold($qty = 1) |
|
| 1342 | + { |
|
| 1343 | + EE_Error::doing_it_wrong( |
|
| 1344 | + __FUNCTION__, |
|
| 1345 | + esc_html__('Please use EE_Datetime::increaseSold() instead', 'event_espresso'), |
|
| 1346 | + '4.9.80.p', |
|
| 1347 | + '5.0.0.p' |
|
| 1348 | + ); |
|
| 1349 | + return $this->increaseSold($qty); |
|
| 1350 | + } |
|
| 1351 | + |
|
| 1352 | + |
|
| 1353 | + /** |
|
| 1354 | + * Decrements (subtracts) sold amount passed by $qty directly in the DB and on the model object. (Ie, no need |
|
| 1355 | + * to save afterwards.) |
|
| 1356 | + * |
|
| 1357 | + * @deprecated 4.9.80.p |
|
| 1358 | + * @param int $qty |
|
| 1359 | + * @return boolean |
|
| 1360 | + * @throws ReflectionException |
|
| 1361 | + * @throws InvalidArgumentException |
|
| 1362 | + * @throws InvalidInterfaceException |
|
| 1363 | + * @throws InvalidDataTypeException |
|
| 1364 | + * @throws EE_Error |
|
| 1365 | + */ |
|
| 1366 | + public function decrease_sold($qty = 1) |
|
| 1367 | + { |
|
| 1368 | + EE_Error::doing_it_wrong( |
|
| 1369 | + __FUNCTION__, |
|
| 1370 | + esc_html__('Please use EE_Datetime::decreaseSold() instead', 'event_espresso'), |
|
| 1371 | + '4.9.80.p', |
|
| 1372 | + '5.0.0.p' |
|
| 1373 | + ); |
|
| 1374 | + return $this->decreaseSold($qty); |
|
| 1375 | + } |
|
| 1376 | + |
|
| 1377 | + |
|
| 1378 | + /** |
|
| 1379 | + * Increments reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 1380 | + * |
|
| 1381 | + * @deprecated 4.9.80.p |
|
| 1382 | + * @param int $qty |
|
| 1383 | + * @return boolean indicating success |
|
| 1384 | + * @throws ReflectionException |
|
| 1385 | + * @throws InvalidArgumentException |
|
| 1386 | + * @throws InvalidInterfaceException |
|
| 1387 | + * @throws InvalidDataTypeException |
|
| 1388 | + * @throws EE_Error |
|
| 1389 | + */ |
|
| 1390 | + public function increase_reserved($qty = 1) |
|
| 1391 | + { |
|
| 1392 | + EE_Error::doing_it_wrong( |
|
| 1393 | + __FUNCTION__, |
|
| 1394 | + esc_html__('Please use EE_Datetime::increaseReserved() instead', 'event_espresso'), |
|
| 1395 | + '4.9.80.p', |
|
| 1396 | + '5.0.0.p' |
|
| 1397 | + ); |
|
| 1398 | + return $this->increaseReserved($qty); |
|
| 1399 | + } |
|
| 1400 | + |
|
| 1401 | + |
|
| 1402 | + /** |
|
| 1403 | + * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 1404 | + * |
|
| 1405 | + * @deprecated 4.9.80.p |
|
| 1406 | + * @param int $qty |
|
| 1407 | + * @return boolean |
|
| 1408 | + * @throws ReflectionException |
|
| 1409 | + * @throws InvalidArgumentException |
|
| 1410 | + * @throws InvalidInterfaceException |
|
| 1411 | + * @throws InvalidDataTypeException |
|
| 1412 | + * @throws EE_Error |
|
| 1413 | + */ |
|
| 1414 | + public function decrease_reserved($qty = 1) |
|
| 1415 | + { |
|
| 1416 | + EE_Error::doing_it_wrong( |
|
| 1417 | + __FUNCTION__, |
|
| 1418 | + esc_html__('Please use EE_Datetime::decreaseReserved() instead', 'event_espresso'), |
|
| 1419 | + '4.9.80.p', |
|
| 1420 | + '5.0.0.p' |
|
| 1421 | + ); |
|
| 1422 | + return $this->decreaseReserved($qty); |
|
| 1423 | + } |
|
| 1424 | 1424 | } |
@@ -64,7 +64,7 @@ |
||
| 64 | 64 | /** |
| 65 | 65 | * Set Answer value |
| 66 | 66 | * |
| 67 | - * @param mixed $ANS_value |
|
| 67 | + * @param string $ANS_value |
|
| 68 | 68 | * @throws EE_Error |
| 69 | 69 | * @throws ReflectionException |
| 70 | 70 | */ |
@@ -10,153 +10,153 @@ |
||
| 10 | 10 | class EE_Answer extends EE_Base_Class |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * @param array $props_n_values |
|
| 15 | - * @return EE_Answer |
|
| 16 | - * @throws EE_Error |
|
| 17 | - * @throws ReflectionException |
|
| 18 | - */ |
|
| 19 | - public static function new_instance($props_n_values = []) |
|
| 20 | - { |
|
| 21 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 22 | - return $has_object ? $has_object : new self($props_n_values); |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @param array $props_n_values |
|
| 28 | - * @return EE_Answer |
|
| 29 | - * @throws EE_Error |
|
| 30 | - * @throws ReflectionException |
|
| 31 | - */ |
|
| 32 | - public static function new_instance_from_db($props_n_values = []) |
|
| 33 | - { |
|
| 34 | - return new self($props_n_values, true); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Set Question ID |
|
| 40 | - * |
|
| 41 | - * @param int $QST_ID |
|
| 42 | - * @throws EE_Error |
|
| 43 | - * @throws ReflectionException |
|
| 44 | - */ |
|
| 45 | - public function set_question($QST_ID = 0) |
|
| 46 | - { |
|
| 47 | - $this->set('QST_ID', $QST_ID); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Set Registration ID |
|
| 53 | - * |
|
| 54 | - * @param int $REG_ID |
|
| 55 | - * @throws EE_Error |
|
| 56 | - * @throws ReflectionException |
|
| 57 | - */ |
|
| 58 | - public function set_registration($REG_ID = 0) |
|
| 59 | - { |
|
| 60 | - $this->set('REG_ID', $REG_ID); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Set Answer value |
|
| 66 | - * |
|
| 67 | - * @param mixed $ANS_value |
|
| 68 | - * @throws EE_Error |
|
| 69 | - * @throws ReflectionException |
|
| 70 | - */ |
|
| 71 | - public function set_value($ANS_value = '') |
|
| 72 | - { |
|
| 73 | - $this->set('ANS_value', $ANS_value); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * get Attendee First Name |
|
| 79 | - * |
|
| 80 | - * @return int |
|
| 81 | - * @throws EE_Error |
|
| 82 | - */ |
|
| 83 | - public function registration_ID() |
|
| 84 | - { |
|
| 85 | - return $this->get('REG_ID'); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * get Attendee Last Name |
|
| 91 | - * |
|
| 92 | - * @return int |
|
| 93 | - * @throws EE_Error |
|
| 94 | - */ |
|
| 95 | - public function question_ID() |
|
| 96 | - { |
|
| 97 | - return $this->get('QST_ID'); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * get Attendee Address |
|
| 103 | - * |
|
| 104 | - * @return string |
|
| 105 | - * @throws EE_Error |
|
| 106 | - */ |
|
| 107 | - public function value() |
|
| 108 | - { |
|
| 109 | - return $this->get('ANS_value'); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Gets a pretty form of the value (mostly applies to answers that have multiple answers) |
|
| 115 | - * |
|
| 116 | - * @param null $schema |
|
| 117 | - * @return string |
|
| 118 | - * @throws EE_Error |
|
| 119 | - */ |
|
| 120 | - public function pretty_value($schema = null) |
|
| 121 | - { |
|
| 122 | - return $this->get_pretty('ANS_value', $schema); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Echoes out a pretty value (even for multi-choice options) |
|
| 128 | - * |
|
| 129 | - * @param string $schema |
|
| 130 | - * @throws EE_Error |
|
| 131 | - */ |
|
| 132 | - public function e_value($schema = null) |
|
| 133 | - { |
|
| 134 | - $this->e('ANS_value', $schema); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Gets the related EE_Question to this EE_Answer |
|
| 140 | - * |
|
| 141 | - * @return EE_Base_Class|EE_Question |
|
| 142 | - * @throws EE_Error |
|
| 143 | - * @throws ReflectionException |
|
| 144 | - */ |
|
| 145 | - public function question() |
|
| 146 | - { |
|
| 147 | - return $this->get_first_related('Question'); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * Gets the related EE_Registration to this EE_Answer |
|
| 153 | - * |
|
| 154 | - * @return EE_Base_Class|EE_Registration |
|
| 155 | - * @throws EE_Error |
|
| 156 | - * @throws ReflectionException |
|
| 157 | - */ |
|
| 158 | - public function registration() |
|
| 159 | - { |
|
| 160 | - return $this->get_first_related('Registration'); |
|
| 161 | - } |
|
| 13 | + /** |
|
| 14 | + * @param array $props_n_values |
|
| 15 | + * @return EE_Answer |
|
| 16 | + * @throws EE_Error |
|
| 17 | + * @throws ReflectionException |
|
| 18 | + */ |
|
| 19 | + public static function new_instance($props_n_values = []) |
|
| 20 | + { |
|
| 21 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 22 | + return $has_object ? $has_object : new self($props_n_values); |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @param array $props_n_values |
|
| 28 | + * @return EE_Answer |
|
| 29 | + * @throws EE_Error |
|
| 30 | + * @throws ReflectionException |
|
| 31 | + */ |
|
| 32 | + public static function new_instance_from_db($props_n_values = []) |
|
| 33 | + { |
|
| 34 | + return new self($props_n_values, true); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Set Question ID |
|
| 40 | + * |
|
| 41 | + * @param int $QST_ID |
|
| 42 | + * @throws EE_Error |
|
| 43 | + * @throws ReflectionException |
|
| 44 | + */ |
|
| 45 | + public function set_question($QST_ID = 0) |
|
| 46 | + { |
|
| 47 | + $this->set('QST_ID', $QST_ID); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Set Registration ID |
|
| 53 | + * |
|
| 54 | + * @param int $REG_ID |
|
| 55 | + * @throws EE_Error |
|
| 56 | + * @throws ReflectionException |
|
| 57 | + */ |
|
| 58 | + public function set_registration($REG_ID = 0) |
|
| 59 | + { |
|
| 60 | + $this->set('REG_ID', $REG_ID); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Set Answer value |
|
| 66 | + * |
|
| 67 | + * @param mixed $ANS_value |
|
| 68 | + * @throws EE_Error |
|
| 69 | + * @throws ReflectionException |
|
| 70 | + */ |
|
| 71 | + public function set_value($ANS_value = '') |
|
| 72 | + { |
|
| 73 | + $this->set('ANS_value', $ANS_value); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * get Attendee First Name |
|
| 79 | + * |
|
| 80 | + * @return int |
|
| 81 | + * @throws EE_Error |
|
| 82 | + */ |
|
| 83 | + public function registration_ID() |
|
| 84 | + { |
|
| 85 | + return $this->get('REG_ID'); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * get Attendee Last Name |
|
| 91 | + * |
|
| 92 | + * @return int |
|
| 93 | + * @throws EE_Error |
|
| 94 | + */ |
|
| 95 | + public function question_ID() |
|
| 96 | + { |
|
| 97 | + return $this->get('QST_ID'); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * get Attendee Address |
|
| 103 | + * |
|
| 104 | + * @return string |
|
| 105 | + * @throws EE_Error |
|
| 106 | + */ |
|
| 107 | + public function value() |
|
| 108 | + { |
|
| 109 | + return $this->get('ANS_value'); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Gets a pretty form of the value (mostly applies to answers that have multiple answers) |
|
| 115 | + * |
|
| 116 | + * @param null $schema |
|
| 117 | + * @return string |
|
| 118 | + * @throws EE_Error |
|
| 119 | + */ |
|
| 120 | + public function pretty_value($schema = null) |
|
| 121 | + { |
|
| 122 | + return $this->get_pretty('ANS_value', $schema); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Echoes out a pretty value (even for multi-choice options) |
|
| 128 | + * |
|
| 129 | + * @param string $schema |
|
| 130 | + * @throws EE_Error |
|
| 131 | + */ |
|
| 132 | + public function e_value($schema = null) |
|
| 133 | + { |
|
| 134 | + $this->e('ANS_value', $schema); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Gets the related EE_Question to this EE_Answer |
|
| 140 | + * |
|
| 141 | + * @return EE_Base_Class|EE_Question |
|
| 142 | + * @throws EE_Error |
|
| 143 | + * @throws ReflectionException |
|
| 144 | + */ |
|
| 145 | + public function question() |
|
| 146 | + { |
|
| 147 | + return $this->get_first_related('Question'); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * Gets the related EE_Registration to this EE_Answer |
|
| 153 | + * |
|
| 154 | + * @return EE_Base_Class|EE_Registration |
|
| 155 | + * @throws EE_Error |
|
| 156 | + * @throws ReflectionException |
|
| 157 | + */ |
|
| 158 | + public function registration() |
|
| 159 | + { |
|
| 160 | + return $this->get_first_related('Registration'); |
|
| 161 | + } |
|
| 162 | 162 | } |
@@ -451,7 +451,7 @@ discard block |
||
| 451 | 451 | * Gets registrations of this attendee |
| 452 | 452 | * |
| 453 | 453 | * @param array $query_params |
| 454 | - * @return array[]|EE_Base_Class[]|EE_Registration[] |
|
| 454 | + * @return EE_Base_Class[] |
|
| 455 | 455 | * @throws EE_Error |
| 456 | 456 | * @throws ReflectionException |
| 457 | 457 | */ |
@@ -497,7 +497,7 @@ discard block |
||
| 497 | 497 | /** |
| 498 | 498 | * returns any events attached to this attendee ($_Event property); |
| 499 | 499 | * |
| 500 | - * @return array |
|
| 500 | + * @return EE_Base_Class[] |
|
| 501 | 501 | * @throws EE_Error |
| 502 | 502 | * @throws ReflectionException |
| 503 | 503 | */ |
@@ -523,7 +523,7 @@ discard block |
||
| 523 | 523 | * and keys are their cleaned values. |
| 524 | 524 | * |
| 525 | 525 | * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class |
| 526 | - * @return EE_Form_Section_Proper|null |
|
| 526 | + * @return null|EE_Billing_Info_Form |
|
| 527 | 527 | * @throws EE_Error |
| 528 | 528 | * @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was |
| 529 | 529 | * used to save the billing info |
@@ -13,807 +13,807 @@ |
||
| 13 | 13 | class EE_Attendee extends EE_CPT_Base implements EEI_Contact, EEI_Address, EEI_Admin_Links, EEI_Attendee |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Sets some dynamic defaults |
|
| 18 | - * |
|
| 19 | - * @param array $fieldValues |
|
| 20 | - * @param bool $bydb |
|
| 21 | - * @param string $timezone |
|
| 22 | - * @param array $date_formats |
|
| 23 | - * @throws EE_Error |
|
| 24 | - * @throws ReflectionException |
|
| 25 | - */ |
|
| 26 | - protected function __construct($fieldValues = null, $bydb = false, $timezone = '', $date_formats = []) |
|
| 27 | - { |
|
| 28 | - if (! isset($fieldValues['ATT_full_name'])) { |
|
| 29 | - $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : ''; |
|
| 30 | - $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : ''; |
|
| 31 | - $fieldValues['ATT_full_name'] = $fname . $lname; |
|
| 32 | - } |
|
| 33 | - if (! isset($fieldValues['ATT_slug'])) { |
|
| 34 | - // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20)); |
|
| 35 | - $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']); |
|
| 36 | - } |
|
| 37 | - if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
| 38 | - $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50); |
|
| 39 | - } |
|
| 40 | - parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @param array $props_n_values incoming values |
|
| 46 | - * @param string $timezone incoming timezone |
|
| 47 | - * (if not set the timezone set for the website will be used.) |
|
| 48 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 49 | - * date_format and the second value is the time format |
|
| 50 | - * @return EE_Attendee |
|
| 51 | - * @throws EE_Error |
|
| 52 | - * @throws ReflectionException |
|
| 53 | - */ |
|
| 54 | - public static function new_instance($props_n_values = [], $timezone = '', $date_formats = []) |
|
| 55 | - { |
|
| 56 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 57 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @param array $props_n_values incoming values from the database |
|
| 63 | - * @param string $timezone incoming timezone as set by the model. |
|
| 64 | - * If not set the timezone for the website will be used. |
|
| 65 | - * @return EE_Attendee |
|
| 66 | - * @throws EE_Error |
|
| 67 | - * @throws EE_Error |
|
| 68 | - * @throws ReflectionException |
|
| 69 | - */ |
|
| 70 | - public static function new_instance_from_db($props_n_values = [], $timezone = '') |
|
| 71 | - { |
|
| 72 | - return new self($props_n_values, true, $timezone); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Set Attendee First Name |
|
| 78 | - * |
|
| 79 | - * @param string $fname |
|
| 80 | - * @throws EE_Error |
|
| 81 | - * @throws ReflectionException |
|
| 82 | - */ |
|
| 83 | - public function set_fname($fname = '') |
|
| 84 | - { |
|
| 85 | - $this->set('ATT_fname', $fname); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Set Attendee Last Name |
|
| 91 | - * |
|
| 92 | - * @param string $lname |
|
| 93 | - * @throws EE_Error |
|
| 94 | - * @throws ReflectionException |
|
| 95 | - */ |
|
| 96 | - public function set_lname($lname = '') |
|
| 97 | - { |
|
| 98 | - $this->set('ATT_lname', $lname); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Set Attendee Address |
|
| 104 | - * |
|
| 105 | - * @param string $address |
|
| 106 | - * @throws EE_Error |
|
| 107 | - * @throws ReflectionException |
|
| 108 | - */ |
|
| 109 | - public function set_address($address = '') |
|
| 110 | - { |
|
| 111 | - $this->set('ATT_address', $address); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Set Attendee Address2 |
|
| 117 | - * |
|
| 118 | - * @param string $address2 |
|
| 119 | - * @throws EE_Error |
|
| 120 | - * @throws ReflectionException |
|
| 121 | - */ |
|
| 122 | - public function set_address2($address2 = '') |
|
| 123 | - { |
|
| 124 | - $this->set('ATT_address2', $address2); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Set Attendee City |
|
| 130 | - * |
|
| 131 | - * @param string $city |
|
| 132 | - * @throws EE_Error |
|
| 133 | - * @throws ReflectionException |
|
| 134 | - */ |
|
| 135 | - public function set_city($city = '') |
|
| 136 | - { |
|
| 137 | - $this->set('ATT_city', $city); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Set Attendee State ID |
|
| 143 | - * |
|
| 144 | - * @param int $STA_ID |
|
| 145 | - * @throws EE_Error |
|
| 146 | - * @throws ReflectionException |
|
| 147 | - */ |
|
| 148 | - public function set_state($STA_ID = 0) |
|
| 149 | - { |
|
| 150 | - $this->set('STA_ID', $STA_ID); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * Set Attendee Country ISO Code |
|
| 156 | - * |
|
| 157 | - * @param string $CNT_ISO |
|
| 158 | - * @throws EE_Error |
|
| 159 | - * @throws ReflectionException |
|
| 160 | - */ |
|
| 161 | - public function set_country($CNT_ISO = '') |
|
| 162 | - { |
|
| 163 | - $this->set('CNT_ISO', $CNT_ISO); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Set Attendee Zip/Postal Code |
|
| 169 | - * |
|
| 170 | - * @param string $zip |
|
| 171 | - * @throws EE_Error |
|
| 172 | - * @throws ReflectionException |
|
| 173 | - */ |
|
| 174 | - public function set_zip($zip = '') |
|
| 175 | - { |
|
| 176 | - $this->set('ATT_zip', $zip); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * Set Attendee Email Address |
|
| 182 | - * |
|
| 183 | - * @param string $email |
|
| 184 | - * @throws EE_Error |
|
| 185 | - * @throws ReflectionException |
|
| 186 | - */ |
|
| 187 | - public function set_email($email = '') |
|
| 188 | - { |
|
| 189 | - $this->set('ATT_email', $email); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * Set Attendee Phone |
|
| 195 | - * |
|
| 196 | - * @param string $phone |
|
| 197 | - * @throws EE_Error |
|
| 198 | - * @throws ReflectionException |
|
| 199 | - */ |
|
| 200 | - public function set_phone($phone = '') |
|
| 201 | - { |
|
| 202 | - $this->set('ATT_phone', $phone); |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * set deleted |
|
| 208 | - * |
|
| 209 | - * @param bool $ATT_deleted |
|
| 210 | - * @throws EE_Error |
|
| 211 | - * @throws ReflectionException |
|
| 212 | - */ |
|
| 213 | - public function set_deleted($ATT_deleted = false) |
|
| 214 | - { |
|
| 215 | - $this->set('ATT_deleted', $ATT_deleted); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * Returns the value for the post_author id saved with the cpt |
|
| 221 | - * |
|
| 222 | - * @return int |
|
| 223 | - * @throws EE_Error |
|
| 224 | - * @since 4.5.0 |
|
| 225 | - */ |
|
| 226 | - public function wp_user() |
|
| 227 | - { |
|
| 228 | - return $this->get('ATT_author'); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * echoes out the attendee's first name |
|
| 234 | - * |
|
| 235 | - * @return void |
|
| 236 | - * @throws EE_Error |
|
| 237 | - */ |
|
| 238 | - public function e_full_name() |
|
| 239 | - { |
|
| 240 | - echo $this->full_name(); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * Returns the first and last name concatenated together with a space. |
|
| 246 | - * |
|
| 247 | - * @param bool $apply_html_entities |
|
| 248 | - * @return string |
|
| 249 | - * @throws EE_Error |
|
| 250 | - */ |
|
| 251 | - public function full_name($apply_html_entities = false) |
|
| 252 | - { |
|
| 253 | - $full_name = [ |
|
| 254 | - $this->fname(), |
|
| 255 | - $this->lname(), |
|
| 256 | - ]; |
|
| 257 | - $full_name = array_filter($full_name); |
|
| 258 | - $full_name = implode(' ', $full_name); |
|
| 259 | - return $apply_html_entities |
|
| 260 | - ? htmlentities($full_name, ENT_QUOTES, 'UTF-8') |
|
| 261 | - : $full_name; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * get Attendee First Name |
|
| 267 | - * |
|
| 268 | - * @return string |
|
| 269 | - * @throws EE_Error |
|
| 270 | - */ |
|
| 271 | - public function fname() |
|
| 272 | - { |
|
| 273 | - return $this->get('ATT_fname'); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * get Attendee Last Name |
|
| 279 | - * |
|
| 280 | - * @return string |
|
| 281 | - * @throws EE_Error |
|
| 282 | - */ |
|
| 283 | - public function lname() |
|
| 284 | - { |
|
| 285 | - return $this->get('ATT_lname'); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * get Attendee Email Address |
|
| 291 | - * |
|
| 292 | - * @return string |
|
| 293 | - * @throws EE_Error |
|
| 294 | - */ |
|
| 295 | - public function email() |
|
| 296 | - { |
|
| 297 | - return $this->get('ATT_email'); |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * get Attendee Phone # |
|
| 303 | - * |
|
| 304 | - * @return string |
|
| 305 | - * @throws EE_Error |
|
| 306 | - */ |
|
| 307 | - public function phone() |
|
| 308 | - { |
|
| 309 | - return $this->get('ATT_phone'); |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * This returns the value of the `ATT_full_name` field |
|
| 315 | - * which is usually equivalent to calling `full_name()` |
|
| 316 | - * unless the post_title field has been directly modified |
|
| 317 | - * in the db for the post (espresso_attendees post type) |
|
| 318 | - * for this attendee. |
|
| 319 | - * |
|
| 320 | - * @param bool $apply_html_entities |
|
| 321 | - * @return string |
|
| 322 | - * @throws EE_Error |
|
| 323 | - */ |
|
| 324 | - public function ATT_full_name($apply_html_entities = false) |
|
| 325 | - { |
|
| 326 | - return $apply_html_entities |
|
| 327 | - ? htmlentities( |
|
| 328 | - $this->get('ATT_full_name'), |
|
| 329 | - ENT_QUOTES, |
|
| 330 | - 'UTF-8' |
|
| 331 | - ) |
|
| 332 | - : $this->get('ATT_full_name'); |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * get Attendee bio |
|
| 338 | - * |
|
| 339 | - * @return string |
|
| 340 | - * @throws EE_Error |
|
| 341 | - */ |
|
| 342 | - public function bio() |
|
| 343 | - { |
|
| 344 | - return $this->get('ATT_bio'); |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - |
|
| 348 | - /** |
|
| 349 | - * get Attendee short bio |
|
| 350 | - * |
|
| 351 | - * @return string |
|
| 352 | - * @throws EE_Error |
|
| 353 | - */ |
|
| 354 | - public function short_bio() |
|
| 355 | - { |
|
| 356 | - return $this->get('ATT_short_bio'); |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * Gets the attendee's full address as an array |
|
| 362 | - * so client code can decide hwo to display it |
|
| 363 | - * |
|
| 364 | - * @return array numerically indexed, |
|
| 365 | - * with each part of the address that is known. |
|
| 366 | - * Eg, if the user only responded to state and country, |
|
| 367 | - * it would be array(0=>'Alabama',1=>'USA') |
|
| 368 | - * @return array |
|
| 369 | - * @throws EE_Error |
|
| 370 | - * @throws ReflectionException |
|
| 371 | - */ |
|
| 372 | - public function full_address_as_array() |
|
| 373 | - { |
|
| 374 | - $full_address_array = []; |
|
| 375 | - $initial_address_fields = ['ATT_address', 'ATT_address2', 'ATT_city',]; |
|
| 376 | - foreach ($initial_address_fields as $address_field_name) { |
|
| 377 | - $address_fields_value = $this->get($address_field_name); |
|
| 378 | - if (! empty($address_fields_value)) { |
|
| 379 | - $full_address_array[] = $address_fields_value; |
|
| 380 | - } |
|
| 381 | - } |
|
| 382 | - // now handle state and country |
|
| 383 | - $state_obj = $this->state_obj(); |
|
| 384 | - if ($state_obj instanceof EE_State) { |
|
| 385 | - $full_address_array[] = $state_obj->name(); |
|
| 386 | - } |
|
| 387 | - $country_obj = $this->country_obj(); |
|
| 388 | - if ($country_obj instanceof EE_Country) { |
|
| 389 | - $full_address_array[] = $country_obj->name(); |
|
| 390 | - } |
|
| 391 | - // lastly get the xip |
|
| 392 | - $zip_value = $this->zip(); |
|
| 393 | - if (! empty($zip_value)) { |
|
| 394 | - $full_address_array[] = $zip_value; |
|
| 395 | - } |
|
| 396 | - return $full_address_array; |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - |
|
| 400 | - /** |
|
| 401 | - * Gets the state set to this attendee |
|
| 402 | - * |
|
| 403 | - * @return EE_Base_Class|EE_State |
|
| 404 | - * @throws EE_Error |
|
| 405 | - * @throws ReflectionException |
|
| 406 | - */ |
|
| 407 | - public function state_obj() |
|
| 408 | - { |
|
| 409 | - return $this->get_first_related('State'); |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * Gets country set for this attendee |
|
| 415 | - * |
|
| 416 | - * @return EE_Base_Class|EE_Country |
|
| 417 | - * @throws EE_Error |
|
| 418 | - * @throws ReflectionException |
|
| 419 | - */ |
|
| 420 | - public function country_obj() |
|
| 421 | - { |
|
| 422 | - return $this->get_first_related('Country'); |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - |
|
| 426 | - /** |
|
| 427 | - * get Attendee Zip/Postal Code |
|
| 428 | - * |
|
| 429 | - * @return string |
|
| 430 | - * @throws EE_Error |
|
| 431 | - */ |
|
| 432 | - public function zip() |
|
| 433 | - { |
|
| 434 | - return $this->get('ATT_zip'); |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - |
|
| 438 | - /** |
|
| 439 | - * get deleted |
|
| 440 | - * |
|
| 441 | - * @return bool |
|
| 442 | - * @throws EE_Error |
|
| 443 | - */ |
|
| 444 | - public function deleted() |
|
| 445 | - { |
|
| 446 | - return $this->get('ATT_deleted'); |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - |
|
| 450 | - /** |
|
| 451 | - * Gets registrations of this attendee |
|
| 452 | - * |
|
| 453 | - * @param array $query_params |
|
| 454 | - * @return array[]|EE_Base_Class[]|EE_Registration[] |
|
| 455 | - * @throws EE_Error |
|
| 456 | - * @throws ReflectionException |
|
| 457 | - */ |
|
| 458 | - public function get_registrations($query_params = []) |
|
| 459 | - { |
|
| 460 | - return $this->get_many_related('Registration', $query_params); |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - |
|
| 464 | - /** |
|
| 465 | - * Gets the most recent registration of this attendee |
|
| 466 | - * |
|
| 467 | - * @return EE_Base_Class|EE_Registration |
|
| 468 | - * @throws EE_Error |
|
| 469 | - * @throws ReflectionException |
|
| 470 | - */ |
|
| 471 | - public function get_most_recent_registration() |
|
| 472 | - { |
|
| 473 | - return $this->get_first_related( |
|
| 474 | - 'Registration', |
|
| 475 | - ['order_by' => ['REG_date' => 'DESC']] |
|
| 476 | - ); // null, 'REG_date', 'DESC', '=', 'OBJECT_K'); |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - |
|
| 480 | - /** |
|
| 481 | - * Gets the most recent registration for this attend at this event |
|
| 482 | - * |
|
| 483 | - * @param int $event_id |
|
| 484 | - * @return EE_Base_Class|EE_Registration |
|
| 485 | - * @throws EE_Error |
|
| 486 | - * @throws ReflectionException |
|
| 487 | - */ |
|
| 488 | - public function get_most_recent_registration_for_event($event_id) |
|
| 489 | - { |
|
| 490 | - return $this->get_first_related( |
|
| 491 | - 'Registration', |
|
| 492 | - [['EVT_ID' => $event_id], 'order_by' => ['REG_date' => 'DESC']] |
|
| 493 | - ); |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - |
|
| 497 | - /** |
|
| 498 | - * returns any events attached to this attendee ($_Event property); |
|
| 499 | - * |
|
| 500 | - * @return array |
|
| 501 | - * @throws EE_Error |
|
| 502 | - * @throws ReflectionException |
|
| 503 | - */ |
|
| 504 | - public function events() |
|
| 505 | - { |
|
| 506 | - return $this->get_many_related('Event'); |
|
| 507 | - } |
|
| 508 | - |
|
| 509 | - |
|
| 510 | - /** |
|
| 511 | - * @return string |
|
| 512 | - * @throws EE_Error |
|
| 513 | - * @throws ReflectionException |
|
| 514 | - */ |
|
| 515 | - public function state_abbrev() |
|
| 516 | - { |
|
| 517 | - return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : ''; |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - |
|
| 521 | - /** |
|
| 522 | - * Gets the billing info array where keys match espresso_reg_page_billing_inputs(), |
|
| 523 | - * and keys are their cleaned values. |
|
| 524 | - * |
|
| 525 | - * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class |
|
| 526 | - * @return EE_Form_Section_Proper|null |
|
| 527 | - * @throws EE_Error |
|
| 528 | - * @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was |
|
| 529 | - * used to save the billing info |
|
| 530 | - */ |
|
| 531 | - public function billing_info_for_payment_method($payment_method) |
|
| 532 | - { |
|
| 533 | - $pm_type = $payment_method->type_obj(); |
|
| 534 | - if (! $pm_type instanceof EE_PMT_Base) { |
|
| 535 | - return null; |
|
| 536 | - } |
|
| 537 | - $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true); |
|
| 538 | - if (! $billing_info) { |
|
| 539 | - return null; |
|
| 540 | - } |
|
| 541 | - $billing_form = $pm_type->billing_form(); |
|
| 542 | - // double-check the form isn't totally hidden, in which case pretend there is no form |
|
| 543 | - $form_totally_hidden = true; |
|
| 544 | - foreach ($billing_form->inputs_in_subsections() as $input) { |
|
| 545 | - if (! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
| 546 | - $form_totally_hidden = false; |
|
| 547 | - break; |
|
| 548 | - } |
|
| 549 | - } |
|
| 550 | - if ($form_totally_hidden) { |
|
| 551 | - return null; |
|
| 552 | - } |
|
| 553 | - if ($billing_form instanceof EE_Form_Section_Proper) { |
|
| 554 | - $billing_form->receive_form_submission([$billing_form->name() => $billing_info], false); |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - return $billing_form; |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - |
|
| 561 | - /** |
|
| 562 | - * Gets the postmeta key that holds this attendee's billing info for the |
|
| 563 | - * specified payment method |
|
| 564 | - * |
|
| 565 | - * @param EE_Payment_Method $payment_method |
|
| 566 | - * @return string |
|
| 567 | - * @throws EE_Error |
|
| 568 | - */ |
|
| 569 | - public function get_billing_info_postmeta_name($payment_method) |
|
| 570 | - { |
|
| 571 | - if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
| 572 | - return 'billing_info_' . $payment_method->type_obj()->system_name(); |
|
| 573 | - } |
|
| 574 | - return null; |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - |
|
| 578 | - /** |
|
| 579 | - * Saves the billing info to the attendee. @param EE_Billing_Attendee_Info_Form $billing_form |
|
| 580 | - * |
|
| 581 | - * @param EE_Payment_Method $payment_method |
|
| 582 | - * @return boolean |
|
| 583 | - * @throws EE_Error |
|
| 584 | - * @see EE_Attendee::billing_info_for_payment_method() which is used to |
|
| 585 | - * retrieve it |
|
| 586 | - */ |
|
| 587 | - public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method) |
|
| 588 | - { |
|
| 589 | - if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
| 590 | - EE_Error::add_error( |
|
| 591 | - __('Cannot save billing info because there is none.', 'event_espresso'), |
|
| 592 | - __FILE__, |
|
| 593 | - __FUNCTION__, |
|
| 594 | - __LINE__ |
|
| 595 | - ); |
|
| 596 | - return false; |
|
| 597 | - } |
|
| 598 | - $billing_form->clean_sensitive_data(); |
|
| 599 | - return update_post_meta( |
|
| 600 | - $this->ID(), |
|
| 601 | - $this->get_billing_info_postmeta_name($payment_method), |
|
| 602 | - $billing_form->input_values(true) |
|
| 603 | - ); |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - |
|
| 607 | - /** |
|
| 608 | - * Return the link to the admin details for the object. |
|
| 609 | - * |
|
| 610 | - * @return string |
|
| 611 | - * @throws EE_Error |
|
| 612 | - * @throws InvalidArgumentException |
|
| 613 | - * @throws InvalidDataTypeException |
|
| 614 | - * @throws InvalidInterfaceException |
|
| 615 | - * @throws ReflectionException |
|
| 616 | - */ |
|
| 617 | - public function get_admin_details_link() |
|
| 618 | - { |
|
| 619 | - return $this->get_admin_edit_link(); |
|
| 620 | - } |
|
| 621 | - |
|
| 622 | - |
|
| 623 | - /** |
|
| 624 | - * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
| 625 | - * |
|
| 626 | - * @return string |
|
| 627 | - * @throws EE_Error |
|
| 628 | - * @throws InvalidArgumentException |
|
| 629 | - * @throws ReflectionException |
|
| 630 | - * @throws InvalidDataTypeException |
|
| 631 | - * @throws InvalidInterfaceException |
|
| 632 | - */ |
|
| 633 | - public function get_admin_edit_link() |
|
| 634 | - { |
|
| 635 | - EE_Registry::instance()->load_helper('URL'); |
|
| 636 | - return EEH_URL::add_query_args_and_nonce( |
|
| 637 | - [ |
|
| 638 | - 'page' => 'espresso_registrations', |
|
| 639 | - 'action' => 'edit_attendee', |
|
| 640 | - 'post' => $this->ID(), |
|
| 641 | - ], |
|
| 642 | - admin_url('admin.php') |
|
| 643 | - ); |
|
| 644 | - } |
|
| 645 | - |
|
| 646 | - |
|
| 647 | - /** |
|
| 648 | - * get Attendee Address |
|
| 649 | - * |
|
| 650 | - * @return string |
|
| 651 | - * @throws EE_Error |
|
| 652 | - */ |
|
| 653 | - public function address() |
|
| 654 | - { |
|
| 655 | - return $this->get('ATT_address'); |
|
| 656 | - } |
|
| 657 | - |
|
| 658 | - |
|
| 659 | - /** |
|
| 660 | - * Returns the link to a settings page for the object. |
|
| 661 | - * |
|
| 662 | - * @return string |
|
| 663 | - * @throws EE_Error |
|
| 664 | - * @throws InvalidArgumentException |
|
| 665 | - * @throws InvalidDataTypeException |
|
| 666 | - * @throws InvalidInterfaceException |
|
| 667 | - * @throws ReflectionException |
|
| 668 | - */ |
|
| 669 | - public function get_admin_settings_link() |
|
| 670 | - { |
|
| 671 | - return $this->get_admin_edit_link(); |
|
| 672 | - } |
|
| 673 | - |
|
| 674 | - |
|
| 675 | - /** |
|
| 676 | - * Returns the link to the "overview" for the object (typically the "list table" view). |
|
| 677 | - * |
|
| 678 | - * @return string |
|
| 679 | - * @throws EE_Error |
|
| 680 | - * @throws InvalidArgumentException |
|
| 681 | - * @throws ReflectionException |
|
| 682 | - * @throws InvalidDataTypeException |
|
| 683 | - * @throws InvalidInterfaceException |
|
| 684 | - */ |
|
| 685 | - public function get_admin_overview_link() |
|
| 686 | - { |
|
| 687 | - EE_Registry::instance()->load_helper('URL'); |
|
| 688 | - return EEH_URL::add_query_args_and_nonce( |
|
| 689 | - [ |
|
| 690 | - 'page' => 'espresso_registrations', |
|
| 691 | - 'action' => 'contact_list', |
|
| 692 | - ], |
|
| 693 | - admin_url('admin.php') |
|
| 694 | - ); |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - |
|
| 698 | - |
|
| 699 | - |
|
| 700 | - |
|
| 701 | - |
|
| 702 | - |
|
| 703 | - |
|
| 704 | - /** |
|
| 705 | - * get Attendee Address2 |
|
| 706 | - * |
|
| 707 | - * @return string |
|
| 708 | - * @throws EE_Error |
|
| 709 | - */ |
|
| 710 | - public function address2() |
|
| 711 | - { |
|
| 712 | - return $this->get('ATT_address2'); |
|
| 713 | - } |
|
| 714 | - |
|
| 715 | - |
|
| 716 | - /** |
|
| 717 | - * Returns the state's name, otherwise 'Unknown' |
|
| 718 | - * |
|
| 719 | - * @return string |
|
| 720 | - * @throws EE_Error |
|
| 721 | - * @throws ReflectionException |
|
| 722 | - */ |
|
| 723 | - public function state_name() |
|
| 724 | - { |
|
| 725 | - if ($this->state_obj()) { |
|
| 726 | - return $this->state_obj()->name(); |
|
| 727 | - } else { |
|
| 728 | - return ''; |
|
| 729 | - } |
|
| 730 | - } |
|
| 731 | - |
|
| 732 | - |
|
| 733 | - /** |
|
| 734 | - * get Attendee City |
|
| 735 | - * |
|
| 736 | - * @return string |
|
| 737 | - * @throws EE_Error |
|
| 738 | - */ |
|
| 739 | - public function city() |
|
| 740 | - { |
|
| 741 | - return $this->get('ATT_city'); |
|
| 742 | - } |
|
| 743 | - |
|
| 744 | - |
|
| 745 | - /** |
|
| 746 | - * either displays the state abbreviation or the state name, as determined |
|
| 747 | - * by the "FHEE__EEI_Address__state__use_abbreviation" filter. |
|
| 748 | - * defaults to abbreviation |
|
| 749 | - * |
|
| 750 | - * @return string |
|
| 751 | - * @throws EE_Error |
|
| 752 | - * @throws ReflectionException |
|
| 753 | - */ |
|
| 754 | - public function state() |
|
| 755 | - { |
|
| 756 | - if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) { |
|
| 757 | - return $this->state_abbrev(); |
|
| 758 | - } |
|
| 759 | - return $this->state_name(); |
|
| 760 | - } |
|
| 761 | - |
|
| 762 | - |
|
| 763 | - /** |
|
| 764 | - * get Attendee State ID |
|
| 765 | - * |
|
| 766 | - * @return string |
|
| 767 | - * @throws EE_Error |
|
| 768 | - */ |
|
| 769 | - public function state_ID() |
|
| 770 | - { |
|
| 771 | - return $this->get('STA_ID'); |
|
| 772 | - } |
|
| 773 | - |
|
| 774 | - |
|
| 775 | - /** |
|
| 776 | - * get Attendee Country ISO Code |
|
| 777 | - * |
|
| 778 | - * @return string |
|
| 779 | - * @throws EE_Error |
|
| 780 | - */ |
|
| 781 | - public function country_ID() |
|
| 782 | - { |
|
| 783 | - return $this->get('CNT_ISO'); |
|
| 784 | - } |
|
| 785 | - |
|
| 786 | - |
|
| 787 | - /** |
|
| 788 | - * Returns the country's name if known, otherwise 'Unknown' |
|
| 789 | - * |
|
| 790 | - * @return string |
|
| 791 | - * @throws EE_Error |
|
| 792 | - * @throws ReflectionException |
|
| 793 | - */ |
|
| 794 | - public function country_name() |
|
| 795 | - { |
|
| 796 | - if ($this->country_obj()) { |
|
| 797 | - return $this->country_obj()->name(); |
|
| 798 | - } |
|
| 799 | - return ''; |
|
| 800 | - } |
|
| 801 | - |
|
| 802 | - |
|
| 803 | - /** |
|
| 804 | - * either displays the country ISO2 code or the country name, as determined |
|
| 805 | - * by the "FHEE__EEI_Address__country__use_abbreviation" filter. |
|
| 806 | - * defaults to abbreviation |
|
| 807 | - * |
|
| 808 | - * @return string |
|
| 809 | - * @throws EE_Error |
|
| 810 | - * @throws ReflectionException |
|
| 811 | - */ |
|
| 812 | - public function country() |
|
| 813 | - { |
|
| 814 | - if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) { |
|
| 815 | - return $this->country_ID(); |
|
| 816 | - } |
|
| 817 | - return $this->country_name(); |
|
| 818 | - } |
|
| 16 | + /** |
|
| 17 | + * Sets some dynamic defaults |
|
| 18 | + * |
|
| 19 | + * @param array $fieldValues |
|
| 20 | + * @param bool $bydb |
|
| 21 | + * @param string $timezone |
|
| 22 | + * @param array $date_formats |
|
| 23 | + * @throws EE_Error |
|
| 24 | + * @throws ReflectionException |
|
| 25 | + */ |
|
| 26 | + protected function __construct($fieldValues = null, $bydb = false, $timezone = '', $date_formats = []) |
|
| 27 | + { |
|
| 28 | + if (! isset($fieldValues['ATT_full_name'])) { |
|
| 29 | + $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : ''; |
|
| 30 | + $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : ''; |
|
| 31 | + $fieldValues['ATT_full_name'] = $fname . $lname; |
|
| 32 | + } |
|
| 33 | + if (! isset($fieldValues['ATT_slug'])) { |
|
| 34 | + // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20)); |
|
| 35 | + $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']); |
|
| 36 | + } |
|
| 37 | + if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
| 38 | + $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50); |
|
| 39 | + } |
|
| 40 | + parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @param array $props_n_values incoming values |
|
| 46 | + * @param string $timezone incoming timezone |
|
| 47 | + * (if not set the timezone set for the website will be used.) |
|
| 48 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 49 | + * date_format and the second value is the time format |
|
| 50 | + * @return EE_Attendee |
|
| 51 | + * @throws EE_Error |
|
| 52 | + * @throws ReflectionException |
|
| 53 | + */ |
|
| 54 | + public static function new_instance($props_n_values = [], $timezone = '', $date_formats = []) |
|
| 55 | + { |
|
| 56 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 57 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @param array $props_n_values incoming values from the database |
|
| 63 | + * @param string $timezone incoming timezone as set by the model. |
|
| 64 | + * If not set the timezone for the website will be used. |
|
| 65 | + * @return EE_Attendee |
|
| 66 | + * @throws EE_Error |
|
| 67 | + * @throws EE_Error |
|
| 68 | + * @throws ReflectionException |
|
| 69 | + */ |
|
| 70 | + public static function new_instance_from_db($props_n_values = [], $timezone = '') |
|
| 71 | + { |
|
| 72 | + return new self($props_n_values, true, $timezone); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Set Attendee First Name |
|
| 78 | + * |
|
| 79 | + * @param string $fname |
|
| 80 | + * @throws EE_Error |
|
| 81 | + * @throws ReflectionException |
|
| 82 | + */ |
|
| 83 | + public function set_fname($fname = '') |
|
| 84 | + { |
|
| 85 | + $this->set('ATT_fname', $fname); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Set Attendee Last Name |
|
| 91 | + * |
|
| 92 | + * @param string $lname |
|
| 93 | + * @throws EE_Error |
|
| 94 | + * @throws ReflectionException |
|
| 95 | + */ |
|
| 96 | + public function set_lname($lname = '') |
|
| 97 | + { |
|
| 98 | + $this->set('ATT_lname', $lname); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Set Attendee Address |
|
| 104 | + * |
|
| 105 | + * @param string $address |
|
| 106 | + * @throws EE_Error |
|
| 107 | + * @throws ReflectionException |
|
| 108 | + */ |
|
| 109 | + public function set_address($address = '') |
|
| 110 | + { |
|
| 111 | + $this->set('ATT_address', $address); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Set Attendee Address2 |
|
| 117 | + * |
|
| 118 | + * @param string $address2 |
|
| 119 | + * @throws EE_Error |
|
| 120 | + * @throws ReflectionException |
|
| 121 | + */ |
|
| 122 | + public function set_address2($address2 = '') |
|
| 123 | + { |
|
| 124 | + $this->set('ATT_address2', $address2); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Set Attendee City |
|
| 130 | + * |
|
| 131 | + * @param string $city |
|
| 132 | + * @throws EE_Error |
|
| 133 | + * @throws ReflectionException |
|
| 134 | + */ |
|
| 135 | + public function set_city($city = '') |
|
| 136 | + { |
|
| 137 | + $this->set('ATT_city', $city); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Set Attendee State ID |
|
| 143 | + * |
|
| 144 | + * @param int $STA_ID |
|
| 145 | + * @throws EE_Error |
|
| 146 | + * @throws ReflectionException |
|
| 147 | + */ |
|
| 148 | + public function set_state($STA_ID = 0) |
|
| 149 | + { |
|
| 150 | + $this->set('STA_ID', $STA_ID); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * Set Attendee Country ISO Code |
|
| 156 | + * |
|
| 157 | + * @param string $CNT_ISO |
|
| 158 | + * @throws EE_Error |
|
| 159 | + * @throws ReflectionException |
|
| 160 | + */ |
|
| 161 | + public function set_country($CNT_ISO = '') |
|
| 162 | + { |
|
| 163 | + $this->set('CNT_ISO', $CNT_ISO); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Set Attendee Zip/Postal Code |
|
| 169 | + * |
|
| 170 | + * @param string $zip |
|
| 171 | + * @throws EE_Error |
|
| 172 | + * @throws ReflectionException |
|
| 173 | + */ |
|
| 174 | + public function set_zip($zip = '') |
|
| 175 | + { |
|
| 176 | + $this->set('ATT_zip', $zip); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * Set Attendee Email Address |
|
| 182 | + * |
|
| 183 | + * @param string $email |
|
| 184 | + * @throws EE_Error |
|
| 185 | + * @throws ReflectionException |
|
| 186 | + */ |
|
| 187 | + public function set_email($email = '') |
|
| 188 | + { |
|
| 189 | + $this->set('ATT_email', $email); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * Set Attendee Phone |
|
| 195 | + * |
|
| 196 | + * @param string $phone |
|
| 197 | + * @throws EE_Error |
|
| 198 | + * @throws ReflectionException |
|
| 199 | + */ |
|
| 200 | + public function set_phone($phone = '') |
|
| 201 | + { |
|
| 202 | + $this->set('ATT_phone', $phone); |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * set deleted |
|
| 208 | + * |
|
| 209 | + * @param bool $ATT_deleted |
|
| 210 | + * @throws EE_Error |
|
| 211 | + * @throws ReflectionException |
|
| 212 | + */ |
|
| 213 | + public function set_deleted($ATT_deleted = false) |
|
| 214 | + { |
|
| 215 | + $this->set('ATT_deleted', $ATT_deleted); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * Returns the value for the post_author id saved with the cpt |
|
| 221 | + * |
|
| 222 | + * @return int |
|
| 223 | + * @throws EE_Error |
|
| 224 | + * @since 4.5.0 |
|
| 225 | + */ |
|
| 226 | + public function wp_user() |
|
| 227 | + { |
|
| 228 | + return $this->get('ATT_author'); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * echoes out the attendee's first name |
|
| 234 | + * |
|
| 235 | + * @return void |
|
| 236 | + * @throws EE_Error |
|
| 237 | + */ |
|
| 238 | + public function e_full_name() |
|
| 239 | + { |
|
| 240 | + echo $this->full_name(); |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * Returns the first and last name concatenated together with a space. |
|
| 246 | + * |
|
| 247 | + * @param bool $apply_html_entities |
|
| 248 | + * @return string |
|
| 249 | + * @throws EE_Error |
|
| 250 | + */ |
|
| 251 | + public function full_name($apply_html_entities = false) |
|
| 252 | + { |
|
| 253 | + $full_name = [ |
|
| 254 | + $this->fname(), |
|
| 255 | + $this->lname(), |
|
| 256 | + ]; |
|
| 257 | + $full_name = array_filter($full_name); |
|
| 258 | + $full_name = implode(' ', $full_name); |
|
| 259 | + return $apply_html_entities |
|
| 260 | + ? htmlentities($full_name, ENT_QUOTES, 'UTF-8') |
|
| 261 | + : $full_name; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * get Attendee First Name |
|
| 267 | + * |
|
| 268 | + * @return string |
|
| 269 | + * @throws EE_Error |
|
| 270 | + */ |
|
| 271 | + public function fname() |
|
| 272 | + { |
|
| 273 | + return $this->get('ATT_fname'); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * get Attendee Last Name |
|
| 279 | + * |
|
| 280 | + * @return string |
|
| 281 | + * @throws EE_Error |
|
| 282 | + */ |
|
| 283 | + public function lname() |
|
| 284 | + { |
|
| 285 | + return $this->get('ATT_lname'); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * get Attendee Email Address |
|
| 291 | + * |
|
| 292 | + * @return string |
|
| 293 | + * @throws EE_Error |
|
| 294 | + */ |
|
| 295 | + public function email() |
|
| 296 | + { |
|
| 297 | + return $this->get('ATT_email'); |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * get Attendee Phone # |
|
| 303 | + * |
|
| 304 | + * @return string |
|
| 305 | + * @throws EE_Error |
|
| 306 | + */ |
|
| 307 | + public function phone() |
|
| 308 | + { |
|
| 309 | + return $this->get('ATT_phone'); |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * This returns the value of the `ATT_full_name` field |
|
| 315 | + * which is usually equivalent to calling `full_name()` |
|
| 316 | + * unless the post_title field has been directly modified |
|
| 317 | + * in the db for the post (espresso_attendees post type) |
|
| 318 | + * for this attendee. |
|
| 319 | + * |
|
| 320 | + * @param bool $apply_html_entities |
|
| 321 | + * @return string |
|
| 322 | + * @throws EE_Error |
|
| 323 | + */ |
|
| 324 | + public function ATT_full_name($apply_html_entities = false) |
|
| 325 | + { |
|
| 326 | + return $apply_html_entities |
|
| 327 | + ? htmlentities( |
|
| 328 | + $this->get('ATT_full_name'), |
|
| 329 | + ENT_QUOTES, |
|
| 330 | + 'UTF-8' |
|
| 331 | + ) |
|
| 332 | + : $this->get('ATT_full_name'); |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * get Attendee bio |
|
| 338 | + * |
|
| 339 | + * @return string |
|
| 340 | + * @throws EE_Error |
|
| 341 | + */ |
|
| 342 | + public function bio() |
|
| 343 | + { |
|
| 344 | + return $this->get('ATT_bio'); |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + |
|
| 348 | + /** |
|
| 349 | + * get Attendee short bio |
|
| 350 | + * |
|
| 351 | + * @return string |
|
| 352 | + * @throws EE_Error |
|
| 353 | + */ |
|
| 354 | + public function short_bio() |
|
| 355 | + { |
|
| 356 | + return $this->get('ATT_short_bio'); |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * Gets the attendee's full address as an array |
|
| 362 | + * so client code can decide hwo to display it |
|
| 363 | + * |
|
| 364 | + * @return array numerically indexed, |
|
| 365 | + * with each part of the address that is known. |
|
| 366 | + * Eg, if the user only responded to state and country, |
|
| 367 | + * it would be array(0=>'Alabama',1=>'USA') |
|
| 368 | + * @return array |
|
| 369 | + * @throws EE_Error |
|
| 370 | + * @throws ReflectionException |
|
| 371 | + */ |
|
| 372 | + public function full_address_as_array() |
|
| 373 | + { |
|
| 374 | + $full_address_array = []; |
|
| 375 | + $initial_address_fields = ['ATT_address', 'ATT_address2', 'ATT_city',]; |
|
| 376 | + foreach ($initial_address_fields as $address_field_name) { |
|
| 377 | + $address_fields_value = $this->get($address_field_name); |
|
| 378 | + if (! empty($address_fields_value)) { |
|
| 379 | + $full_address_array[] = $address_fields_value; |
|
| 380 | + } |
|
| 381 | + } |
|
| 382 | + // now handle state and country |
|
| 383 | + $state_obj = $this->state_obj(); |
|
| 384 | + if ($state_obj instanceof EE_State) { |
|
| 385 | + $full_address_array[] = $state_obj->name(); |
|
| 386 | + } |
|
| 387 | + $country_obj = $this->country_obj(); |
|
| 388 | + if ($country_obj instanceof EE_Country) { |
|
| 389 | + $full_address_array[] = $country_obj->name(); |
|
| 390 | + } |
|
| 391 | + // lastly get the xip |
|
| 392 | + $zip_value = $this->zip(); |
|
| 393 | + if (! empty($zip_value)) { |
|
| 394 | + $full_address_array[] = $zip_value; |
|
| 395 | + } |
|
| 396 | + return $full_address_array; |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * Gets the state set to this attendee |
|
| 402 | + * |
|
| 403 | + * @return EE_Base_Class|EE_State |
|
| 404 | + * @throws EE_Error |
|
| 405 | + * @throws ReflectionException |
|
| 406 | + */ |
|
| 407 | + public function state_obj() |
|
| 408 | + { |
|
| 409 | + return $this->get_first_related('State'); |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * Gets country set for this attendee |
|
| 415 | + * |
|
| 416 | + * @return EE_Base_Class|EE_Country |
|
| 417 | + * @throws EE_Error |
|
| 418 | + * @throws ReflectionException |
|
| 419 | + */ |
|
| 420 | + public function country_obj() |
|
| 421 | + { |
|
| 422 | + return $this->get_first_related('Country'); |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + |
|
| 426 | + /** |
|
| 427 | + * get Attendee Zip/Postal Code |
|
| 428 | + * |
|
| 429 | + * @return string |
|
| 430 | + * @throws EE_Error |
|
| 431 | + */ |
|
| 432 | + public function zip() |
|
| 433 | + { |
|
| 434 | + return $this->get('ATT_zip'); |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + |
|
| 438 | + /** |
|
| 439 | + * get deleted |
|
| 440 | + * |
|
| 441 | + * @return bool |
|
| 442 | + * @throws EE_Error |
|
| 443 | + */ |
|
| 444 | + public function deleted() |
|
| 445 | + { |
|
| 446 | + return $this->get('ATT_deleted'); |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + |
|
| 450 | + /** |
|
| 451 | + * Gets registrations of this attendee |
|
| 452 | + * |
|
| 453 | + * @param array $query_params |
|
| 454 | + * @return array[]|EE_Base_Class[]|EE_Registration[] |
|
| 455 | + * @throws EE_Error |
|
| 456 | + * @throws ReflectionException |
|
| 457 | + */ |
|
| 458 | + public function get_registrations($query_params = []) |
|
| 459 | + { |
|
| 460 | + return $this->get_many_related('Registration', $query_params); |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + |
|
| 464 | + /** |
|
| 465 | + * Gets the most recent registration of this attendee |
|
| 466 | + * |
|
| 467 | + * @return EE_Base_Class|EE_Registration |
|
| 468 | + * @throws EE_Error |
|
| 469 | + * @throws ReflectionException |
|
| 470 | + */ |
|
| 471 | + public function get_most_recent_registration() |
|
| 472 | + { |
|
| 473 | + return $this->get_first_related( |
|
| 474 | + 'Registration', |
|
| 475 | + ['order_by' => ['REG_date' => 'DESC']] |
|
| 476 | + ); // null, 'REG_date', 'DESC', '=', 'OBJECT_K'); |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + |
|
| 480 | + /** |
|
| 481 | + * Gets the most recent registration for this attend at this event |
|
| 482 | + * |
|
| 483 | + * @param int $event_id |
|
| 484 | + * @return EE_Base_Class|EE_Registration |
|
| 485 | + * @throws EE_Error |
|
| 486 | + * @throws ReflectionException |
|
| 487 | + */ |
|
| 488 | + public function get_most_recent_registration_for_event($event_id) |
|
| 489 | + { |
|
| 490 | + return $this->get_first_related( |
|
| 491 | + 'Registration', |
|
| 492 | + [['EVT_ID' => $event_id], 'order_by' => ['REG_date' => 'DESC']] |
|
| 493 | + ); |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + |
|
| 497 | + /** |
|
| 498 | + * returns any events attached to this attendee ($_Event property); |
|
| 499 | + * |
|
| 500 | + * @return array |
|
| 501 | + * @throws EE_Error |
|
| 502 | + * @throws ReflectionException |
|
| 503 | + */ |
|
| 504 | + public function events() |
|
| 505 | + { |
|
| 506 | + return $this->get_many_related('Event'); |
|
| 507 | + } |
|
| 508 | + |
|
| 509 | + |
|
| 510 | + /** |
|
| 511 | + * @return string |
|
| 512 | + * @throws EE_Error |
|
| 513 | + * @throws ReflectionException |
|
| 514 | + */ |
|
| 515 | + public function state_abbrev() |
|
| 516 | + { |
|
| 517 | + return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : ''; |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + |
|
| 521 | + /** |
|
| 522 | + * Gets the billing info array where keys match espresso_reg_page_billing_inputs(), |
|
| 523 | + * and keys are their cleaned values. |
|
| 524 | + * |
|
| 525 | + * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class |
|
| 526 | + * @return EE_Form_Section_Proper|null |
|
| 527 | + * @throws EE_Error |
|
| 528 | + * @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was |
|
| 529 | + * used to save the billing info |
|
| 530 | + */ |
|
| 531 | + public function billing_info_for_payment_method($payment_method) |
|
| 532 | + { |
|
| 533 | + $pm_type = $payment_method->type_obj(); |
|
| 534 | + if (! $pm_type instanceof EE_PMT_Base) { |
|
| 535 | + return null; |
|
| 536 | + } |
|
| 537 | + $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true); |
|
| 538 | + if (! $billing_info) { |
|
| 539 | + return null; |
|
| 540 | + } |
|
| 541 | + $billing_form = $pm_type->billing_form(); |
|
| 542 | + // double-check the form isn't totally hidden, in which case pretend there is no form |
|
| 543 | + $form_totally_hidden = true; |
|
| 544 | + foreach ($billing_form->inputs_in_subsections() as $input) { |
|
| 545 | + if (! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
| 546 | + $form_totally_hidden = false; |
|
| 547 | + break; |
|
| 548 | + } |
|
| 549 | + } |
|
| 550 | + if ($form_totally_hidden) { |
|
| 551 | + return null; |
|
| 552 | + } |
|
| 553 | + if ($billing_form instanceof EE_Form_Section_Proper) { |
|
| 554 | + $billing_form->receive_form_submission([$billing_form->name() => $billing_info], false); |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + return $billing_form; |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + |
|
| 561 | + /** |
|
| 562 | + * Gets the postmeta key that holds this attendee's billing info for the |
|
| 563 | + * specified payment method |
|
| 564 | + * |
|
| 565 | + * @param EE_Payment_Method $payment_method |
|
| 566 | + * @return string |
|
| 567 | + * @throws EE_Error |
|
| 568 | + */ |
|
| 569 | + public function get_billing_info_postmeta_name($payment_method) |
|
| 570 | + { |
|
| 571 | + if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
| 572 | + return 'billing_info_' . $payment_method->type_obj()->system_name(); |
|
| 573 | + } |
|
| 574 | + return null; |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + |
|
| 578 | + /** |
|
| 579 | + * Saves the billing info to the attendee. @param EE_Billing_Attendee_Info_Form $billing_form |
|
| 580 | + * |
|
| 581 | + * @param EE_Payment_Method $payment_method |
|
| 582 | + * @return boolean |
|
| 583 | + * @throws EE_Error |
|
| 584 | + * @see EE_Attendee::billing_info_for_payment_method() which is used to |
|
| 585 | + * retrieve it |
|
| 586 | + */ |
|
| 587 | + public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method) |
|
| 588 | + { |
|
| 589 | + if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
| 590 | + EE_Error::add_error( |
|
| 591 | + __('Cannot save billing info because there is none.', 'event_espresso'), |
|
| 592 | + __FILE__, |
|
| 593 | + __FUNCTION__, |
|
| 594 | + __LINE__ |
|
| 595 | + ); |
|
| 596 | + return false; |
|
| 597 | + } |
|
| 598 | + $billing_form->clean_sensitive_data(); |
|
| 599 | + return update_post_meta( |
|
| 600 | + $this->ID(), |
|
| 601 | + $this->get_billing_info_postmeta_name($payment_method), |
|
| 602 | + $billing_form->input_values(true) |
|
| 603 | + ); |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + |
|
| 607 | + /** |
|
| 608 | + * Return the link to the admin details for the object. |
|
| 609 | + * |
|
| 610 | + * @return string |
|
| 611 | + * @throws EE_Error |
|
| 612 | + * @throws InvalidArgumentException |
|
| 613 | + * @throws InvalidDataTypeException |
|
| 614 | + * @throws InvalidInterfaceException |
|
| 615 | + * @throws ReflectionException |
|
| 616 | + */ |
|
| 617 | + public function get_admin_details_link() |
|
| 618 | + { |
|
| 619 | + return $this->get_admin_edit_link(); |
|
| 620 | + } |
|
| 621 | + |
|
| 622 | + |
|
| 623 | + /** |
|
| 624 | + * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
| 625 | + * |
|
| 626 | + * @return string |
|
| 627 | + * @throws EE_Error |
|
| 628 | + * @throws InvalidArgumentException |
|
| 629 | + * @throws ReflectionException |
|
| 630 | + * @throws InvalidDataTypeException |
|
| 631 | + * @throws InvalidInterfaceException |
|
| 632 | + */ |
|
| 633 | + public function get_admin_edit_link() |
|
| 634 | + { |
|
| 635 | + EE_Registry::instance()->load_helper('URL'); |
|
| 636 | + return EEH_URL::add_query_args_and_nonce( |
|
| 637 | + [ |
|
| 638 | + 'page' => 'espresso_registrations', |
|
| 639 | + 'action' => 'edit_attendee', |
|
| 640 | + 'post' => $this->ID(), |
|
| 641 | + ], |
|
| 642 | + admin_url('admin.php') |
|
| 643 | + ); |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + |
|
| 647 | + /** |
|
| 648 | + * get Attendee Address |
|
| 649 | + * |
|
| 650 | + * @return string |
|
| 651 | + * @throws EE_Error |
|
| 652 | + */ |
|
| 653 | + public function address() |
|
| 654 | + { |
|
| 655 | + return $this->get('ATT_address'); |
|
| 656 | + } |
|
| 657 | + |
|
| 658 | + |
|
| 659 | + /** |
|
| 660 | + * Returns the link to a settings page for the object. |
|
| 661 | + * |
|
| 662 | + * @return string |
|
| 663 | + * @throws EE_Error |
|
| 664 | + * @throws InvalidArgumentException |
|
| 665 | + * @throws InvalidDataTypeException |
|
| 666 | + * @throws InvalidInterfaceException |
|
| 667 | + * @throws ReflectionException |
|
| 668 | + */ |
|
| 669 | + public function get_admin_settings_link() |
|
| 670 | + { |
|
| 671 | + return $this->get_admin_edit_link(); |
|
| 672 | + } |
|
| 673 | + |
|
| 674 | + |
|
| 675 | + /** |
|
| 676 | + * Returns the link to the "overview" for the object (typically the "list table" view). |
|
| 677 | + * |
|
| 678 | + * @return string |
|
| 679 | + * @throws EE_Error |
|
| 680 | + * @throws InvalidArgumentException |
|
| 681 | + * @throws ReflectionException |
|
| 682 | + * @throws InvalidDataTypeException |
|
| 683 | + * @throws InvalidInterfaceException |
|
| 684 | + */ |
|
| 685 | + public function get_admin_overview_link() |
|
| 686 | + { |
|
| 687 | + EE_Registry::instance()->load_helper('URL'); |
|
| 688 | + return EEH_URL::add_query_args_and_nonce( |
|
| 689 | + [ |
|
| 690 | + 'page' => 'espresso_registrations', |
|
| 691 | + 'action' => 'contact_list', |
|
| 692 | + ], |
|
| 693 | + admin_url('admin.php') |
|
| 694 | + ); |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + |
|
| 698 | + |
|
| 699 | + |
|
| 700 | + |
|
| 701 | + |
|
| 702 | + |
|
| 703 | + |
|
| 704 | + /** |
|
| 705 | + * get Attendee Address2 |
|
| 706 | + * |
|
| 707 | + * @return string |
|
| 708 | + * @throws EE_Error |
|
| 709 | + */ |
|
| 710 | + public function address2() |
|
| 711 | + { |
|
| 712 | + return $this->get('ATT_address2'); |
|
| 713 | + } |
|
| 714 | + |
|
| 715 | + |
|
| 716 | + /** |
|
| 717 | + * Returns the state's name, otherwise 'Unknown' |
|
| 718 | + * |
|
| 719 | + * @return string |
|
| 720 | + * @throws EE_Error |
|
| 721 | + * @throws ReflectionException |
|
| 722 | + */ |
|
| 723 | + public function state_name() |
|
| 724 | + { |
|
| 725 | + if ($this->state_obj()) { |
|
| 726 | + return $this->state_obj()->name(); |
|
| 727 | + } else { |
|
| 728 | + return ''; |
|
| 729 | + } |
|
| 730 | + } |
|
| 731 | + |
|
| 732 | + |
|
| 733 | + /** |
|
| 734 | + * get Attendee City |
|
| 735 | + * |
|
| 736 | + * @return string |
|
| 737 | + * @throws EE_Error |
|
| 738 | + */ |
|
| 739 | + public function city() |
|
| 740 | + { |
|
| 741 | + return $this->get('ATT_city'); |
|
| 742 | + } |
|
| 743 | + |
|
| 744 | + |
|
| 745 | + /** |
|
| 746 | + * either displays the state abbreviation or the state name, as determined |
|
| 747 | + * by the "FHEE__EEI_Address__state__use_abbreviation" filter. |
|
| 748 | + * defaults to abbreviation |
|
| 749 | + * |
|
| 750 | + * @return string |
|
| 751 | + * @throws EE_Error |
|
| 752 | + * @throws ReflectionException |
|
| 753 | + */ |
|
| 754 | + public function state() |
|
| 755 | + { |
|
| 756 | + if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) { |
|
| 757 | + return $this->state_abbrev(); |
|
| 758 | + } |
|
| 759 | + return $this->state_name(); |
|
| 760 | + } |
|
| 761 | + |
|
| 762 | + |
|
| 763 | + /** |
|
| 764 | + * get Attendee State ID |
|
| 765 | + * |
|
| 766 | + * @return string |
|
| 767 | + * @throws EE_Error |
|
| 768 | + */ |
|
| 769 | + public function state_ID() |
|
| 770 | + { |
|
| 771 | + return $this->get('STA_ID'); |
|
| 772 | + } |
|
| 773 | + |
|
| 774 | + |
|
| 775 | + /** |
|
| 776 | + * get Attendee Country ISO Code |
|
| 777 | + * |
|
| 778 | + * @return string |
|
| 779 | + * @throws EE_Error |
|
| 780 | + */ |
|
| 781 | + public function country_ID() |
|
| 782 | + { |
|
| 783 | + return $this->get('CNT_ISO'); |
|
| 784 | + } |
|
| 785 | + |
|
| 786 | + |
|
| 787 | + /** |
|
| 788 | + * Returns the country's name if known, otherwise 'Unknown' |
|
| 789 | + * |
|
| 790 | + * @return string |
|
| 791 | + * @throws EE_Error |
|
| 792 | + * @throws ReflectionException |
|
| 793 | + */ |
|
| 794 | + public function country_name() |
|
| 795 | + { |
|
| 796 | + if ($this->country_obj()) { |
|
| 797 | + return $this->country_obj()->name(); |
|
| 798 | + } |
|
| 799 | + return ''; |
|
| 800 | + } |
|
| 801 | + |
|
| 802 | + |
|
| 803 | + /** |
|
| 804 | + * either displays the country ISO2 code or the country name, as determined |
|
| 805 | + * by the "FHEE__EEI_Address__country__use_abbreviation" filter. |
|
| 806 | + * defaults to abbreviation |
|
| 807 | + * |
|
| 808 | + * @return string |
|
| 809 | + * @throws EE_Error |
|
| 810 | + * @throws ReflectionException |
|
| 811 | + */ |
|
| 812 | + public function country() |
|
| 813 | + { |
|
| 814 | + if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) { |
|
| 815 | + return $this->country_ID(); |
|
| 816 | + } |
|
| 817 | + return $this->country_name(); |
|
| 818 | + } |
|
| 819 | 819 | } |
@@ -25,16 +25,16 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | protected function __construct($fieldValues = null, $bydb = false, $timezone = '', $date_formats = []) |
| 27 | 27 | { |
| 28 | - if (! isset($fieldValues['ATT_full_name'])) { |
|
| 29 | - $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : ''; |
|
| 28 | + if ( ! isset($fieldValues['ATT_full_name'])) { |
|
| 29 | + $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'].' ' : ''; |
|
| 30 | 30 | $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : ''; |
| 31 | - $fieldValues['ATT_full_name'] = $fname . $lname; |
|
| 31 | + $fieldValues['ATT_full_name'] = $fname.$lname; |
|
| 32 | 32 | } |
| 33 | - if (! isset($fieldValues['ATT_slug'])) { |
|
| 33 | + if ( ! isset($fieldValues['ATT_slug'])) { |
|
| 34 | 34 | // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20)); |
| 35 | 35 | $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']); |
| 36 | 36 | } |
| 37 | - if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
| 37 | + if ( ! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
| 38 | 38 | $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50); |
| 39 | 39 | } |
| 40 | 40 | parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
@@ -372,10 +372,10 @@ discard block |
||
| 372 | 372 | public function full_address_as_array() |
| 373 | 373 | { |
| 374 | 374 | $full_address_array = []; |
| 375 | - $initial_address_fields = ['ATT_address', 'ATT_address2', 'ATT_city',]; |
|
| 375 | + $initial_address_fields = ['ATT_address', 'ATT_address2', 'ATT_city', ]; |
|
| 376 | 376 | foreach ($initial_address_fields as $address_field_name) { |
| 377 | 377 | $address_fields_value = $this->get($address_field_name); |
| 378 | - if (! empty($address_fields_value)) { |
|
| 378 | + if ( ! empty($address_fields_value)) { |
|
| 379 | 379 | $full_address_array[] = $address_fields_value; |
| 380 | 380 | } |
| 381 | 381 | } |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | } |
| 391 | 391 | // lastly get the xip |
| 392 | 392 | $zip_value = $this->zip(); |
| 393 | - if (! empty($zip_value)) { |
|
| 393 | + if ( ! empty($zip_value)) { |
|
| 394 | 394 | $full_address_array[] = $zip_value; |
| 395 | 395 | } |
| 396 | 396 | return $full_address_array; |
@@ -531,18 +531,18 @@ discard block |
||
| 531 | 531 | public function billing_info_for_payment_method($payment_method) |
| 532 | 532 | { |
| 533 | 533 | $pm_type = $payment_method->type_obj(); |
| 534 | - if (! $pm_type instanceof EE_PMT_Base) { |
|
| 534 | + if ( ! $pm_type instanceof EE_PMT_Base) { |
|
| 535 | 535 | return null; |
| 536 | 536 | } |
| 537 | 537 | $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true); |
| 538 | - if (! $billing_info) { |
|
| 538 | + if ( ! $billing_info) { |
|
| 539 | 539 | return null; |
| 540 | 540 | } |
| 541 | 541 | $billing_form = $pm_type->billing_form(); |
| 542 | 542 | // double-check the form isn't totally hidden, in which case pretend there is no form |
| 543 | 543 | $form_totally_hidden = true; |
| 544 | 544 | foreach ($billing_form->inputs_in_subsections() as $input) { |
| 545 | - if (! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
| 545 | + if ( ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
| 546 | 546 | $form_totally_hidden = false; |
| 547 | 547 | break; |
| 548 | 548 | } |
@@ -569,7 +569,7 @@ discard block |
||
| 569 | 569 | public function get_billing_info_postmeta_name($payment_method) |
| 570 | 570 | { |
| 571 | 571 | if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
| 572 | - return 'billing_info_' . $payment_method->type_obj()->system_name(); |
|
| 572 | + return 'billing_info_'.$payment_method->type_obj()->system_name(); |
|
| 573 | 573 | } |
| 574 | 574 | return null; |
| 575 | 575 | } |
@@ -586,7 +586,7 @@ discard block |
||
| 586 | 586 | */ |
| 587 | 587 | public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method) |
| 588 | 588 | { |
| 589 | - if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
| 589 | + if ( ! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
| 590 | 590 | EE_Error::add_error( |
| 591 | 591 | __('Cannot save billing info because there is none.', 'event_espresso'), |
| 592 | 592 | __FILE__, |
@@ -339,8 +339,8 @@ |
||
| 339 | 339 | * and dies (in order to avoid other plugins from messing up the csv output) |
| 340 | 340 | * |
| 341 | 341 | * @param string $filename the filename you want to give the file |
| 342 | - * @param array $model_data_array 3d array, as described in EE_CSV::write_model_data_to_csv() |
|
| 343 | - * @return bool | void writes CSV file to output and dies |
|
| 342 | + * @param boolean $model_data_array 3d array, as described in EE_CSV::write_model_data_to_csv() |
|
| 343 | + * @return boolean|null | void writes CSV file to output and dies |
|
| 344 | 344 | * @throws EE_Error |
| 345 | 345 | * @throws ReflectionException |
| 346 | 346 | */ |
@@ -13,625 +13,625 @@ |
||
| 13 | 13 | class EE_CSV |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * string used for 1st cell in exports, |
|
| 18 | - * which indicates that the following 2 rows will be metadata keys and values |
|
| 19 | - */ |
|
| 20 | - const metadata_header = 'Event Espresso Export Meta Data'; |
|
| 21 | - |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * instance of the EE_CSV object |
|
| 25 | - * |
|
| 26 | - * @var EE_CSV |
|
| 27 | - */ |
|
| 28 | - private static $_instance; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var array |
|
| 32 | - */ |
|
| 33 | - private $_primary_keys; |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * private constructor to prevent direct creation |
|
| 38 | - * |
|
| 39 | - * @return void |
|
| 40 | - */ |
|
| 41 | - private function __construct() |
|
| 42 | - { |
|
| 43 | - global $wpdb; |
|
| 44 | - |
|
| 45 | - $this->_primary_keys = [ |
|
| 46 | - $wpdb->prefix . 'esp_answer' => ['ANS_ID'], |
|
| 47 | - $wpdb->prefix . 'esp_attendee' => ['ATT_ID'], |
|
| 48 | - $wpdb->prefix . 'esp_datetime' => ['DTT_ID'], |
|
| 49 | - $wpdb->prefix . 'esp_event_question_group' => ['EQG_ID'], |
|
| 50 | - $wpdb->prefix . 'esp_message_template' => ['MTP_ID'], |
|
| 51 | - $wpdb->prefix . 'esp_payment' => ['PAY_ID'], |
|
| 52 | - $wpdb->prefix . 'esp_price' => ['PRC_ID'], |
|
| 53 | - $wpdb->prefix . 'esp_price_type' => ['PRT_ID'], |
|
| 54 | - $wpdb->prefix . 'esp_question' => ['QST_ID'], |
|
| 55 | - $wpdb->prefix . 'esp_question_group' => ['QSG_ID'], |
|
| 56 | - $wpdb->prefix . 'esp_question_group_question' => ['QGQ_ID'], |
|
| 57 | - $wpdb->prefix . 'esp_question_option' => ['QSO_ID'], |
|
| 58 | - $wpdb->prefix . 'esp_registration' => ['REG_ID'], |
|
| 59 | - $wpdb->prefix . 'esp_status' => ['STS_ID'], |
|
| 60 | - $wpdb->prefix . 'esp_transaction' => ['TXN_ID'], |
|
| 61 | - $wpdb->prefix . 'esp_transaction' => ['TXN_ID'], |
|
| 62 | - $wpdb->prefix . 'events_detail' => ['id'], |
|
| 63 | - $wpdb->prefix . 'events_category_detail' => ['id'], |
|
| 64 | - $wpdb->prefix . 'events_category_rel' => ['id'], |
|
| 65 | - $wpdb->prefix . 'events_venue' => ['id'], |
|
| 66 | - $wpdb->prefix . 'events_venue_rel' => ['emeta_id'], |
|
| 67 | - $wpdb->prefix . 'events_locale' => ['id'], |
|
| 68 | - $wpdb->prefix . 'events_locale_rel' => ['id'], |
|
| 69 | - $wpdb->prefix . 'events_personnel' => ['id'], |
|
| 70 | - $wpdb->prefix . 'events_personnel_rel' => ['id'], |
|
| 71 | - ]; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @ singleton method used to instantiate class object |
|
| 77 | - * @ access public |
|
| 78 | - * |
|
| 79 | - * @return EE_CSV |
|
| 80 | - */ |
|
| 81 | - public static function instance() |
|
| 82 | - { |
|
| 83 | - // check if class object is instantiated |
|
| 84 | - if (! self::$_instance instanceof EE_CSV) { |
|
| 85 | - self::$_instance = new self(); |
|
| 86 | - } |
|
| 87 | - return self::$_instance; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @Import contents of csv file and store values in an array to be manipulated by other functions |
|
| 93 | - * @access public |
|
| 94 | - * @param string $path_to_file - the csv file to be imported including the path to it's location. |
|
| 95 | - * If $model_name is provided, assumes that each row in the CSV represents a |
|
| 96 | - * model object for that model If $model_name ISN'T provided, assumes that |
|
| 97 | - * before model object data, there is a row where the first entry is simply |
|
| 98 | - * 'MODEL', and next entry is the model's name, (untranslated) like Event, and |
|
| 99 | - * then maybe a row of headers, and then the model data. Eg. |
|
| 100 | - * '<br>MODEL,Event,<br>EVT_ID,EVT_name,...<br>1,Monkey |
|
| 101 | - * Party,...<br>2,Llamarama,...<br>MODEL,Venue,<br>VNU_ID,VNU_name<br>1,The |
|
| 102 | - * Forest |
|
| 103 | - * @param string $model_name model name if we know what model we're importing |
|
| 104 | - * @param boolean $first_row_is_headers - whether the first row of data is headers or not - TRUE = headers, FALSE = |
|
| 105 | - * data |
|
| 106 | - * @return mixed - array on success - multi dimensional with headers as keys (if headers exist) OR string on fail - |
|
| 107 | - * error message like the following array('Event'=>array( |
|
| 108 | - * array('EVT_ID'=>1,'EVT_name'=>'bob party',...), |
|
| 109 | - * array('EVT_ID'=>2,'EVT_name'=>'llamarama',...), |
|
| 110 | - * ... |
|
| 111 | - * ) |
|
| 112 | - * 'Venue'=>array( |
|
| 113 | - * array('VNU_ID'=>1,'VNU_name'=>'the shack',...), |
|
| 114 | - * array('VNU_ID'=>2,'VNU_name'=>'tree house',...), |
|
| 115 | - * ... |
|
| 116 | - * ) |
|
| 117 | - * ... |
|
| 118 | - * ) |
|
| 119 | - * @throws EE_Error |
|
| 120 | - */ |
|
| 121 | - public function import_csv_to_model_data_array($path_to_file, $model_name = false, $first_row_is_headers = true) |
|
| 122 | - { |
|
| 123 | - $multi_dimensional_array = $this->import_csv_to_multi_dimensional_array($path_to_file); |
|
| 124 | - if (empty($multi_dimensional_array)) { |
|
| 125 | - return false; |
|
| 126 | - } |
|
| 127 | - // gotta start somewhere |
|
| 128 | - $row = 1; |
|
| 129 | - // array to store csv data in |
|
| 130 | - $ee_formatted_data = []; |
|
| 131 | - // array to store headers (column names) |
|
| 132 | - $headers = []; |
|
| 133 | - foreach ($multi_dimensional_array as $data) { |
|
| 134 | - // if first cell is MODEL, then second cell is the MODEL name |
|
| 135 | - if ($data[0] == 'MODEL') { |
|
| 136 | - $model_name = $data[1]; |
|
| 137 | - // don't bother looking for model data in this row. |
|
| 138 | - // The rest of this row should be blank |
|
| 139 | - // AND pretend this is the first row again |
|
| 140 | - $row = 1; |
|
| 141 | - // reset headers |
|
| 142 | - $headers = []; |
|
| 143 | - continue; |
|
| 144 | - } |
|
| 145 | - if (strpos($data[0], EE_CSV::metadata_header) !== false) { |
|
| 146 | - $model_name = EE_CSV::metadata_header; |
|
| 147 | - // store like model data, we just won't try importing it etc. |
|
| 148 | - $row = 1; |
|
| 149 | - continue; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - |
|
| 153 | - // how many columns are there? |
|
| 154 | - $columns = count($data); |
|
| 155 | - |
|
| 156 | - $model_entry = []; |
|
| 157 | - // loop through each column |
|
| 158 | - for ($i = 0; $i < $columns; $i++) { |
|
| 159 | - // replace csv_enclosures with backslashed quotes |
|
| 160 | - $data[ $i ] = str_replace('"""', '\\"', $data[ $i ]); |
|
| 161 | - // do we need to grab the column names? |
|
| 162 | - if ($row === 1) { |
|
| 163 | - if ($first_row_is_headers) { |
|
| 164 | - // store the column names to use for keys |
|
| 165 | - $column_name = $data[ $i ]; |
|
| 166 | - // check it's not blank... sometimes CSV editing programs |
|
| 167 | - // add a bunch of empty columns onto the end... |
|
| 168 | - if (! $column_name) { |
|
| 169 | - continue; |
|
| 170 | - } |
|
| 171 | - $matches = []; |
|
| 172 | - if ($model_name == EE_CSV::metadata_header) { |
|
| 173 | - $headers[ $i ] = $column_name; |
|
| 174 | - } else { |
|
| 175 | - // now get the db table name from it (the part between square brackets) |
|
| 176 | - $success = preg_match('~(.*)\[(.*)\]~', $column_name, $matches); |
|
| 177 | - if (! $success) { |
|
| 178 | - EE_Error::add_error( |
|
| 179 | - sprintf( |
|
| 180 | - esc_html__( |
|
| 181 | - "The column titled %s is invalid for importing. It must be be in the format of 'Nice Name[model_field_name]' in row %s", |
|
| 182 | - "event_espresso" |
|
| 183 | - ), |
|
| 184 | - $column_name, |
|
| 185 | - implode(",", $data) |
|
| 186 | - ), |
|
| 187 | - __FILE__, |
|
| 188 | - __FUNCTION__, |
|
| 189 | - __LINE__ |
|
| 190 | - ); |
|
| 191 | - return false; |
|
| 192 | - } |
|
| 193 | - $headers[ $i ] = $matches[2]; |
|
| 194 | - } |
|
| 195 | - } else { |
|
| 196 | - // no column names means our final array will just use counters for keys |
|
| 197 | - $model_entry[ $headers[ $i ] ] = $data[ $i ]; |
|
| 198 | - $headers[ $i ] = $i; |
|
| 199 | - } |
|
| 200 | - // and we need to store csv data |
|
| 201 | - } else { |
|
| 202 | - // this column isn' ta header, store it if there is a header for it |
|
| 203 | - if (isset($headers[ $i ])) { |
|
| 204 | - $model_entry[ $headers[ $i ] ] = $data[ $i ]; |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - } |
|
| 208 | - // save the row's data IF it's a non-header-row |
|
| 209 | - if (! $first_row_is_headers || $row > 1) { |
|
| 210 | - $ee_formatted_data[ $model_name ][] = $model_entry; |
|
| 211 | - } |
|
| 212 | - // advance to next row |
|
| 213 | - $row++; |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - // delete the uploaded file |
|
| 217 | - unlink($path_to_file); |
|
| 218 | - |
|
| 219 | - // it's good to give back |
|
| 220 | - return $ee_formatted_data; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * Generic CSV-functionality to turn an entire CSV file into a single array that's |
|
| 226 | - * NOT in a specific format to EE. It's just a 2-level array, with top-level arrays |
|
| 227 | - * representing each row in the CSV file, and the second-level arrays being each column in that row |
|
| 228 | - * |
|
| 229 | - * @param string $path_to_file |
|
| 230 | - * @return array of arrays. Top-level array has rows, second-level array has each item |
|
| 231 | - * @throws EE_Error |
|
| 232 | - */ |
|
| 233 | - public function import_csv_to_multi_dimensional_array($path_to_file) |
|
| 234 | - { |
|
| 235 | - // needed to deal with Mac line endings |
|
| 236 | - ini_set('auto_detect_line_endings', true); |
|
| 237 | - // because fgetcsv does not correctly deal with backslashed quotes such as \" |
|
| 238 | - // we'll read the file into a string |
|
| 239 | - $file_contents = $this->read_unicode_file($path_to_file); |
|
| 240 | - // replace backslashed quotes with CSV enclosures |
|
| 241 | - $file_contents = str_replace('\\"', '"""', $file_contents); |
|
| 242 | - // HEY YOU! PUT THAT FILE BACK!!! |
|
| 243 | - file_put_contents($path_to_file, $file_contents); |
|
| 244 | - |
|
| 245 | - if (($file_handle = fopen($path_to_file, "r")) !== false) { |
|
| 246 | - $csv_array = []; |
|
| 247 | - // in PHP 5.3 fgetcsv accepts a 5th parameter, but the pre 5.3 versions |
|
| 248 | - // of fgetcsv choke if passed more than 4 - is that crazy or what? |
|
| 249 | - if (version_compare(PHP_VERSION, '5.3.0') < 0) { |
|
| 250 | - // PHP 5.2- version |
|
| 251 | - // loop through each row of the file |
|
| 252 | - while (($data = fgetcsv($file_handle)) !== false) { |
|
| 253 | - $csv_array[] = $data; |
|
| 254 | - } |
|
| 255 | - } else { |
|
| 256 | - // loop through each row of the file |
|
| 257 | - while (($data = fgetcsv($file_handle)) !== false) { |
|
| 258 | - $csv_array[] = $data; |
|
| 259 | - } |
|
| 260 | - } |
|
| 261 | - # Close the File. |
|
| 262 | - fclose($file_handle); |
|
| 263 | - return $csv_array; |
|
| 264 | - } |
|
| 265 | - EE_Error::add_error( |
|
| 266 | - sprintf( |
|
| 267 | - esc_html__( |
|
| 268 | - "An error occurred - the file: %s could not opened.", |
|
| 269 | - "event_espresso" |
|
| 270 | - ), |
|
| 271 | - $path_to_file |
|
| 272 | - ), |
|
| 273 | - __FILE__, |
|
| 274 | - __FUNCTION__, |
|
| 275 | - __LINE__ |
|
| 276 | - ); |
|
| 277 | - return []; |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * Opens a unicode or utf file |
|
| 283 | - * (normal file_get_contents has difficulty reading a unicode file) |
|
| 284 | - * |
|
| 285 | - * @param string $file_path |
|
| 286 | - * @return string |
|
| 287 | - * @throws EE_Error |
|
| 288 | - * @see http://stackoverflow.com/questions/15092764/how-to-read-unicode-text-file-in-php |
|
| 289 | - */ |
|
| 290 | - private function read_unicode_file($file_path) |
|
| 291 | - { |
|
| 292 | - $fc = ""; |
|
| 293 | - $fh = fopen($file_path, "rb"); |
|
| 294 | - if (! $fh) { |
|
| 295 | - throw new EE_Error( |
|
| 296 | - sprintf( |
|
| 297 | - esc_html__("Cannot open file for read: %s<br>\n", 'event_espresso'), |
|
| 298 | - $file_path |
|
| 299 | - ) |
|
| 300 | - ); |
|
| 301 | - } |
|
| 302 | - $file_length = filesize($file_path); |
|
| 303 | - $bc = fread($fh, $file_length); |
|
| 304 | - for ($i = 0; $i < $file_length; $i++) { |
|
| 305 | - $c = substr($bc, $i, 1); |
|
| 306 | - if ((ord($c) != 0) && (ord($c) != 13)) { |
|
| 307 | - $fc = $fc . $c; |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - if ((ord(substr($fc, 0, 1)) == 255) && (ord(substr($fc, 1, 1)) == 254)) { |
|
| 311 | - $fc = substr($fc, 2); |
|
| 312 | - } |
|
| 313 | - return ($fc); |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * @param $csv_data_array |
|
| 319 | - * @param false $model_name |
|
| 320 | - * @return bool |
|
| 321 | - * @throws EE_Error |
|
| 322 | - */ |
|
| 323 | - public function save_csv_to_db($csv_data_array, $model_name = false) |
|
| 324 | - { |
|
| 325 | - EE_Error::doing_it_wrong( |
|
| 326 | - 'save_csv_to_db', |
|
| 327 | - esc_html__( |
|
| 328 | - 'Function moved to EE_Import and renamed to save_csv_data_array_to_db', |
|
| 329 | - 'event_espresso' |
|
| 330 | - ), |
|
| 331 | - '4.6.7' |
|
| 332 | - ); |
|
| 333 | - return EE_Import::instance()->save_csv_data_array_to_db($csv_data_array, $model_name); |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * Writes the CSV file to the output buffer, with rows corresponding to $model_data_array, |
|
| 339 | - * and dies (in order to avoid other plugins from messing up the csv output) |
|
| 340 | - * |
|
| 341 | - * @param string $filename the filename you want to give the file |
|
| 342 | - * @param array $model_data_array 3d array, as described in EE_CSV::write_model_data_to_csv() |
|
| 343 | - * @return bool | void writes CSV file to output and dies |
|
| 344 | - * @throws EE_Error |
|
| 345 | - * @throws ReflectionException |
|
| 346 | - */ |
|
| 347 | - public function export_multiple_model_data_to_csv($filename, $model_data_array) |
|
| 348 | - { |
|
| 349 | - $file_handle = $this->begin_sending_csv($filename); |
|
| 350 | - $this->write_model_data_to_csv($file_handle, $model_data_array); |
|
| 351 | - $this->end_sending_csv($file_handle); |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * Sends HTTP headers to indicate that the browser should download a file, |
|
| 357 | - * and starts writing the file to PHP's output. Returns the file handle so other functions can |
|
| 358 | - * also write to it |
|
| 359 | - * |
|
| 360 | - * @param string $filename the name of the file that the user will download |
|
| 361 | - * @return resource, like the results of fopen(), which can be used for fwrite, fputcsv2, etc. |
|
| 362 | - */ |
|
| 363 | - public function begin_sending_csv($filename) |
|
| 364 | - { |
|
| 365 | - // grab file extension |
|
| 366 | - $ext = substr(strrchr($filename, '.'), 1); |
|
| 367 | - if ($ext == '.csv' or $ext == '.xls') { |
|
| 368 | - str_replace($ext, '', $filename); |
|
| 369 | - } |
|
| 370 | - $filename .= '.csv'; |
|
| 371 | - |
|
| 372 | - // if somebody's been naughty and already started outputting stuff, trash it |
|
| 373 | - // and start writing our stuff. |
|
| 374 | - if (ob_get_length()) { |
|
| 375 | - @ob_flush(); |
|
| 376 | - @flush(); |
|
| 377 | - @ob_end_flush(); |
|
| 378 | - } |
|
| 379 | - @ob_start(); |
|
| 380 | - header("Pragma: public"); |
|
| 381 | - header("Expires: 0"); |
|
| 382 | - header("Pragma: no-cache"); |
|
| 383 | - header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); |
|
| 384 | - // header("Content-Type: application/force-download"); |
|
| 385 | - // header("Content-Type: application/octet-stream"); |
|
| 386 | - // header("Content-Type: application/download"); |
|
| 387 | - header('Content-disposition: attachment; filename=' . $filename); |
|
| 388 | - header("Content-Type: text/csv; charset=utf-8"); |
|
| 389 | - do_action('AHEE__EE_CSV__begin_sending_csv__headers'); |
|
| 390 | - echo apply_filters( |
|
| 391 | - 'FHEE__EE_CSV__begin_sending_csv__start_writing', |
|
| 392 | - "\xEF\xBB\xBF" |
|
| 393 | - ); // makes excel open it as UTF-8. UTF-8 BOM, see http://stackoverflow.com/a/4440143/2773835 |
|
| 394 | - return fopen('php://output', 'w'); |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * Given an open file, writes all the model data to it in the format the importer expects. |
|
| 400 | - * Usually preceded by begin_sending_csv($filename), and followed by end_sending_csv($file_handle). |
|
| 401 | - * |
|
| 402 | - * @param resource $file_handle |
|
| 403 | - * @param array $model_data_array is assumed to be a 3d array: 1st layer has keys of model names (eg 'Event'), |
|
| 404 | - * next layer is numerically indexed to represent each model object (eg, each |
|
| 405 | - * individual event), and the last layer has all the attributes of that model |
|
| 406 | - * object (eg, the event's id, name, etc) |
|
| 407 | - * @return void |
|
| 408 | - * @throws EE_Error |
|
| 409 | - * @throws ReflectionException |
|
| 410 | - */ |
|
| 411 | - public function write_model_data_to_csv($file_handle, $model_data_array) |
|
| 412 | - { |
|
| 413 | - $this->write_metadata_to_csv($file_handle); |
|
| 414 | - foreach ($model_data_array as $model_name => $model_instance_arrays) { |
|
| 415 | - // first: output a special row stating the model |
|
| 416 | - $this->fputcsv2($file_handle, ['MODEL', $model_name]); |
|
| 417 | - // if we have items to put in the CSV, do it normally |
|
| 418 | - |
|
| 419 | - if (! empty($model_instance_arrays)) { |
|
| 420 | - $this->write_data_array_to_csv($file_handle, $model_instance_arrays); |
|
| 421 | - } else { |
|
| 422 | - // echo "no data to write... so just write the headers"; |
|
| 423 | - // so there's actually NO model objects for that model. |
|
| 424 | - // probably still want to show the columns |
|
| 425 | - $model = EE_Registry::instance()->load_model($model_name); |
|
| 426 | - $column_names = []; |
|
| 427 | - foreach ($model->field_settings() as $field) { |
|
| 428 | - $column_names[ $field->get_nicename() . "[" . $field->get_name() . "]" ] = null; |
|
| 429 | - } |
|
| 430 | - $this->write_data_array_to_csv($file_handle, [$column_names]); |
|
| 431 | - } |
|
| 432 | - } |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - |
|
| 436 | - /** |
|
| 437 | - * Writes some meta data to the CSV as a bunch of columns. Initially we're only |
|
| 438 | - * mentioning the version and timezone |
|
| 439 | - * |
|
| 440 | - * @param resource $file_handle |
|
| 441 | - * @throws EE_Error |
|
| 442 | - * @throws EE_Error |
|
| 443 | - */ |
|
| 444 | - public function write_metadata_to_csv($file_handle) |
|
| 445 | - { |
|
| 446 | - $data_row = [EE_CSV::metadata_header];// do NOT translate because this exact string is used when importing |
|
| 447 | - $this->fputcsv2($file_handle, $data_row); |
|
| 448 | - $meta_data = [ |
|
| 449 | - 0 => [ |
|
| 450 | - 'version' => espresso_version(), |
|
| 451 | - 'timezone' => EEH_DTT_Helper::get_timezone(), |
|
| 452 | - 'time_of_export' => current_time('mysql'), |
|
| 453 | - 'site_url' => site_url(), |
|
| 454 | - ], |
|
| 455 | - ]; |
|
| 456 | - $this->write_data_array_to_csv($file_handle, $meta_data); |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - |
|
| 460 | - /** |
|
| 461 | - * @Drop in replacement for PHP's fputcsv function - but this one works!!! |
|
| 462 | - * @access private |
|
| 463 | - * @param resource $fh - file handle - what we are writing to |
|
| 464 | - * @param array $row - individual row of csv data |
|
| 465 | - * @param string $delimiter - csv delimiter |
|
| 466 | - * @param string $enclosure - csv enclosure |
|
| 467 | - * @param string $mysql_null - allows php NULL to be overridden with MySQl's insertable NULL value |
|
| 468 | - * @return void |
|
| 469 | - */ |
|
| 470 | - private function fputcsv2($fh, array $row, $delimiter = ',', $enclosure = '"', $mysql_null = false) |
|
| 471 | - { |
|
| 472 | - // Allow user to filter the csv delimiter and enclosure for other countries csv standards |
|
| 473 | - $delimiter = apply_filters('FHEE__EE_CSV__fputcsv2__delimiter', $delimiter); |
|
| 474 | - $enclosure = apply_filters('FHEE__EE_CSV__fputcsv2__enclosure', $enclosure); |
|
| 475 | - |
|
| 476 | - $delimiter_esc = preg_quote($delimiter, '/'); |
|
| 477 | - $enclosure_esc = preg_quote($enclosure, '/'); |
|
| 478 | - |
|
| 479 | - $output = []; |
|
| 480 | - foreach ($row as $field_value) { |
|
| 481 | - if (is_object($field_value) || is_array($field_value)) { |
|
| 482 | - $field_value = serialize($field_value); |
|
| 483 | - } |
|
| 484 | - if ($field_value === null && $mysql_null) { |
|
| 485 | - $output[] = 'NULL'; |
|
| 486 | - continue; |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - $output[] = preg_match("/(?:${delimiter_esc}|${enclosure_esc}|\s)/", $field_value) |
|
| 490 | - ? ($enclosure . str_replace($enclosure, $enclosure . $enclosure, $field_value) . $enclosure) |
|
| 491 | - : $field_value; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - fwrite($fh, join($delimiter, $output) . PHP_EOL); |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - |
|
| 498 | - /** |
|
| 499 | - * Writes $data to the csv file open in $file_handle. uses the array indices of $data for column headers |
|
| 500 | - * |
|
| 501 | - * @param resource $file_handle |
|
| 502 | - * @param array $data 2D array, first numerically-indexed, |
|
| 503 | - * and next-level-down preferably indexed by string |
|
| 504 | - * @return boolean if we successfully wrote to the CSV or not. |
|
| 505 | - * If there's no $data, we consider that a success |
|
| 506 | - * (because we wrote everything there was...nothing) |
|
| 507 | - * @throws EE_Error |
|
| 508 | - * @throws EE_Error |
|
| 509 | - */ |
|
| 510 | - public function write_data_array_to_csv($file_handle, $data) |
|
| 511 | - { |
|
| 512 | - // determine if $data is actually a 2d array |
|
| 513 | - if ($data && is_array($data) && is_array(EEH_Array::get_one_item_from_array($data))) { |
|
| 514 | - // make sure top level is numerically indexed, |
|
| 515 | - |
|
| 516 | - if (EEH_Array::is_associative_array($data)) { |
|
| 517 | - throw new EE_Error( |
|
| 518 | - sprintf( |
|
| 519 | - esc_html__( |
|
| 520 | - "top-level array must be numerically indexed. Does these look like numbers to you? %s", |
|
| 521 | - "event_espresso" |
|
| 522 | - ), |
|
| 523 | - implode(",", array_keys($data)) |
|
| 524 | - ) |
|
| 525 | - ); |
|
| 526 | - } |
|
| 527 | - $item_in_top_level_array = EEH_Array::get_one_item_from_array($data); |
|
| 528 | - // now, is the last item in the top-level array of $data an associative or numeric array? |
|
| 529 | - if (EEH_Array::is_associative_array($item_in_top_level_array)) { |
|
| 530 | - // its associative, so we want to output its keys as column headers |
|
| 531 | - $keys = array_keys($item_in_top_level_array); |
|
| 532 | - $this->fputcsv2($file_handle, $keys); |
|
| 533 | - } |
|
| 534 | - // start writing data |
|
| 535 | - foreach ($data as $data_row) { |
|
| 536 | - $this->fputcsv2($file_handle, $data_row); |
|
| 537 | - } |
|
| 538 | - return true; |
|
| 539 | - } |
|
| 540 | - // no data TO write... so we can assume that's a success |
|
| 541 | - return true; |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - |
|
| 545 | - /** |
|
| 546 | - * Should be called after begin_sending_csv(), and one or more write_data_array_to_csv()s. |
|
| 547 | - * Calls exit to prevent polluting the CSV file with other junk |
|
| 548 | - * |
|
| 549 | - * @param resource $fh file_handle where we're writing the CSV to |
|
| 550 | - */ |
|
| 551 | - public function end_sending_csv($fh) |
|
| 552 | - { |
|
| 553 | - fclose($fh); |
|
| 554 | - exit(0); |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - |
|
| 558 | - /** |
|
| 559 | - * @Export contents of an array to csv file |
|
| 560 | - * @access public |
|
| 561 | - * @param array $data - the array of data to be converted to csv and exported |
|
| 562 | - * @param string $filename - name for newly created csv file |
|
| 563 | - * @return bool TRUE on success, FALSE on fail |
|
| 564 | - */ |
|
| 565 | - public function export_array_to_csv($data = false, $filename = false) |
|
| 566 | - { |
|
| 567 | - // no data file?? get outta here |
|
| 568 | - if (! $data or ! is_array($data) or empty($data)) { |
|
| 569 | - return false; |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - // no filename?? get outta here |
|
| 573 | - if (! $filename) { |
|
| 574 | - return false; |
|
| 575 | - } |
|
| 576 | - $fh = $this->begin_sending_csv($filename); |
|
| 577 | - $this->end_sending_csv($fh); |
|
| 578 | - return true; |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - |
|
| 582 | - /** |
|
| 583 | - * @Determine the maximum upload file size based on php.ini settings |
|
| 584 | - * @access public |
|
| 585 | - * @param int $percent_of_max - desired percentage of the max upload_mb |
|
| 586 | - * @return int KB |
|
| 587 | - */ |
|
| 588 | - public function get_max_upload_size($percent_of_max = false) |
|
| 589 | - { |
|
| 590 | - $max_upload = (int) (ini_get('upload_max_filesize')); |
|
| 591 | - $max_post = (int) (ini_get('post_max_size')); |
|
| 592 | - $memory_limit = (int) (ini_get('memory_limit')); |
|
| 593 | - |
|
| 594 | - // determine the smallest of the three values from above |
|
| 595 | - $upload_mb = min($max_upload, $max_post, $memory_limit); |
|
| 596 | - |
|
| 597 | - // convert MB to KB |
|
| 598 | - $upload_mb = $upload_mb * 1024; |
|
| 599 | - |
|
| 600 | - // don't want the full monty? then reduce the max upload size |
|
| 601 | - if ($percent_of_max) { |
|
| 602 | - // is percent_of_max like this -> 50 or like this -> 0.50 ? |
|
| 603 | - if ($percent_of_max > 1) { |
|
| 604 | - // changes 50 to 0.50 |
|
| 605 | - $percent_of_max = $percent_of_max / 100; |
|
| 606 | - } |
|
| 607 | - // make upload_mb a percentage of the max upload_mb |
|
| 608 | - $upload_mb = $upload_mb * $percent_of_max; |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - return $upload_mb; |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - |
|
| 615 | - /** |
|
| 616 | - * Gets the date format to use in teh csv. filterable |
|
| 617 | - * |
|
| 618 | - * @param string $current_format |
|
| 619 | - * @return string |
|
| 620 | - */ |
|
| 621 | - public function get_date_format_for_csv($current_format = null) |
|
| 622 | - { |
|
| 623 | - return apply_filters('FHEE__EE_CSV__get_date_format_for_csv__format', 'Y-m-d', $current_format); |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - |
|
| 627 | - /** |
|
| 628 | - * Gets the time format we want to use in CSV reports. Filterable |
|
| 629 | - * |
|
| 630 | - * @param string $current_format |
|
| 631 | - * @return string |
|
| 632 | - */ |
|
| 633 | - public function get_time_format_for_csv($current_format = null) |
|
| 634 | - { |
|
| 635 | - return apply_filters('FHEE__EE_CSV__get_time_format_for_csv__format', 'H:i:s', $current_format); |
|
| 636 | - } |
|
| 16 | + /** |
|
| 17 | + * string used for 1st cell in exports, |
|
| 18 | + * which indicates that the following 2 rows will be metadata keys and values |
|
| 19 | + */ |
|
| 20 | + const metadata_header = 'Event Espresso Export Meta Data'; |
|
| 21 | + |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * instance of the EE_CSV object |
|
| 25 | + * |
|
| 26 | + * @var EE_CSV |
|
| 27 | + */ |
|
| 28 | + private static $_instance; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var array |
|
| 32 | + */ |
|
| 33 | + private $_primary_keys; |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * private constructor to prevent direct creation |
|
| 38 | + * |
|
| 39 | + * @return void |
|
| 40 | + */ |
|
| 41 | + private function __construct() |
|
| 42 | + { |
|
| 43 | + global $wpdb; |
|
| 44 | + |
|
| 45 | + $this->_primary_keys = [ |
|
| 46 | + $wpdb->prefix . 'esp_answer' => ['ANS_ID'], |
|
| 47 | + $wpdb->prefix . 'esp_attendee' => ['ATT_ID'], |
|
| 48 | + $wpdb->prefix . 'esp_datetime' => ['DTT_ID'], |
|
| 49 | + $wpdb->prefix . 'esp_event_question_group' => ['EQG_ID'], |
|
| 50 | + $wpdb->prefix . 'esp_message_template' => ['MTP_ID'], |
|
| 51 | + $wpdb->prefix . 'esp_payment' => ['PAY_ID'], |
|
| 52 | + $wpdb->prefix . 'esp_price' => ['PRC_ID'], |
|
| 53 | + $wpdb->prefix . 'esp_price_type' => ['PRT_ID'], |
|
| 54 | + $wpdb->prefix . 'esp_question' => ['QST_ID'], |
|
| 55 | + $wpdb->prefix . 'esp_question_group' => ['QSG_ID'], |
|
| 56 | + $wpdb->prefix . 'esp_question_group_question' => ['QGQ_ID'], |
|
| 57 | + $wpdb->prefix . 'esp_question_option' => ['QSO_ID'], |
|
| 58 | + $wpdb->prefix . 'esp_registration' => ['REG_ID'], |
|
| 59 | + $wpdb->prefix . 'esp_status' => ['STS_ID'], |
|
| 60 | + $wpdb->prefix . 'esp_transaction' => ['TXN_ID'], |
|
| 61 | + $wpdb->prefix . 'esp_transaction' => ['TXN_ID'], |
|
| 62 | + $wpdb->prefix . 'events_detail' => ['id'], |
|
| 63 | + $wpdb->prefix . 'events_category_detail' => ['id'], |
|
| 64 | + $wpdb->prefix . 'events_category_rel' => ['id'], |
|
| 65 | + $wpdb->prefix . 'events_venue' => ['id'], |
|
| 66 | + $wpdb->prefix . 'events_venue_rel' => ['emeta_id'], |
|
| 67 | + $wpdb->prefix . 'events_locale' => ['id'], |
|
| 68 | + $wpdb->prefix . 'events_locale_rel' => ['id'], |
|
| 69 | + $wpdb->prefix . 'events_personnel' => ['id'], |
|
| 70 | + $wpdb->prefix . 'events_personnel_rel' => ['id'], |
|
| 71 | + ]; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @ singleton method used to instantiate class object |
|
| 77 | + * @ access public |
|
| 78 | + * |
|
| 79 | + * @return EE_CSV |
|
| 80 | + */ |
|
| 81 | + public static function instance() |
|
| 82 | + { |
|
| 83 | + // check if class object is instantiated |
|
| 84 | + if (! self::$_instance instanceof EE_CSV) { |
|
| 85 | + self::$_instance = new self(); |
|
| 86 | + } |
|
| 87 | + return self::$_instance; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @Import contents of csv file and store values in an array to be manipulated by other functions |
|
| 93 | + * @access public |
|
| 94 | + * @param string $path_to_file - the csv file to be imported including the path to it's location. |
|
| 95 | + * If $model_name is provided, assumes that each row in the CSV represents a |
|
| 96 | + * model object for that model If $model_name ISN'T provided, assumes that |
|
| 97 | + * before model object data, there is a row where the first entry is simply |
|
| 98 | + * 'MODEL', and next entry is the model's name, (untranslated) like Event, and |
|
| 99 | + * then maybe a row of headers, and then the model data. Eg. |
|
| 100 | + * '<br>MODEL,Event,<br>EVT_ID,EVT_name,...<br>1,Monkey |
|
| 101 | + * Party,...<br>2,Llamarama,...<br>MODEL,Venue,<br>VNU_ID,VNU_name<br>1,The |
|
| 102 | + * Forest |
|
| 103 | + * @param string $model_name model name if we know what model we're importing |
|
| 104 | + * @param boolean $first_row_is_headers - whether the first row of data is headers or not - TRUE = headers, FALSE = |
|
| 105 | + * data |
|
| 106 | + * @return mixed - array on success - multi dimensional with headers as keys (if headers exist) OR string on fail - |
|
| 107 | + * error message like the following array('Event'=>array( |
|
| 108 | + * array('EVT_ID'=>1,'EVT_name'=>'bob party',...), |
|
| 109 | + * array('EVT_ID'=>2,'EVT_name'=>'llamarama',...), |
|
| 110 | + * ... |
|
| 111 | + * ) |
|
| 112 | + * 'Venue'=>array( |
|
| 113 | + * array('VNU_ID'=>1,'VNU_name'=>'the shack',...), |
|
| 114 | + * array('VNU_ID'=>2,'VNU_name'=>'tree house',...), |
|
| 115 | + * ... |
|
| 116 | + * ) |
|
| 117 | + * ... |
|
| 118 | + * ) |
|
| 119 | + * @throws EE_Error |
|
| 120 | + */ |
|
| 121 | + public function import_csv_to_model_data_array($path_to_file, $model_name = false, $first_row_is_headers = true) |
|
| 122 | + { |
|
| 123 | + $multi_dimensional_array = $this->import_csv_to_multi_dimensional_array($path_to_file); |
|
| 124 | + if (empty($multi_dimensional_array)) { |
|
| 125 | + return false; |
|
| 126 | + } |
|
| 127 | + // gotta start somewhere |
|
| 128 | + $row = 1; |
|
| 129 | + // array to store csv data in |
|
| 130 | + $ee_formatted_data = []; |
|
| 131 | + // array to store headers (column names) |
|
| 132 | + $headers = []; |
|
| 133 | + foreach ($multi_dimensional_array as $data) { |
|
| 134 | + // if first cell is MODEL, then second cell is the MODEL name |
|
| 135 | + if ($data[0] == 'MODEL') { |
|
| 136 | + $model_name = $data[1]; |
|
| 137 | + // don't bother looking for model data in this row. |
|
| 138 | + // The rest of this row should be blank |
|
| 139 | + // AND pretend this is the first row again |
|
| 140 | + $row = 1; |
|
| 141 | + // reset headers |
|
| 142 | + $headers = []; |
|
| 143 | + continue; |
|
| 144 | + } |
|
| 145 | + if (strpos($data[0], EE_CSV::metadata_header) !== false) { |
|
| 146 | + $model_name = EE_CSV::metadata_header; |
|
| 147 | + // store like model data, we just won't try importing it etc. |
|
| 148 | + $row = 1; |
|
| 149 | + continue; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + |
|
| 153 | + // how many columns are there? |
|
| 154 | + $columns = count($data); |
|
| 155 | + |
|
| 156 | + $model_entry = []; |
|
| 157 | + // loop through each column |
|
| 158 | + for ($i = 0; $i < $columns; $i++) { |
|
| 159 | + // replace csv_enclosures with backslashed quotes |
|
| 160 | + $data[ $i ] = str_replace('"""', '\\"', $data[ $i ]); |
|
| 161 | + // do we need to grab the column names? |
|
| 162 | + if ($row === 1) { |
|
| 163 | + if ($first_row_is_headers) { |
|
| 164 | + // store the column names to use for keys |
|
| 165 | + $column_name = $data[ $i ]; |
|
| 166 | + // check it's not blank... sometimes CSV editing programs |
|
| 167 | + // add a bunch of empty columns onto the end... |
|
| 168 | + if (! $column_name) { |
|
| 169 | + continue; |
|
| 170 | + } |
|
| 171 | + $matches = []; |
|
| 172 | + if ($model_name == EE_CSV::metadata_header) { |
|
| 173 | + $headers[ $i ] = $column_name; |
|
| 174 | + } else { |
|
| 175 | + // now get the db table name from it (the part between square brackets) |
|
| 176 | + $success = preg_match('~(.*)\[(.*)\]~', $column_name, $matches); |
|
| 177 | + if (! $success) { |
|
| 178 | + EE_Error::add_error( |
|
| 179 | + sprintf( |
|
| 180 | + esc_html__( |
|
| 181 | + "The column titled %s is invalid for importing. It must be be in the format of 'Nice Name[model_field_name]' in row %s", |
|
| 182 | + "event_espresso" |
|
| 183 | + ), |
|
| 184 | + $column_name, |
|
| 185 | + implode(",", $data) |
|
| 186 | + ), |
|
| 187 | + __FILE__, |
|
| 188 | + __FUNCTION__, |
|
| 189 | + __LINE__ |
|
| 190 | + ); |
|
| 191 | + return false; |
|
| 192 | + } |
|
| 193 | + $headers[ $i ] = $matches[2]; |
|
| 194 | + } |
|
| 195 | + } else { |
|
| 196 | + // no column names means our final array will just use counters for keys |
|
| 197 | + $model_entry[ $headers[ $i ] ] = $data[ $i ]; |
|
| 198 | + $headers[ $i ] = $i; |
|
| 199 | + } |
|
| 200 | + // and we need to store csv data |
|
| 201 | + } else { |
|
| 202 | + // this column isn' ta header, store it if there is a header for it |
|
| 203 | + if (isset($headers[ $i ])) { |
|
| 204 | + $model_entry[ $headers[ $i ] ] = $data[ $i ]; |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + } |
|
| 208 | + // save the row's data IF it's a non-header-row |
|
| 209 | + if (! $first_row_is_headers || $row > 1) { |
|
| 210 | + $ee_formatted_data[ $model_name ][] = $model_entry; |
|
| 211 | + } |
|
| 212 | + // advance to next row |
|
| 213 | + $row++; |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + // delete the uploaded file |
|
| 217 | + unlink($path_to_file); |
|
| 218 | + |
|
| 219 | + // it's good to give back |
|
| 220 | + return $ee_formatted_data; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * Generic CSV-functionality to turn an entire CSV file into a single array that's |
|
| 226 | + * NOT in a specific format to EE. It's just a 2-level array, with top-level arrays |
|
| 227 | + * representing each row in the CSV file, and the second-level arrays being each column in that row |
|
| 228 | + * |
|
| 229 | + * @param string $path_to_file |
|
| 230 | + * @return array of arrays. Top-level array has rows, second-level array has each item |
|
| 231 | + * @throws EE_Error |
|
| 232 | + */ |
|
| 233 | + public function import_csv_to_multi_dimensional_array($path_to_file) |
|
| 234 | + { |
|
| 235 | + // needed to deal with Mac line endings |
|
| 236 | + ini_set('auto_detect_line_endings', true); |
|
| 237 | + // because fgetcsv does not correctly deal with backslashed quotes such as \" |
|
| 238 | + // we'll read the file into a string |
|
| 239 | + $file_contents = $this->read_unicode_file($path_to_file); |
|
| 240 | + // replace backslashed quotes with CSV enclosures |
|
| 241 | + $file_contents = str_replace('\\"', '"""', $file_contents); |
|
| 242 | + // HEY YOU! PUT THAT FILE BACK!!! |
|
| 243 | + file_put_contents($path_to_file, $file_contents); |
|
| 244 | + |
|
| 245 | + if (($file_handle = fopen($path_to_file, "r")) !== false) { |
|
| 246 | + $csv_array = []; |
|
| 247 | + // in PHP 5.3 fgetcsv accepts a 5th parameter, but the pre 5.3 versions |
|
| 248 | + // of fgetcsv choke if passed more than 4 - is that crazy or what? |
|
| 249 | + if (version_compare(PHP_VERSION, '5.3.0') < 0) { |
|
| 250 | + // PHP 5.2- version |
|
| 251 | + // loop through each row of the file |
|
| 252 | + while (($data = fgetcsv($file_handle)) !== false) { |
|
| 253 | + $csv_array[] = $data; |
|
| 254 | + } |
|
| 255 | + } else { |
|
| 256 | + // loop through each row of the file |
|
| 257 | + while (($data = fgetcsv($file_handle)) !== false) { |
|
| 258 | + $csv_array[] = $data; |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | + # Close the File. |
|
| 262 | + fclose($file_handle); |
|
| 263 | + return $csv_array; |
|
| 264 | + } |
|
| 265 | + EE_Error::add_error( |
|
| 266 | + sprintf( |
|
| 267 | + esc_html__( |
|
| 268 | + "An error occurred - the file: %s could not opened.", |
|
| 269 | + "event_espresso" |
|
| 270 | + ), |
|
| 271 | + $path_to_file |
|
| 272 | + ), |
|
| 273 | + __FILE__, |
|
| 274 | + __FUNCTION__, |
|
| 275 | + __LINE__ |
|
| 276 | + ); |
|
| 277 | + return []; |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * Opens a unicode or utf file |
|
| 283 | + * (normal file_get_contents has difficulty reading a unicode file) |
|
| 284 | + * |
|
| 285 | + * @param string $file_path |
|
| 286 | + * @return string |
|
| 287 | + * @throws EE_Error |
|
| 288 | + * @see http://stackoverflow.com/questions/15092764/how-to-read-unicode-text-file-in-php |
|
| 289 | + */ |
|
| 290 | + private function read_unicode_file($file_path) |
|
| 291 | + { |
|
| 292 | + $fc = ""; |
|
| 293 | + $fh = fopen($file_path, "rb"); |
|
| 294 | + if (! $fh) { |
|
| 295 | + throw new EE_Error( |
|
| 296 | + sprintf( |
|
| 297 | + esc_html__("Cannot open file for read: %s<br>\n", 'event_espresso'), |
|
| 298 | + $file_path |
|
| 299 | + ) |
|
| 300 | + ); |
|
| 301 | + } |
|
| 302 | + $file_length = filesize($file_path); |
|
| 303 | + $bc = fread($fh, $file_length); |
|
| 304 | + for ($i = 0; $i < $file_length; $i++) { |
|
| 305 | + $c = substr($bc, $i, 1); |
|
| 306 | + if ((ord($c) != 0) && (ord($c) != 13)) { |
|
| 307 | + $fc = $fc . $c; |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + if ((ord(substr($fc, 0, 1)) == 255) && (ord(substr($fc, 1, 1)) == 254)) { |
|
| 311 | + $fc = substr($fc, 2); |
|
| 312 | + } |
|
| 313 | + return ($fc); |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * @param $csv_data_array |
|
| 319 | + * @param false $model_name |
|
| 320 | + * @return bool |
|
| 321 | + * @throws EE_Error |
|
| 322 | + */ |
|
| 323 | + public function save_csv_to_db($csv_data_array, $model_name = false) |
|
| 324 | + { |
|
| 325 | + EE_Error::doing_it_wrong( |
|
| 326 | + 'save_csv_to_db', |
|
| 327 | + esc_html__( |
|
| 328 | + 'Function moved to EE_Import and renamed to save_csv_data_array_to_db', |
|
| 329 | + 'event_espresso' |
|
| 330 | + ), |
|
| 331 | + '4.6.7' |
|
| 332 | + ); |
|
| 333 | + return EE_Import::instance()->save_csv_data_array_to_db($csv_data_array, $model_name); |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * Writes the CSV file to the output buffer, with rows corresponding to $model_data_array, |
|
| 339 | + * and dies (in order to avoid other plugins from messing up the csv output) |
|
| 340 | + * |
|
| 341 | + * @param string $filename the filename you want to give the file |
|
| 342 | + * @param array $model_data_array 3d array, as described in EE_CSV::write_model_data_to_csv() |
|
| 343 | + * @return bool | void writes CSV file to output and dies |
|
| 344 | + * @throws EE_Error |
|
| 345 | + * @throws ReflectionException |
|
| 346 | + */ |
|
| 347 | + public function export_multiple_model_data_to_csv($filename, $model_data_array) |
|
| 348 | + { |
|
| 349 | + $file_handle = $this->begin_sending_csv($filename); |
|
| 350 | + $this->write_model_data_to_csv($file_handle, $model_data_array); |
|
| 351 | + $this->end_sending_csv($file_handle); |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * Sends HTTP headers to indicate that the browser should download a file, |
|
| 357 | + * and starts writing the file to PHP's output. Returns the file handle so other functions can |
|
| 358 | + * also write to it |
|
| 359 | + * |
|
| 360 | + * @param string $filename the name of the file that the user will download |
|
| 361 | + * @return resource, like the results of fopen(), which can be used for fwrite, fputcsv2, etc. |
|
| 362 | + */ |
|
| 363 | + public function begin_sending_csv($filename) |
|
| 364 | + { |
|
| 365 | + // grab file extension |
|
| 366 | + $ext = substr(strrchr($filename, '.'), 1); |
|
| 367 | + if ($ext == '.csv' or $ext == '.xls') { |
|
| 368 | + str_replace($ext, '', $filename); |
|
| 369 | + } |
|
| 370 | + $filename .= '.csv'; |
|
| 371 | + |
|
| 372 | + // if somebody's been naughty and already started outputting stuff, trash it |
|
| 373 | + // and start writing our stuff. |
|
| 374 | + if (ob_get_length()) { |
|
| 375 | + @ob_flush(); |
|
| 376 | + @flush(); |
|
| 377 | + @ob_end_flush(); |
|
| 378 | + } |
|
| 379 | + @ob_start(); |
|
| 380 | + header("Pragma: public"); |
|
| 381 | + header("Expires: 0"); |
|
| 382 | + header("Pragma: no-cache"); |
|
| 383 | + header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); |
|
| 384 | + // header("Content-Type: application/force-download"); |
|
| 385 | + // header("Content-Type: application/octet-stream"); |
|
| 386 | + // header("Content-Type: application/download"); |
|
| 387 | + header('Content-disposition: attachment; filename=' . $filename); |
|
| 388 | + header("Content-Type: text/csv; charset=utf-8"); |
|
| 389 | + do_action('AHEE__EE_CSV__begin_sending_csv__headers'); |
|
| 390 | + echo apply_filters( |
|
| 391 | + 'FHEE__EE_CSV__begin_sending_csv__start_writing', |
|
| 392 | + "\xEF\xBB\xBF" |
|
| 393 | + ); // makes excel open it as UTF-8. UTF-8 BOM, see http://stackoverflow.com/a/4440143/2773835 |
|
| 394 | + return fopen('php://output', 'w'); |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * Given an open file, writes all the model data to it in the format the importer expects. |
|
| 400 | + * Usually preceded by begin_sending_csv($filename), and followed by end_sending_csv($file_handle). |
|
| 401 | + * |
|
| 402 | + * @param resource $file_handle |
|
| 403 | + * @param array $model_data_array is assumed to be a 3d array: 1st layer has keys of model names (eg 'Event'), |
|
| 404 | + * next layer is numerically indexed to represent each model object (eg, each |
|
| 405 | + * individual event), and the last layer has all the attributes of that model |
|
| 406 | + * object (eg, the event's id, name, etc) |
|
| 407 | + * @return void |
|
| 408 | + * @throws EE_Error |
|
| 409 | + * @throws ReflectionException |
|
| 410 | + */ |
|
| 411 | + public function write_model_data_to_csv($file_handle, $model_data_array) |
|
| 412 | + { |
|
| 413 | + $this->write_metadata_to_csv($file_handle); |
|
| 414 | + foreach ($model_data_array as $model_name => $model_instance_arrays) { |
|
| 415 | + // first: output a special row stating the model |
|
| 416 | + $this->fputcsv2($file_handle, ['MODEL', $model_name]); |
|
| 417 | + // if we have items to put in the CSV, do it normally |
|
| 418 | + |
|
| 419 | + if (! empty($model_instance_arrays)) { |
|
| 420 | + $this->write_data_array_to_csv($file_handle, $model_instance_arrays); |
|
| 421 | + } else { |
|
| 422 | + // echo "no data to write... so just write the headers"; |
|
| 423 | + // so there's actually NO model objects for that model. |
|
| 424 | + // probably still want to show the columns |
|
| 425 | + $model = EE_Registry::instance()->load_model($model_name); |
|
| 426 | + $column_names = []; |
|
| 427 | + foreach ($model->field_settings() as $field) { |
|
| 428 | + $column_names[ $field->get_nicename() . "[" . $field->get_name() . "]" ] = null; |
|
| 429 | + } |
|
| 430 | + $this->write_data_array_to_csv($file_handle, [$column_names]); |
|
| 431 | + } |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + |
|
| 436 | + /** |
|
| 437 | + * Writes some meta data to the CSV as a bunch of columns. Initially we're only |
|
| 438 | + * mentioning the version and timezone |
|
| 439 | + * |
|
| 440 | + * @param resource $file_handle |
|
| 441 | + * @throws EE_Error |
|
| 442 | + * @throws EE_Error |
|
| 443 | + */ |
|
| 444 | + public function write_metadata_to_csv($file_handle) |
|
| 445 | + { |
|
| 446 | + $data_row = [EE_CSV::metadata_header];// do NOT translate because this exact string is used when importing |
|
| 447 | + $this->fputcsv2($file_handle, $data_row); |
|
| 448 | + $meta_data = [ |
|
| 449 | + 0 => [ |
|
| 450 | + 'version' => espresso_version(), |
|
| 451 | + 'timezone' => EEH_DTT_Helper::get_timezone(), |
|
| 452 | + 'time_of_export' => current_time('mysql'), |
|
| 453 | + 'site_url' => site_url(), |
|
| 454 | + ], |
|
| 455 | + ]; |
|
| 456 | + $this->write_data_array_to_csv($file_handle, $meta_data); |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + |
|
| 460 | + /** |
|
| 461 | + * @Drop in replacement for PHP's fputcsv function - but this one works!!! |
|
| 462 | + * @access private |
|
| 463 | + * @param resource $fh - file handle - what we are writing to |
|
| 464 | + * @param array $row - individual row of csv data |
|
| 465 | + * @param string $delimiter - csv delimiter |
|
| 466 | + * @param string $enclosure - csv enclosure |
|
| 467 | + * @param string $mysql_null - allows php NULL to be overridden with MySQl's insertable NULL value |
|
| 468 | + * @return void |
|
| 469 | + */ |
|
| 470 | + private function fputcsv2($fh, array $row, $delimiter = ',', $enclosure = '"', $mysql_null = false) |
|
| 471 | + { |
|
| 472 | + // Allow user to filter the csv delimiter and enclosure for other countries csv standards |
|
| 473 | + $delimiter = apply_filters('FHEE__EE_CSV__fputcsv2__delimiter', $delimiter); |
|
| 474 | + $enclosure = apply_filters('FHEE__EE_CSV__fputcsv2__enclosure', $enclosure); |
|
| 475 | + |
|
| 476 | + $delimiter_esc = preg_quote($delimiter, '/'); |
|
| 477 | + $enclosure_esc = preg_quote($enclosure, '/'); |
|
| 478 | + |
|
| 479 | + $output = []; |
|
| 480 | + foreach ($row as $field_value) { |
|
| 481 | + if (is_object($field_value) || is_array($field_value)) { |
|
| 482 | + $field_value = serialize($field_value); |
|
| 483 | + } |
|
| 484 | + if ($field_value === null && $mysql_null) { |
|
| 485 | + $output[] = 'NULL'; |
|
| 486 | + continue; |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + $output[] = preg_match("/(?:${delimiter_esc}|${enclosure_esc}|\s)/", $field_value) |
|
| 490 | + ? ($enclosure . str_replace($enclosure, $enclosure . $enclosure, $field_value) . $enclosure) |
|
| 491 | + : $field_value; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + fwrite($fh, join($delimiter, $output) . PHP_EOL); |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + |
|
| 498 | + /** |
|
| 499 | + * Writes $data to the csv file open in $file_handle. uses the array indices of $data for column headers |
|
| 500 | + * |
|
| 501 | + * @param resource $file_handle |
|
| 502 | + * @param array $data 2D array, first numerically-indexed, |
|
| 503 | + * and next-level-down preferably indexed by string |
|
| 504 | + * @return boolean if we successfully wrote to the CSV or not. |
|
| 505 | + * If there's no $data, we consider that a success |
|
| 506 | + * (because we wrote everything there was...nothing) |
|
| 507 | + * @throws EE_Error |
|
| 508 | + * @throws EE_Error |
|
| 509 | + */ |
|
| 510 | + public function write_data_array_to_csv($file_handle, $data) |
|
| 511 | + { |
|
| 512 | + // determine if $data is actually a 2d array |
|
| 513 | + if ($data && is_array($data) && is_array(EEH_Array::get_one_item_from_array($data))) { |
|
| 514 | + // make sure top level is numerically indexed, |
|
| 515 | + |
|
| 516 | + if (EEH_Array::is_associative_array($data)) { |
|
| 517 | + throw new EE_Error( |
|
| 518 | + sprintf( |
|
| 519 | + esc_html__( |
|
| 520 | + "top-level array must be numerically indexed. Does these look like numbers to you? %s", |
|
| 521 | + "event_espresso" |
|
| 522 | + ), |
|
| 523 | + implode(",", array_keys($data)) |
|
| 524 | + ) |
|
| 525 | + ); |
|
| 526 | + } |
|
| 527 | + $item_in_top_level_array = EEH_Array::get_one_item_from_array($data); |
|
| 528 | + // now, is the last item in the top-level array of $data an associative or numeric array? |
|
| 529 | + if (EEH_Array::is_associative_array($item_in_top_level_array)) { |
|
| 530 | + // its associative, so we want to output its keys as column headers |
|
| 531 | + $keys = array_keys($item_in_top_level_array); |
|
| 532 | + $this->fputcsv2($file_handle, $keys); |
|
| 533 | + } |
|
| 534 | + // start writing data |
|
| 535 | + foreach ($data as $data_row) { |
|
| 536 | + $this->fputcsv2($file_handle, $data_row); |
|
| 537 | + } |
|
| 538 | + return true; |
|
| 539 | + } |
|
| 540 | + // no data TO write... so we can assume that's a success |
|
| 541 | + return true; |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + |
|
| 545 | + /** |
|
| 546 | + * Should be called after begin_sending_csv(), and one or more write_data_array_to_csv()s. |
|
| 547 | + * Calls exit to prevent polluting the CSV file with other junk |
|
| 548 | + * |
|
| 549 | + * @param resource $fh file_handle where we're writing the CSV to |
|
| 550 | + */ |
|
| 551 | + public function end_sending_csv($fh) |
|
| 552 | + { |
|
| 553 | + fclose($fh); |
|
| 554 | + exit(0); |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + |
|
| 558 | + /** |
|
| 559 | + * @Export contents of an array to csv file |
|
| 560 | + * @access public |
|
| 561 | + * @param array $data - the array of data to be converted to csv and exported |
|
| 562 | + * @param string $filename - name for newly created csv file |
|
| 563 | + * @return bool TRUE on success, FALSE on fail |
|
| 564 | + */ |
|
| 565 | + public function export_array_to_csv($data = false, $filename = false) |
|
| 566 | + { |
|
| 567 | + // no data file?? get outta here |
|
| 568 | + if (! $data or ! is_array($data) or empty($data)) { |
|
| 569 | + return false; |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + // no filename?? get outta here |
|
| 573 | + if (! $filename) { |
|
| 574 | + return false; |
|
| 575 | + } |
|
| 576 | + $fh = $this->begin_sending_csv($filename); |
|
| 577 | + $this->end_sending_csv($fh); |
|
| 578 | + return true; |
|
| 579 | + } |
|
| 580 | + |
|
| 581 | + |
|
| 582 | + /** |
|
| 583 | + * @Determine the maximum upload file size based on php.ini settings |
|
| 584 | + * @access public |
|
| 585 | + * @param int $percent_of_max - desired percentage of the max upload_mb |
|
| 586 | + * @return int KB |
|
| 587 | + */ |
|
| 588 | + public function get_max_upload_size($percent_of_max = false) |
|
| 589 | + { |
|
| 590 | + $max_upload = (int) (ini_get('upload_max_filesize')); |
|
| 591 | + $max_post = (int) (ini_get('post_max_size')); |
|
| 592 | + $memory_limit = (int) (ini_get('memory_limit')); |
|
| 593 | + |
|
| 594 | + // determine the smallest of the three values from above |
|
| 595 | + $upload_mb = min($max_upload, $max_post, $memory_limit); |
|
| 596 | + |
|
| 597 | + // convert MB to KB |
|
| 598 | + $upload_mb = $upload_mb * 1024; |
|
| 599 | + |
|
| 600 | + // don't want the full monty? then reduce the max upload size |
|
| 601 | + if ($percent_of_max) { |
|
| 602 | + // is percent_of_max like this -> 50 or like this -> 0.50 ? |
|
| 603 | + if ($percent_of_max > 1) { |
|
| 604 | + // changes 50 to 0.50 |
|
| 605 | + $percent_of_max = $percent_of_max / 100; |
|
| 606 | + } |
|
| 607 | + // make upload_mb a percentage of the max upload_mb |
|
| 608 | + $upload_mb = $upload_mb * $percent_of_max; |
|
| 609 | + } |
|
| 610 | + |
|
| 611 | + return $upload_mb; |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + |
|
| 615 | + /** |
|
| 616 | + * Gets the date format to use in teh csv. filterable |
|
| 617 | + * |
|
| 618 | + * @param string $current_format |
|
| 619 | + * @return string |
|
| 620 | + */ |
|
| 621 | + public function get_date_format_for_csv($current_format = null) |
|
| 622 | + { |
|
| 623 | + return apply_filters('FHEE__EE_CSV__get_date_format_for_csv__format', 'Y-m-d', $current_format); |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + |
|
| 627 | + /** |
|
| 628 | + * Gets the time format we want to use in CSV reports. Filterable |
|
| 629 | + * |
|
| 630 | + * @param string $current_format |
|
| 631 | + * @return string |
|
| 632 | + */ |
|
| 633 | + public function get_time_format_for_csv($current_format = null) |
|
| 634 | + { |
|
| 635 | + return apply_filters('FHEE__EE_CSV__get_time_format_for_csv__format', 'H:i:s', $current_format); |
|
| 636 | + } |
|
| 637 | 637 | } |
@@ -43,31 +43,31 @@ discard block |
||
| 43 | 43 | global $wpdb; |
| 44 | 44 | |
| 45 | 45 | $this->_primary_keys = [ |
| 46 | - $wpdb->prefix . 'esp_answer' => ['ANS_ID'], |
|
| 47 | - $wpdb->prefix . 'esp_attendee' => ['ATT_ID'], |
|
| 48 | - $wpdb->prefix . 'esp_datetime' => ['DTT_ID'], |
|
| 49 | - $wpdb->prefix . 'esp_event_question_group' => ['EQG_ID'], |
|
| 50 | - $wpdb->prefix . 'esp_message_template' => ['MTP_ID'], |
|
| 51 | - $wpdb->prefix . 'esp_payment' => ['PAY_ID'], |
|
| 52 | - $wpdb->prefix . 'esp_price' => ['PRC_ID'], |
|
| 53 | - $wpdb->prefix . 'esp_price_type' => ['PRT_ID'], |
|
| 54 | - $wpdb->prefix . 'esp_question' => ['QST_ID'], |
|
| 55 | - $wpdb->prefix . 'esp_question_group' => ['QSG_ID'], |
|
| 56 | - $wpdb->prefix . 'esp_question_group_question' => ['QGQ_ID'], |
|
| 57 | - $wpdb->prefix . 'esp_question_option' => ['QSO_ID'], |
|
| 58 | - $wpdb->prefix . 'esp_registration' => ['REG_ID'], |
|
| 59 | - $wpdb->prefix . 'esp_status' => ['STS_ID'], |
|
| 60 | - $wpdb->prefix . 'esp_transaction' => ['TXN_ID'], |
|
| 61 | - $wpdb->prefix . 'esp_transaction' => ['TXN_ID'], |
|
| 62 | - $wpdb->prefix . 'events_detail' => ['id'], |
|
| 63 | - $wpdb->prefix . 'events_category_detail' => ['id'], |
|
| 64 | - $wpdb->prefix . 'events_category_rel' => ['id'], |
|
| 65 | - $wpdb->prefix . 'events_venue' => ['id'], |
|
| 66 | - $wpdb->prefix . 'events_venue_rel' => ['emeta_id'], |
|
| 67 | - $wpdb->prefix . 'events_locale' => ['id'], |
|
| 68 | - $wpdb->prefix . 'events_locale_rel' => ['id'], |
|
| 69 | - $wpdb->prefix . 'events_personnel' => ['id'], |
|
| 70 | - $wpdb->prefix . 'events_personnel_rel' => ['id'], |
|
| 46 | + $wpdb->prefix.'esp_answer' => ['ANS_ID'], |
|
| 47 | + $wpdb->prefix.'esp_attendee' => ['ATT_ID'], |
|
| 48 | + $wpdb->prefix.'esp_datetime' => ['DTT_ID'], |
|
| 49 | + $wpdb->prefix.'esp_event_question_group' => ['EQG_ID'], |
|
| 50 | + $wpdb->prefix.'esp_message_template' => ['MTP_ID'], |
|
| 51 | + $wpdb->prefix.'esp_payment' => ['PAY_ID'], |
|
| 52 | + $wpdb->prefix.'esp_price' => ['PRC_ID'], |
|
| 53 | + $wpdb->prefix.'esp_price_type' => ['PRT_ID'], |
|
| 54 | + $wpdb->prefix.'esp_question' => ['QST_ID'], |
|
| 55 | + $wpdb->prefix.'esp_question_group' => ['QSG_ID'], |
|
| 56 | + $wpdb->prefix.'esp_question_group_question' => ['QGQ_ID'], |
|
| 57 | + $wpdb->prefix.'esp_question_option' => ['QSO_ID'], |
|
| 58 | + $wpdb->prefix.'esp_registration' => ['REG_ID'], |
|
| 59 | + $wpdb->prefix.'esp_status' => ['STS_ID'], |
|
| 60 | + $wpdb->prefix.'esp_transaction' => ['TXN_ID'], |
|
| 61 | + $wpdb->prefix.'esp_transaction' => ['TXN_ID'], |
|
| 62 | + $wpdb->prefix.'events_detail' => ['id'], |
|
| 63 | + $wpdb->prefix.'events_category_detail' => ['id'], |
|
| 64 | + $wpdb->prefix.'events_category_rel' => ['id'], |
|
| 65 | + $wpdb->prefix.'events_venue' => ['id'], |
|
| 66 | + $wpdb->prefix.'events_venue_rel' => ['emeta_id'], |
|
| 67 | + $wpdb->prefix.'events_locale' => ['id'], |
|
| 68 | + $wpdb->prefix.'events_locale_rel' => ['id'], |
|
| 69 | + $wpdb->prefix.'events_personnel' => ['id'], |
|
| 70 | + $wpdb->prefix.'events_personnel_rel' => ['id'], |
|
| 71 | 71 | ]; |
| 72 | 72 | } |
| 73 | 73 | |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | public static function instance() |
| 82 | 82 | { |
| 83 | 83 | // check if class object is instantiated |
| 84 | - if (! self::$_instance instanceof EE_CSV) { |
|
| 84 | + if ( ! self::$_instance instanceof EE_CSV) { |
|
| 85 | 85 | self::$_instance = new self(); |
| 86 | 86 | } |
| 87 | 87 | return self::$_instance; |
@@ -157,24 +157,24 @@ discard block |
||
| 157 | 157 | // loop through each column |
| 158 | 158 | for ($i = 0; $i < $columns; $i++) { |
| 159 | 159 | // replace csv_enclosures with backslashed quotes |
| 160 | - $data[ $i ] = str_replace('"""', '\\"', $data[ $i ]); |
|
| 160 | + $data[$i] = str_replace('"""', '\\"', $data[$i]); |
|
| 161 | 161 | // do we need to grab the column names? |
| 162 | 162 | if ($row === 1) { |
| 163 | 163 | if ($first_row_is_headers) { |
| 164 | 164 | // store the column names to use for keys |
| 165 | - $column_name = $data[ $i ]; |
|
| 165 | + $column_name = $data[$i]; |
|
| 166 | 166 | // check it's not blank... sometimes CSV editing programs |
| 167 | 167 | // add a bunch of empty columns onto the end... |
| 168 | - if (! $column_name) { |
|
| 168 | + if ( ! $column_name) { |
|
| 169 | 169 | continue; |
| 170 | 170 | } |
| 171 | 171 | $matches = []; |
| 172 | 172 | if ($model_name == EE_CSV::metadata_header) { |
| 173 | - $headers[ $i ] = $column_name; |
|
| 173 | + $headers[$i] = $column_name; |
|
| 174 | 174 | } else { |
| 175 | 175 | // now get the db table name from it (the part between square brackets) |
| 176 | 176 | $success = preg_match('~(.*)\[(.*)\]~', $column_name, $matches); |
| 177 | - if (! $success) { |
|
| 177 | + if ( ! $success) { |
|
| 178 | 178 | EE_Error::add_error( |
| 179 | 179 | sprintf( |
| 180 | 180 | esc_html__( |
@@ -190,24 +190,24 @@ discard block |
||
| 190 | 190 | ); |
| 191 | 191 | return false; |
| 192 | 192 | } |
| 193 | - $headers[ $i ] = $matches[2]; |
|
| 193 | + $headers[$i] = $matches[2]; |
|
| 194 | 194 | } |
| 195 | 195 | } else { |
| 196 | 196 | // no column names means our final array will just use counters for keys |
| 197 | - $model_entry[ $headers[ $i ] ] = $data[ $i ]; |
|
| 198 | - $headers[ $i ] = $i; |
|
| 197 | + $model_entry[$headers[$i]] = $data[$i]; |
|
| 198 | + $headers[$i] = $i; |
|
| 199 | 199 | } |
| 200 | 200 | // and we need to store csv data |
| 201 | 201 | } else { |
| 202 | 202 | // this column isn' ta header, store it if there is a header for it |
| 203 | - if (isset($headers[ $i ])) { |
|
| 204 | - $model_entry[ $headers[ $i ] ] = $data[ $i ]; |
|
| 203 | + if (isset($headers[$i])) { |
|
| 204 | + $model_entry[$headers[$i]] = $data[$i]; |
|
| 205 | 205 | } |
| 206 | 206 | } |
| 207 | 207 | } |
| 208 | 208 | // save the row's data IF it's a non-header-row |
| 209 | - if (! $first_row_is_headers || $row > 1) { |
|
| 210 | - $ee_formatted_data[ $model_name ][] = $model_entry; |
|
| 209 | + if ( ! $first_row_is_headers || $row > 1) { |
|
| 210 | + $ee_formatted_data[$model_name][] = $model_entry; |
|
| 211 | 211 | } |
| 212 | 212 | // advance to next row |
| 213 | 213 | $row++; |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | { |
| 292 | 292 | $fc = ""; |
| 293 | 293 | $fh = fopen($file_path, "rb"); |
| 294 | - if (! $fh) { |
|
| 294 | + if ( ! $fh) { |
|
| 295 | 295 | throw new EE_Error( |
| 296 | 296 | sprintf( |
| 297 | 297 | esc_html__("Cannot open file for read: %s<br>\n", 'event_espresso'), |
@@ -304,7 +304,7 @@ discard block |
||
| 304 | 304 | for ($i = 0; $i < $file_length; $i++) { |
| 305 | 305 | $c = substr($bc, $i, 1); |
| 306 | 306 | if ((ord($c) != 0) && (ord($c) != 13)) { |
| 307 | - $fc = $fc . $c; |
|
| 307 | + $fc = $fc.$c; |
|
| 308 | 308 | } |
| 309 | 309 | } |
| 310 | 310 | if ((ord(substr($fc, 0, 1)) == 255) && (ord(substr($fc, 1, 1)) == 254)) { |
@@ -384,7 +384,7 @@ discard block |
||
| 384 | 384 | // header("Content-Type: application/force-download"); |
| 385 | 385 | // header("Content-Type: application/octet-stream"); |
| 386 | 386 | // header("Content-Type: application/download"); |
| 387 | - header('Content-disposition: attachment; filename=' . $filename); |
|
| 387 | + header('Content-disposition: attachment; filename='.$filename); |
|
| 388 | 388 | header("Content-Type: text/csv; charset=utf-8"); |
| 389 | 389 | do_action('AHEE__EE_CSV__begin_sending_csv__headers'); |
| 390 | 390 | echo apply_filters( |
@@ -416,7 +416,7 @@ discard block |
||
| 416 | 416 | $this->fputcsv2($file_handle, ['MODEL', $model_name]); |
| 417 | 417 | // if we have items to put in the CSV, do it normally |
| 418 | 418 | |
| 419 | - if (! empty($model_instance_arrays)) { |
|
| 419 | + if ( ! empty($model_instance_arrays)) { |
|
| 420 | 420 | $this->write_data_array_to_csv($file_handle, $model_instance_arrays); |
| 421 | 421 | } else { |
| 422 | 422 | // echo "no data to write... so just write the headers"; |
@@ -425,7 +425,7 @@ discard block |
||
| 425 | 425 | $model = EE_Registry::instance()->load_model($model_name); |
| 426 | 426 | $column_names = []; |
| 427 | 427 | foreach ($model->field_settings() as $field) { |
| 428 | - $column_names[ $field->get_nicename() . "[" . $field->get_name() . "]" ] = null; |
|
| 428 | + $column_names[$field->get_nicename()."[".$field->get_name()."]"] = null; |
|
| 429 | 429 | } |
| 430 | 430 | $this->write_data_array_to_csv($file_handle, [$column_names]); |
| 431 | 431 | } |
@@ -443,7 +443,7 @@ discard block |
||
| 443 | 443 | */ |
| 444 | 444 | public function write_metadata_to_csv($file_handle) |
| 445 | 445 | { |
| 446 | - $data_row = [EE_CSV::metadata_header];// do NOT translate because this exact string is used when importing |
|
| 446 | + $data_row = [EE_CSV::metadata_header]; // do NOT translate because this exact string is used when importing |
|
| 447 | 447 | $this->fputcsv2($file_handle, $data_row); |
| 448 | 448 | $meta_data = [ |
| 449 | 449 | 0 => [ |
@@ -487,11 +487,11 @@ discard block |
||
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | $output[] = preg_match("/(?:${delimiter_esc}|${enclosure_esc}|\s)/", $field_value) |
| 490 | - ? ($enclosure . str_replace($enclosure, $enclosure . $enclosure, $field_value) . $enclosure) |
|
| 490 | + ? ($enclosure.str_replace($enclosure, $enclosure.$enclosure, $field_value).$enclosure) |
|
| 491 | 491 | : $field_value; |
| 492 | 492 | } |
| 493 | 493 | |
| 494 | - fwrite($fh, join($delimiter, $output) . PHP_EOL); |
|
| 494 | + fwrite($fh, join($delimiter, $output).PHP_EOL); |
|
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | |
@@ -565,12 +565,12 @@ discard block |
||
| 565 | 565 | public function export_array_to_csv($data = false, $filename = false) |
| 566 | 566 | { |
| 567 | 567 | // no data file?? get outta here |
| 568 | - if (! $data or ! is_array($data) or empty($data)) { |
|
| 568 | + if ( ! $data or ! is_array($data) or empty($data)) { |
|
| 569 | 569 | return false; |
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | // no filename?? get outta here |
| 573 | - if (! $filename) { |
|
| 573 | + if ( ! $filename) { |
|
| 574 | 574 | return false; |
| 575 | 575 | } |
| 576 | 576 | $fh = $this->begin_sending_csv($filename); |
@@ -10,136 +10,136 @@ |
||
| 10 | 10 | class EE_Country extends EE_Base_Class |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * @param array $props_n_values |
|
| 15 | - * @return EE_Country|mixed |
|
| 16 | - * @throws EE_Error |
|
| 17 | - * @throws ReflectionException |
|
| 18 | - */ |
|
| 19 | - public static function new_instance($props_n_values = []) |
|
| 20 | - { |
|
| 21 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 22 | - return $has_object ? $has_object : new self($props_n_values); |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @param array $props_n_values |
|
| 28 | - * @return EE_Country |
|
| 29 | - * @throws EE_Error |
|
| 30 | - * @throws ReflectionException |
|
| 31 | - */ |
|
| 32 | - public static function new_instance_from_db($props_n_values = []) |
|
| 33 | - { |
|
| 34 | - return new self($props_n_values, true); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Gets the country name |
|
| 40 | - * |
|
| 41 | - * @return string |
|
| 42 | - * @throws EE_Error |
|
| 43 | - */ |
|
| 44 | - public function name() |
|
| 45 | - { |
|
| 46 | - return $this->get('CNT_name'); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * gets the country's currency code |
|
| 52 | - * |
|
| 53 | - * @return string |
|
| 54 | - * @throws EE_Error |
|
| 55 | - */ |
|
| 56 | - public function currency_code() |
|
| 57 | - { |
|
| 58 | - return $this->get('CNT_cur_code'); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * gets the country's currency sign/symbol |
|
| 64 | - * |
|
| 65 | - * @return string |
|
| 66 | - * @throws EE_Error |
|
| 67 | - */ |
|
| 68 | - public function currency_sign() |
|
| 69 | - { |
|
| 70 | - $CNT_cur_sign = $this->get('CNT_cur_sign'); |
|
| 71 | - return $CNT_cur_sign ? $CNT_cur_sign : ''; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Currency name singular |
|
| 77 | - * |
|
| 78 | - * @return string |
|
| 79 | - * @throws EE_Error |
|
| 80 | - */ |
|
| 81 | - public function currency_name_single() |
|
| 82 | - { |
|
| 83 | - return $this->get('CNT_cur_single'); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Currency name plural |
|
| 89 | - * |
|
| 90 | - * @return string |
|
| 91 | - * @throws EE_Error |
|
| 92 | - */ |
|
| 93 | - public function currency_name_plural() |
|
| 94 | - { |
|
| 95 | - return $this->get('CNT_cur_plural'); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * currency_sign_before - ie: $TRUE or FALSE$ |
|
| 101 | - * |
|
| 102 | - * @return boolean |
|
| 103 | - * @throws EE_Error |
|
| 104 | - */ |
|
| 105 | - public function currency_sign_before() |
|
| 106 | - { |
|
| 107 | - return $this->get('CNT_cur_sign_b4'); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * currency_decimal_places : 2 = 0.00 3 = 0.000 |
|
| 113 | - * |
|
| 114 | - * @return integer |
|
| 115 | - * @throws EE_Error |
|
| 116 | - */ |
|
| 117 | - public function currency_decimal_places() |
|
| 118 | - { |
|
| 119 | - return $this->get('CNT_cur_dec_plc'); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * currency_decimal_mark : (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 125 | - * |
|
| 126 | - * @return string |
|
| 127 | - * @throws EE_Error |
|
| 128 | - */ |
|
| 129 | - public function currency_decimal_mark() |
|
| 130 | - { |
|
| 131 | - return $this->get('CNT_cur_dec_mrk'); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * currency thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 137 | - * |
|
| 138 | - * @return string |
|
| 139 | - * @throws EE_Error |
|
| 140 | - */ |
|
| 141 | - public function currency_thousands_separator() |
|
| 142 | - { |
|
| 143 | - return $this->get('CNT_cur_thsnds'); |
|
| 144 | - } |
|
| 13 | + /** |
|
| 14 | + * @param array $props_n_values |
|
| 15 | + * @return EE_Country|mixed |
|
| 16 | + * @throws EE_Error |
|
| 17 | + * @throws ReflectionException |
|
| 18 | + */ |
|
| 19 | + public static function new_instance($props_n_values = []) |
|
| 20 | + { |
|
| 21 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 22 | + return $has_object ? $has_object : new self($props_n_values); |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @param array $props_n_values |
|
| 28 | + * @return EE_Country |
|
| 29 | + * @throws EE_Error |
|
| 30 | + * @throws ReflectionException |
|
| 31 | + */ |
|
| 32 | + public static function new_instance_from_db($props_n_values = []) |
|
| 33 | + { |
|
| 34 | + return new self($props_n_values, true); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Gets the country name |
|
| 40 | + * |
|
| 41 | + * @return string |
|
| 42 | + * @throws EE_Error |
|
| 43 | + */ |
|
| 44 | + public function name() |
|
| 45 | + { |
|
| 46 | + return $this->get('CNT_name'); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * gets the country's currency code |
|
| 52 | + * |
|
| 53 | + * @return string |
|
| 54 | + * @throws EE_Error |
|
| 55 | + */ |
|
| 56 | + public function currency_code() |
|
| 57 | + { |
|
| 58 | + return $this->get('CNT_cur_code'); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * gets the country's currency sign/symbol |
|
| 64 | + * |
|
| 65 | + * @return string |
|
| 66 | + * @throws EE_Error |
|
| 67 | + */ |
|
| 68 | + public function currency_sign() |
|
| 69 | + { |
|
| 70 | + $CNT_cur_sign = $this->get('CNT_cur_sign'); |
|
| 71 | + return $CNT_cur_sign ? $CNT_cur_sign : ''; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Currency name singular |
|
| 77 | + * |
|
| 78 | + * @return string |
|
| 79 | + * @throws EE_Error |
|
| 80 | + */ |
|
| 81 | + public function currency_name_single() |
|
| 82 | + { |
|
| 83 | + return $this->get('CNT_cur_single'); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Currency name plural |
|
| 89 | + * |
|
| 90 | + * @return string |
|
| 91 | + * @throws EE_Error |
|
| 92 | + */ |
|
| 93 | + public function currency_name_plural() |
|
| 94 | + { |
|
| 95 | + return $this->get('CNT_cur_plural'); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * currency_sign_before - ie: $TRUE or FALSE$ |
|
| 101 | + * |
|
| 102 | + * @return boolean |
|
| 103 | + * @throws EE_Error |
|
| 104 | + */ |
|
| 105 | + public function currency_sign_before() |
|
| 106 | + { |
|
| 107 | + return $this->get('CNT_cur_sign_b4'); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * currency_decimal_places : 2 = 0.00 3 = 0.000 |
|
| 113 | + * |
|
| 114 | + * @return integer |
|
| 115 | + * @throws EE_Error |
|
| 116 | + */ |
|
| 117 | + public function currency_decimal_places() |
|
| 118 | + { |
|
| 119 | + return $this->get('CNT_cur_dec_plc'); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * currency_decimal_mark : (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 125 | + * |
|
| 126 | + * @return string |
|
| 127 | + * @throws EE_Error |
|
| 128 | + */ |
|
| 129 | + public function currency_decimal_mark() |
|
| 130 | + { |
|
| 131 | + return $this->get('CNT_cur_dec_mrk'); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * currency thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 137 | + * |
|
| 138 | + * @return string |
|
| 139 | + * @throws EE_Error |
|
| 140 | + */ |
|
| 141 | + public function currency_thousands_separator() |
|
| 142 | + { |
|
| 143 | + return $this->get('CNT_cur_thsnds'); |
|
| 144 | + } |
|
| 145 | 145 | } |
@@ -12,7 +12,7 @@ |
||
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * @param array $props_n_values |
| 15 | - * @return EE_Country|mixed |
|
| 15 | + * @return EE_Base_Class |
|
| 16 | 16 | * @throws EE_Error |
| 17 | 17 | * @throws ReflectionException |
| 18 | 18 | */ |
@@ -176,7 +176,7 @@ |
||
| 176 | 176 | { |
| 177 | 177 | $model_name_of_related_obj = $this->OBJ_type(); |
| 178 | 178 | $is_model_name = EE_Registry::instance()->is_model_name($model_name_of_related_obj); |
| 179 | - if (! $is_model_name) { |
|
| 179 | + if ( ! $is_model_name) { |
|
| 180 | 180 | return null; |
| 181 | 181 | } |
| 182 | 182 | return $this->get_first_related($model_name_of_related_obj); |
@@ -10,240 +10,240 @@ |
||
| 10 | 10 | class EE_Change_Log extends EE_Base_Class |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * @param array $props_n_values incoming values |
|
| 15 | - * @param string $timezone incoming timezone |
|
| 16 | - * If not set the timezone for the website will be used. |
|
| 17 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 18 | - * date_format and the second value is the time format |
|
| 19 | - * @return EE_Change_Log |
|
| 20 | - * @throws EE_Error |
|
| 21 | - * @throws ReflectionException |
|
| 22 | - */ |
|
| 23 | - public static function new_instance($props_n_values = [], $timezone = '', $date_formats = []) |
|
| 24 | - { |
|
| 25 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 26 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @param array $props_n_values incoming values from the database |
|
| 32 | - * @param string $timezone incoming timezone as set by the model. |
|
| 33 | - * If not set the timezone for the website will be used. |
|
| 34 | - * @return EE_Change_Log |
|
| 35 | - * @throws EE_Error |
|
| 36 | - * @throws ReflectionException |
|
| 37 | - */ |
|
| 38 | - public static function new_instance_from_db($props_n_values = [], $timezone = '') |
|
| 39 | - { |
|
| 40 | - return new self($props_n_values, true, $timezone); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Gets message |
|
| 46 | - * |
|
| 47 | - * @return mixed |
|
| 48 | - * @throws EE_Error |
|
| 49 | - */ |
|
| 50 | - public function message() |
|
| 51 | - { |
|
| 52 | - return $this->get('LOG_message'); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Sets message |
|
| 58 | - * |
|
| 59 | - * @param mixed $message |
|
| 60 | - * @throws EE_Error |
|
| 61 | - * @throws ReflectionException |
|
| 62 | - */ |
|
| 63 | - public function set_message($message) |
|
| 64 | - { |
|
| 65 | - $this->set('LOG_message', $message); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Gets time |
|
| 71 | - * |
|
| 72 | - * @return string |
|
| 73 | - * @throws EE_Error |
|
| 74 | - */ |
|
| 75 | - public function time() |
|
| 76 | - { |
|
| 77 | - return $this->get('LOG_time'); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Sets time |
|
| 83 | - * |
|
| 84 | - * @param string $time |
|
| 85 | - * @throws EE_Error |
|
| 86 | - * @throws ReflectionException |
|
| 87 | - */ |
|
| 88 | - public function set_time($time) |
|
| 89 | - { |
|
| 90 | - $this->set('LOG_time', $time); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * Return the localized log type label. |
|
| 96 | - * |
|
| 97 | - * @return string |
|
| 98 | - * @throws EE_Error |
|
| 99 | - */ |
|
| 100 | - public function log_type_label() |
|
| 101 | - { |
|
| 102 | - return EEM_Change_Log::get_pretty_label_for_type($this->log_type()); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Gets log_type |
|
| 108 | - * |
|
| 109 | - * @return string |
|
| 110 | - * @throws EE_Error |
|
| 111 | - */ |
|
| 112 | - public function log_type() |
|
| 113 | - { |
|
| 114 | - return $this->get('LOG_type'); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Sets log_type |
|
| 120 | - * |
|
| 121 | - * @param string $log_type |
|
| 122 | - * @throws EE_Error |
|
| 123 | - * @throws ReflectionException |
|
| 124 | - */ |
|
| 125 | - public function set_log_type($log_type) |
|
| 126 | - { |
|
| 127 | - $this->set('LOG_type', $log_type); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Gets OBJ_ID (the ID of the item related to this log) |
|
| 133 | - * |
|
| 134 | - * @return mixed |
|
| 135 | - * @throws EE_Error |
|
| 136 | - */ |
|
| 137 | - public function OBJ_ID() |
|
| 138 | - { |
|
| 139 | - return $this->get('OBJ_ID'); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Gets wp_user |
|
| 145 | - * |
|
| 146 | - * @return int |
|
| 147 | - * @throws EE_Error |
|
| 148 | - */ |
|
| 149 | - public function wp_user() |
|
| 150 | - { |
|
| 151 | - return $this->get('LOG_wp_user'); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Sets wp_user |
|
| 157 | - * |
|
| 158 | - * @param int $wp_user_id |
|
| 159 | - * @throws EE_Error |
|
| 160 | - * @throws ReflectionException |
|
| 161 | - */ |
|
| 162 | - public function set_wp_user($wp_user_id) |
|
| 163 | - { |
|
| 164 | - $this->set('LOG_wp_user', $wp_user_id); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Gets the model object attached to this log |
|
| 170 | - * |
|
| 171 | - * @return EE_Base_Class |
|
| 172 | - * @throws EE_Error |
|
| 173 | - * @throws ReflectionException |
|
| 174 | - */ |
|
| 175 | - public function object() |
|
| 176 | - { |
|
| 177 | - $model_name_of_related_obj = $this->OBJ_type(); |
|
| 178 | - $is_model_name = EE_Registry::instance()->is_model_name($model_name_of_related_obj); |
|
| 179 | - if (! $is_model_name) { |
|
| 180 | - return null; |
|
| 181 | - } |
|
| 182 | - return $this->get_first_related($model_name_of_related_obj); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * Gets type of the model object related to this log |
|
| 188 | - * |
|
| 189 | - * @return string |
|
| 190 | - * @throws EE_Error |
|
| 191 | - */ |
|
| 192 | - public function OBJ_type() |
|
| 193 | - { |
|
| 194 | - return $this->get('OBJ_type'); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * Shorthand for setting the OBJ_ID and OBJ_type. Slightly handier than using |
|
| 200 | - * _add_relation_to because you don't have to specify what type of model you're |
|
| 201 | - * associating it with |
|
| 202 | - * |
|
| 203 | - * @param EE_Base_Class $object |
|
| 204 | - * @param boolean $save |
|
| 205 | - * @return bool if $save=true, NULL is $save=false |
|
| 206 | - * @throws EE_Error |
|
| 207 | - * @throws ReflectionException |
|
| 208 | - */ |
|
| 209 | - public function set_object($object, $save = true) |
|
| 210 | - { |
|
| 211 | - if ($object instanceof EE_Base_Class) { |
|
| 212 | - $this->set_OBJ_type($object->get_model()->get_this_model_name()); |
|
| 213 | - $this->set_OBJ_ID($object->ID()); |
|
| 214 | - } else { |
|
| 215 | - $this->set_OBJ_type(null); |
|
| 216 | - $this->set_OBJ_ID(null); |
|
| 217 | - } |
|
| 218 | - if ($save) { |
|
| 219 | - return $this->save(); |
|
| 220 | - } |
|
| 221 | - return null; |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * Sets type |
|
| 227 | - * |
|
| 228 | - * @param string $type |
|
| 229 | - * @throws EE_Error |
|
| 230 | - * @throws ReflectionException |
|
| 231 | - */ |
|
| 232 | - public function set_OBJ_type($type) |
|
| 233 | - { |
|
| 234 | - $this->set('OBJ_type', $type); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * Sets OBJ_ID |
|
| 240 | - * |
|
| 241 | - * @param mixed $OBJ_ID |
|
| 242 | - * @throws EE_Error |
|
| 243 | - * @throws ReflectionException |
|
| 244 | - */ |
|
| 245 | - public function set_OBJ_ID($OBJ_ID) |
|
| 246 | - { |
|
| 247 | - $this->set('OBJ_ID', $OBJ_ID); |
|
| 248 | - } |
|
| 13 | + /** |
|
| 14 | + * @param array $props_n_values incoming values |
|
| 15 | + * @param string $timezone incoming timezone |
|
| 16 | + * If not set the timezone for the website will be used. |
|
| 17 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 18 | + * date_format and the second value is the time format |
|
| 19 | + * @return EE_Change_Log |
|
| 20 | + * @throws EE_Error |
|
| 21 | + * @throws ReflectionException |
|
| 22 | + */ |
|
| 23 | + public static function new_instance($props_n_values = [], $timezone = '', $date_formats = []) |
|
| 24 | + { |
|
| 25 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 26 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @param array $props_n_values incoming values from the database |
|
| 32 | + * @param string $timezone incoming timezone as set by the model. |
|
| 33 | + * If not set the timezone for the website will be used. |
|
| 34 | + * @return EE_Change_Log |
|
| 35 | + * @throws EE_Error |
|
| 36 | + * @throws ReflectionException |
|
| 37 | + */ |
|
| 38 | + public static function new_instance_from_db($props_n_values = [], $timezone = '') |
|
| 39 | + { |
|
| 40 | + return new self($props_n_values, true, $timezone); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Gets message |
|
| 46 | + * |
|
| 47 | + * @return mixed |
|
| 48 | + * @throws EE_Error |
|
| 49 | + */ |
|
| 50 | + public function message() |
|
| 51 | + { |
|
| 52 | + return $this->get('LOG_message'); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Sets message |
|
| 58 | + * |
|
| 59 | + * @param mixed $message |
|
| 60 | + * @throws EE_Error |
|
| 61 | + * @throws ReflectionException |
|
| 62 | + */ |
|
| 63 | + public function set_message($message) |
|
| 64 | + { |
|
| 65 | + $this->set('LOG_message', $message); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Gets time |
|
| 71 | + * |
|
| 72 | + * @return string |
|
| 73 | + * @throws EE_Error |
|
| 74 | + */ |
|
| 75 | + public function time() |
|
| 76 | + { |
|
| 77 | + return $this->get('LOG_time'); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Sets time |
|
| 83 | + * |
|
| 84 | + * @param string $time |
|
| 85 | + * @throws EE_Error |
|
| 86 | + * @throws ReflectionException |
|
| 87 | + */ |
|
| 88 | + public function set_time($time) |
|
| 89 | + { |
|
| 90 | + $this->set('LOG_time', $time); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * Return the localized log type label. |
|
| 96 | + * |
|
| 97 | + * @return string |
|
| 98 | + * @throws EE_Error |
|
| 99 | + */ |
|
| 100 | + public function log_type_label() |
|
| 101 | + { |
|
| 102 | + return EEM_Change_Log::get_pretty_label_for_type($this->log_type()); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Gets log_type |
|
| 108 | + * |
|
| 109 | + * @return string |
|
| 110 | + * @throws EE_Error |
|
| 111 | + */ |
|
| 112 | + public function log_type() |
|
| 113 | + { |
|
| 114 | + return $this->get('LOG_type'); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Sets log_type |
|
| 120 | + * |
|
| 121 | + * @param string $log_type |
|
| 122 | + * @throws EE_Error |
|
| 123 | + * @throws ReflectionException |
|
| 124 | + */ |
|
| 125 | + public function set_log_type($log_type) |
|
| 126 | + { |
|
| 127 | + $this->set('LOG_type', $log_type); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * Gets OBJ_ID (the ID of the item related to this log) |
|
| 133 | + * |
|
| 134 | + * @return mixed |
|
| 135 | + * @throws EE_Error |
|
| 136 | + */ |
|
| 137 | + public function OBJ_ID() |
|
| 138 | + { |
|
| 139 | + return $this->get('OBJ_ID'); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Gets wp_user |
|
| 145 | + * |
|
| 146 | + * @return int |
|
| 147 | + * @throws EE_Error |
|
| 148 | + */ |
|
| 149 | + public function wp_user() |
|
| 150 | + { |
|
| 151 | + return $this->get('LOG_wp_user'); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Sets wp_user |
|
| 157 | + * |
|
| 158 | + * @param int $wp_user_id |
|
| 159 | + * @throws EE_Error |
|
| 160 | + * @throws ReflectionException |
|
| 161 | + */ |
|
| 162 | + public function set_wp_user($wp_user_id) |
|
| 163 | + { |
|
| 164 | + $this->set('LOG_wp_user', $wp_user_id); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Gets the model object attached to this log |
|
| 170 | + * |
|
| 171 | + * @return EE_Base_Class |
|
| 172 | + * @throws EE_Error |
|
| 173 | + * @throws ReflectionException |
|
| 174 | + */ |
|
| 175 | + public function object() |
|
| 176 | + { |
|
| 177 | + $model_name_of_related_obj = $this->OBJ_type(); |
|
| 178 | + $is_model_name = EE_Registry::instance()->is_model_name($model_name_of_related_obj); |
|
| 179 | + if (! $is_model_name) { |
|
| 180 | + return null; |
|
| 181 | + } |
|
| 182 | + return $this->get_first_related($model_name_of_related_obj); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * Gets type of the model object related to this log |
|
| 188 | + * |
|
| 189 | + * @return string |
|
| 190 | + * @throws EE_Error |
|
| 191 | + */ |
|
| 192 | + public function OBJ_type() |
|
| 193 | + { |
|
| 194 | + return $this->get('OBJ_type'); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * Shorthand for setting the OBJ_ID and OBJ_type. Slightly handier than using |
|
| 200 | + * _add_relation_to because you don't have to specify what type of model you're |
|
| 201 | + * associating it with |
|
| 202 | + * |
|
| 203 | + * @param EE_Base_Class $object |
|
| 204 | + * @param boolean $save |
|
| 205 | + * @return bool if $save=true, NULL is $save=false |
|
| 206 | + * @throws EE_Error |
|
| 207 | + * @throws ReflectionException |
|
| 208 | + */ |
|
| 209 | + public function set_object($object, $save = true) |
|
| 210 | + { |
|
| 211 | + if ($object instanceof EE_Base_Class) { |
|
| 212 | + $this->set_OBJ_type($object->get_model()->get_this_model_name()); |
|
| 213 | + $this->set_OBJ_ID($object->ID()); |
|
| 214 | + } else { |
|
| 215 | + $this->set_OBJ_type(null); |
|
| 216 | + $this->set_OBJ_ID(null); |
|
| 217 | + } |
|
| 218 | + if ($save) { |
|
| 219 | + return $this->save(); |
|
| 220 | + } |
|
| 221 | + return null; |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * Sets type |
|
| 227 | + * |
|
| 228 | + * @param string $type |
|
| 229 | + * @throws EE_Error |
|
| 230 | + * @throws ReflectionException |
|
| 231 | + */ |
|
| 232 | + public function set_OBJ_type($type) |
|
| 233 | + { |
|
| 234 | + $this->set('OBJ_type', $type); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * Sets OBJ_ID |
|
| 240 | + * |
|
| 241 | + * @param mixed $OBJ_ID |
|
| 242 | + * @throws EE_Error |
|
| 243 | + * @throws ReflectionException |
|
| 244 | + */ |
|
| 245 | + public function set_OBJ_ID($OBJ_ID) |
|
| 246 | + { |
|
| 247 | + $this->set('OBJ_ID', $OBJ_ID); |
|
| 248 | + } |
|
| 249 | 249 | } |
@@ -44,7 +44,7 @@ |
||
| 44 | 44 | * @param array $props_n_values incoming values from the database |
| 45 | 45 | * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
| 46 | 46 | * the website will be used. |
| 47 | - * @return EE_Attendee |
|
| 47 | + * @return EE_Currency_Payment_Method |
|
| 48 | 48 | */ |
| 49 | 49 | public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
| 50 | 50 | { |
@@ -14,40 +14,40 @@ |
||
| 14 | 14 | class EE_Currency_Payment_Method extends EE_Base_Class |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** Currency to Payment Method Link ID @var CPM_ID */ |
|
| 18 | - protected $_CPM_ID = null; |
|
| 19 | - /** Currency Code @var CUR_code */ |
|
| 20 | - protected $_CUR_code = null; |
|
| 21 | - /** Payment Method ID @var PMD_ID */ |
|
| 22 | - protected $_PMD_ID = null; |
|
| 23 | - protected $_Payment_Method; |
|
| 24 | - protected $_Currency; |
|
| 17 | + /** Currency to Payment Method Link ID @var CPM_ID */ |
|
| 18 | + protected $_CPM_ID = null; |
|
| 19 | + /** Currency Code @var CUR_code */ |
|
| 20 | + protected $_CUR_code = null; |
|
| 21 | + /** Payment Method ID @var PMD_ID */ |
|
| 22 | + protected $_PMD_ID = null; |
|
| 23 | + protected $_Payment_Method; |
|
| 24 | + protected $_Currency; |
|
| 25 | 25 | |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * |
|
| 29 | - * @param array $props_n_values incoming values |
|
| 30 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 31 | - * used.) |
|
| 32 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 33 | - * date_format and the second value is the time format |
|
| 34 | - * @return EE_Attendee |
|
| 35 | - */ |
|
| 36 | - public static function new_instance($props_n_values = array(), $timezone = '', $date_formats = array()) |
|
| 37 | - { |
|
| 38 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 39 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 40 | - } |
|
| 27 | + /** |
|
| 28 | + * |
|
| 29 | + * @param array $props_n_values incoming values |
|
| 30 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 31 | + * used.) |
|
| 32 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 33 | + * date_format and the second value is the time format |
|
| 34 | + * @return EE_Attendee |
|
| 35 | + */ |
|
| 36 | + public static function new_instance($props_n_values = array(), $timezone = '', $date_formats = array()) |
|
| 37 | + { |
|
| 38 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 39 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @param array $props_n_values incoming values from the database |
|
| 45 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 46 | - * the website will be used. |
|
| 47 | - * @return EE_Attendee |
|
| 48 | - */ |
|
| 49 | - public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
| 50 | - { |
|
| 51 | - return new self($props_n_values, true, $timezone); |
|
| 52 | - } |
|
| 43 | + /** |
|
| 44 | + * @param array $props_n_values incoming values from the database |
|
| 45 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 46 | + * the website will be used. |
|
| 47 | + * @return EE_Attendee |
|
| 48 | + */ |
|
| 49 | + public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
| 50 | + { |
|
| 51 | + return new self($props_n_values, true, $timezone); |
|
| 52 | + } |
|
| 53 | 53 | } |
@@ -30,7 +30,7 @@ |
||
| 30 | 30 | * @param array $props_n_values incoming values from the database |
| 31 | 31 | * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
| 32 | 32 | * the website will be used. |
| 33 | - * @return EE_Attendee |
|
| 33 | + * @return EE_Datetime_Ticket |
|
| 34 | 34 | */ |
| 35 | 35 | public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
| 36 | 36 | { |
@@ -10,30 +10,30 @@ |
||
| 10 | 10 | class EE_Datetime_Ticket extends EE_Base_Class |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * |
|
| 15 | - * @param array $props_n_values incoming values |
|
| 16 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 17 | - * used.) |
|
| 18 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 19 | - * date_format and the second value is the time format |
|
| 20 | - * @return EE_Attendee |
|
| 21 | - */ |
|
| 22 | - public static function new_instance($props_n_values = array(), $timezone = '', $date_formats = array()) |
|
| 23 | - { |
|
| 24 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 25 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 26 | - } |
|
| 13 | + /** |
|
| 14 | + * |
|
| 15 | + * @param array $props_n_values incoming values |
|
| 16 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 17 | + * used.) |
|
| 18 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 19 | + * date_format and the second value is the time format |
|
| 20 | + * @return EE_Attendee |
|
| 21 | + */ |
|
| 22 | + public static function new_instance($props_n_values = array(), $timezone = '', $date_formats = array()) |
|
| 23 | + { |
|
| 24 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 25 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @param array $props_n_values incoming values from the database |
|
| 31 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 32 | - * the website will be used. |
|
| 33 | - * @return EE_Attendee |
|
| 34 | - */ |
|
| 35 | - public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
| 36 | - { |
|
| 37 | - return new self($props_n_values, true, $timezone); |
|
| 38 | - } |
|
| 29 | + /** |
|
| 30 | + * @param array $props_n_values incoming values from the database |
|
| 31 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 32 | + * the website will be used. |
|
| 33 | + * @return EE_Attendee |
|
| 34 | + */ |
|
| 35 | + public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
| 36 | + { |
|
| 37 | + return new self($props_n_values, true, $timezone); |
|
| 38 | + } |
|
| 39 | 39 | } |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * @param array $props_n_values incoming values from the database |
| 40 | 40 | * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
| 41 | 41 | * the website will be used. |
| 42 | - * @return EE_Attendee |
|
| 42 | + * @return EE_Question_Option |
|
| 43 | 43 | */ |
| 44 | 44 | public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
| 45 | 45 | { |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * Sets the option's key value |
| 52 | 52 | * |
| 53 | 53 | * @param string $value |
| 54 | - * @return bool success |
|
| 54 | + * @return boolean|null success |
|
| 55 | 55 | */ |
| 56 | 56 | public function set_value($value) |
| 57 | 57 | { |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | * Sets the option's Display Text |
| 64 | 64 | * |
| 65 | 65 | * @param string $text |
| 66 | - * @return bool success |
|
| 66 | + * @return boolean|null success |
|
| 67 | 67 | */ |
| 68 | 68 | public function set_desc($text) |
| 69 | 69 | { |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * |
| 77 | 77 | * @access public |
| 78 | 78 | * @param integer $order |
| 79 | - * @return bool $success |
|
| 79 | + * @return boolean|null $success |
|
| 80 | 80 | */ |
| 81 | 81 | public function set_order($order) |
| 82 | 82 | { |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | * Sets the ID of the related question |
| 89 | 89 | * |
| 90 | 90 | * @param int $question_ID |
| 91 | - * @return bool success |
|
| 91 | + * @return boolean|null success |
|
| 92 | 92 | */ |
| 93 | 93 | public function set_question_ID($question_ID) |
| 94 | 94 | { |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | * Sets the option's opt_group |
| 101 | 101 | * |
| 102 | 102 | * @param string $text |
| 103 | - * @return bool success |
|
| 103 | + * @return string success |
|
| 104 | 104 | */ |
| 105 | 105 | public function set_opt_group($text) |
| 106 | 106 | { |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | * Sets QSO_system |
| 223 | 223 | * |
| 224 | 224 | * @param string $QSO_system |
| 225 | - * @return bool |
|
| 225 | + * @return boolean|null |
|
| 226 | 226 | */ |
| 227 | 227 | public function set_system($QSO_system) |
| 228 | 228 | { |
@@ -10,222 +10,222 @@ |
||
| 10 | 10 | class EE_Question_Option extends EE_Soft_Delete_Base_Class implements EEI_Duplicatable |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * Question Option Opt Group Name |
|
| 15 | - * |
|
| 16 | - * @access protected |
|
| 17 | - * @var string |
|
| 18 | - */ |
|
| 19 | - protected $_QSO_opt_group = null; |
|
| 20 | - |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * |
|
| 24 | - * @param array $props_n_values incoming values |
|
| 25 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 26 | - * used.) |
|
| 27 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 28 | - * date_format and the second value is the time format |
|
| 29 | - * @return EE_Attendee |
|
| 30 | - */ |
|
| 31 | - public static function new_instance($props_n_values = array(), $timezone = '', $date_formats = array()) |
|
| 32 | - { |
|
| 33 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 34 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @param array $props_n_values incoming values from the database |
|
| 40 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 41 | - * the website will be used. |
|
| 42 | - * @return EE_Attendee |
|
| 43 | - */ |
|
| 44 | - public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
| 45 | - { |
|
| 46 | - return new self($props_n_values, true, $timezone); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Sets the option's key value |
|
| 52 | - * |
|
| 53 | - * @param string $value |
|
| 54 | - * @return bool success |
|
| 55 | - */ |
|
| 56 | - public function set_value($value) |
|
| 57 | - { |
|
| 58 | - $this->set('QSO_value', $value); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Sets the option's Display Text |
|
| 64 | - * |
|
| 65 | - * @param string $text |
|
| 66 | - * @return bool success |
|
| 67 | - */ |
|
| 68 | - public function set_desc($text) |
|
| 69 | - { |
|
| 70 | - $this->set('QSO_desc', $text); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Sets the order for this option |
|
| 76 | - * |
|
| 77 | - * @access public |
|
| 78 | - * @param integer $order |
|
| 79 | - * @return bool $success |
|
| 80 | - */ |
|
| 81 | - public function set_order($order) |
|
| 82 | - { |
|
| 83 | - $this->set('QSO_order', $order); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Sets the ID of the related question |
|
| 89 | - * |
|
| 90 | - * @param int $question_ID |
|
| 91 | - * @return bool success |
|
| 92 | - */ |
|
| 93 | - public function set_question_ID($question_ID) |
|
| 94 | - { |
|
| 95 | - $this->set('QST_ID', $question_ID); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Sets the option's opt_group |
|
| 101 | - * |
|
| 102 | - * @param string $text |
|
| 103 | - * @return bool success |
|
| 104 | - */ |
|
| 105 | - public function set_opt_group($text) |
|
| 106 | - { |
|
| 107 | - return $this->_QSO_opt_group = $text; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Gets the option's key value |
|
| 113 | - * |
|
| 114 | - * @return string |
|
| 115 | - */ |
|
| 116 | - public function value() |
|
| 117 | - { |
|
| 118 | - return $this->get('QSO_value'); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Gets the option's display text |
|
| 124 | - * |
|
| 125 | - * @return string |
|
| 126 | - */ |
|
| 127 | - public function desc() |
|
| 128 | - { |
|
| 129 | - return $this->get('QSO_desc'); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Returns whether this option has been deleted or not |
|
| 135 | - * |
|
| 136 | - * @return boolean |
|
| 137 | - */ |
|
| 138 | - public function deleted() |
|
| 139 | - { |
|
| 140 | - return $this->get('QSO_deleted'); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Returns the order or the Question Option |
|
| 146 | - * |
|
| 147 | - * @access public |
|
| 148 | - * @return integer |
|
| 149 | - */ |
|
| 150 | - public function order() |
|
| 151 | - { |
|
| 152 | - return $this->get('QSO_option'); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Gets the related question's ID |
|
| 158 | - * |
|
| 159 | - * @return int |
|
| 160 | - */ |
|
| 161 | - public function question_ID() |
|
| 162 | - { |
|
| 163 | - return $this->get('QST_ID'); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Returns the question related to this question option |
|
| 169 | - * |
|
| 170 | - * @return EE_Question |
|
| 171 | - */ |
|
| 172 | - public function question() |
|
| 173 | - { |
|
| 174 | - return $this->get_first_related('Question'); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * Gets the option's opt_group |
|
| 180 | - * |
|
| 181 | - * @return string |
|
| 182 | - */ |
|
| 183 | - public function opt_group() |
|
| 184 | - { |
|
| 185 | - return $this->_QSO_opt_group; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * Duplicates this question option. By default the new question option will be for the same question, |
|
| 190 | - * but that can be overriden by setting the 'QST_ID' option |
|
| 191 | - * |
|
| 192 | - * @param array $options { |
|
| 193 | - * @type int $QST_ID the QST_ID attribute of this question option, otherwise it will be for the same question |
|
| 194 | - * as the original |
|
| 195 | - */ |
|
| 196 | - public function duplicate($options = array()) |
|
| 197 | - { |
|
| 198 | - $new_question_option = clone $this; |
|
| 199 | - $new_question_option->set('QSO_ID', null); |
|
| 200 | - if ( |
|
| 201 | - array_key_exists( |
|
| 202 | - 'QST_ID', |
|
| 203 | - $options |
|
| 204 | - ) |
|
| 205 | - ) {// use array_key_exists instead of isset because NULL might be a valid value |
|
| 206 | - $new_question_option->set_question_ID($options['QST_ID']); |
|
| 207 | - } |
|
| 208 | - $new_question_option->save(); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * Gets the QSO_system value |
|
| 213 | - * |
|
| 214 | - * @return string|null |
|
| 215 | - */ |
|
| 216 | - public function system() |
|
| 217 | - { |
|
| 218 | - return $this->get('QSO_system'); |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * Sets QSO_system |
|
| 223 | - * |
|
| 224 | - * @param string $QSO_system |
|
| 225 | - * @return bool |
|
| 226 | - */ |
|
| 227 | - public function set_system($QSO_system) |
|
| 228 | - { |
|
| 229 | - return $this->set('QSO_system', $QSO_system); |
|
| 230 | - } |
|
| 13 | + /** |
|
| 14 | + * Question Option Opt Group Name |
|
| 15 | + * |
|
| 16 | + * @access protected |
|
| 17 | + * @var string |
|
| 18 | + */ |
|
| 19 | + protected $_QSO_opt_group = null; |
|
| 20 | + |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * |
|
| 24 | + * @param array $props_n_values incoming values |
|
| 25 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 26 | + * used.) |
|
| 27 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 28 | + * date_format and the second value is the time format |
|
| 29 | + * @return EE_Attendee |
|
| 30 | + */ |
|
| 31 | + public static function new_instance($props_n_values = array(), $timezone = '', $date_formats = array()) |
|
| 32 | + { |
|
| 33 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 34 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @param array $props_n_values incoming values from the database |
|
| 40 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 41 | + * the website will be used. |
|
| 42 | + * @return EE_Attendee |
|
| 43 | + */ |
|
| 44 | + public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
| 45 | + { |
|
| 46 | + return new self($props_n_values, true, $timezone); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Sets the option's key value |
|
| 52 | + * |
|
| 53 | + * @param string $value |
|
| 54 | + * @return bool success |
|
| 55 | + */ |
|
| 56 | + public function set_value($value) |
|
| 57 | + { |
|
| 58 | + $this->set('QSO_value', $value); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Sets the option's Display Text |
|
| 64 | + * |
|
| 65 | + * @param string $text |
|
| 66 | + * @return bool success |
|
| 67 | + */ |
|
| 68 | + public function set_desc($text) |
|
| 69 | + { |
|
| 70 | + $this->set('QSO_desc', $text); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Sets the order for this option |
|
| 76 | + * |
|
| 77 | + * @access public |
|
| 78 | + * @param integer $order |
|
| 79 | + * @return bool $success |
|
| 80 | + */ |
|
| 81 | + public function set_order($order) |
|
| 82 | + { |
|
| 83 | + $this->set('QSO_order', $order); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Sets the ID of the related question |
|
| 89 | + * |
|
| 90 | + * @param int $question_ID |
|
| 91 | + * @return bool success |
|
| 92 | + */ |
|
| 93 | + public function set_question_ID($question_ID) |
|
| 94 | + { |
|
| 95 | + $this->set('QST_ID', $question_ID); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Sets the option's opt_group |
|
| 101 | + * |
|
| 102 | + * @param string $text |
|
| 103 | + * @return bool success |
|
| 104 | + */ |
|
| 105 | + public function set_opt_group($text) |
|
| 106 | + { |
|
| 107 | + return $this->_QSO_opt_group = $text; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Gets the option's key value |
|
| 113 | + * |
|
| 114 | + * @return string |
|
| 115 | + */ |
|
| 116 | + public function value() |
|
| 117 | + { |
|
| 118 | + return $this->get('QSO_value'); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Gets the option's display text |
|
| 124 | + * |
|
| 125 | + * @return string |
|
| 126 | + */ |
|
| 127 | + public function desc() |
|
| 128 | + { |
|
| 129 | + return $this->get('QSO_desc'); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Returns whether this option has been deleted or not |
|
| 135 | + * |
|
| 136 | + * @return boolean |
|
| 137 | + */ |
|
| 138 | + public function deleted() |
|
| 139 | + { |
|
| 140 | + return $this->get('QSO_deleted'); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Returns the order or the Question Option |
|
| 146 | + * |
|
| 147 | + * @access public |
|
| 148 | + * @return integer |
|
| 149 | + */ |
|
| 150 | + public function order() |
|
| 151 | + { |
|
| 152 | + return $this->get('QSO_option'); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Gets the related question's ID |
|
| 158 | + * |
|
| 159 | + * @return int |
|
| 160 | + */ |
|
| 161 | + public function question_ID() |
|
| 162 | + { |
|
| 163 | + return $this->get('QST_ID'); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Returns the question related to this question option |
|
| 169 | + * |
|
| 170 | + * @return EE_Question |
|
| 171 | + */ |
|
| 172 | + public function question() |
|
| 173 | + { |
|
| 174 | + return $this->get_first_related('Question'); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * Gets the option's opt_group |
|
| 180 | + * |
|
| 181 | + * @return string |
|
| 182 | + */ |
|
| 183 | + public function opt_group() |
|
| 184 | + { |
|
| 185 | + return $this->_QSO_opt_group; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * Duplicates this question option. By default the new question option will be for the same question, |
|
| 190 | + * but that can be overriden by setting the 'QST_ID' option |
|
| 191 | + * |
|
| 192 | + * @param array $options { |
|
| 193 | + * @type int $QST_ID the QST_ID attribute of this question option, otherwise it will be for the same question |
|
| 194 | + * as the original |
|
| 195 | + */ |
|
| 196 | + public function duplicate($options = array()) |
|
| 197 | + { |
|
| 198 | + $new_question_option = clone $this; |
|
| 199 | + $new_question_option->set('QSO_ID', null); |
|
| 200 | + if ( |
|
| 201 | + array_key_exists( |
|
| 202 | + 'QST_ID', |
|
| 203 | + $options |
|
| 204 | + ) |
|
| 205 | + ) {// use array_key_exists instead of isset because NULL might be a valid value |
|
| 206 | + $new_question_option->set_question_ID($options['QST_ID']); |
|
| 207 | + } |
|
| 208 | + $new_question_option->save(); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * Gets the QSO_system value |
|
| 213 | + * |
|
| 214 | + * @return string|null |
|
| 215 | + */ |
|
| 216 | + public function system() |
|
| 217 | + { |
|
| 218 | + return $this->get('QSO_system'); |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * Sets QSO_system |
|
| 223 | + * |
|
| 224 | + * @param string $QSO_system |
|
| 225 | + * @return bool |
|
| 226 | + */ |
|
| 227 | + public function set_system($QSO_system) |
|
| 228 | + { |
|
| 229 | + return $this->set('QSO_system', $QSO_system); |
|
| 230 | + } |
|
| 231 | 231 | } |