@@ -10,875 +10,875 @@ |
||
| 10 | 10 | class EE_Message extends EE_Base_Class implements EEI_Admin_Links |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * @deprecated 4.9.0 Added for backward compat with add-on's |
|
| 15 | - * @type null |
|
| 16 | - */ |
|
| 17 | - public $template_pack; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * @deprecated 4.9.0 Added for backward compat with add-on's |
|
| 21 | - * @type null |
|
| 22 | - */ |
|
| 23 | - public $template_variation; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @deprecated 4.9.0 Added for backward compat with add-on's |
|
| 27 | - * @type string |
|
| 28 | - */ |
|
| 29 | - public $content = ''; |
|
| 30 | - |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @type EE_messenger $_messenger |
|
| 34 | - */ |
|
| 35 | - protected $_messenger = null; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @type EE_message_type $_message_type |
|
| 39 | - */ |
|
| 40 | - protected $_message_type = null; |
|
| 41 | - |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @param array $props_n_values |
|
| 45 | - * @param string $timezone |
|
| 46 | - * @param array $date_formats incoming date formats in an array. First value is the date_format, second is time |
|
| 47 | - * format. |
|
| 48 | - * @return EE_Message |
|
| 49 | - */ |
|
| 50 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 51 | - { |
|
| 52 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 53 | - // if object doesn't exist, let's generate a unique token on instantiation so that its available even before saving to db. |
|
| 54 | - if (! $has_object) { |
|
| 55 | - EE_Registry::instance()->load_helper('URL'); |
|
| 56 | - $props_n_values['MSG_token'] = EEH_URL::generate_unique_token(); |
|
| 57 | - } |
|
| 58 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @param array $props_n_values |
|
| 64 | - * @param string $timezone |
|
| 65 | - * @return EE_Message |
|
| 66 | - */ |
|
| 67 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 68 | - { |
|
| 69 | - return new self($props_n_values, true, $timezone); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Gets MSG_token |
|
| 75 | - * |
|
| 76 | - * @return int |
|
| 77 | - */ |
|
| 78 | - public function MSG_token() |
|
| 79 | - { |
|
| 80 | - return $this->get('MSG_token'); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * Sets MSG_token |
|
| 86 | - * |
|
| 87 | - * @param int $MSG_token |
|
| 88 | - */ |
|
| 89 | - public function set_MSG_token($MSG_token) |
|
| 90 | - { |
|
| 91 | - $this->set('MSG_token', $MSG_token); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Gets GRP_ID |
|
| 97 | - * |
|
| 98 | - * @return int |
|
| 99 | - */ |
|
| 100 | - public function GRP_ID() |
|
| 101 | - { |
|
| 102 | - return $this->get('GRP_ID'); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Sets GRP_ID |
|
| 108 | - * |
|
| 109 | - * @param int $GRP_ID |
|
| 110 | - */ |
|
| 111 | - public function set_GRP_ID($GRP_ID) |
|
| 112 | - { |
|
| 113 | - $this->set('GRP_ID', $GRP_ID); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Gets TXN_ID |
|
| 119 | - * |
|
| 120 | - * @return int |
|
| 121 | - */ |
|
| 122 | - public function TXN_ID() |
|
| 123 | - { |
|
| 124 | - return $this->get('TXN_ID'); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Sets TXN_ID |
|
| 130 | - * |
|
| 131 | - * @param int $TXN_ID |
|
| 132 | - */ |
|
| 133 | - public function set_TXN_ID($TXN_ID) |
|
| 134 | - { |
|
| 135 | - $this->set('TXN_ID', $TXN_ID); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Gets messenger |
|
| 141 | - * |
|
| 142 | - * @return string |
|
| 143 | - */ |
|
| 144 | - public function messenger() |
|
| 145 | - { |
|
| 146 | - return $this->get('MSG_messenger'); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Sets messenger |
|
| 152 | - * |
|
| 153 | - * @param string $messenger |
|
| 154 | - */ |
|
| 155 | - public function set_messenger($messenger) |
|
| 156 | - { |
|
| 157 | - $this->set('MSG_messenger', $messenger); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * Returns corresponding messenger object for the set messenger on this message |
|
| 163 | - * |
|
| 164 | - * @return EE_messenger | null |
|
| 165 | - */ |
|
| 166 | - public function messenger_object() |
|
| 167 | - { |
|
| 168 | - return $this->_messenger; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * Sets messenger |
|
| 174 | - * |
|
| 175 | - * @param EE_messenger $messenger |
|
| 176 | - */ |
|
| 177 | - public function set_messenger_object(EE_messenger $messenger) |
|
| 178 | - { |
|
| 179 | - $this->_messenger = $messenger; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * validates messenger |
|
| 185 | - * |
|
| 186 | - * @param bool $throw_exceptions |
|
| 187 | - * @return bool |
|
| 188 | - * @throws \EE_Error |
|
| 189 | - */ |
|
| 190 | - public function valid_messenger($throw_exceptions = false) |
|
| 191 | - { |
|
| 192 | - if ($this->_messenger instanceof EE_messenger) { |
|
| 193 | - return true; |
|
| 194 | - } |
|
| 195 | - if ($throw_exceptions) { |
|
| 196 | - throw new EE_Error( |
|
| 197 | - sprintf( |
|
| 198 | - __( |
|
| 199 | - 'The "%1$s" messenger set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.', |
|
| 200 | - 'event_espresso' |
|
| 201 | - ), |
|
| 202 | - $this->messenger() |
|
| 203 | - ) |
|
| 204 | - ); |
|
| 205 | - } |
|
| 206 | - return false; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * This returns the set localized label for the messenger on this message. |
|
| 212 | - * Note, if unable to retrieve the EE_messenger object then will just return the messenger slug saved |
|
| 213 | - * with this message. |
|
| 214 | - * |
|
| 215 | - * @param bool $plural whether to return the plural label or not. |
|
| 216 | - * @return string |
|
| 217 | - */ |
|
| 218 | - public function messenger_label($plural = false) |
|
| 219 | - { |
|
| 220 | - $label_type = $plural ? 'plural' : 'singular'; |
|
| 221 | - $messenger = $this->messenger_object(); |
|
| 222 | - return $messenger instanceof EE_messenger ? $messenger->label[ $label_type ] : $this->messenger(); |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * Gets message_type |
|
| 228 | - * |
|
| 229 | - * @return string |
|
| 230 | - */ |
|
| 231 | - public function message_type() |
|
| 232 | - { |
|
| 233 | - return $this->get('MSG_message_type'); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * Sets message_type |
|
| 239 | - * |
|
| 240 | - * @param string $message_type |
|
| 241 | - */ |
|
| 242 | - public function set_message_type($message_type) |
|
| 243 | - { |
|
| 244 | - $this->set('MSG_message_type', $message_type); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * Returns the message type object for the set message type on this message |
|
| 250 | - * |
|
| 251 | - * @return EE_message_type | null |
|
| 252 | - */ |
|
| 253 | - public function message_type_object() |
|
| 254 | - { |
|
| 255 | - return $this->_message_type; |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * Sets message_type |
|
| 261 | - * |
|
| 262 | - * @param EE_message_type $message_type |
|
| 263 | - * @param bool $set_priority This indicates whether to set the priority to whatever the priority is on |
|
| 264 | - * the message type or not. |
|
| 265 | - */ |
|
| 266 | - public function set_message_type_object(EE_message_type $message_type, $set_priority = false) |
|
| 267 | - { |
|
| 268 | - $this->_message_type = $message_type; |
|
| 269 | - if ($set_priority) { |
|
| 270 | - $this->set_priority($this->_message_type->get_priority()); |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * validates message_type |
|
| 277 | - * |
|
| 278 | - * @param bool $throw_exceptions |
|
| 279 | - * @return bool |
|
| 280 | - * @throws \EE_Error |
|
| 281 | - */ |
|
| 282 | - public function valid_message_type($throw_exceptions = false) |
|
| 283 | - { |
|
| 284 | - if ($this->_message_type instanceof EE_message_type) { |
|
| 285 | - return true; |
|
| 286 | - } |
|
| 287 | - if ($throw_exceptions) { |
|
| 288 | - throw new EE_Error( |
|
| 289 | - sprintf( |
|
| 290 | - __( |
|
| 291 | - 'The %1$s message type set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.', |
|
| 292 | - 'event_espresso' |
|
| 293 | - ), |
|
| 294 | - $this->message_type() |
|
| 295 | - ) |
|
| 296 | - ); |
|
| 297 | - } |
|
| 298 | - return false; |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * validates messenger and message_type (that they are valid EE_messenger and EE_message_type objects). |
|
| 304 | - * |
|
| 305 | - * @param bool $throw_exceptions |
|
| 306 | - * @return bool |
|
| 307 | - * @throws \EE_Error |
|
| 308 | - */ |
|
| 309 | - public function is_valid($throw_exceptions = false) |
|
| 310 | - { |
|
| 311 | - if ($this->valid_messenger($throw_exceptions) && $this->valid_message_type($throw_exceptions)) { |
|
| 312 | - return true; |
|
| 313 | - } |
|
| 314 | - return false; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * This validates whether the internal messenger and message type objects are valid for sending. |
|
| 320 | - * Three checks are done: |
|
| 321 | - * 1. There is a valid messenger object. |
|
| 322 | - * 2. There is a valid message type object. |
|
| 323 | - * 3. The message type object is active for the messenger. |
|
| 324 | - * |
|
| 325 | - * @throws EE_Error But only if $throw_exceptions is set to true. |
|
| 326 | - * @param bool $throw_exceptions |
|
| 327 | - * @return bool |
|
| 328 | - */ |
|
| 329 | - public function is_valid_for_sending_or_generation($throw_exceptions = false) |
|
| 330 | - { |
|
| 331 | - $valid = false; |
|
| 332 | - if ($this->is_valid($throw_exceptions)) { |
|
| 333 | - /** @var EE_Message_Resource_Manager $message_resource_manager */ |
|
| 334 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 335 | - $valid = $message_resource_manager->is_message_type_active_for_messenger( |
|
| 336 | - $this->messenger(), |
|
| 337 | - $this->message_type() |
|
| 338 | - ); |
|
| 339 | - if (! $valid && $throw_exceptions) { |
|
| 340 | - throw new EE_Error( |
|
| 341 | - sprintf( |
|
| 342 | - __( |
|
| 343 | - 'The %1$s message type is not a valid message type for the %2$s messenger so it will not be sent.', |
|
| 344 | - 'event_espresso' |
|
| 345 | - ), |
|
| 346 | - $this->message_type(), |
|
| 347 | - $this->messenger() |
|
| 348 | - ) |
|
| 349 | - ); |
|
| 350 | - } |
|
| 351 | - } |
|
| 352 | - return $valid; |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - |
|
| 356 | - /** |
|
| 357 | - * This returns the set localized label for the message type on this message. |
|
| 358 | - * Note, if unable to retrieve the EE_message_type object then will just return the message type slug saved |
|
| 359 | - * with this message. |
|
| 360 | - * |
|
| 361 | - * @param bool $plural whether to return the plural label or not. |
|
| 362 | - * @return string |
|
| 363 | - */ |
|
| 364 | - public function message_type_label($plural = false) |
|
| 365 | - { |
|
| 366 | - $label_type = $plural ? 'plural' : 'singular'; |
|
| 367 | - $message_type = $this->message_type_object(); |
|
| 368 | - return $message_type instanceof EE_message_type |
|
| 369 | - ? $message_type->label[ $label_type ] |
|
| 370 | - : str_replace( |
|
| 371 | - '_', |
|
| 372 | - ' ', |
|
| 373 | - $this->message_type() |
|
| 374 | - ); |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - |
|
| 378 | - /** |
|
| 379 | - * Gets context |
|
| 380 | - * |
|
| 381 | - * @return string |
|
| 382 | - */ |
|
| 383 | - public function context() |
|
| 384 | - { |
|
| 385 | - return $this->get('MSG_context'); |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - |
|
| 389 | - /** |
|
| 390 | - * This returns the corresponding localized label for the given context slug, if possible from installed message |
|
| 391 | - * types. Otherwise, this will just return the set context slug on this object. |
|
| 392 | - * |
|
| 393 | - * @return string |
|
| 394 | - */ |
|
| 395 | - public function context_label() |
|
| 396 | - { |
|
| 397 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 398 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 399 | - $contexts = $message_resource_manager->get_all_contexts(); |
|
| 400 | - return isset($contexts[ $this->context() ]) ? $contexts[ $this->context() ] : $this->context(); |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * Sets context |
|
| 406 | - * |
|
| 407 | - * @param string $context |
|
| 408 | - */ |
|
| 409 | - public function set_context($context) |
|
| 410 | - { |
|
| 411 | - $this->set('MSG_context', $context); |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - |
|
| 415 | - /** |
|
| 416 | - * Gets recipient_ID |
|
| 417 | - * |
|
| 418 | - * @return int |
|
| 419 | - */ |
|
| 420 | - public function recipient_ID() |
|
| 421 | - { |
|
| 422 | - return $this->get('MSG_recipient_ID'); |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - |
|
| 426 | - /** |
|
| 427 | - * Sets recipient_ID |
|
| 428 | - * |
|
| 429 | - * @param string $recipient_ID |
|
| 430 | - */ |
|
| 431 | - public function set_recipient_ID($recipient_ID) |
|
| 432 | - { |
|
| 433 | - $this->set('MSG_recipient_ID', $recipient_ID); |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * Gets recipient_type |
|
| 439 | - * |
|
| 440 | - * @return string |
|
| 441 | - */ |
|
| 442 | - public function recipient_type() |
|
| 443 | - { |
|
| 444 | - return $this->get('MSG_recipient_type'); |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - |
|
| 448 | - /** |
|
| 449 | - * Return the related object matching the recipient type and ID. |
|
| 450 | - * |
|
| 451 | - * @return EE_Base_Class | null |
|
| 452 | - */ |
|
| 453 | - public function recipient_object() |
|
| 454 | - { |
|
| 455 | - if (! $this->recipient_type() || ! $this->recipient_ID()) { |
|
| 456 | - return null; |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - return $this->get_first_related($this->recipient_type()); |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * Sets recipient_type |
|
| 465 | - * |
|
| 466 | - * @param string $recipient_type |
|
| 467 | - */ |
|
| 468 | - public function set_recipient_type($recipient_type) |
|
| 469 | - { |
|
| 470 | - $this->set('MSG_recipient_type', $recipient_type); |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - |
|
| 474 | - /** |
|
| 475 | - * Gets content |
|
| 476 | - * |
|
| 477 | - * @return string |
|
| 478 | - */ |
|
| 479 | - public function content() |
|
| 480 | - { |
|
| 481 | - return $this->get('MSG_content'); |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - |
|
| 485 | - /** |
|
| 486 | - * Sets content |
|
| 487 | - * |
|
| 488 | - * @param string $content |
|
| 489 | - */ |
|
| 490 | - public function set_content($content) |
|
| 491 | - { |
|
| 492 | - $this->set('MSG_content', $content); |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - |
|
| 496 | - /** |
|
| 497 | - * Gets subject |
|
| 498 | - * |
|
| 499 | - * @return string |
|
| 500 | - */ |
|
| 501 | - public function subject() |
|
| 502 | - { |
|
| 503 | - return $this->get('MSG_subject'); |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - |
|
| 507 | - /** |
|
| 508 | - * Sets subject |
|
| 509 | - * |
|
| 510 | - * @param string $subject |
|
| 511 | - */ |
|
| 512 | - public function set_subject($subject) |
|
| 513 | - { |
|
| 514 | - $this->set('MSG_subject', $subject); |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - |
|
| 518 | - /** |
|
| 519 | - * Gets to |
|
| 520 | - * |
|
| 521 | - * @return string |
|
| 522 | - */ |
|
| 523 | - public function to() |
|
| 524 | - { |
|
| 525 | - $to = $this->get('MSG_to'); |
|
| 526 | - return empty($to) ? __('No recipient', 'event_espresso') : $to; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - |
|
| 530 | - /** |
|
| 531 | - * Sets to |
|
| 532 | - * |
|
| 533 | - * @param string $to |
|
| 534 | - */ |
|
| 535 | - public function set_to($to) |
|
| 536 | - { |
|
| 537 | - $this->set('MSG_to', $to); |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - |
|
| 541 | - /** |
|
| 542 | - * Gets from |
|
| 543 | - * |
|
| 544 | - * @return string |
|
| 545 | - */ |
|
| 546 | - public function from() |
|
| 547 | - { |
|
| 548 | - return $this->get('MSG_from'); |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - |
|
| 552 | - /** |
|
| 553 | - * Sets from |
|
| 554 | - * |
|
| 555 | - * @param string $from |
|
| 556 | - */ |
|
| 557 | - public function set_from($from) |
|
| 558 | - { |
|
| 559 | - $this->set('MSG_from', $from); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - |
|
| 563 | - /** |
|
| 564 | - * Gets priority |
|
| 565 | - * |
|
| 566 | - * @return int |
|
| 567 | - */ |
|
| 568 | - public function priority() |
|
| 569 | - { |
|
| 570 | - return $this->get('MSG_priority'); |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - |
|
| 574 | - /** |
|
| 575 | - * Sets priority |
|
| 576 | - * Note. Send Now Messengers always override any priority that may be set on a Message. So |
|
| 577 | - * this method calls the send_now method to verify that. |
|
| 578 | - * |
|
| 579 | - * @param int $priority |
|
| 580 | - */ |
|
| 581 | - public function set_priority($priority) |
|
| 582 | - { |
|
| 583 | - $priority = $this->send_now() ? EEM_Message::priority_high : $priority; |
|
| 584 | - parent::set('MSG_priority', $priority); |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - |
|
| 588 | - /** |
|
| 589 | - * Overrides parent::set method so we can capture any sets for priority. |
|
| 590 | - * |
|
| 591 | - * @see parent::set() for phpdocs |
|
| 592 | - * @param string $field_name |
|
| 593 | - * @param mixed $field_value |
|
| 594 | - * @param bool $use_default |
|
| 595 | - * @throws EE_Error |
|
| 596 | - */ |
|
| 597 | - public function set($field_name, $field_value, $use_default = false) |
|
| 598 | - { |
|
| 599 | - if ($field_name === 'MSG_priority') { |
|
| 600 | - $this->set_priority($field_value); |
|
| 601 | - } |
|
| 602 | - parent::set($field_name, $field_value, $use_default); |
|
| 603 | - } |
|
| 604 | - |
|
| 605 | - |
|
| 606 | - /** |
|
| 607 | - * @return bool |
|
| 608 | - * @throws \EE_Error |
|
| 609 | - */ |
|
| 610 | - public function send_now() |
|
| 611 | - { |
|
| 612 | - $send_now = $this->valid_messenger() && $this->messenger_object()->send_now() ? EEM_Message::priority_high |
|
| 613 | - : $this->priority(); |
|
| 614 | - return $send_now === EEM_Message::priority_high ? true : false; |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - |
|
| 618 | - /** |
|
| 619 | - * Gets STS_ID |
|
| 620 | - * |
|
| 621 | - * @return string |
|
| 622 | - */ |
|
| 623 | - public function STS_ID() |
|
| 624 | - { |
|
| 625 | - return $this->get('STS_ID'); |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - |
|
| 629 | - /** |
|
| 630 | - * Sets STS_ID |
|
| 631 | - * |
|
| 632 | - * @param string $STS_ID |
|
| 633 | - */ |
|
| 634 | - public function set_STS_ID($STS_ID) |
|
| 635 | - { |
|
| 636 | - $this->set('STS_ID', $STS_ID); |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - |
|
| 640 | - /** |
|
| 641 | - * Gets created |
|
| 642 | - * |
|
| 643 | - * @return string |
|
| 644 | - */ |
|
| 645 | - public function created() |
|
| 646 | - { |
|
| 647 | - return $this->get('MSG_created'); |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - |
|
| 651 | - /** |
|
| 652 | - * Sets created |
|
| 653 | - * |
|
| 654 | - * @param string $created |
|
| 655 | - */ |
|
| 656 | - public function set_created($created) |
|
| 657 | - { |
|
| 658 | - $this->set('MSG_created', $created); |
|
| 659 | - } |
|
| 660 | - |
|
| 661 | - |
|
| 662 | - /** |
|
| 663 | - * Gets modified |
|
| 664 | - * |
|
| 665 | - * @return string |
|
| 666 | - */ |
|
| 667 | - public function modified() |
|
| 668 | - { |
|
| 669 | - return $this->get('MSG_modified'); |
|
| 670 | - } |
|
| 671 | - |
|
| 672 | - |
|
| 673 | - /** |
|
| 674 | - * Sets modified |
|
| 675 | - * |
|
| 676 | - * @param string $modified |
|
| 677 | - */ |
|
| 678 | - public function set_modified($modified) |
|
| 679 | - { |
|
| 680 | - $this->set('MSG_modified', $modified); |
|
| 681 | - } |
|
| 682 | - |
|
| 683 | - |
|
| 684 | - /** |
|
| 685 | - * Sets generation data for this message. |
|
| 686 | - * |
|
| 687 | - * @param mixed $data |
|
| 688 | - */ |
|
| 689 | - public function set_generation_data($data) |
|
| 690 | - { |
|
| 691 | - $this->set_field_or_extra_meta('MSG_generation_data', $data); |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - |
|
| 695 | - /** |
|
| 696 | - * Returns any set generation data for this message. |
|
| 697 | - * |
|
| 698 | - * @return mixed|null |
|
| 699 | - */ |
|
| 700 | - public function get_generation_data() |
|
| 701 | - { |
|
| 702 | - return $this->get_field_or_extra_meta('MSG_generation_data'); |
|
| 703 | - } |
|
| 704 | - |
|
| 705 | - |
|
| 706 | - /** |
|
| 707 | - * Gets any error message. |
|
| 708 | - * |
|
| 709 | - * @return mixed|null |
|
| 710 | - */ |
|
| 711 | - public function error_message() |
|
| 712 | - { |
|
| 713 | - return $this->get_field_or_extra_meta('MSG_error'); |
|
| 714 | - } |
|
| 715 | - |
|
| 716 | - |
|
| 717 | - /** |
|
| 718 | - * Sets an error message. |
|
| 719 | - * |
|
| 720 | - * @param $message |
|
| 721 | - * @return bool|int |
|
| 722 | - */ |
|
| 723 | - public function set_error_message($message) |
|
| 724 | - { |
|
| 725 | - return $this->set_field_or_extra_meta('MSG_error', $message); |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - |
|
| 729 | - /** |
|
| 730 | - * This retrieves the associated template pack with this message. |
|
| 731 | - * |
|
| 732 | - * @return EE_Messages_Template_Pack | null |
|
| 733 | - */ |
|
| 734 | - public function get_template_pack() |
|
| 735 | - { |
|
| 736 | - /** |
|
| 737 | - * This is deprecated functionality that will be removed eventually but included here now for backward compat. |
|
| 738 | - */ |
|
| 739 | - if (! empty($this->template_pack)) { |
|
| 740 | - return $this->template_pack; |
|
| 741 | - } |
|
| 742 | - /** @type EE_Message_Template_Group $grp */ |
|
| 743 | - $grp = $this->get_first_related('Message_Template_Group'); |
|
| 744 | - // if no group then let's try to get the first related group by internal messenger and message type (will use global grp). |
|
| 745 | - if (! $grp instanceof EE_Message_Template_Group) { |
|
| 746 | - $grp = EEM_Message_Template_Group::instance()->get_one( |
|
| 747 | - array( |
|
| 748 | - array( |
|
| 749 | - 'MTP_messenger' => $this->messenger(), |
|
| 750 | - 'MTP_message_type' => $this->message_type(), |
|
| 751 | - 'MTP_is_global' => true, |
|
| 752 | - ), |
|
| 753 | - ) |
|
| 754 | - ); |
|
| 755 | - } |
|
| 756 | - |
|
| 757 | - return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack() : null; |
|
| 758 | - } |
|
| 759 | - |
|
| 760 | - |
|
| 761 | - /** |
|
| 762 | - * Retrieves the variation used for generating this message. |
|
| 763 | - * |
|
| 764 | - * @return string |
|
| 765 | - */ |
|
| 766 | - public function get_template_pack_variation() |
|
| 767 | - { |
|
| 768 | - /** |
|
| 769 | - * This is deprecated functionality that will be removed eventually but included here now for backward compat. |
|
| 770 | - */ |
|
| 771 | - if (! empty($this->template_variation)) { |
|
| 772 | - return $this->template_variation; |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - /** @type EE_Message_Template_Group $grp */ |
|
| 776 | - $grp = $this->get_first_related('Message_Template_Group'); |
|
| 777 | - |
|
| 778 | - // if no group then let's try to get the first related group by internal messenger and message type (will use global grp). |
|
| 779 | - if (! $grp instanceof EE_Message_Template_Group) { |
|
| 780 | - $grp = EEM_Message_Template_Group::instance()->get_one( |
|
| 781 | - array( |
|
| 782 | - array( |
|
| 783 | - 'MTP_messenger' => $this->messenger(), |
|
| 784 | - 'MTP_message_type' => $this->message_type(), |
|
| 785 | - 'MTP_is_global' => true, |
|
| 786 | - ), |
|
| 787 | - ) |
|
| 788 | - ); |
|
| 789 | - } |
|
| 790 | - |
|
| 791 | - return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack_variation() : ''; |
|
| 792 | - } |
|
| 793 | - |
|
| 794 | - /** |
|
| 795 | - * Return the link to the admin details for the object. |
|
| 796 | - * |
|
| 797 | - * @return string |
|
| 798 | - */ |
|
| 799 | - public function get_admin_details_link() |
|
| 800 | - { |
|
| 801 | - EE_Registry::instance()->load_helper('URL'); |
|
| 802 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 803 | - switch ($this->STS_ID()) { |
|
| 804 | - case EEM_Message::status_failed: |
|
| 805 | - case EEM_Message::status_debug_only: |
|
| 806 | - return EEH_MSG_Template::generate_error_display_trigger($this); |
|
| 807 | - break; |
|
| 808 | - |
|
| 809 | - case EEM_Message::status_sent: |
|
| 810 | - return EEH_MSG_Template::generate_browser_trigger($this); |
|
| 811 | - break; |
|
| 812 | - |
|
| 813 | - default: |
|
| 814 | - return ''; |
|
| 815 | - } |
|
| 816 | - } |
|
| 817 | - |
|
| 818 | - /** |
|
| 819 | - * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
| 820 | - * |
|
| 821 | - * @return string |
|
| 822 | - */ |
|
| 823 | - public function get_admin_edit_link() |
|
| 824 | - { |
|
| 825 | - return $this->get_admin_details_link(); |
|
| 826 | - } |
|
| 827 | - |
|
| 828 | - /** |
|
| 829 | - * Returns the link to a settings page for the object. |
|
| 830 | - * |
|
| 831 | - * @return string |
|
| 832 | - */ |
|
| 833 | - public function get_admin_settings_link() |
|
| 834 | - { |
|
| 835 | - EE_Registry::instance()->load_helper('URL'); |
|
| 836 | - return EEH_URL::add_query_args_and_nonce( |
|
| 837 | - array( |
|
| 838 | - 'page' => 'espresso_messages', |
|
| 839 | - 'action' => 'settings', |
|
| 840 | - ), |
|
| 841 | - admin_url('admin.php') |
|
| 842 | - ); |
|
| 843 | - } |
|
| 844 | - |
|
| 845 | - /** |
|
| 846 | - * Returns the link to the "overview" for the object (typically the "list table" view). |
|
| 847 | - * |
|
| 848 | - * @return string |
|
| 849 | - */ |
|
| 850 | - public function get_admin_overview_link() |
|
| 851 | - { |
|
| 852 | - EE_Registry::instance()->load_helper('URL'); |
|
| 853 | - return EEH_URL::add_query_args_and_nonce( |
|
| 854 | - array( |
|
| 855 | - 'page' => 'espresso_messages', |
|
| 856 | - 'action' => 'default', |
|
| 857 | - ), |
|
| 858 | - admin_url('admin.php') |
|
| 859 | - ); |
|
| 860 | - } |
|
| 861 | - |
|
| 862 | - |
|
| 863 | - /** |
|
| 864 | - * This sets the EEM_Message::status_messenger_executing class on the message and the appropriate error message for |
|
| 865 | - * it. |
|
| 866 | - * Note this also SAVES the current message object to the db because it adds an error message to accompany the |
|
| 867 | - * status. |
|
| 868 | - * |
|
| 869 | - */ |
|
| 870 | - public function set_messenger_is_executing() |
|
| 871 | - { |
|
| 872 | - $this->set_STS_ID(EEM_Message::status_messenger_executing); |
|
| 873 | - $this->set_error_message( |
|
| 874 | - esc_html__( |
|
| 875 | - 'A message with this status indicates that there was a problem that occurred while the message was being |
|
| 13 | + /** |
|
| 14 | + * @deprecated 4.9.0 Added for backward compat with add-on's |
|
| 15 | + * @type null |
|
| 16 | + */ |
|
| 17 | + public $template_pack; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * @deprecated 4.9.0 Added for backward compat with add-on's |
|
| 21 | + * @type null |
|
| 22 | + */ |
|
| 23 | + public $template_variation; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @deprecated 4.9.0 Added for backward compat with add-on's |
|
| 27 | + * @type string |
|
| 28 | + */ |
|
| 29 | + public $content = ''; |
|
| 30 | + |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @type EE_messenger $_messenger |
|
| 34 | + */ |
|
| 35 | + protected $_messenger = null; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @type EE_message_type $_message_type |
|
| 39 | + */ |
|
| 40 | + protected $_message_type = null; |
|
| 41 | + |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @param array $props_n_values |
|
| 45 | + * @param string $timezone |
|
| 46 | + * @param array $date_formats incoming date formats in an array. First value is the date_format, second is time |
|
| 47 | + * format. |
|
| 48 | + * @return EE_Message |
|
| 49 | + */ |
|
| 50 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 51 | + { |
|
| 52 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 53 | + // if object doesn't exist, let's generate a unique token on instantiation so that its available even before saving to db. |
|
| 54 | + if (! $has_object) { |
|
| 55 | + EE_Registry::instance()->load_helper('URL'); |
|
| 56 | + $props_n_values['MSG_token'] = EEH_URL::generate_unique_token(); |
|
| 57 | + } |
|
| 58 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @param array $props_n_values |
|
| 64 | + * @param string $timezone |
|
| 65 | + * @return EE_Message |
|
| 66 | + */ |
|
| 67 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 68 | + { |
|
| 69 | + return new self($props_n_values, true, $timezone); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Gets MSG_token |
|
| 75 | + * |
|
| 76 | + * @return int |
|
| 77 | + */ |
|
| 78 | + public function MSG_token() |
|
| 79 | + { |
|
| 80 | + return $this->get('MSG_token'); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * Sets MSG_token |
|
| 86 | + * |
|
| 87 | + * @param int $MSG_token |
|
| 88 | + */ |
|
| 89 | + public function set_MSG_token($MSG_token) |
|
| 90 | + { |
|
| 91 | + $this->set('MSG_token', $MSG_token); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Gets GRP_ID |
|
| 97 | + * |
|
| 98 | + * @return int |
|
| 99 | + */ |
|
| 100 | + public function GRP_ID() |
|
| 101 | + { |
|
| 102 | + return $this->get('GRP_ID'); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Sets GRP_ID |
|
| 108 | + * |
|
| 109 | + * @param int $GRP_ID |
|
| 110 | + */ |
|
| 111 | + public function set_GRP_ID($GRP_ID) |
|
| 112 | + { |
|
| 113 | + $this->set('GRP_ID', $GRP_ID); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Gets TXN_ID |
|
| 119 | + * |
|
| 120 | + * @return int |
|
| 121 | + */ |
|
| 122 | + public function TXN_ID() |
|
| 123 | + { |
|
| 124 | + return $this->get('TXN_ID'); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Sets TXN_ID |
|
| 130 | + * |
|
| 131 | + * @param int $TXN_ID |
|
| 132 | + */ |
|
| 133 | + public function set_TXN_ID($TXN_ID) |
|
| 134 | + { |
|
| 135 | + $this->set('TXN_ID', $TXN_ID); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Gets messenger |
|
| 141 | + * |
|
| 142 | + * @return string |
|
| 143 | + */ |
|
| 144 | + public function messenger() |
|
| 145 | + { |
|
| 146 | + return $this->get('MSG_messenger'); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Sets messenger |
|
| 152 | + * |
|
| 153 | + * @param string $messenger |
|
| 154 | + */ |
|
| 155 | + public function set_messenger($messenger) |
|
| 156 | + { |
|
| 157 | + $this->set('MSG_messenger', $messenger); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * Returns corresponding messenger object for the set messenger on this message |
|
| 163 | + * |
|
| 164 | + * @return EE_messenger | null |
|
| 165 | + */ |
|
| 166 | + public function messenger_object() |
|
| 167 | + { |
|
| 168 | + return $this->_messenger; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * Sets messenger |
|
| 174 | + * |
|
| 175 | + * @param EE_messenger $messenger |
|
| 176 | + */ |
|
| 177 | + public function set_messenger_object(EE_messenger $messenger) |
|
| 178 | + { |
|
| 179 | + $this->_messenger = $messenger; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * validates messenger |
|
| 185 | + * |
|
| 186 | + * @param bool $throw_exceptions |
|
| 187 | + * @return bool |
|
| 188 | + * @throws \EE_Error |
|
| 189 | + */ |
|
| 190 | + public function valid_messenger($throw_exceptions = false) |
|
| 191 | + { |
|
| 192 | + if ($this->_messenger instanceof EE_messenger) { |
|
| 193 | + return true; |
|
| 194 | + } |
|
| 195 | + if ($throw_exceptions) { |
|
| 196 | + throw new EE_Error( |
|
| 197 | + sprintf( |
|
| 198 | + __( |
|
| 199 | + 'The "%1$s" messenger set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.', |
|
| 200 | + 'event_espresso' |
|
| 201 | + ), |
|
| 202 | + $this->messenger() |
|
| 203 | + ) |
|
| 204 | + ); |
|
| 205 | + } |
|
| 206 | + return false; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * This returns the set localized label for the messenger on this message. |
|
| 212 | + * Note, if unable to retrieve the EE_messenger object then will just return the messenger slug saved |
|
| 213 | + * with this message. |
|
| 214 | + * |
|
| 215 | + * @param bool $plural whether to return the plural label or not. |
|
| 216 | + * @return string |
|
| 217 | + */ |
|
| 218 | + public function messenger_label($plural = false) |
|
| 219 | + { |
|
| 220 | + $label_type = $plural ? 'plural' : 'singular'; |
|
| 221 | + $messenger = $this->messenger_object(); |
|
| 222 | + return $messenger instanceof EE_messenger ? $messenger->label[ $label_type ] : $this->messenger(); |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * Gets message_type |
|
| 228 | + * |
|
| 229 | + * @return string |
|
| 230 | + */ |
|
| 231 | + public function message_type() |
|
| 232 | + { |
|
| 233 | + return $this->get('MSG_message_type'); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * Sets message_type |
|
| 239 | + * |
|
| 240 | + * @param string $message_type |
|
| 241 | + */ |
|
| 242 | + public function set_message_type($message_type) |
|
| 243 | + { |
|
| 244 | + $this->set('MSG_message_type', $message_type); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * Returns the message type object for the set message type on this message |
|
| 250 | + * |
|
| 251 | + * @return EE_message_type | null |
|
| 252 | + */ |
|
| 253 | + public function message_type_object() |
|
| 254 | + { |
|
| 255 | + return $this->_message_type; |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * Sets message_type |
|
| 261 | + * |
|
| 262 | + * @param EE_message_type $message_type |
|
| 263 | + * @param bool $set_priority This indicates whether to set the priority to whatever the priority is on |
|
| 264 | + * the message type or not. |
|
| 265 | + */ |
|
| 266 | + public function set_message_type_object(EE_message_type $message_type, $set_priority = false) |
|
| 267 | + { |
|
| 268 | + $this->_message_type = $message_type; |
|
| 269 | + if ($set_priority) { |
|
| 270 | + $this->set_priority($this->_message_type->get_priority()); |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * validates message_type |
|
| 277 | + * |
|
| 278 | + * @param bool $throw_exceptions |
|
| 279 | + * @return bool |
|
| 280 | + * @throws \EE_Error |
|
| 281 | + */ |
|
| 282 | + public function valid_message_type($throw_exceptions = false) |
|
| 283 | + { |
|
| 284 | + if ($this->_message_type instanceof EE_message_type) { |
|
| 285 | + return true; |
|
| 286 | + } |
|
| 287 | + if ($throw_exceptions) { |
|
| 288 | + throw new EE_Error( |
|
| 289 | + sprintf( |
|
| 290 | + __( |
|
| 291 | + 'The %1$s message type set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.', |
|
| 292 | + 'event_espresso' |
|
| 293 | + ), |
|
| 294 | + $this->message_type() |
|
| 295 | + ) |
|
| 296 | + ); |
|
| 297 | + } |
|
| 298 | + return false; |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * validates messenger and message_type (that they are valid EE_messenger and EE_message_type objects). |
|
| 304 | + * |
|
| 305 | + * @param bool $throw_exceptions |
|
| 306 | + * @return bool |
|
| 307 | + * @throws \EE_Error |
|
| 308 | + */ |
|
| 309 | + public function is_valid($throw_exceptions = false) |
|
| 310 | + { |
|
| 311 | + if ($this->valid_messenger($throw_exceptions) && $this->valid_message_type($throw_exceptions)) { |
|
| 312 | + return true; |
|
| 313 | + } |
|
| 314 | + return false; |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * This validates whether the internal messenger and message type objects are valid for sending. |
|
| 320 | + * Three checks are done: |
|
| 321 | + * 1. There is a valid messenger object. |
|
| 322 | + * 2. There is a valid message type object. |
|
| 323 | + * 3. The message type object is active for the messenger. |
|
| 324 | + * |
|
| 325 | + * @throws EE_Error But only if $throw_exceptions is set to true. |
|
| 326 | + * @param bool $throw_exceptions |
|
| 327 | + * @return bool |
|
| 328 | + */ |
|
| 329 | + public function is_valid_for_sending_or_generation($throw_exceptions = false) |
|
| 330 | + { |
|
| 331 | + $valid = false; |
|
| 332 | + if ($this->is_valid($throw_exceptions)) { |
|
| 333 | + /** @var EE_Message_Resource_Manager $message_resource_manager */ |
|
| 334 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 335 | + $valid = $message_resource_manager->is_message_type_active_for_messenger( |
|
| 336 | + $this->messenger(), |
|
| 337 | + $this->message_type() |
|
| 338 | + ); |
|
| 339 | + if (! $valid && $throw_exceptions) { |
|
| 340 | + throw new EE_Error( |
|
| 341 | + sprintf( |
|
| 342 | + __( |
|
| 343 | + 'The %1$s message type is not a valid message type for the %2$s messenger so it will not be sent.', |
|
| 344 | + 'event_espresso' |
|
| 345 | + ), |
|
| 346 | + $this->message_type(), |
|
| 347 | + $this->messenger() |
|
| 348 | + ) |
|
| 349 | + ); |
|
| 350 | + } |
|
| 351 | + } |
|
| 352 | + return $valid; |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + |
|
| 356 | + /** |
|
| 357 | + * This returns the set localized label for the message type on this message. |
|
| 358 | + * Note, if unable to retrieve the EE_message_type object then will just return the message type slug saved |
|
| 359 | + * with this message. |
|
| 360 | + * |
|
| 361 | + * @param bool $plural whether to return the plural label or not. |
|
| 362 | + * @return string |
|
| 363 | + */ |
|
| 364 | + public function message_type_label($plural = false) |
|
| 365 | + { |
|
| 366 | + $label_type = $plural ? 'plural' : 'singular'; |
|
| 367 | + $message_type = $this->message_type_object(); |
|
| 368 | + return $message_type instanceof EE_message_type |
|
| 369 | + ? $message_type->label[ $label_type ] |
|
| 370 | + : str_replace( |
|
| 371 | + '_', |
|
| 372 | + ' ', |
|
| 373 | + $this->message_type() |
|
| 374 | + ); |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + |
|
| 378 | + /** |
|
| 379 | + * Gets context |
|
| 380 | + * |
|
| 381 | + * @return string |
|
| 382 | + */ |
|
| 383 | + public function context() |
|
| 384 | + { |
|
| 385 | + return $this->get('MSG_context'); |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + |
|
| 389 | + /** |
|
| 390 | + * This returns the corresponding localized label for the given context slug, if possible from installed message |
|
| 391 | + * types. Otherwise, this will just return the set context slug on this object. |
|
| 392 | + * |
|
| 393 | + * @return string |
|
| 394 | + */ |
|
| 395 | + public function context_label() |
|
| 396 | + { |
|
| 397 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 398 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 399 | + $contexts = $message_resource_manager->get_all_contexts(); |
|
| 400 | + return isset($contexts[ $this->context() ]) ? $contexts[ $this->context() ] : $this->context(); |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * Sets context |
|
| 406 | + * |
|
| 407 | + * @param string $context |
|
| 408 | + */ |
|
| 409 | + public function set_context($context) |
|
| 410 | + { |
|
| 411 | + $this->set('MSG_context', $context); |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + |
|
| 415 | + /** |
|
| 416 | + * Gets recipient_ID |
|
| 417 | + * |
|
| 418 | + * @return int |
|
| 419 | + */ |
|
| 420 | + public function recipient_ID() |
|
| 421 | + { |
|
| 422 | + return $this->get('MSG_recipient_ID'); |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + |
|
| 426 | + /** |
|
| 427 | + * Sets recipient_ID |
|
| 428 | + * |
|
| 429 | + * @param string $recipient_ID |
|
| 430 | + */ |
|
| 431 | + public function set_recipient_ID($recipient_ID) |
|
| 432 | + { |
|
| 433 | + $this->set('MSG_recipient_ID', $recipient_ID); |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * Gets recipient_type |
|
| 439 | + * |
|
| 440 | + * @return string |
|
| 441 | + */ |
|
| 442 | + public function recipient_type() |
|
| 443 | + { |
|
| 444 | + return $this->get('MSG_recipient_type'); |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + |
|
| 448 | + /** |
|
| 449 | + * Return the related object matching the recipient type and ID. |
|
| 450 | + * |
|
| 451 | + * @return EE_Base_Class | null |
|
| 452 | + */ |
|
| 453 | + public function recipient_object() |
|
| 454 | + { |
|
| 455 | + if (! $this->recipient_type() || ! $this->recipient_ID()) { |
|
| 456 | + return null; |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + return $this->get_first_related($this->recipient_type()); |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * Sets recipient_type |
|
| 465 | + * |
|
| 466 | + * @param string $recipient_type |
|
| 467 | + */ |
|
| 468 | + public function set_recipient_type($recipient_type) |
|
| 469 | + { |
|
| 470 | + $this->set('MSG_recipient_type', $recipient_type); |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + |
|
| 474 | + /** |
|
| 475 | + * Gets content |
|
| 476 | + * |
|
| 477 | + * @return string |
|
| 478 | + */ |
|
| 479 | + public function content() |
|
| 480 | + { |
|
| 481 | + return $this->get('MSG_content'); |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + |
|
| 485 | + /** |
|
| 486 | + * Sets content |
|
| 487 | + * |
|
| 488 | + * @param string $content |
|
| 489 | + */ |
|
| 490 | + public function set_content($content) |
|
| 491 | + { |
|
| 492 | + $this->set('MSG_content', $content); |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + |
|
| 496 | + /** |
|
| 497 | + * Gets subject |
|
| 498 | + * |
|
| 499 | + * @return string |
|
| 500 | + */ |
|
| 501 | + public function subject() |
|
| 502 | + { |
|
| 503 | + return $this->get('MSG_subject'); |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + |
|
| 507 | + /** |
|
| 508 | + * Sets subject |
|
| 509 | + * |
|
| 510 | + * @param string $subject |
|
| 511 | + */ |
|
| 512 | + public function set_subject($subject) |
|
| 513 | + { |
|
| 514 | + $this->set('MSG_subject', $subject); |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + |
|
| 518 | + /** |
|
| 519 | + * Gets to |
|
| 520 | + * |
|
| 521 | + * @return string |
|
| 522 | + */ |
|
| 523 | + public function to() |
|
| 524 | + { |
|
| 525 | + $to = $this->get('MSG_to'); |
|
| 526 | + return empty($to) ? __('No recipient', 'event_espresso') : $to; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + |
|
| 530 | + /** |
|
| 531 | + * Sets to |
|
| 532 | + * |
|
| 533 | + * @param string $to |
|
| 534 | + */ |
|
| 535 | + public function set_to($to) |
|
| 536 | + { |
|
| 537 | + $this->set('MSG_to', $to); |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + |
|
| 541 | + /** |
|
| 542 | + * Gets from |
|
| 543 | + * |
|
| 544 | + * @return string |
|
| 545 | + */ |
|
| 546 | + public function from() |
|
| 547 | + { |
|
| 548 | + return $this->get('MSG_from'); |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + |
|
| 552 | + /** |
|
| 553 | + * Sets from |
|
| 554 | + * |
|
| 555 | + * @param string $from |
|
| 556 | + */ |
|
| 557 | + public function set_from($from) |
|
| 558 | + { |
|
| 559 | + $this->set('MSG_from', $from); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + |
|
| 563 | + /** |
|
| 564 | + * Gets priority |
|
| 565 | + * |
|
| 566 | + * @return int |
|
| 567 | + */ |
|
| 568 | + public function priority() |
|
| 569 | + { |
|
| 570 | + return $this->get('MSG_priority'); |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + |
|
| 574 | + /** |
|
| 575 | + * Sets priority |
|
| 576 | + * Note. Send Now Messengers always override any priority that may be set on a Message. So |
|
| 577 | + * this method calls the send_now method to verify that. |
|
| 578 | + * |
|
| 579 | + * @param int $priority |
|
| 580 | + */ |
|
| 581 | + public function set_priority($priority) |
|
| 582 | + { |
|
| 583 | + $priority = $this->send_now() ? EEM_Message::priority_high : $priority; |
|
| 584 | + parent::set('MSG_priority', $priority); |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + |
|
| 588 | + /** |
|
| 589 | + * Overrides parent::set method so we can capture any sets for priority. |
|
| 590 | + * |
|
| 591 | + * @see parent::set() for phpdocs |
|
| 592 | + * @param string $field_name |
|
| 593 | + * @param mixed $field_value |
|
| 594 | + * @param bool $use_default |
|
| 595 | + * @throws EE_Error |
|
| 596 | + */ |
|
| 597 | + public function set($field_name, $field_value, $use_default = false) |
|
| 598 | + { |
|
| 599 | + if ($field_name === 'MSG_priority') { |
|
| 600 | + $this->set_priority($field_value); |
|
| 601 | + } |
|
| 602 | + parent::set($field_name, $field_value, $use_default); |
|
| 603 | + } |
|
| 604 | + |
|
| 605 | + |
|
| 606 | + /** |
|
| 607 | + * @return bool |
|
| 608 | + * @throws \EE_Error |
|
| 609 | + */ |
|
| 610 | + public function send_now() |
|
| 611 | + { |
|
| 612 | + $send_now = $this->valid_messenger() && $this->messenger_object()->send_now() ? EEM_Message::priority_high |
|
| 613 | + : $this->priority(); |
|
| 614 | + return $send_now === EEM_Message::priority_high ? true : false; |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + |
|
| 618 | + /** |
|
| 619 | + * Gets STS_ID |
|
| 620 | + * |
|
| 621 | + * @return string |
|
| 622 | + */ |
|
| 623 | + public function STS_ID() |
|
| 624 | + { |
|
| 625 | + return $this->get('STS_ID'); |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + |
|
| 629 | + /** |
|
| 630 | + * Sets STS_ID |
|
| 631 | + * |
|
| 632 | + * @param string $STS_ID |
|
| 633 | + */ |
|
| 634 | + public function set_STS_ID($STS_ID) |
|
| 635 | + { |
|
| 636 | + $this->set('STS_ID', $STS_ID); |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + |
|
| 640 | + /** |
|
| 641 | + * Gets created |
|
| 642 | + * |
|
| 643 | + * @return string |
|
| 644 | + */ |
|
| 645 | + public function created() |
|
| 646 | + { |
|
| 647 | + return $this->get('MSG_created'); |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + |
|
| 651 | + /** |
|
| 652 | + * Sets created |
|
| 653 | + * |
|
| 654 | + * @param string $created |
|
| 655 | + */ |
|
| 656 | + public function set_created($created) |
|
| 657 | + { |
|
| 658 | + $this->set('MSG_created', $created); |
|
| 659 | + } |
|
| 660 | + |
|
| 661 | + |
|
| 662 | + /** |
|
| 663 | + * Gets modified |
|
| 664 | + * |
|
| 665 | + * @return string |
|
| 666 | + */ |
|
| 667 | + public function modified() |
|
| 668 | + { |
|
| 669 | + return $this->get('MSG_modified'); |
|
| 670 | + } |
|
| 671 | + |
|
| 672 | + |
|
| 673 | + /** |
|
| 674 | + * Sets modified |
|
| 675 | + * |
|
| 676 | + * @param string $modified |
|
| 677 | + */ |
|
| 678 | + public function set_modified($modified) |
|
| 679 | + { |
|
| 680 | + $this->set('MSG_modified', $modified); |
|
| 681 | + } |
|
| 682 | + |
|
| 683 | + |
|
| 684 | + /** |
|
| 685 | + * Sets generation data for this message. |
|
| 686 | + * |
|
| 687 | + * @param mixed $data |
|
| 688 | + */ |
|
| 689 | + public function set_generation_data($data) |
|
| 690 | + { |
|
| 691 | + $this->set_field_or_extra_meta('MSG_generation_data', $data); |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + |
|
| 695 | + /** |
|
| 696 | + * Returns any set generation data for this message. |
|
| 697 | + * |
|
| 698 | + * @return mixed|null |
|
| 699 | + */ |
|
| 700 | + public function get_generation_data() |
|
| 701 | + { |
|
| 702 | + return $this->get_field_or_extra_meta('MSG_generation_data'); |
|
| 703 | + } |
|
| 704 | + |
|
| 705 | + |
|
| 706 | + /** |
|
| 707 | + * Gets any error message. |
|
| 708 | + * |
|
| 709 | + * @return mixed|null |
|
| 710 | + */ |
|
| 711 | + public function error_message() |
|
| 712 | + { |
|
| 713 | + return $this->get_field_or_extra_meta('MSG_error'); |
|
| 714 | + } |
|
| 715 | + |
|
| 716 | + |
|
| 717 | + /** |
|
| 718 | + * Sets an error message. |
|
| 719 | + * |
|
| 720 | + * @param $message |
|
| 721 | + * @return bool|int |
|
| 722 | + */ |
|
| 723 | + public function set_error_message($message) |
|
| 724 | + { |
|
| 725 | + return $this->set_field_or_extra_meta('MSG_error', $message); |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + |
|
| 729 | + /** |
|
| 730 | + * This retrieves the associated template pack with this message. |
|
| 731 | + * |
|
| 732 | + * @return EE_Messages_Template_Pack | null |
|
| 733 | + */ |
|
| 734 | + public function get_template_pack() |
|
| 735 | + { |
|
| 736 | + /** |
|
| 737 | + * This is deprecated functionality that will be removed eventually but included here now for backward compat. |
|
| 738 | + */ |
|
| 739 | + if (! empty($this->template_pack)) { |
|
| 740 | + return $this->template_pack; |
|
| 741 | + } |
|
| 742 | + /** @type EE_Message_Template_Group $grp */ |
|
| 743 | + $grp = $this->get_first_related('Message_Template_Group'); |
|
| 744 | + // if no group then let's try to get the first related group by internal messenger and message type (will use global grp). |
|
| 745 | + if (! $grp instanceof EE_Message_Template_Group) { |
|
| 746 | + $grp = EEM_Message_Template_Group::instance()->get_one( |
|
| 747 | + array( |
|
| 748 | + array( |
|
| 749 | + 'MTP_messenger' => $this->messenger(), |
|
| 750 | + 'MTP_message_type' => $this->message_type(), |
|
| 751 | + 'MTP_is_global' => true, |
|
| 752 | + ), |
|
| 753 | + ) |
|
| 754 | + ); |
|
| 755 | + } |
|
| 756 | + |
|
| 757 | + return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack() : null; |
|
| 758 | + } |
|
| 759 | + |
|
| 760 | + |
|
| 761 | + /** |
|
| 762 | + * Retrieves the variation used for generating this message. |
|
| 763 | + * |
|
| 764 | + * @return string |
|
| 765 | + */ |
|
| 766 | + public function get_template_pack_variation() |
|
| 767 | + { |
|
| 768 | + /** |
|
| 769 | + * This is deprecated functionality that will be removed eventually but included here now for backward compat. |
|
| 770 | + */ |
|
| 771 | + if (! empty($this->template_variation)) { |
|
| 772 | + return $this->template_variation; |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + /** @type EE_Message_Template_Group $grp */ |
|
| 776 | + $grp = $this->get_first_related('Message_Template_Group'); |
|
| 777 | + |
|
| 778 | + // if no group then let's try to get the first related group by internal messenger and message type (will use global grp). |
|
| 779 | + if (! $grp instanceof EE_Message_Template_Group) { |
|
| 780 | + $grp = EEM_Message_Template_Group::instance()->get_one( |
|
| 781 | + array( |
|
| 782 | + array( |
|
| 783 | + 'MTP_messenger' => $this->messenger(), |
|
| 784 | + 'MTP_message_type' => $this->message_type(), |
|
| 785 | + 'MTP_is_global' => true, |
|
| 786 | + ), |
|
| 787 | + ) |
|
| 788 | + ); |
|
| 789 | + } |
|
| 790 | + |
|
| 791 | + return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack_variation() : ''; |
|
| 792 | + } |
|
| 793 | + |
|
| 794 | + /** |
|
| 795 | + * Return the link to the admin details for the object. |
|
| 796 | + * |
|
| 797 | + * @return string |
|
| 798 | + */ |
|
| 799 | + public function get_admin_details_link() |
|
| 800 | + { |
|
| 801 | + EE_Registry::instance()->load_helper('URL'); |
|
| 802 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 803 | + switch ($this->STS_ID()) { |
|
| 804 | + case EEM_Message::status_failed: |
|
| 805 | + case EEM_Message::status_debug_only: |
|
| 806 | + return EEH_MSG_Template::generate_error_display_trigger($this); |
|
| 807 | + break; |
|
| 808 | + |
|
| 809 | + case EEM_Message::status_sent: |
|
| 810 | + return EEH_MSG_Template::generate_browser_trigger($this); |
|
| 811 | + break; |
|
| 812 | + |
|
| 813 | + default: |
|
| 814 | + return ''; |
|
| 815 | + } |
|
| 816 | + } |
|
| 817 | + |
|
| 818 | + /** |
|
| 819 | + * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
| 820 | + * |
|
| 821 | + * @return string |
|
| 822 | + */ |
|
| 823 | + public function get_admin_edit_link() |
|
| 824 | + { |
|
| 825 | + return $this->get_admin_details_link(); |
|
| 826 | + } |
|
| 827 | + |
|
| 828 | + /** |
|
| 829 | + * Returns the link to a settings page for the object. |
|
| 830 | + * |
|
| 831 | + * @return string |
|
| 832 | + */ |
|
| 833 | + public function get_admin_settings_link() |
|
| 834 | + { |
|
| 835 | + EE_Registry::instance()->load_helper('URL'); |
|
| 836 | + return EEH_URL::add_query_args_and_nonce( |
|
| 837 | + array( |
|
| 838 | + 'page' => 'espresso_messages', |
|
| 839 | + 'action' => 'settings', |
|
| 840 | + ), |
|
| 841 | + admin_url('admin.php') |
|
| 842 | + ); |
|
| 843 | + } |
|
| 844 | + |
|
| 845 | + /** |
|
| 846 | + * Returns the link to the "overview" for the object (typically the "list table" view). |
|
| 847 | + * |
|
| 848 | + * @return string |
|
| 849 | + */ |
|
| 850 | + public function get_admin_overview_link() |
|
| 851 | + { |
|
| 852 | + EE_Registry::instance()->load_helper('URL'); |
|
| 853 | + return EEH_URL::add_query_args_and_nonce( |
|
| 854 | + array( |
|
| 855 | + 'page' => 'espresso_messages', |
|
| 856 | + 'action' => 'default', |
|
| 857 | + ), |
|
| 858 | + admin_url('admin.php') |
|
| 859 | + ); |
|
| 860 | + } |
|
| 861 | + |
|
| 862 | + |
|
| 863 | + /** |
|
| 864 | + * This sets the EEM_Message::status_messenger_executing class on the message and the appropriate error message for |
|
| 865 | + * it. |
|
| 866 | + * Note this also SAVES the current message object to the db because it adds an error message to accompany the |
|
| 867 | + * status. |
|
| 868 | + * |
|
| 869 | + */ |
|
| 870 | + public function set_messenger_is_executing() |
|
| 871 | + { |
|
| 872 | + $this->set_STS_ID(EEM_Message::status_messenger_executing); |
|
| 873 | + $this->set_error_message( |
|
| 874 | + esc_html__( |
|
| 875 | + 'A message with this status indicates that there was a problem that occurred while the message was being |
|
| 876 | 876 | processed by the messenger. It is still possible that the message was sent successfully, but at some |
| 877 | 877 | point during the processing there was a failure. This usually is indicative of a timeout issue with PHP |
| 878 | 878 | or memory limits being reached. If you see this repeatedly you may want to consider upgrading the memory |
| 879 | 879 | available to PHP on your server.', |
| 880 | - 'event_espresso' |
|
| 881 | - ) |
|
| 882 | - ); |
|
| 883 | - } |
|
| 880 | + 'event_espresso' |
|
| 881 | + ) |
|
| 882 | + ); |
|
| 883 | + } |
|
| 884 | 884 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | { |
| 52 | 52 | $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
| 53 | 53 | // if object doesn't exist, let's generate a unique token on instantiation so that its available even before saving to db. |
| 54 | - if (! $has_object) { |
|
| 54 | + if ( ! $has_object) { |
|
| 55 | 55 | EE_Registry::instance()->load_helper('URL'); |
| 56 | 56 | $props_n_values['MSG_token'] = EEH_URL::generate_unique_token(); |
| 57 | 57 | } |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | { |
| 220 | 220 | $label_type = $plural ? 'plural' : 'singular'; |
| 221 | 221 | $messenger = $this->messenger_object(); |
| 222 | - return $messenger instanceof EE_messenger ? $messenger->label[ $label_type ] : $this->messenger(); |
|
| 222 | + return $messenger instanceof EE_messenger ? $messenger->label[$label_type] : $this->messenger(); |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | $this->messenger(), |
| 337 | 337 | $this->message_type() |
| 338 | 338 | ); |
| 339 | - if (! $valid && $throw_exceptions) { |
|
| 339 | + if ( ! $valid && $throw_exceptions) { |
|
| 340 | 340 | throw new EE_Error( |
| 341 | 341 | sprintf( |
| 342 | 342 | __( |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | $label_type = $plural ? 'plural' : 'singular'; |
| 367 | 367 | $message_type = $this->message_type_object(); |
| 368 | 368 | return $message_type instanceof EE_message_type |
| 369 | - ? $message_type->label[ $label_type ] |
|
| 369 | + ? $message_type->label[$label_type] |
|
| 370 | 370 | : str_replace( |
| 371 | 371 | '_', |
| 372 | 372 | ' ', |
@@ -397,7 +397,7 @@ discard block |
||
| 397 | 397 | /** @type EE_Message_Resource_Manager $message_resource_manager */ |
| 398 | 398 | $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
| 399 | 399 | $contexts = $message_resource_manager->get_all_contexts(); |
| 400 | - return isset($contexts[ $this->context() ]) ? $contexts[ $this->context() ] : $this->context(); |
|
| 400 | + return isset($contexts[$this->context()]) ? $contexts[$this->context()] : $this->context(); |
|
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | |
@@ -452,7 +452,7 @@ discard block |
||
| 452 | 452 | */ |
| 453 | 453 | public function recipient_object() |
| 454 | 454 | { |
| 455 | - if (! $this->recipient_type() || ! $this->recipient_ID()) { |
|
| 455 | + if ( ! $this->recipient_type() || ! $this->recipient_ID()) { |
|
| 456 | 456 | return null; |
| 457 | 457 | } |
| 458 | 458 | |
@@ -736,13 +736,13 @@ discard block |
||
| 736 | 736 | /** |
| 737 | 737 | * This is deprecated functionality that will be removed eventually but included here now for backward compat. |
| 738 | 738 | */ |
| 739 | - if (! empty($this->template_pack)) { |
|
| 739 | + if ( ! empty($this->template_pack)) { |
|
| 740 | 740 | return $this->template_pack; |
| 741 | 741 | } |
| 742 | 742 | /** @type EE_Message_Template_Group $grp */ |
| 743 | 743 | $grp = $this->get_first_related('Message_Template_Group'); |
| 744 | 744 | // if no group then let's try to get the first related group by internal messenger and message type (will use global grp). |
| 745 | - if (! $grp instanceof EE_Message_Template_Group) { |
|
| 745 | + if ( ! $grp instanceof EE_Message_Template_Group) { |
|
| 746 | 746 | $grp = EEM_Message_Template_Group::instance()->get_one( |
| 747 | 747 | array( |
| 748 | 748 | array( |
@@ -768,7 +768,7 @@ discard block |
||
| 768 | 768 | /** |
| 769 | 769 | * This is deprecated functionality that will be removed eventually but included here now for backward compat. |
| 770 | 770 | */ |
| 771 | - if (! empty($this->template_variation)) { |
|
| 771 | + if ( ! empty($this->template_variation)) { |
|
| 772 | 772 | return $this->template_variation; |
| 773 | 773 | } |
| 774 | 774 | |
@@ -776,7 +776,7 @@ discard block |
||
| 776 | 776 | $grp = $this->get_first_related('Message_Template_Group'); |
| 777 | 777 | |
| 778 | 778 | // if no group then let's try to get the first related group by internal messenger and message type (will use global grp). |
| 779 | - if (! $grp instanceof EE_Message_Template_Group) { |
|
| 779 | + if ( ! $grp instanceof EE_Message_Template_Group) { |
|
| 780 | 780 | $grp = EEM_Message_Template_Group::instance()->get_one( |
| 781 | 781 | array( |
| 782 | 782 | array( |
@@ -16,673 +16,673 @@ |
||
| 16 | 16 | class EE_CSV |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - // instance of the EE_CSV object |
|
| 20 | - private static $_instance = null; |
|
| 21 | - |
|
| 22 | - |
|
| 23 | - // multidimensional array to store update & error messages |
|
| 24 | - // var $_notices = array( 'updates' => array(), 'errors' => array() ); |
|
| 25 | - |
|
| 26 | - |
|
| 27 | - private $_primary_keys; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * |
|
| 31 | - * @var EE_Registry |
|
| 32 | - */ |
|
| 33 | - private $EE; |
|
| 34 | - /** |
|
| 35 | - * string used for 1st cell in exports, which indicates that the following 2 rows will be metadata keys and values |
|
| 36 | - */ |
|
| 37 | - const metadata_header = 'Event Espresso Export Meta Data'; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * private constructor to prevent direct creation |
|
| 41 | - * |
|
| 42 | - * @Constructor |
|
| 43 | - * @access private |
|
| 44 | - * @return void |
|
| 45 | - */ |
|
| 46 | - private function __construct() |
|
| 47 | - { |
|
| 48 | - global $wpdb; |
|
| 49 | - |
|
| 50 | - $this->_primary_keys = array( |
|
| 51 | - $wpdb->prefix . 'esp_answer' => array('ANS_ID'), |
|
| 52 | - $wpdb->prefix . 'esp_attendee' => array('ATT_ID'), |
|
| 53 | - $wpdb->prefix . 'esp_datetime' => array('DTT_ID'), |
|
| 54 | - $wpdb->prefix . 'esp_event_question_group' => array('EQG_ID'), |
|
| 55 | - $wpdb->prefix . 'esp_message_template' => array('MTP_ID'), |
|
| 56 | - $wpdb->prefix . 'esp_payment' => array('PAY_ID'), |
|
| 57 | - $wpdb->prefix . 'esp_price' => array('PRC_ID'), |
|
| 58 | - $wpdb->prefix . 'esp_price_type' => array('PRT_ID'), |
|
| 59 | - $wpdb->prefix . 'esp_question' => array('QST_ID'), |
|
| 60 | - $wpdb->prefix . 'esp_question_group' => array('QSG_ID'), |
|
| 61 | - $wpdb->prefix . 'esp_question_group_question' => array('QGQ_ID'), |
|
| 62 | - $wpdb->prefix . 'esp_question_option' => array('QSO_ID'), |
|
| 63 | - $wpdb->prefix . 'esp_registration' => array('REG_ID'), |
|
| 64 | - $wpdb->prefix . 'esp_status' => array('STS_ID'), |
|
| 65 | - $wpdb->prefix . 'esp_transaction' => array('TXN_ID'), |
|
| 66 | - $wpdb->prefix . 'esp_transaction' => array('TXN_ID'), |
|
| 67 | - $wpdb->prefix . 'events_detail' => array('id'), |
|
| 68 | - $wpdb->prefix . 'events_category_detail' => array('id'), |
|
| 69 | - $wpdb->prefix . 'events_category_rel' => array('id'), |
|
| 70 | - $wpdb->prefix . 'events_venue' => array('id'), |
|
| 71 | - $wpdb->prefix . 'events_venue_rel' => array('emeta_id'), |
|
| 72 | - $wpdb->prefix . 'events_locale' => array('id'), |
|
| 73 | - $wpdb->prefix . 'events_locale_rel' => array('id'), |
|
| 74 | - $wpdb->prefix . 'events_personnel' => array('id'), |
|
| 75 | - $wpdb->prefix . 'events_personnel_rel' => array('id'), |
|
| 76 | - ); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @ singleton method used to instantiate class object |
|
| 82 | - * @ access public |
|
| 83 | - * |
|
| 84 | - * @return EE_CSV |
|
| 85 | - */ |
|
| 86 | - public static function instance() |
|
| 87 | - { |
|
| 88 | - // check if class object is instantiated |
|
| 89 | - if (self::$_instance === null or ! is_object(self::$_instance) or ! (self::$_instance instanceof EE_CSV)) { |
|
| 90 | - self::$_instance = new self(); |
|
| 91 | - } |
|
| 92 | - return self::$_instance; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Opens a unicode or utf file (normal file_get_contents has difficulty readin ga unicode file. @see |
|
| 97 | - * http://stackoverflow.com/questions/15092764/how-to-read-unicode-text-file-in-php |
|
| 98 | - * |
|
| 99 | - * @param string $file_path |
|
| 100 | - * @return string |
|
| 101 | - * @throws EE_Error |
|
| 102 | - */ |
|
| 103 | - private function read_unicode_file($file_path) |
|
| 104 | - { |
|
| 105 | - $fc = ""; |
|
| 106 | - $fh = fopen($file_path, "rb"); |
|
| 107 | - if (! $fh) { |
|
| 108 | - throw new EE_Error(sprintf(__("Cannot open file for read: %s<br>\n", 'event_espresso'), $file_path)); |
|
| 109 | - } |
|
| 110 | - $flen = filesize($file_path); |
|
| 111 | - $bc = fread($fh, $flen); |
|
| 112 | - for ($i = 0; $i < $flen; $i++) { |
|
| 113 | - $c = substr($bc, $i, 1); |
|
| 114 | - if ((ord($c) != 0) && (ord($c) != 13)) { |
|
| 115 | - $fc = $fc . $c; |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - if ((ord(substr($fc, 0, 1)) == 255) && (ord(substr($fc, 1, 1)) == 254)) { |
|
| 119 | - $fc = substr($fc, 2); |
|
| 120 | - } |
|
| 121 | - return ($fc); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Generic CSV-functionality to turn an entire CSV file into a single array that's |
|
| 127 | - * NOT in a specific format to EE. It's just a 2-level array, with top-level arrays |
|
| 128 | - * representing each row in the CSV file, and the second-level arrays being each column in that row |
|
| 129 | - * |
|
| 130 | - * @param string $path_to_file |
|
| 131 | - * @return array of arrays. Top-level array has rows, second-level array has each item |
|
| 132 | - */ |
|
| 133 | - public function import_csv_to_multi_dimensional_array($path_to_file) |
|
| 134 | - { |
|
| 135 | - // needed to deal with Mac line endings |
|
| 136 | - ini_set('auto_detect_line_endings', true); |
|
| 137 | - |
|
| 138 | - // because fgetcsv does not correctly deal with backslashed quotes such as \" |
|
| 139 | - // we'll read the file into a string |
|
| 140 | - $file_contents = $this->read_unicode_file($path_to_file); |
|
| 141 | - // replace backslashed quotes with CSV enclosures |
|
| 142 | - $file_contents = str_replace('\\"', '"""', $file_contents); |
|
| 143 | - // HEY YOU! PUT THAT FILE BACK!!! |
|
| 144 | - file_put_contents($path_to_file, $file_contents); |
|
| 145 | - |
|
| 146 | - if (($file_handle = fopen($path_to_file, "r")) !== false) { |
|
| 147 | - # Set the parent multidimensional array key to 0. |
|
| 148 | - $nn = 0; |
|
| 149 | - $csvarray = array(); |
|
| 150 | - |
|
| 151 | - // in PHP 5.3 fgetcsv accepts a 5th parameter, but the pre 5.3 versions of fgetcsv choke if passed more than 4 - is that crazy or what? |
|
| 152 | - if (version_compare(PHP_VERSION, '5.3.0') < 0) { |
|
| 153 | - // PHP 5.2- version |
|
| 154 | - // loop through each row of the file |
|
| 155 | - while (($data = fgetcsv($file_handle, 0, ',', '"')) !== false) { |
|
| 156 | - $csvarray[] = $data; |
|
| 157 | - } |
|
| 158 | - } else { |
|
| 159 | - // loop through each row of the file |
|
| 160 | - while (($data = fgetcsv($file_handle, 0, ',', '"', '\\')) !== false) { |
|
| 161 | - $csvarray[] = $data; |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - # Close the File. |
|
| 165 | - fclose($file_handle); |
|
| 166 | - return $csvarray; |
|
| 167 | - } else { |
|
| 168 | - EE_Error::add_error( |
|
| 169 | - sprintf(__("An error occurred - the file: %s could not opened.", "event_espresso"), $path_to_file), |
|
| 170 | - __FILE__, |
|
| 171 | - __FUNCTION__, |
|
| 172 | - __LINE__ |
|
| 173 | - ); |
|
| 174 | - return false; |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * @Import contents of csv file and store values in an array to be manipulated by other functions |
|
| 181 | - * @access public |
|
| 182 | - * @param string $path_to_file - the csv file to be imported including the path to it's location. |
|
| 183 | - * If $model_name is provided, assumes that each row in the CSV represents a |
|
| 184 | - * model object for that model If $model_name ISN'T provided, assumes that |
|
| 185 | - * before model object data, there is a row where the first entry is simply |
|
| 186 | - * 'MODEL', and next entry is the model's name, (untranslated) like Event, and |
|
| 187 | - * then maybe a row of headers, and then the model data. Eg. |
|
| 188 | - * '<br>MODEL,Event,<br>EVT_ID,EVT_name,...<br>1,Monkey |
|
| 189 | - * Party,...<br>2,Llamarama,...<br>MODEL,Venue,<br>VNU_ID,VNU_name<br>1,The |
|
| 190 | - * Forest |
|
| 191 | - * @param string $model_name model name if we know what model we're importing |
|
| 192 | - * @param boolean $first_row_is_headers - whether the first row of data is headers or not - TRUE = headers, FALSE = |
|
| 193 | - * data |
|
| 194 | - * @return mixed - array on success - multi dimensional with headers as keys (if headers exist) OR string on fail - |
|
| 195 | - * error message like the following array('Event'=>array( array('EVT_ID'=>1,'EVT_name'=>'bob |
|
| 196 | - * party',...), array('EVT_ID'=>2,'EVT_name'=>'llamarama',...), |
|
| 197 | - * ... |
|
| 198 | - * ) |
|
| 199 | - * 'Venue'=>array( |
|
| 200 | - * array('VNU_ID'=>1,'VNU_name'=>'the shack',...), |
|
| 201 | - * array('VNU_ID'=>2,'VNU_name'=>'tree house',...), |
|
| 202 | - * ... |
|
| 203 | - * ) |
|
| 204 | - * ... |
|
| 205 | - * ) |
|
| 206 | - */ |
|
| 207 | - public function import_csv_to_model_data_array($path_to_file, $model_name = false, $first_row_is_headers = true) |
|
| 208 | - { |
|
| 209 | - $multi_dimensional_array = $this->import_csv_to_multi_dimensional_array($path_to_file); |
|
| 210 | - if (! $multi_dimensional_array) { |
|
| 211 | - return false; |
|
| 212 | - } |
|
| 213 | - // gotta start somewhere |
|
| 214 | - $row = 1; |
|
| 215 | - // array to store csv data in |
|
| 216 | - $ee_formatted_data = array(); |
|
| 217 | - // array to store headers (column names) |
|
| 218 | - $headers = array(); |
|
| 219 | - foreach ($multi_dimensional_array as $data) { |
|
| 220 | - // if first cell is MODEL, then second cell is the MODEL name |
|
| 221 | - if ($data[0] == 'MODEL') { |
|
| 222 | - $model_name = $data[1]; |
|
| 223 | - // don't bother looking for model data in this row. The rest of this |
|
| 224 | - // row should be blank |
|
| 225 | - // AND pretend this is the first row again |
|
| 226 | - $row = 1; |
|
| 227 | - // reset headers |
|
| 228 | - $headers = array(); |
|
| 229 | - continue; |
|
| 230 | - } |
|
| 231 | - if (strpos($data[0], EE_CSV::metadata_header) !== false) { |
|
| 232 | - $model_name = EE_CSV::metadata_header; |
|
| 233 | - // store like model data, we just won't try importing it etc. |
|
| 234 | - $row = 1; |
|
| 235 | - continue; |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - |
|
| 239 | - // how many columns are there? |
|
| 240 | - $columns = count($data); |
|
| 241 | - |
|
| 242 | - $model_entry = array(); |
|
| 243 | - // loop through each column |
|
| 244 | - for ($i = 0; $i < $columns; $i++) { |
|
| 245 | - // replace csv_enclosures with backslashed quotes |
|
| 246 | - $data[ $i ] = str_replace('"""', '\\"', $data[ $i ]); |
|
| 247 | - // do we need to grab the column names? |
|
| 248 | - if ($row === 1) { |
|
| 249 | - if ($first_row_is_headers) { |
|
| 250 | - // store the column names to use for keys |
|
| 251 | - $column_name = $data[ $i ]; |
|
| 252 | - // check it's not blank... sometimes CSV editign programs adda bunch of empty columns onto the end... |
|
| 253 | - if (! $column_name) { |
|
| 254 | - continue; |
|
| 255 | - } |
|
| 256 | - $matches = array(); |
|
| 257 | - if ($model_name == EE_CSV::metadata_header) { |
|
| 258 | - $headers[ $i ] = $column_name; |
|
| 259 | - } else { |
|
| 260 | - // now get the db table name from it (the part between square brackets) |
|
| 261 | - $success = preg_match('~(.*)\[(.*)\]~', $column_name, $matches); |
|
| 262 | - if (! $success) { |
|
| 263 | - EE_Error::add_error( |
|
| 264 | - sprintf( |
|
| 265 | - __( |
|
| 266 | - "The column titled %s is invalid for importing. It must be be in the format of 'Nice Name[model_field_name]' in row %s", |
|
| 267 | - "event_espresso" |
|
| 268 | - ), |
|
| 269 | - $column_name, |
|
| 270 | - implode(",", $data) |
|
| 271 | - ), |
|
| 272 | - __FILE__, |
|
| 273 | - __FUNCTION__, |
|
| 274 | - __LINE__ |
|
| 275 | - ); |
|
| 276 | - return false; |
|
| 277 | - } |
|
| 278 | - $headers[ $i ] = $matches[2]; |
|
| 279 | - } |
|
| 280 | - } else { |
|
| 281 | - // no column names means our final array will just use counters for keys |
|
| 282 | - $model_entry[ $headers[ $i ] ] = $data[ $i ]; |
|
| 283 | - $headers[ $i ] = $i; |
|
| 284 | - } |
|
| 285 | - // and we need to store csv data |
|
| 286 | - } else { |
|
| 287 | - // this column isn' ta header, store it if there is a header for it |
|
| 288 | - if (isset($headers[ $i ])) { |
|
| 289 | - $model_entry[ $headers[ $i ] ] = $data[ $i ]; |
|
| 290 | - } |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - // save the row's data IF it's a non-header-row |
|
| 294 | - if (! $first_row_is_headers || ($first_row_is_headers && $row > 1)) { |
|
| 295 | - $ee_formatted_data[ $model_name ][] = $model_entry; |
|
| 296 | - } |
|
| 297 | - // advance to next row |
|
| 298 | - $row++; |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - // delete the uploaded file |
|
| 302 | - unlink($path_to_file); |
|
| 303 | - // echo '<pre style="height:auto;border:2px solid lightblue;">' . print_r( $ee_formatted_data, TRUE ) . '</pre><br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>'; |
|
| 304 | - // die(); |
|
| 305 | - |
|
| 306 | - // it's good to give back |
|
| 307 | - return $ee_formatted_data; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - |
|
| 311 | - public function save_csv_to_db($csv_data_array, $model_name = false) |
|
| 312 | - { |
|
| 313 | - EE_Error::doing_it_wrong( |
|
| 314 | - 'save_csv_to_db', |
|
| 315 | - __( |
|
| 316 | - 'Function moved to EE_Import and renamed to save_csv_data_array_to_db', |
|
| 317 | - 'event_espresso' |
|
| 318 | - ), |
|
| 319 | - '4.6.7' |
|
| 320 | - ); |
|
| 321 | - return EE_Import::instance()->save_csv_data_array_to_db($csv_data_array, $model_name); |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * Sends HTTP headers to indicate that the browser should download a file, |
|
| 326 | - * and starts writing the file to PHP's output. Returns the file handle so other functions can |
|
| 327 | - * also write to it |
|
| 328 | - * |
|
| 329 | - * @param string $new_filename the name of the file that the user will download |
|
| 330 | - * @return resource, like the results of fopen(), which can be used for fwrite, fputcsv2, etc. |
|
| 331 | - */ |
|
| 332 | - public function begin_sending_csv($filename) |
|
| 333 | - { |
|
| 334 | - // grab file extension |
|
| 335 | - $ext = substr(strrchr($filename, '.'), 1); |
|
| 336 | - if ($ext == '.csv' or $ext == '.xls') { |
|
| 337 | - str_replace($ext, '', $filename); |
|
| 338 | - } |
|
| 339 | - $filename .= '.csv'; |
|
| 340 | - |
|
| 341 | - // if somebody's been naughty and already started outputting stuff, trash it |
|
| 342 | - // and start writing our stuff. |
|
| 343 | - if (ob_get_length()) { |
|
| 344 | - @ob_flush(); |
|
| 345 | - @flush(); |
|
| 346 | - @ob_end_flush(); |
|
| 347 | - } |
|
| 348 | - @ob_start(); |
|
| 349 | - header("Pragma: public"); |
|
| 350 | - header("Expires: 0"); |
|
| 351 | - header("Pragma: no-cache"); |
|
| 352 | - header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); |
|
| 353 | - // header("Content-Type: application/force-download"); |
|
| 354 | - // header("Content-Type: application/octet-stream"); |
|
| 355 | - // header("Content-Type: application/download"); |
|
| 356 | - header('Content-disposition: attachment; filename=' . $filename); |
|
| 357 | - header("Content-Type: text/csv; charset=utf-8"); |
|
| 358 | - do_action('AHEE__EE_CSV__begin_sending_csv__headers'); |
|
| 359 | - echo apply_filters( |
|
| 360 | - 'FHEE__EE_CSV__begin_sending_csv__start_writing', |
|
| 361 | - "\xEF\xBB\xBF" |
|
| 362 | - ); // makes excel open it as UTF-8. UTF-8 BOM, see http://stackoverflow.com/a/4440143/2773835 |
|
| 363 | - $fh = fopen('php://output', 'w'); |
|
| 364 | - return $fh; |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - /** |
|
| 368 | - * Writes some meta data to the CSV as a bunch of columns. Initially we're only |
|
| 369 | - * mentioning the version and timezone |
|
| 370 | - * |
|
| 371 | - * @param resource $filehandle |
|
| 372 | - */ |
|
| 373 | - public function write_metadata_to_csv($filehandle) |
|
| 374 | - { |
|
| 375 | - $data_row = array(EE_CSV::metadata_header);// do NOT translate because this exact string is used when importing |
|
| 376 | - $this->fputcsv2($filehandle, $data_row); |
|
| 377 | - $meta_data = array( |
|
| 378 | - 0 => array( |
|
| 379 | - 'version' => espresso_version(), |
|
| 380 | - 'timezone' => EEH_DTT_Helper::get_timezone(), |
|
| 381 | - 'time_of_export' => current_time('mysql'), |
|
| 382 | - 'site_url' => site_url(), |
|
| 383 | - ), |
|
| 384 | - ); |
|
| 385 | - $this->write_data_array_to_csv($filehandle, $meta_data); |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - |
|
| 389 | - /** |
|
| 390 | - * Writes $data to the csv file open in $filehandle. uses the array indices of $data for column headers |
|
| 391 | - * |
|
| 392 | - * @param array $data 2D array, first numerically-indexed, and next-level-down preferably indexed |
|
| 393 | - * by string |
|
| 394 | - * @param boolean $add_csv_column_names whether or not we should add the keys in the bottom-most array as a row for |
|
| 395 | - * headers in the CSV. Eg, if $data looked like |
|
| 396 | - * array(0=>array('EVT_ID'=>1,'EVT_name'=>'monkey'...), 1=>array(...),...)) |
|
| 397 | - * then the first row we'd write to the CSV would be "EVT_ID,EVT_name,..." |
|
| 398 | - * @return boolean if we successfully wrote to the CSV or not. If there's no $data, we consider that a success |
|
| 399 | - * (because we wrote everything there was...nothing) |
|
| 400 | - */ |
|
| 401 | - public function write_data_array_to_csv($filehandle, $data) |
|
| 402 | - { |
|
| 403 | - |
|
| 404 | - |
|
| 405 | - // determine if $data is actually a 2d array |
|
| 406 | - if ($data && is_array($data) && is_array(EEH_Array::get_one_item_from_array($data))) { |
|
| 407 | - // make sure top level is numerically indexed, |
|
| 408 | - |
|
| 409 | - if (EEH_Array::is_associative_array($data)) { |
|
| 410 | - throw new EE_Error( |
|
| 411 | - sprintf( |
|
| 412 | - __( |
|
| 413 | - "top-level array must be numerically indexed. Does these look like numbers to you? %s", |
|
| 414 | - "event_espresso" |
|
| 415 | - ), |
|
| 416 | - implode(",", array_keys($data)) |
|
| 417 | - ) |
|
| 418 | - ); |
|
| 419 | - } |
|
| 420 | - $item_in_top_level_array = EEH_Array::get_one_item_from_array($data); |
|
| 421 | - // now, is the last item in the top-level array of $data an associative or numeric array? |
|
| 422 | - if (EEH_Array::is_associative_array($item_in_top_level_array)) { |
|
| 423 | - // its associative, so we want to output its keys as column headers |
|
| 424 | - $keys = array_keys($item_in_top_level_array); |
|
| 425 | - echo $this->fputcsv2($filehandle, $keys); |
|
| 426 | - } |
|
| 427 | - // start writing data |
|
| 428 | - foreach ($data as $data_row) { |
|
| 429 | - echo $this->fputcsv2($filehandle, $data_row); |
|
| 430 | - } |
|
| 431 | - return true; |
|
| 432 | - } else { |
|
| 433 | - // no data TO write... so we can assume that's a success |
|
| 434 | - return true; |
|
| 435 | - } |
|
| 436 | - // //if 2nd level is indexed by strings, use those as csv column headers (ie, the first row) |
|
| 437 | - // |
|
| 438 | - // |
|
| 439 | - // $no_table = TRUE; |
|
| 440 | - // |
|
| 441 | - // // loop through data and add each row to the file/stream as csv |
|
| 442 | - // foreach ( $data as $model_name => $model_data ) { |
|
| 443 | - // // test first row to see if it is data or a model name |
|
| 444 | - // $model = EE_Registry::instance();->load_model($model_name); |
|
| 445 | - // //if the model really exists, |
|
| 446 | - // if ( $model ) { |
|
| 447 | - // |
|
| 448 | - // // we have a table name |
|
| 449 | - // $no_table = FALSE; |
|
| 450 | - // |
|
| 451 | - // // put the tablename into an array cuz that's how fputcsv rolls |
|
| 452 | - // $model_name_row = array( 'MODEL', $model_name ); |
|
| 453 | - // |
|
| 454 | - // // add table name to csv output |
|
| 455 | - // echo self::fputcsv2($filehandle, $model_name_row); |
|
| 456 | - // |
|
| 457 | - // // now get the rest of the data |
|
| 458 | - // foreach ( $model_data as $row ) { |
|
| 459 | - // // output the row |
|
| 460 | - // echo self::fputcsv2($filehandle, $row); |
|
| 461 | - // } |
|
| 462 | - // |
|
| 463 | - // } |
|
| 464 | - // |
|
| 465 | - // if ( $no_table ) { |
|
| 466 | - // // no table so just put the data |
|
| 467 | - // echo self::fputcsv2($filehandle, $model_data); |
|
| 468 | - // } |
|
| 469 | - // |
|
| 470 | - // } // END OF foreach ( $data ) |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - /** |
|
| 474 | - * Should be called after begin_sending_csv(), and one or more write_data_array_to_csv()s. |
|
| 475 | - * Calls exit to prevent polluting the CSV file with other junk |
|
| 476 | - * |
|
| 477 | - * @param resource $fh filehandle where we're writing the CSV to |
|
| 478 | - */ |
|
| 479 | - public function end_sending_csv($fh) |
|
| 480 | - { |
|
| 481 | - fclose($fh); |
|
| 482 | - exit(0); |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - /** |
|
| 486 | - * Given an open file, writes all the model data to it in the format the importer expects. |
|
| 487 | - * Usually preceded by begin_sending_csv($filename), and followed by end_sending_csv($filehandle). |
|
| 488 | - * |
|
| 489 | - * @param resource $filehandle |
|
| 490 | - * @param array $model_data_array is assumed to be a 3d array: 1st layer has keys of model names (eg 'Event'), |
|
| 491 | - * next layer is numerically indexed to represent each model object (eg, each |
|
| 492 | - * individual event), and the last layer has all the attributes o fthat model |
|
| 493 | - * object (eg, the event's id, name, etc) |
|
| 494 | - * @return boolean success |
|
| 495 | - */ |
|
| 496 | - public function write_model_data_to_csv($filehandle, $model_data_array) |
|
| 497 | - { |
|
| 498 | - $this->write_metadata_to_csv($filehandle); |
|
| 499 | - foreach ($model_data_array as $model_name => $model_instance_arrays) { |
|
| 500 | - // first: output a special row stating the model |
|
| 501 | - echo $this->fputcsv2($filehandle, array('MODEL', $model_name)); |
|
| 502 | - // if we have items to put in the CSV, do it normally |
|
| 503 | - |
|
| 504 | - if (! empty($model_instance_arrays)) { |
|
| 505 | - $this->write_data_array_to_csv($filehandle, $model_instance_arrays); |
|
| 506 | - } else { |
|
| 507 | - // echo "no data to write... so just write the headers"; |
|
| 508 | - // so there's actually NO model objects for that model. |
|
| 509 | - // probably still want to show the columns |
|
| 510 | - $model = EE_Registry::instance()->load_model($model_name); |
|
| 511 | - $column_names = array(); |
|
| 512 | - foreach ($model->field_settings() as $field) { |
|
| 513 | - $column_names[ $field->get_nicename() . "[" . $field->get_name() . "]" ] = null; |
|
| 514 | - } |
|
| 515 | - $this->write_data_array_to_csv($filehandle, array($column_names)); |
|
| 516 | - } |
|
| 517 | - } |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - /** |
|
| 521 | - * Writes the CSV file to the output buffer, with rows corresponding to $model_data_array, |
|
| 522 | - * and dies (in order to avoid other plugins from messing up the csv output) |
|
| 523 | - * |
|
| 524 | - * @param string $filename the filename you want to give the file |
|
| 525 | - * @param array $model_data_array 3d array, as described in EE_CSV::write_model_data_to_csv() |
|
| 526 | - * @return bool | void writes CSV file to output and dies |
|
| 527 | - */ |
|
| 528 | - public function export_multiple_model_data_to_csv($filename, $model_data_array) |
|
| 529 | - { |
|
| 530 | - $filehandle = $this->begin_sending_csv($filename); |
|
| 531 | - $this->write_model_data_to_csv($filehandle, $model_data_array); |
|
| 532 | - $this->end_sending_csv($filehandle); |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - /** |
|
| 536 | - * @Export contents of an array to csv file |
|
| 537 | - * @access public |
|
| 538 | - * @param array $data - the array of data to be converted to csv and exported |
|
| 539 | - * @param string $filename - name for newly created csv file |
|
| 540 | - * @return TRUE on success, FALSE on fail |
|
| 541 | - */ |
|
| 542 | - public function export_array_to_csv($data = false, $filename = false) |
|
| 543 | - { |
|
| 544 | - |
|
| 545 | - // no data file?? get outta here |
|
| 546 | - if (! $data or ! is_array($data) or empty($data)) { |
|
| 547 | - return false; |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - // no filename?? get outta here |
|
| 551 | - if (! $filename) { |
|
| 552 | - return false; |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - |
|
| 556 | - // somebody told me i might need this ??? |
|
| 557 | - global $wpdb; |
|
| 558 | - $prefix = $wpdb->prefix; |
|
| 559 | - |
|
| 560 | - |
|
| 561 | - $fh = $this->begin_sending_csv($filename); |
|
| 562 | - |
|
| 563 | - |
|
| 564 | - $this->end_sending_csv($fh); |
|
| 565 | - } |
|
| 566 | - |
|
| 567 | - |
|
| 568 | - /** |
|
| 569 | - * @Determine the maximum upload file size based on php.ini settings |
|
| 570 | - * @access public |
|
| 571 | - * @param int $percent_of_max - desired percentage of the max upload_mb |
|
| 572 | - * @return int KB |
|
| 573 | - */ |
|
| 574 | - public function get_max_upload_size($percent_of_max = false) |
|
| 575 | - { |
|
| 576 | - |
|
| 577 | - $max_upload = (int) (ini_get('upload_max_filesize')); |
|
| 578 | - $max_post = (int) (ini_get('post_max_size')); |
|
| 579 | - $memory_limit = (int) (ini_get('memory_limit')); |
|
| 580 | - |
|
| 581 | - // determine the smallest of the three values from above |
|
| 582 | - $upload_mb = min($max_upload, $max_post, $memory_limit); |
|
| 583 | - |
|
| 584 | - // convert MB to KB |
|
| 585 | - $upload_mb = $upload_mb * 1024; |
|
| 586 | - |
|
| 587 | - // don't want the full monty? then reduce the max uplaod size |
|
| 588 | - if ($percent_of_max) { |
|
| 589 | - // is percent_of_max like this -> 50 or like this -> 0.50 ? |
|
| 590 | - if ($percent_of_max > 1) { |
|
| 591 | - // chnages 50 to 0.50 |
|
| 592 | - $percent_of_max = $percent_of_max / 100; |
|
| 593 | - } |
|
| 594 | - // make upload_mb a percentage of the max upload_mb |
|
| 595 | - $upload_mb = $upload_mb * $percent_of_max; |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - return $upload_mb; |
|
| 599 | - } |
|
| 600 | - |
|
| 601 | - |
|
| 602 | - /** |
|
| 603 | - * @Drop in replacement for PHP's fputcsv function - but this one works!!! |
|
| 604 | - * @access private |
|
| 605 | - * @param resource $fh - file handle - what we are writing to |
|
| 606 | - * @param array $row - individual row of csv data |
|
| 607 | - * @param string $delimiter - csv delimiter |
|
| 608 | - * @param string $enclosure - csv enclosure |
|
| 609 | - * @param string $mysql_null - allows php NULL to be overridden with MySQl's insertable NULL value |
|
| 610 | - * @return void |
|
| 611 | - */ |
|
| 612 | - private function fputcsv2($fh, array $row, $delimiter = ',', $enclosure = '"', $mysql_null = false) |
|
| 613 | - { |
|
| 614 | - // Allow user to filter the csv delimiter and enclosure for other countries csv standards |
|
| 615 | - $delimiter = apply_filters('FHEE__EE_CSV__fputcsv2__delimiter', $delimiter); |
|
| 616 | - $enclosure = apply_filters('FHEE__EE_CSV__fputcsv2__enclosure', $enclosure); |
|
| 617 | - |
|
| 618 | - $delimiter_esc = preg_quote($delimiter, '/'); |
|
| 619 | - $enclosure_esc = preg_quote($enclosure, '/'); |
|
| 620 | - |
|
| 621 | - $output = array(); |
|
| 622 | - foreach ($row as $field_value) { |
|
| 623 | - if (is_object($field_value) || is_array($field_value)) { |
|
| 624 | - $field_value = serialize($field_value); |
|
| 625 | - } |
|
| 626 | - if ($field_value === null && $mysql_null) { |
|
| 627 | - $output[] = 'NULL'; |
|
| 628 | - continue; |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - $output[] = preg_match("/(?:${delimiter_esc}|${enclosure_esc}|\s)/", $field_value) ? |
|
| 632 | - ($enclosure . str_replace($enclosure, $enclosure . $enclosure, $field_value) . $enclosure) |
|
| 633 | - : $field_value; |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - fwrite($fh, join($delimiter, $output) . PHP_EOL); |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - |
|
| 640 | - // /** |
|
| 641 | - // * @CSV Import / Export messages |
|
| 642 | - // * @access public |
|
| 643 | - // * @return void |
|
| 644 | - // */ |
|
| 645 | - // public function csv_admin_notices() |
|
| 646 | - // { |
|
| 647 | - // |
|
| 648 | - // // We play both kinds of music here! Country AND Western! - err... I mean, cycle through both types of notices |
|
| 649 | - // foreach (array('updates', 'errors') as $type) { |
|
| 650 | - // |
|
| 651 | - // // if particular notice type is not empty, then "You've got Mail" |
|
| 652 | - // if (! empty($this->_notices[ $type ])) { |
|
| 653 | - // |
|
| 654 | - // // is it an update or an error ? |
|
| 655 | - // $msg_class = $type == 'updates' ? 'updated' : 'error'; |
|
| 656 | - // echo '<div id="message" class="' . $msg_class . '">'; |
|
| 657 | - // // display each notice, however many that may be |
|
| 658 | - // foreach ($this->_notices[ $type ] as $message) { |
|
| 659 | - // echo '<p>' . $message . '</p>'; |
|
| 660 | - // } |
|
| 661 | - // // wrap it up |
|
| 662 | - // echo '</div>'; |
|
| 663 | - // } |
|
| 664 | - // } |
|
| 665 | - // } |
|
| 666 | - |
|
| 667 | - /** |
|
| 668 | - * Gets the date format to use in teh csv. filterable |
|
| 669 | - * |
|
| 670 | - * @param string $current_format |
|
| 671 | - * @return string |
|
| 672 | - */ |
|
| 673 | - public function get_date_format_for_csv($current_format = null) |
|
| 674 | - { |
|
| 675 | - return apply_filters('FHEE__EE_CSV__get_date_format_for_csv__format', 'Y-m-d', $current_format); |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - /** |
|
| 679 | - * Gets the time format we want to use in CSV reports. Filterable |
|
| 680 | - * |
|
| 681 | - * @param string $current_format |
|
| 682 | - * @return string |
|
| 683 | - */ |
|
| 684 | - public function get_time_format_for_csv($current_format = null) |
|
| 685 | - { |
|
| 686 | - return apply_filters('FHEE__EE_CSV__get_time_format_for_csv__format', 'H:i:s', $current_format); |
|
| 687 | - } |
|
| 19 | + // instance of the EE_CSV object |
|
| 20 | + private static $_instance = null; |
|
| 21 | + |
|
| 22 | + |
|
| 23 | + // multidimensional array to store update & error messages |
|
| 24 | + // var $_notices = array( 'updates' => array(), 'errors' => array() ); |
|
| 25 | + |
|
| 26 | + |
|
| 27 | + private $_primary_keys; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * |
|
| 31 | + * @var EE_Registry |
|
| 32 | + */ |
|
| 33 | + private $EE; |
|
| 34 | + /** |
|
| 35 | + * string used for 1st cell in exports, which indicates that the following 2 rows will be metadata keys and values |
|
| 36 | + */ |
|
| 37 | + const metadata_header = 'Event Espresso Export Meta Data'; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * private constructor to prevent direct creation |
|
| 41 | + * |
|
| 42 | + * @Constructor |
|
| 43 | + * @access private |
|
| 44 | + * @return void |
|
| 45 | + */ |
|
| 46 | + private function __construct() |
|
| 47 | + { |
|
| 48 | + global $wpdb; |
|
| 49 | + |
|
| 50 | + $this->_primary_keys = array( |
|
| 51 | + $wpdb->prefix . 'esp_answer' => array('ANS_ID'), |
|
| 52 | + $wpdb->prefix . 'esp_attendee' => array('ATT_ID'), |
|
| 53 | + $wpdb->prefix . 'esp_datetime' => array('DTT_ID'), |
|
| 54 | + $wpdb->prefix . 'esp_event_question_group' => array('EQG_ID'), |
|
| 55 | + $wpdb->prefix . 'esp_message_template' => array('MTP_ID'), |
|
| 56 | + $wpdb->prefix . 'esp_payment' => array('PAY_ID'), |
|
| 57 | + $wpdb->prefix . 'esp_price' => array('PRC_ID'), |
|
| 58 | + $wpdb->prefix . 'esp_price_type' => array('PRT_ID'), |
|
| 59 | + $wpdb->prefix . 'esp_question' => array('QST_ID'), |
|
| 60 | + $wpdb->prefix . 'esp_question_group' => array('QSG_ID'), |
|
| 61 | + $wpdb->prefix . 'esp_question_group_question' => array('QGQ_ID'), |
|
| 62 | + $wpdb->prefix . 'esp_question_option' => array('QSO_ID'), |
|
| 63 | + $wpdb->prefix . 'esp_registration' => array('REG_ID'), |
|
| 64 | + $wpdb->prefix . 'esp_status' => array('STS_ID'), |
|
| 65 | + $wpdb->prefix . 'esp_transaction' => array('TXN_ID'), |
|
| 66 | + $wpdb->prefix . 'esp_transaction' => array('TXN_ID'), |
|
| 67 | + $wpdb->prefix . 'events_detail' => array('id'), |
|
| 68 | + $wpdb->prefix . 'events_category_detail' => array('id'), |
|
| 69 | + $wpdb->prefix . 'events_category_rel' => array('id'), |
|
| 70 | + $wpdb->prefix . 'events_venue' => array('id'), |
|
| 71 | + $wpdb->prefix . 'events_venue_rel' => array('emeta_id'), |
|
| 72 | + $wpdb->prefix . 'events_locale' => array('id'), |
|
| 73 | + $wpdb->prefix . 'events_locale_rel' => array('id'), |
|
| 74 | + $wpdb->prefix . 'events_personnel' => array('id'), |
|
| 75 | + $wpdb->prefix . 'events_personnel_rel' => array('id'), |
|
| 76 | + ); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @ singleton method used to instantiate class object |
|
| 82 | + * @ access public |
|
| 83 | + * |
|
| 84 | + * @return EE_CSV |
|
| 85 | + */ |
|
| 86 | + public static function instance() |
|
| 87 | + { |
|
| 88 | + // check if class object is instantiated |
|
| 89 | + if (self::$_instance === null or ! is_object(self::$_instance) or ! (self::$_instance instanceof EE_CSV)) { |
|
| 90 | + self::$_instance = new self(); |
|
| 91 | + } |
|
| 92 | + return self::$_instance; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Opens a unicode or utf file (normal file_get_contents has difficulty readin ga unicode file. @see |
|
| 97 | + * http://stackoverflow.com/questions/15092764/how-to-read-unicode-text-file-in-php |
|
| 98 | + * |
|
| 99 | + * @param string $file_path |
|
| 100 | + * @return string |
|
| 101 | + * @throws EE_Error |
|
| 102 | + */ |
|
| 103 | + private function read_unicode_file($file_path) |
|
| 104 | + { |
|
| 105 | + $fc = ""; |
|
| 106 | + $fh = fopen($file_path, "rb"); |
|
| 107 | + if (! $fh) { |
|
| 108 | + throw new EE_Error(sprintf(__("Cannot open file for read: %s<br>\n", 'event_espresso'), $file_path)); |
|
| 109 | + } |
|
| 110 | + $flen = filesize($file_path); |
|
| 111 | + $bc = fread($fh, $flen); |
|
| 112 | + for ($i = 0; $i < $flen; $i++) { |
|
| 113 | + $c = substr($bc, $i, 1); |
|
| 114 | + if ((ord($c) != 0) && (ord($c) != 13)) { |
|
| 115 | + $fc = $fc . $c; |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + if ((ord(substr($fc, 0, 1)) == 255) && (ord(substr($fc, 1, 1)) == 254)) { |
|
| 119 | + $fc = substr($fc, 2); |
|
| 120 | + } |
|
| 121 | + return ($fc); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Generic CSV-functionality to turn an entire CSV file into a single array that's |
|
| 127 | + * NOT in a specific format to EE. It's just a 2-level array, with top-level arrays |
|
| 128 | + * representing each row in the CSV file, and the second-level arrays being each column in that row |
|
| 129 | + * |
|
| 130 | + * @param string $path_to_file |
|
| 131 | + * @return array of arrays. Top-level array has rows, second-level array has each item |
|
| 132 | + */ |
|
| 133 | + public function import_csv_to_multi_dimensional_array($path_to_file) |
|
| 134 | + { |
|
| 135 | + // needed to deal with Mac line endings |
|
| 136 | + ini_set('auto_detect_line_endings', true); |
|
| 137 | + |
|
| 138 | + // because fgetcsv does not correctly deal with backslashed quotes such as \" |
|
| 139 | + // we'll read the file into a string |
|
| 140 | + $file_contents = $this->read_unicode_file($path_to_file); |
|
| 141 | + // replace backslashed quotes with CSV enclosures |
|
| 142 | + $file_contents = str_replace('\\"', '"""', $file_contents); |
|
| 143 | + // HEY YOU! PUT THAT FILE BACK!!! |
|
| 144 | + file_put_contents($path_to_file, $file_contents); |
|
| 145 | + |
|
| 146 | + if (($file_handle = fopen($path_to_file, "r")) !== false) { |
|
| 147 | + # Set the parent multidimensional array key to 0. |
|
| 148 | + $nn = 0; |
|
| 149 | + $csvarray = array(); |
|
| 150 | + |
|
| 151 | + // in PHP 5.3 fgetcsv accepts a 5th parameter, but the pre 5.3 versions of fgetcsv choke if passed more than 4 - is that crazy or what? |
|
| 152 | + if (version_compare(PHP_VERSION, '5.3.0') < 0) { |
|
| 153 | + // PHP 5.2- version |
|
| 154 | + // loop through each row of the file |
|
| 155 | + while (($data = fgetcsv($file_handle, 0, ',', '"')) !== false) { |
|
| 156 | + $csvarray[] = $data; |
|
| 157 | + } |
|
| 158 | + } else { |
|
| 159 | + // loop through each row of the file |
|
| 160 | + while (($data = fgetcsv($file_handle, 0, ',', '"', '\\')) !== false) { |
|
| 161 | + $csvarray[] = $data; |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + # Close the File. |
|
| 165 | + fclose($file_handle); |
|
| 166 | + return $csvarray; |
|
| 167 | + } else { |
|
| 168 | + EE_Error::add_error( |
|
| 169 | + sprintf(__("An error occurred - the file: %s could not opened.", "event_espresso"), $path_to_file), |
|
| 170 | + __FILE__, |
|
| 171 | + __FUNCTION__, |
|
| 172 | + __LINE__ |
|
| 173 | + ); |
|
| 174 | + return false; |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * @Import contents of csv file and store values in an array to be manipulated by other functions |
|
| 181 | + * @access public |
|
| 182 | + * @param string $path_to_file - the csv file to be imported including the path to it's location. |
|
| 183 | + * If $model_name is provided, assumes that each row in the CSV represents a |
|
| 184 | + * model object for that model If $model_name ISN'T provided, assumes that |
|
| 185 | + * before model object data, there is a row where the first entry is simply |
|
| 186 | + * 'MODEL', and next entry is the model's name, (untranslated) like Event, and |
|
| 187 | + * then maybe a row of headers, and then the model data. Eg. |
|
| 188 | + * '<br>MODEL,Event,<br>EVT_ID,EVT_name,...<br>1,Monkey |
|
| 189 | + * Party,...<br>2,Llamarama,...<br>MODEL,Venue,<br>VNU_ID,VNU_name<br>1,The |
|
| 190 | + * Forest |
|
| 191 | + * @param string $model_name model name if we know what model we're importing |
|
| 192 | + * @param boolean $first_row_is_headers - whether the first row of data is headers or not - TRUE = headers, FALSE = |
|
| 193 | + * data |
|
| 194 | + * @return mixed - array on success - multi dimensional with headers as keys (if headers exist) OR string on fail - |
|
| 195 | + * error message like the following array('Event'=>array( array('EVT_ID'=>1,'EVT_name'=>'bob |
|
| 196 | + * party',...), array('EVT_ID'=>2,'EVT_name'=>'llamarama',...), |
|
| 197 | + * ... |
|
| 198 | + * ) |
|
| 199 | + * 'Venue'=>array( |
|
| 200 | + * array('VNU_ID'=>1,'VNU_name'=>'the shack',...), |
|
| 201 | + * array('VNU_ID'=>2,'VNU_name'=>'tree house',...), |
|
| 202 | + * ... |
|
| 203 | + * ) |
|
| 204 | + * ... |
|
| 205 | + * ) |
|
| 206 | + */ |
|
| 207 | + public function import_csv_to_model_data_array($path_to_file, $model_name = false, $first_row_is_headers = true) |
|
| 208 | + { |
|
| 209 | + $multi_dimensional_array = $this->import_csv_to_multi_dimensional_array($path_to_file); |
|
| 210 | + if (! $multi_dimensional_array) { |
|
| 211 | + return false; |
|
| 212 | + } |
|
| 213 | + // gotta start somewhere |
|
| 214 | + $row = 1; |
|
| 215 | + // array to store csv data in |
|
| 216 | + $ee_formatted_data = array(); |
|
| 217 | + // array to store headers (column names) |
|
| 218 | + $headers = array(); |
|
| 219 | + foreach ($multi_dimensional_array as $data) { |
|
| 220 | + // if first cell is MODEL, then second cell is the MODEL name |
|
| 221 | + if ($data[0] == 'MODEL') { |
|
| 222 | + $model_name = $data[1]; |
|
| 223 | + // don't bother looking for model data in this row. The rest of this |
|
| 224 | + // row should be blank |
|
| 225 | + // AND pretend this is the first row again |
|
| 226 | + $row = 1; |
|
| 227 | + // reset headers |
|
| 228 | + $headers = array(); |
|
| 229 | + continue; |
|
| 230 | + } |
|
| 231 | + if (strpos($data[0], EE_CSV::metadata_header) !== false) { |
|
| 232 | + $model_name = EE_CSV::metadata_header; |
|
| 233 | + // store like model data, we just won't try importing it etc. |
|
| 234 | + $row = 1; |
|
| 235 | + continue; |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + |
|
| 239 | + // how many columns are there? |
|
| 240 | + $columns = count($data); |
|
| 241 | + |
|
| 242 | + $model_entry = array(); |
|
| 243 | + // loop through each column |
|
| 244 | + for ($i = 0; $i < $columns; $i++) { |
|
| 245 | + // replace csv_enclosures with backslashed quotes |
|
| 246 | + $data[ $i ] = str_replace('"""', '\\"', $data[ $i ]); |
|
| 247 | + // do we need to grab the column names? |
|
| 248 | + if ($row === 1) { |
|
| 249 | + if ($first_row_is_headers) { |
|
| 250 | + // store the column names to use for keys |
|
| 251 | + $column_name = $data[ $i ]; |
|
| 252 | + // check it's not blank... sometimes CSV editign programs adda bunch of empty columns onto the end... |
|
| 253 | + if (! $column_name) { |
|
| 254 | + continue; |
|
| 255 | + } |
|
| 256 | + $matches = array(); |
|
| 257 | + if ($model_name == EE_CSV::metadata_header) { |
|
| 258 | + $headers[ $i ] = $column_name; |
|
| 259 | + } else { |
|
| 260 | + // now get the db table name from it (the part between square brackets) |
|
| 261 | + $success = preg_match('~(.*)\[(.*)\]~', $column_name, $matches); |
|
| 262 | + if (! $success) { |
|
| 263 | + EE_Error::add_error( |
|
| 264 | + sprintf( |
|
| 265 | + __( |
|
| 266 | + "The column titled %s is invalid for importing. It must be be in the format of 'Nice Name[model_field_name]' in row %s", |
|
| 267 | + "event_espresso" |
|
| 268 | + ), |
|
| 269 | + $column_name, |
|
| 270 | + implode(",", $data) |
|
| 271 | + ), |
|
| 272 | + __FILE__, |
|
| 273 | + __FUNCTION__, |
|
| 274 | + __LINE__ |
|
| 275 | + ); |
|
| 276 | + return false; |
|
| 277 | + } |
|
| 278 | + $headers[ $i ] = $matches[2]; |
|
| 279 | + } |
|
| 280 | + } else { |
|
| 281 | + // no column names means our final array will just use counters for keys |
|
| 282 | + $model_entry[ $headers[ $i ] ] = $data[ $i ]; |
|
| 283 | + $headers[ $i ] = $i; |
|
| 284 | + } |
|
| 285 | + // and we need to store csv data |
|
| 286 | + } else { |
|
| 287 | + // this column isn' ta header, store it if there is a header for it |
|
| 288 | + if (isset($headers[ $i ])) { |
|
| 289 | + $model_entry[ $headers[ $i ] ] = $data[ $i ]; |
|
| 290 | + } |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + // save the row's data IF it's a non-header-row |
|
| 294 | + if (! $first_row_is_headers || ($first_row_is_headers && $row > 1)) { |
|
| 295 | + $ee_formatted_data[ $model_name ][] = $model_entry; |
|
| 296 | + } |
|
| 297 | + // advance to next row |
|
| 298 | + $row++; |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + // delete the uploaded file |
|
| 302 | + unlink($path_to_file); |
|
| 303 | + // echo '<pre style="height:auto;border:2px solid lightblue;">' . print_r( $ee_formatted_data, TRUE ) . '</pre><br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>'; |
|
| 304 | + // die(); |
|
| 305 | + |
|
| 306 | + // it's good to give back |
|
| 307 | + return $ee_formatted_data; |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + |
|
| 311 | + public function save_csv_to_db($csv_data_array, $model_name = false) |
|
| 312 | + { |
|
| 313 | + EE_Error::doing_it_wrong( |
|
| 314 | + 'save_csv_to_db', |
|
| 315 | + __( |
|
| 316 | + 'Function moved to EE_Import and renamed to save_csv_data_array_to_db', |
|
| 317 | + 'event_espresso' |
|
| 318 | + ), |
|
| 319 | + '4.6.7' |
|
| 320 | + ); |
|
| 321 | + return EE_Import::instance()->save_csv_data_array_to_db($csv_data_array, $model_name); |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * Sends HTTP headers to indicate that the browser should download a file, |
|
| 326 | + * and starts writing the file to PHP's output. Returns the file handle so other functions can |
|
| 327 | + * also write to it |
|
| 328 | + * |
|
| 329 | + * @param string $new_filename the name of the file that the user will download |
|
| 330 | + * @return resource, like the results of fopen(), which can be used for fwrite, fputcsv2, etc. |
|
| 331 | + */ |
|
| 332 | + public function begin_sending_csv($filename) |
|
| 333 | + { |
|
| 334 | + // grab file extension |
|
| 335 | + $ext = substr(strrchr($filename, '.'), 1); |
|
| 336 | + if ($ext == '.csv' or $ext == '.xls') { |
|
| 337 | + str_replace($ext, '', $filename); |
|
| 338 | + } |
|
| 339 | + $filename .= '.csv'; |
|
| 340 | + |
|
| 341 | + // if somebody's been naughty and already started outputting stuff, trash it |
|
| 342 | + // and start writing our stuff. |
|
| 343 | + if (ob_get_length()) { |
|
| 344 | + @ob_flush(); |
|
| 345 | + @flush(); |
|
| 346 | + @ob_end_flush(); |
|
| 347 | + } |
|
| 348 | + @ob_start(); |
|
| 349 | + header("Pragma: public"); |
|
| 350 | + header("Expires: 0"); |
|
| 351 | + header("Pragma: no-cache"); |
|
| 352 | + header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); |
|
| 353 | + // header("Content-Type: application/force-download"); |
|
| 354 | + // header("Content-Type: application/octet-stream"); |
|
| 355 | + // header("Content-Type: application/download"); |
|
| 356 | + header('Content-disposition: attachment; filename=' . $filename); |
|
| 357 | + header("Content-Type: text/csv; charset=utf-8"); |
|
| 358 | + do_action('AHEE__EE_CSV__begin_sending_csv__headers'); |
|
| 359 | + echo apply_filters( |
|
| 360 | + 'FHEE__EE_CSV__begin_sending_csv__start_writing', |
|
| 361 | + "\xEF\xBB\xBF" |
|
| 362 | + ); // makes excel open it as UTF-8. UTF-8 BOM, see http://stackoverflow.com/a/4440143/2773835 |
|
| 363 | + $fh = fopen('php://output', 'w'); |
|
| 364 | + return $fh; |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + /** |
|
| 368 | + * Writes some meta data to the CSV as a bunch of columns. Initially we're only |
|
| 369 | + * mentioning the version and timezone |
|
| 370 | + * |
|
| 371 | + * @param resource $filehandle |
|
| 372 | + */ |
|
| 373 | + public function write_metadata_to_csv($filehandle) |
|
| 374 | + { |
|
| 375 | + $data_row = array(EE_CSV::metadata_header);// do NOT translate because this exact string is used when importing |
|
| 376 | + $this->fputcsv2($filehandle, $data_row); |
|
| 377 | + $meta_data = array( |
|
| 378 | + 0 => array( |
|
| 379 | + 'version' => espresso_version(), |
|
| 380 | + 'timezone' => EEH_DTT_Helper::get_timezone(), |
|
| 381 | + 'time_of_export' => current_time('mysql'), |
|
| 382 | + 'site_url' => site_url(), |
|
| 383 | + ), |
|
| 384 | + ); |
|
| 385 | + $this->write_data_array_to_csv($filehandle, $meta_data); |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + |
|
| 389 | + /** |
|
| 390 | + * Writes $data to the csv file open in $filehandle. uses the array indices of $data for column headers |
|
| 391 | + * |
|
| 392 | + * @param array $data 2D array, first numerically-indexed, and next-level-down preferably indexed |
|
| 393 | + * by string |
|
| 394 | + * @param boolean $add_csv_column_names whether or not we should add the keys in the bottom-most array as a row for |
|
| 395 | + * headers in the CSV. Eg, if $data looked like |
|
| 396 | + * array(0=>array('EVT_ID'=>1,'EVT_name'=>'monkey'...), 1=>array(...),...)) |
|
| 397 | + * then the first row we'd write to the CSV would be "EVT_ID,EVT_name,..." |
|
| 398 | + * @return boolean if we successfully wrote to the CSV or not. If there's no $data, we consider that a success |
|
| 399 | + * (because we wrote everything there was...nothing) |
|
| 400 | + */ |
|
| 401 | + public function write_data_array_to_csv($filehandle, $data) |
|
| 402 | + { |
|
| 403 | + |
|
| 404 | + |
|
| 405 | + // determine if $data is actually a 2d array |
|
| 406 | + if ($data && is_array($data) && is_array(EEH_Array::get_one_item_from_array($data))) { |
|
| 407 | + // make sure top level is numerically indexed, |
|
| 408 | + |
|
| 409 | + if (EEH_Array::is_associative_array($data)) { |
|
| 410 | + throw new EE_Error( |
|
| 411 | + sprintf( |
|
| 412 | + __( |
|
| 413 | + "top-level array must be numerically indexed. Does these look like numbers to you? %s", |
|
| 414 | + "event_espresso" |
|
| 415 | + ), |
|
| 416 | + implode(",", array_keys($data)) |
|
| 417 | + ) |
|
| 418 | + ); |
|
| 419 | + } |
|
| 420 | + $item_in_top_level_array = EEH_Array::get_one_item_from_array($data); |
|
| 421 | + // now, is the last item in the top-level array of $data an associative or numeric array? |
|
| 422 | + if (EEH_Array::is_associative_array($item_in_top_level_array)) { |
|
| 423 | + // its associative, so we want to output its keys as column headers |
|
| 424 | + $keys = array_keys($item_in_top_level_array); |
|
| 425 | + echo $this->fputcsv2($filehandle, $keys); |
|
| 426 | + } |
|
| 427 | + // start writing data |
|
| 428 | + foreach ($data as $data_row) { |
|
| 429 | + echo $this->fputcsv2($filehandle, $data_row); |
|
| 430 | + } |
|
| 431 | + return true; |
|
| 432 | + } else { |
|
| 433 | + // no data TO write... so we can assume that's a success |
|
| 434 | + return true; |
|
| 435 | + } |
|
| 436 | + // //if 2nd level is indexed by strings, use those as csv column headers (ie, the first row) |
|
| 437 | + // |
|
| 438 | + // |
|
| 439 | + // $no_table = TRUE; |
|
| 440 | + // |
|
| 441 | + // // loop through data and add each row to the file/stream as csv |
|
| 442 | + // foreach ( $data as $model_name => $model_data ) { |
|
| 443 | + // // test first row to see if it is data or a model name |
|
| 444 | + // $model = EE_Registry::instance();->load_model($model_name); |
|
| 445 | + // //if the model really exists, |
|
| 446 | + // if ( $model ) { |
|
| 447 | + // |
|
| 448 | + // // we have a table name |
|
| 449 | + // $no_table = FALSE; |
|
| 450 | + // |
|
| 451 | + // // put the tablename into an array cuz that's how fputcsv rolls |
|
| 452 | + // $model_name_row = array( 'MODEL', $model_name ); |
|
| 453 | + // |
|
| 454 | + // // add table name to csv output |
|
| 455 | + // echo self::fputcsv2($filehandle, $model_name_row); |
|
| 456 | + // |
|
| 457 | + // // now get the rest of the data |
|
| 458 | + // foreach ( $model_data as $row ) { |
|
| 459 | + // // output the row |
|
| 460 | + // echo self::fputcsv2($filehandle, $row); |
|
| 461 | + // } |
|
| 462 | + // |
|
| 463 | + // } |
|
| 464 | + // |
|
| 465 | + // if ( $no_table ) { |
|
| 466 | + // // no table so just put the data |
|
| 467 | + // echo self::fputcsv2($filehandle, $model_data); |
|
| 468 | + // } |
|
| 469 | + // |
|
| 470 | + // } // END OF foreach ( $data ) |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + /** |
|
| 474 | + * Should be called after begin_sending_csv(), and one or more write_data_array_to_csv()s. |
|
| 475 | + * Calls exit to prevent polluting the CSV file with other junk |
|
| 476 | + * |
|
| 477 | + * @param resource $fh filehandle where we're writing the CSV to |
|
| 478 | + */ |
|
| 479 | + public function end_sending_csv($fh) |
|
| 480 | + { |
|
| 481 | + fclose($fh); |
|
| 482 | + exit(0); |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + /** |
|
| 486 | + * Given an open file, writes all the model data to it in the format the importer expects. |
|
| 487 | + * Usually preceded by begin_sending_csv($filename), and followed by end_sending_csv($filehandle). |
|
| 488 | + * |
|
| 489 | + * @param resource $filehandle |
|
| 490 | + * @param array $model_data_array is assumed to be a 3d array: 1st layer has keys of model names (eg 'Event'), |
|
| 491 | + * next layer is numerically indexed to represent each model object (eg, each |
|
| 492 | + * individual event), and the last layer has all the attributes o fthat model |
|
| 493 | + * object (eg, the event's id, name, etc) |
|
| 494 | + * @return boolean success |
|
| 495 | + */ |
|
| 496 | + public function write_model_data_to_csv($filehandle, $model_data_array) |
|
| 497 | + { |
|
| 498 | + $this->write_metadata_to_csv($filehandle); |
|
| 499 | + foreach ($model_data_array as $model_name => $model_instance_arrays) { |
|
| 500 | + // first: output a special row stating the model |
|
| 501 | + echo $this->fputcsv2($filehandle, array('MODEL', $model_name)); |
|
| 502 | + // if we have items to put in the CSV, do it normally |
|
| 503 | + |
|
| 504 | + if (! empty($model_instance_arrays)) { |
|
| 505 | + $this->write_data_array_to_csv($filehandle, $model_instance_arrays); |
|
| 506 | + } else { |
|
| 507 | + // echo "no data to write... so just write the headers"; |
|
| 508 | + // so there's actually NO model objects for that model. |
|
| 509 | + // probably still want to show the columns |
|
| 510 | + $model = EE_Registry::instance()->load_model($model_name); |
|
| 511 | + $column_names = array(); |
|
| 512 | + foreach ($model->field_settings() as $field) { |
|
| 513 | + $column_names[ $field->get_nicename() . "[" . $field->get_name() . "]" ] = null; |
|
| 514 | + } |
|
| 515 | + $this->write_data_array_to_csv($filehandle, array($column_names)); |
|
| 516 | + } |
|
| 517 | + } |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + /** |
|
| 521 | + * Writes the CSV file to the output buffer, with rows corresponding to $model_data_array, |
|
| 522 | + * and dies (in order to avoid other plugins from messing up the csv output) |
|
| 523 | + * |
|
| 524 | + * @param string $filename the filename you want to give the file |
|
| 525 | + * @param array $model_data_array 3d array, as described in EE_CSV::write_model_data_to_csv() |
|
| 526 | + * @return bool | void writes CSV file to output and dies |
|
| 527 | + */ |
|
| 528 | + public function export_multiple_model_data_to_csv($filename, $model_data_array) |
|
| 529 | + { |
|
| 530 | + $filehandle = $this->begin_sending_csv($filename); |
|
| 531 | + $this->write_model_data_to_csv($filehandle, $model_data_array); |
|
| 532 | + $this->end_sending_csv($filehandle); |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + /** |
|
| 536 | + * @Export contents of an array to csv file |
|
| 537 | + * @access public |
|
| 538 | + * @param array $data - the array of data to be converted to csv and exported |
|
| 539 | + * @param string $filename - name for newly created csv file |
|
| 540 | + * @return TRUE on success, FALSE on fail |
|
| 541 | + */ |
|
| 542 | + public function export_array_to_csv($data = false, $filename = false) |
|
| 543 | + { |
|
| 544 | + |
|
| 545 | + // no data file?? get outta here |
|
| 546 | + if (! $data or ! is_array($data) or empty($data)) { |
|
| 547 | + return false; |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + // no filename?? get outta here |
|
| 551 | + if (! $filename) { |
|
| 552 | + return false; |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + |
|
| 556 | + // somebody told me i might need this ??? |
|
| 557 | + global $wpdb; |
|
| 558 | + $prefix = $wpdb->prefix; |
|
| 559 | + |
|
| 560 | + |
|
| 561 | + $fh = $this->begin_sending_csv($filename); |
|
| 562 | + |
|
| 563 | + |
|
| 564 | + $this->end_sending_csv($fh); |
|
| 565 | + } |
|
| 566 | + |
|
| 567 | + |
|
| 568 | + /** |
|
| 569 | + * @Determine the maximum upload file size based on php.ini settings |
|
| 570 | + * @access public |
|
| 571 | + * @param int $percent_of_max - desired percentage of the max upload_mb |
|
| 572 | + * @return int KB |
|
| 573 | + */ |
|
| 574 | + public function get_max_upload_size($percent_of_max = false) |
|
| 575 | + { |
|
| 576 | + |
|
| 577 | + $max_upload = (int) (ini_get('upload_max_filesize')); |
|
| 578 | + $max_post = (int) (ini_get('post_max_size')); |
|
| 579 | + $memory_limit = (int) (ini_get('memory_limit')); |
|
| 580 | + |
|
| 581 | + // determine the smallest of the three values from above |
|
| 582 | + $upload_mb = min($max_upload, $max_post, $memory_limit); |
|
| 583 | + |
|
| 584 | + // convert MB to KB |
|
| 585 | + $upload_mb = $upload_mb * 1024; |
|
| 586 | + |
|
| 587 | + // don't want the full monty? then reduce the max uplaod size |
|
| 588 | + if ($percent_of_max) { |
|
| 589 | + // is percent_of_max like this -> 50 or like this -> 0.50 ? |
|
| 590 | + if ($percent_of_max > 1) { |
|
| 591 | + // chnages 50 to 0.50 |
|
| 592 | + $percent_of_max = $percent_of_max / 100; |
|
| 593 | + } |
|
| 594 | + // make upload_mb a percentage of the max upload_mb |
|
| 595 | + $upload_mb = $upload_mb * $percent_of_max; |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + return $upload_mb; |
|
| 599 | + } |
|
| 600 | + |
|
| 601 | + |
|
| 602 | + /** |
|
| 603 | + * @Drop in replacement for PHP's fputcsv function - but this one works!!! |
|
| 604 | + * @access private |
|
| 605 | + * @param resource $fh - file handle - what we are writing to |
|
| 606 | + * @param array $row - individual row of csv data |
|
| 607 | + * @param string $delimiter - csv delimiter |
|
| 608 | + * @param string $enclosure - csv enclosure |
|
| 609 | + * @param string $mysql_null - allows php NULL to be overridden with MySQl's insertable NULL value |
|
| 610 | + * @return void |
|
| 611 | + */ |
|
| 612 | + private function fputcsv2($fh, array $row, $delimiter = ',', $enclosure = '"', $mysql_null = false) |
|
| 613 | + { |
|
| 614 | + // Allow user to filter the csv delimiter and enclosure for other countries csv standards |
|
| 615 | + $delimiter = apply_filters('FHEE__EE_CSV__fputcsv2__delimiter', $delimiter); |
|
| 616 | + $enclosure = apply_filters('FHEE__EE_CSV__fputcsv2__enclosure', $enclosure); |
|
| 617 | + |
|
| 618 | + $delimiter_esc = preg_quote($delimiter, '/'); |
|
| 619 | + $enclosure_esc = preg_quote($enclosure, '/'); |
|
| 620 | + |
|
| 621 | + $output = array(); |
|
| 622 | + foreach ($row as $field_value) { |
|
| 623 | + if (is_object($field_value) || is_array($field_value)) { |
|
| 624 | + $field_value = serialize($field_value); |
|
| 625 | + } |
|
| 626 | + if ($field_value === null && $mysql_null) { |
|
| 627 | + $output[] = 'NULL'; |
|
| 628 | + continue; |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + $output[] = preg_match("/(?:${delimiter_esc}|${enclosure_esc}|\s)/", $field_value) ? |
|
| 632 | + ($enclosure . str_replace($enclosure, $enclosure . $enclosure, $field_value) . $enclosure) |
|
| 633 | + : $field_value; |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + fwrite($fh, join($delimiter, $output) . PHP_EOL); |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + |
|
| 640 | + // /** |
|
| 641 | + // * @CSV Import / Export messages |
|
| 642 | + // * @access public |
|
| 643 | + // * @return void |
|
| 644 | + // */ |
|
| 645 | + // public function csv_admin_notices() |
|
| 646 | + // { |
|
| 647 | + // |
|
| 648 | + // // We play both kinds of music here! Country AND Western! - err... I mean, cycle through both types of notices |
|
| 649 | + // foreach (array('updates', 'errors') as $type) { |
|
| 650 | + // |
|
| 651 | + // // if particular notice type is not empty, then "You've got Mail" |
|
| 652 | + // if (! empty($this->_notices[ $type ])) { |
|
| 653 | + // |
|
| 654 | + // // is it an update or an error ? |
|
| 655 | + // $msg_class = $type == 'updates' ? 'updated' : 'error'; |
|
| 656 | + // echo '<div id="message" class="' . $msg_class . '">'; |
|
| 657 | + // // display each notice, however many that may be |
|
| 658 | + // foreach ($this->_notices[ $type ] as $message) { |
|
| 659 | + // echo '<p>' . $message . '</p>'; |
|
| 660 | + // } |
|
| 661 | + // // wrap it up |
|
| 662 | + // echo '</div>'; |
|
| 663 | + // } |
|
| 664 | + // } |
|
| 665 | + // } |
|
| 666 | + |
|
| 667 | + /** |
|
| 668 | + * Gets the date format to use in teh csv. filterable |
|
| 669 | + * |
|
| 670 | + * @param string $current_format |
|
| 671 | + * @return string |
|
| 672 | + */ |
|
| 673 | + public function get_date_format_for_csv($current_format = null) |
|
| 674 | + { |
|
| 675 | + return apply_filters('FHEE__EE_CSV__get_date_format_for_csv__format', 'Y-m-d', $current_format); |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + /** |
|
| 679 | + * Gets the time format we want to use in CSV reports. Filterable |
|
| 680 | + * |
|
| 681 | + * @param string $current_format |
|
| 682 | + * @return string |
|
| 683 | + */ |
|
| 684 | + public function get_time_format_for_csv($current_format = null) |
|
| 685 | + { |
|
| 686 | + return apply_filters('FHEE__EE_CSV__get_time_format_for_csv__format', 'H:i:s', $current_format); |
|
| 687 | + } |
|
| 688 | 688 | } |
@@ -48,31 +48,31 @@ discard block |
||
| 48 | 48 | global $wpdb; |
| 49 | 49 | |
| 50 | 50 | $this->_primary_keys = array( |
| 51 | - $wpdb->prefix . 'esp_answer' => array('ANS_ID'), |
|
| 52 | - $wpdb->prefix . 'esp_attendee' => array('ATT_ID'), |
|
| 53 | - $wpdb->prefix . 'esp_datetime' => array('DTT_ID'), |
|
| 54 | - $wpdb->prefix . 'esp_event_question_group' => array('EQG_ID'), |
|
| 55 | - $wpdb->prefix . 'esp_message_template' => array('MTP_ID'), |
|
| 56 | - $wpdb->prefix . 'esp_payment' => array('PAY_ID'), |
|
| 57 | - $wpdb->prefix . 'esp_price' => array('PRC_ID'), |
|
| 58 | - $wpdb->prefix . 'esp_price_type' => array('PRT_ID'), |
|
| 59 | - $wpdb->prefix . 'esp_question' => array('QST_ID'), |
|
| 60 | - $wpdb->prefix . 'esp_question_group' => array('QSG_ID'), |
|
| 61 | - $wpdb->prefix . 'esp_question_group_question' => array('QGQ_ID'), |
|
| 62 | - $wpdb->prefix . 'esp_question_option' => array('QSO_ID'), |
|
| 63 | - $wpdb->prefix . 'esp_registration' => array('REG_ID'), |
|
| 64 | - $wpdb->prefix . 'esp_status' => array('STS_ID'), |
|
| 65 | - $wpdb->prefix . 'esp_transaction' => array('TXN_ID'), |
|
| 66 | - $wpdb->prefix . 'esp_transaction' => array('TXN_ID'), |
|
| 67 | - $wpdb->prefix . 'events_detail' => array('id'), |
|
| 68 | - $wpdb->prefix . 'events_category_detail' => array('id'), |
|
| 69 | - $wpdb->prefix . 'events_category_rel' => array('id'), |
|
| 70 | - $wpdb->prefix . 'events_venue' => array('id'), |
|
| 71 | - $wpdb->prefix . 'events_venue_rel' => array('emeta_id'), |
|
| 72 | - $wpdb->prefix . 'events_locale' => array('id'), |
|
| 73 | - $wpdb->prefix . 'events_locale_rel' => array('id'), |
|
| 74 | - $wpdb->prefix . 'events_personnel' => array('id'), |
|
| 75 | - $wpdb->prefix . 'events_personnel_rel' => array('id'), |
|
| 51 | + $wpdb->prefix.'esp_answer' => array('ANS_ID'), |
|
| 52 | + $wpdb->prefix.'esp_attendee' => array('ATT_ID'), |
|
| 53 | + $wpdb->prefix.'esp_datetime' => array('DTT_ID'), |
|
| 54 | + $wpdb->prefix.'esp_event_question_group' => array('EQG_ID'), |
|
| 55 | + $wpdb->prefix.'esp_message_template' => array('MTP_ID'), |
|
| 56 | + $wpdb->prefix.'esp_payment' => array('PAY_ID'), |
|
| 57 | + $wpdb->prefix.'esp_price' => array('PRC_ID'), |
|
| 58 | + $wpdb->prefix.'esp_price_type' => array('PRT_ID'), |
|
| 59 | + $wpdb->prefix.'esp_question' => array('QST_ID'), |
|
| 60 | + $wpdb->prefix.'esp_question_group' => array('QSG_ID'), |
|
| 61 | + $wpdb->prefix.'esp_question_group_question' => array('QGQ_ID'), |
|
| 62 | + $wpdb->prefix.'esp_question_option' => array('QSO_ID'), |
|
| 63 | + $wpdb->prefix.'esp_registration' => array('REG_ID'), |
|
| 64 | + $wpdb->prefix.'esp_status' => array('STS_ID'), |
|
| 65 | + $wpdb->prefix.'esp_transaction' => array('TXN_ID'), |
|
| 66 | + $wpdb->prefix.'esp_transaction' => array('TXN_ID'), |
|
| 67 | + $wpdb->prefix.'events_detail' => array('id'), |
|
| 68 | + $wpdb->prefix.'events_category_detail' => array('id'), |
|
| 69 | + $wpdb->prefix.'events_category_rel' => array('id'), |
|
| 70 | + $wpdb->prefix.'events_venue' => array('id'), |
|
| 71 | + $wpdb->prefix.'events_venue_rel' => array('emeta_id'), |
|
| 72 | + $wpdb->prefix.'events_locale' => array('id'), |
|
| 73 | + $wpdb->prefix.'events_locale_rel' => array('id'), |
|
| 74 | + $wpdb->prefix.'events_personnel' => array('id'), |
|
| 75 | + $wpdb->prefix.'events_personnel_rel' => array('id'), |
|
| 76 | 76 | ); |
| 77 | 77 | } |
| 78 | 78 | |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | { |
| 105 | 105 | $fc = ""; |
| 106 | 106 | $fh = fopen($file_path, "rb"); |
| 107 | - if (! $fh) { |
|
| 107 | + if ( ! $fh) { |
|
| 108 | 108 | throw new EE_Error(sprintf(__("Cannot open file for read: %s<br>\n", 'event_espresso'), $file_path)); |
| 109 | 109 | } |
| 110 | 110 | $flen = filesize($file_path); |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | for ($i = 0; $i < $flen; $i++) { |
| 113 | 113 | $c = substr($bc, $i, 1); |
| 114 | 114 | if ((ord($c) != 0) && (ord($c) != 13)) { |
| 115 | - $fc = $fc . $c; |
|
| 115 | + $fc = $fc.$c; |
|
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | 118 | if ((ord(substr($fc, 0, 1)) == 255) && (ord(substr($fc, 1, 1)) == 254)) { |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | public function import_csv_to_model_data_array($path_to_file, $model_name = false, $first_row_is_headers = true) |
| 208 | 208 | { |
| 209 | 209 | $multi_dimensional_array = $this->import_csv_to_multi_dimensional_array($path_to_file); |
| 210 | - if (! $multi_dimensional_array) { |
|
| 210 | + if ( ! $multi_dimensional_array) { |
|
| 211 | 211 | return false; |
| 212 | 212 | } |
| 213 | 213 | // gotta start somewhere |
@@ -243,23 +243,23 @@ discard block |
||
| 243 | 243 | // loop through each column |
| 244 | 244 | for ($i = 0; $i < $columns; $i++) { |
| 245 | 245 | // replace csv_enclosures with backslashed quotes |
| 246 | - $data[ $i ] = str_replace('"""', '\\"', $data[ $i ]); |
|
| 246 | + $data[$i] = str_replace('"""', '\\"', $data[$i]); |
|
| 247 | 247 | // do we need to grab the column names? |
| 248 | 248 | if ($row === 1) { |
| 249 | 249 | if ($first_row_is_headers) { |
| 250 | 250 | // store the column names to use for keys |
| 251 | - $column_name = $data[ $i ]; |
|
| 251 | + $column_name = $data[$i]; |
|
| 252 | 252 | // check it's not blank... sometimes CSV editign programs adda bunch of empty columns onto the end... |
| 253 | - if (! $column_name) { |
|
| 253 | + if ( ! $column_name) { |
|
| 254 | 254 | continue; |
| 255 | 255 | } |
| 256 | 256 | $matches = array(); |
| 257 | 257 | if ($model_name == EE_CSV::metadata_header) { |
| 258 | - $headers[ $i ] = $column_name; |
|
| 258 | + $headers[$i] = $column_name; |
|
| 259 | 259 | } else { |
| 260 | 260 | // now get the db table name from it (the part between square brackets) |
| 261 | 261 | $success = preg_match('~(.*)\[(.*)\]~', $column_name, $matches); |
| 262 | - if (! $success) { |
|
| 262 | + if ( ! $success) { |
|
| 263 | 263 | EE_Error::add_error( |
| 264 | 264 | sprintf( |
| 265 | 265 | __( |
@@ -275,24 +275,24 @@ discard block |
||
| 275 | 275 | ); |
| 276 | 276 | return false; |
| 277 | 277 | } |
| 278 | - $headers[ $i ] = $matches[2]; |
|
| 278 | + $headers[$i] = $matches[2]; |
|
| 279 | 279 | } |
| 280 | 280 | } else { |
| 281 | 281 | // no column names means our final array will just use counters for keys |
| 282 | - $model_entry[ $headers[ $i ] ] = $data[ $i ]; |
|
| 283 | - $headers[ $i ] = $i; |
|
| 282 | + $model_entry[$headers[$i]] = $data[$i]; |
|
| 283 | + $headers[$i] = $i; |
|
| 284 | 284 | } |
| 285 | 285 | // and we need to store csv data |
| 286 | 286 | } else { |
| 287 | 287 | // this column isn' ta header, store it if there is a header for it |
| 288 | - if (isset($headers[ $i ])) { |
|
| 289 | - $model_entry[ $headers[ $i ] ] = $data[ $i ]; |
|
| 288 | + if (isset($headers[$i])) { |
|
| 289 | + $model_entry[$headers[$i]] = $data[$i]; |
|
| 290 | 290 | } |
| 291 | 291 | } |
| 292 | 292 | } |
| 293 | 293 | // save the row's data IF it's a non-header-row |
| 294 | - if (! $first_row_is_headers || ($first_row_is_headers && $row > 1)) { |
|
| 295 | - $ee_formatted_data[ $model_name ][] = $model_entry; |
|
| 294 | + if ( ! $first_row_is_headers || ($first_row_is_headers && $row > 1)) { |
|
| 295 | + $ee_formatted_data[$model_name][] = $model_entry; |
|
| 296 | 296 | } |
| 297 | 297 | // advance to next row |
| 298 | 298 | $row++; |
@@ -353,7 +353,7 @@ discard block |
||
| 353 | 353 | // header("Content-Type: application/force-download"); |
| 354 | 354 | // header("Content-Type: application/octet-stream"); |
| 355 | 355 | // header("Content-Type: application/download"); |
| 356 | - header('Content-disposition: attachment; filename=' . $filename); |
|
| 356 | + header('Content-disposition: attachment; filename='.$filename); |
|
| 357 | 357 | header("Content-Type: text/csv; charset=utf-8"); |
| 358 | 358 | do_action('AHEE__EE_CSV__begin_sending_csv__headers'); |
| 359 | 359 | echo apply_filters( |
@@ -372,7 +372,7 @@ discard block |
||
| 372 | 372 | */ |
| 373 | 373 | public function write_metadata_to_csv($filehandle) |
| 374 | 374 | { |
| 375 | - $data_row = array(EE_CSV::metadata_header);// do NOT translate because this exact string is used when importing |
|
| 375 | + $data_row = array(EE_CSV::metadata_header); // do NOT translate because this exact string is used when importing |
|
| 376 | 376 | $this->fputcsv2($filehandle, $data_row); |
| 377 | 377 | $meta_data = array( |
| 378 | 378 | 0 => array( |
@@ -501,7 +501,7 @@ discard block |
||
| 501 | 501 | echo $this->fputcsv2($filehandle, array('MODEL', $model_name)); |
| 502 | 502 | // if we have items to put in the CSV, do it normally |
| 503 | 503 | |
| 504 | - if (! empty($model_instance_arrays)) { |
|
| 504 | + if ( ! empty($model_instance_arrays)) { |
|
| 505 | 505 | $this->write_data_array_to_csv($filehandle, $model_instance_arrays); |
| 506 | 506 | } else { |
| 507 | 507 | // echo "no data to write... so just write the headers"; |
@@ -510,7 +510,7 @@ discard block |
||
| 510 | 510 | $model = EE_Registry::instance()->load_model($model_name); |
| 511 | 511 | $column_names = array(); |
| 512 | 512 | foreach ($model->field_settings() as $field) { |
| 513 | - $column_names[ $field->get_nicename() . "[" . $field->get_name() . "]" ] = null; |
|
| 513 | + $column_names[$field->get_nicename()."[".$field->get_name()."]"] = null; |
|
| 514 | 514 | } |
| 515 | 515 | $this->write_data_array_to_csv($filehandle, array($column_names)); |
| 516 | 516 | } |
@@ -543,12 +543,12 @@ discard block |
||
| 543 | 543 | { |
| 544 | 544 | |
| 545 | 545 | // no data file?? get outta here |
| 546 | - if (! $data or ! is_array($data) or empty($data)) { |
|
| 546 | + if ( ! $data or ! is_array($data) or empty($data)) { |
|
| 547 | 547 | return false; |
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | // no filename?? get outta here |
| 551 | - if (! $filename) { |
|
| 551 | + if ( ! $filename) { |
|
| 552 | 552 | return false; |
| 553 | 553 | } |
| 554 | 554 | |
@@ -629,11 +629,11 @@ discard block |
||
| 629 | 629 | } |
| 630 | 630 | |
| 631 | 631 | $output[] = preg_match("/(?:${delimiter_esc}|${enclosure_esc}|\s)/", $field_value) ? |
| 632 | - ($enclosure . str_replace($enclosure, $enclosure . $enclosure, $field_value) . $enclosure) |
|
| 632 | + ($enclosure.str_replace($enclosure, $enclosure.$enclosure, $field_value).$enclosure) |
|
| 633 | 633 | : $field_value; |
| 634 | 634 | } |
| 635 | 635 | |
| 636 | - fwrite($fh, join($delimiter, $output) . PHP_EOL); |
|
| 636 | + fwrite($fh, join($delimiter, $output).PHP_EOL); |
|
| 637 | 637 | } |
| 638 | 638 | |
| 639 | 639 | |
@@ -12,25 +12,25 @@ |
||
| 12 | 12 | class EE_Extra_Join extends EE_Base_Class |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @param array $props_n_values |
|
| 17 | - * @param null $timezone |
|
| 18 | - * @return EE_Extra_Join|mixed |
|
| 19 | - */ |
|
| 20 | - public static function new_instance($props_n_values = array(), $timezone = null) |
|
| 21 | - { |
|
| 22 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
| 23 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone); |
|
| 24 | - } |
|
| 15 | + /** |
|
| 16 | + * @param array $props_n_values |
|
| 17 | + * @param null $timezone |
|
| 18 | + * @return EE_Extra_Join|mixed |
|
| 19 | + */ |
|
| 20 | + public static function new_instance($props_n_values = array(), $timezone = null) |
|
| 21 | + { |
|
| 22 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
| 23 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone); |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @param array $props_n_values |
|
| 29 | - * @param null $timezone |
|
| 30 | - * @return EE_Extra_Join |
|
| 31 | - */ |
|
| 32 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 33 | - { |
|
| 34 | - return new self($props_n_values, true, $timezone); |
|
| 35 | - } |
|
| 27 | + /** |
|
| 28 | + * @param array $props_n_values |
|
| 29 | + * @param null $timezone |
|
| 30 | + * @return EE_Extra_Join |
|
| 31 | + */ |
|
| 32 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 33 | + { |
|
| 34 | + return new self($props_n_values, true, $timezone); |
|
| 35 | + } |
|
| 36 | 36 | } |
@@ -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 = null, $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 = null, $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 = null) |
|
| 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 = null) |
|
| 50 | + { |
|
| 51 | + return new self($props_n_values, true, $timezone); |
|
| 52 | + } |
|
| 53 | 53 | } |
@@ -12,280 +12,280 @@ |
||
| 12 | 12 | class EE_Question_Group extends EE_Soft_Delete_Base_Class |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @param array $props_n_values |
|
| 17 | - * @return EE_Question_Group|mixed |
|
| 18 | - */ |
|
| 19 | - public static function new_instance($props_n_values = array()) |
|
| 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_Question_Group |
|
| 29 | - */ |
|
| 30 | - public static function new_instance_from_db($props_n_values = array()) |
|
| 31 | - { |
|
| 32 | - return new self($props_n_values, true); |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * gets the question group's name |
|
| 38 | - * |
|
| 39 | - * @access public |
|
| 40 | - * @param bool $pretty |
|
| 41 | - * @return string |
|
| 42 | - */ |
|
| 43 | - public function name($pretty = false) |
|
| 44 | - { |
|
| 45 | - return $pretty ? $this->get_pretty('QSG_name') : $this->get('QSG_name'); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Gets the question group's internal name |
|
| 51 | - * |
|
| 52 | - * @access public |
|
| 53 | - * @return string |
|
| 54 | - */ |
|
| 55 | - public function identifier() |
|
| 56 | - { |
|
| 57 | - return $this->get('QSG_identifier'); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Gets the question group's description |
|
| 63 | - * |
|
| 64 | - * @access public |
|
| 65 | - * @param bool $pretty |
|
| 66 | - * @return string |
|
| 67 | - */ |
|
| 68 | - public function desc($pretty = false) |
|
| 69 | - { |
|
| 70 | - return $pretty ? $this->get_pretty('QSG_desc') : $this->get('QSG_desc'); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Gets the question group's order number in a sequence |
|
| 76 | - * of other question groups |
|
| 77 | - * |
|
| 78 | - * @access public |
|
| 79 | - * @return int |
|
| 80 | - */ |
|
| 81 | - public function order() |
|
| 82 | - { |
|
| 83 | - return $this->get('QSG_order'); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Returns whether to show the group's name on the frontend |
|
| 89 | - * |
|
| 90 | - * @access public |
|
| 91 | - * @return boolean |
|
| 92 | - */ |
|
| 93 | - public function show_group_name() |
|
| 94 | - { |
|
| 95 | - return $this->get('QSG_show_group_name'); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Returns whether to show the group's description |
|
| 101 | - * on the frontend |
|
| 102 | - * |
|
| 103 | - * @access public |
|
| 104 | - * @return boolean |
|
| 105 | - */ |
|
| 106 | - public function show_group_desc() |
|
| 107 | - { |
|
| 108 | - return $this->get('QSG_show_group_desc'); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Returns whether this is a 'system group' (meaning |
|
| 114 | - * a question group integral to the system, whose questions |
|
| 115 | - * relate to the attendee table) |
|
| 116 | - * |
|
| 117 | - * @access public |
|
| 118 | - * @return int |
|
| 119 | - */ |
|
| 120 | - public function system_group() |
|
| 121 | - { |
|
| 122 | - return $this->get('QSG_system'); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * get the author of the question group. |
|
| 128 | - * |
|
| 129 | - * @since 4.5.0 |
|
| 130 | - * |
|
| 131 | - * @return int |
|
| 132 | - */ |
|
| 133 | - public function wp_user() |
|
| 134 | - { |
|
| 135 | - return $this->get('QSG_wp_user'); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Returns whether this question group has |
|
| 141 | - * been deleted |
|
| 142 | - * |
|
| 143 | - * @access public |
|
| 144 | - * @return boolean |
|
| 145 | - */ |
|
| 146 | - public function deleted() |
|
| 147 | - { |
|
| 148 | - return $this->get('QST_deleted'); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Gets an array of questions with questions IN the group at the start of the array and questions NOT in the group |
|
| 154 | - * at the end of the array. Questions in the group are ordered by Question_Group_Question.QGQ_order and questions |
|
| 155 | - * NOT in the group are ordered by Question.QGQ_order |
|
| 156 | - * |
|
| 157 | - * @return EE_Question[] |
|
| 158 | - */ |
|
| 159 | - public function questions_in_and_not_in_group() |
|
| 160 | - { |
|
| 161 | - $questions_in_group = $this->questions(); |
|
| 162 | - $exclude_question_ids = ! empty($questions_in_group) ? array_keys($questions_in_group) : array(); |
|
| 163 | - $questions_not_in_group = $this->questions_not_in_group($exclude_question_ids); |
|
| 164 | - return $questions_in_group + $questions_not_in_group; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Gets all the questions which are part of this question group (ordered Question_Group_Question.QGQ_order) |
|
| 170 | - * |
|
| 171 | - * @param array $query_params |
|
| 172 | - * @return EE_Question[] |
|
| 173 | - */ |
|
| 174 | - public function questions($query_params = array()) |
|
| 175 | - { |
|
| 176 | - $query_params = ! empty($query_params) ? $query_params |
|
| 177 | - : array('order_by' => array('Question_Group_Question.QGQ_order' => 'ASC')); |
|
| 178 | - return $this->ID() ? $this->get_many_related('Question', $query_params) : array(); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Gets all the questions which are NOT part of this question group. |
|
| 184 | - * |
|
| 185 | - * @param mixed $question_IDS_in_group if empty array then all questions returned. if FALSE then we first get |
|
| 186 | - * questions in this group and exclude them from questions get all. IF empty |
|
| 187 | - * array then we just return all questions. |
|
| 188 | - * @return EE_Question[] |
|
| 189 | - */ |
|
| 190 | - public function questions_not_in_group($question_IDS_in_group = false) |
|
| 191 | - { |
|
| 192 | - if ($question_IDS_in_group === false) { |
|
| 193 | - $questions = $this->questions(); |
|
| 194 | - $question_IDS_in_group = ! empty($questions) ? array_keys($questions) : array(); |
|
| 195 | - } |
|
| 196 | - $_where = ! empty($question_IDS_in_group) ? array('QST_ID' => array('not_in', $question_IDS_in_group)) |
|
| 197 | - : array(); |
|
| 198 | - |
|
| 199 | - return EEM_Question::instance()->get_all(array($_where, 'order_by' => array('QST_ID' => 'ASC'))); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Gets all events which are related to this question group |
|
| 205 | - * |
|
| 206 | - * @return EE_Event[] |
|
| 207 | - */ |
|
| 208 | - public function events() |
|
| 209 | - { |
|
| 210 | - return $this->get_many_related('Event'); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Adds the question to this question group |
|
| 216 | - * |
|
| 217 | - * @param EE_Question || int $question object or ID |
|
| 218 | - * @return boolean if successful |
|
| 219 | - */ |
|
| 220 | - public function add_question($questionObjectOrID) |
|
| 221 | - { |
|
| 222 | - return $this->_add_relation_to($questionObjectOrID, 'Question'); |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * Removes the question from this question group |
|
| 228 | - * |
|
| 229 | - * @param EE_Question || int $question object or ID |
|
| 230 | - * @return boolean of success |
|
| 231 | - */ |
|
| 232 | - public function remove_question($questionObjectOrID) |
|
| 233 | - { |
|
| 234 | - return $this->_remove_relation_to($questionObjectOrID, 'Question'); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * @param $questionObjectOrID |
|
| 240 | - * @param $qst_order |
|
| 241 | - * @return int |
|
| 242 | - */ |
|
| 243 | - public function update_question_order($questionObjectOrID, $qst_order) |
|
| 244 | - { |
|
| 245 | - $qst_ID = $questionObjectOrID instanceof EE_Question ? $questionObjectOrID->ID() : (int) $questionObjectOrID; |
|
| 246 | - return EEM_Question_Group_Question::instance()->update( |
|
| 247 | - array('QGQ_order' => $qst_order), |
|
| 248 | - array( |
|
| 249 | - array( |
|
| 250 | - 'QST_ID' => $qst_ID, |
|
| 251 | - 'QSG_ID' => $this->ID(), |
|
| 252 | - ), |
|
| 253 | - ) |
|
| 254 | - ); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * Basically this is method just returns whether the question group has any questions with answers. This is used |
|
| 260 | - * by the admin currently to determine whether we should display the ui for deleting permanently or not b/c |
|
| 261 | - * question groups with questions that have answers should not be possible to delete permanently |
|
| 262 | - * |
|
| 263 | - * @return boolean true if has questions with answers, false if not. |
|
| 264 | - */ |
|
| 265 | - public function has_questions_with_answers() |
|
| 266 | - { |
|
| 267 | - $has_answers = false; |
|
| 268 | - $questions = $this->get_many_related('Question'); |
|
| 269 | - foreach ($questions as $question) { |
|
| 270 | - if ($question->count_related('Answer') > 0) { |
|
| 271 | - $has_answers = true; |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - return $has_answers; |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * The purpose of this method is set the question group order for this question group to be the max out of all |
|
| 280 | - * question groups |
|
| 281 | - * |
|
| 282 | - * @access public |
|
| 283 | - * @return void |
|
| 284 | - */ |
|
| 285 | - public function set_order_to_latest() |
|
| 286 | - { |
|
| 287 | - $latest_order = $this->get_model()->get_latest_question_group_order(); |
|
| 288 | - $latest_order++; |
|
| 289 | - $this->set('QSG_order', $latest_order); |
|
| 290 | - } |
|
| 15 | + /** |
|
| 16 | + * @param array $props_n_values |
|
| 17 | + * @return EE_Question_Group|mixed |
|
| 18 | + */ |
|
| 19 | + public static function new_instance($props_n_values = array()) |
|
| 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_Question_Group |
|
| 29 | + */ |
|
| 30 | + public static function new_instance_from_db($props_n_values = array()) |
|
| 31 | + { |
|
| 32 | + return new self($props_n_values, true); |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * gets the question group's name |
|
| 38 | + * |
|
| 39 | + * @access public |
|
| 40 | + * @param bool $pretty |
|
| 41 | + * @return string |
|
| 42 | + */ |
|
| 43 | + public function name($pretty = false) |
|
| 44 | + { |
|
| 45 | + return $pretty ? $this->get_pretty('QSG_name') : $this->get('QSG_name'); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Gets the question group's internal name |
|
| 51 | + * |
|
| 52 | + * @access public |
|
| 53 | + * @return string |
|
| 54 | + */ |
|
| 55 | + public function identifier() |
|
| 56 | + { |
|
| 57 | + return $this->get('QSG_identifier'); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Gets the question group's description |
|
| 63 | + * |
|
| 64 | + * @access public |
|
| 65 | + * @param bool $pretty |
|
| 66 | + * @return string |
|
| 67 | + */ |
|
| 68 | + public function desc($pretty = false) |
|
| 69 | + { |
|
| 70 | + return $pretty ? $this->get_pretty('QSG_desc') : $this->get('QSG_desc'); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Gets the question group's order number in a sequence |
|
| 76 | + * of other question groups |
|
| 77 | + * |
|
| 78 | + * @access public |
|
| 79 | + * @return int |
|
| 80 | + */ |
|
| 81 | + public function order() |
|
| 82 | + { |
|
| 83 | + return $this->get('QSG_order'); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Returns whether to show the group's name on the frontend |
|
| 89 | + * |
|
| 90 | + * @access public |
|
| 91 | + * @return boolean |
|
| 92 | + */ |
|
| 93 | + public function show_group_name() |
|
| 94 | + { |
|
| 95 | + return $this->get('QSG_show_group_name'); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Returns whether to show the group's description |
|
| 101 | + * on the frontend |
|
| 102 | + * |
|
| 103 | + * @access public |
|
| 104 | + * @return boolean |
|
| 105 | + */ |
|
| 106 | + public function show_group_desc() |
|
| 107 | + { |
|
| 108 | + return $this->get('QSG_show_group_desc'); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Returns whether this is a 'system group' (meaning |
|
| 114 | + * a question group integral to the system, whose questions |
|
| 115 | + * relate to the attendee table) |
|
| 116 | + * |
|
| 117 | + * @access public |
|
| 118 | + * @return int |
|
| 119 | + */ |
|
| 120 | + public function system_group() |
|
| 121 | + { |
|
| 122 | + return $this->get('QSG_system'); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * get the author of the question group. |
|
| 128 | + * |
|
| 129 | + * @since 4.5.0 |
|
| 130 | + * |
|
| 131 | + * @return int |
|
| 132 | + */ |
|
| 133 | + public function wp_user() |
|
| 134 | + { |
|
| 135 | + return $this->get('QSG_wp_user'); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Returns whether this question group has |
|
| 141 | + * been deleted |
|
| 142 | + * |
|
| 143 | + * @access public |
|
| 144 | + * @return boolean |
|
| 145 | + */ |
|
| 146 | + public function deleted() |
|
| 147 | + { |
|
| 148 | + return $this->get('QST_deleted'); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Gets an array of questions with questions IN the group at the start of the array and questions NOT in the group |
|
| 154 | + * at the end of the array. Questions in the group are ordered by Question_Group_Question.QGQ_order and questions |
|
| 155 | + * NOT in the group are ordered by Question.QGQ_order |
|
| 156 | + * |
|
| 157 | + * @return EE_Question[] |
|
| 158 | + */ |
|
| 159 | + public function questions_in_and_not_in_group() |
|
| 160 | + { |
|
| 161 | + $questions_in_group = $this->questions(); |
|
| 162 | + $exclude_question_ids = ! empty($questions_in_group) ? array_keys($questions_in_group) : array(); |
|
| 163 | + $questions_not_in_group = $this->questions_not_in_group($exclude_question_ids); |
|
| 164 | + return $questions_in_group + $questions_not_in_group; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Gets all the questions which are part of this question group (ordered Question_Group_Question.QGQ_order) |
|
| 170 | + * |
|
| 171 | + * @param array $query_params |
|
| 172 | + * @return EE_Question[] |
|
| 173 | + */ |
|
| 174 | + public function questions($query_params = array()) |
|
| 175 | + { |
|
| 176 | + $query_params = ! empty($query_params) ? $query_params |
|
| 177 | + : array('order_by' => array('Question_Group_Question.QGQ_order' => 'ASC')); |
|
| 178 | + return $this->ID() ? $this->get_many_related('Question', $query_params) : array(); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Gets all the questions which are NOT part of this question group. |
|
| 184 | + * |
|
| 185 | + * @param mixed $question_IDS_in_group if empty array then all questions returned. if FALSE then we first get |
|
| 186 | + * questions in this group and exclude them from questions get all. IF empty |
|
| 187 | + * array then we just return all questions. |
|
| 188 | + * @return EE_Question[] |
|
| 189 | + */ |
|
| 190 | + public function questions_not_in_group($question_IDS_in_group = false) |
|
| 191 | + { |
|
| 192 | + if ($question_IDS_in_group === false) { |
|
| 193 | + $questions = $this->questions(); |
|
| 194 | + $question_IDS_in_group = ! empty($questions) ? array_keys($questions) : array(); |
|
| 195 | + } |
|
| 196 | + $_where = ! empty($question_IDS_in_group) ? array('QST_ID' => array('not_in', $question_IDS_in_group)) |
|
| 197 | + : array(); |
|
| 198 | + |
|
| 199 | + return EEM_Question::instance()->get_all(array($_where, 'order_by' => array('QST_ID' => 'ASC'))); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Gets all events which are related to this question group |
|
| 205 | + * |
|
| 206 | + * @return EE_Event[] |
|
| 207 | + */ |
|
| 208 | + public function events() |
|
| 209 | + { |
|
| 210 | + return $this->get_many_related('Event'); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Adds the question to this question group |
|
| 216 | + * |
|
| 217 | + * @param EE_Question || int $question object or ID |
|
| 218 | + * @return boolean if successful |
|
| 219 | + */ |
|
| 220 | + public function add_question($questionObjectOrID) |
|
| 221 | + { |
|
| 222 | + return $this->_add_relation_to($questionObjectOrID, 'Question'); |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * Removes the question from this question group |
|
| 228 | + * |
|
| 229 | + * @param EE_Question || int $question object or ID |
|
| 230 | + * @return boolean of success |
|
| 231 | + */ |
|
| 232 | + public function remove_question($questionObjectOrID) |
|
| 233 | + { |
|
| 234 | + return $this->_remove_relation_to($questionObjectOrID, 'Question'); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * @param $questionObjectOrID |
|
| 240 | + * @param $qst_order |
|
| 241 | + * @return int |
|
| 242 | + */ |
|
| 243 | + public function update_question_order($questionObjectOrID, $qst_order) |
|
| 244 | + { |
|
| 245 | + $qst_ID = $questionObjectOrID instanceof EE_Question ? $questionObjectOrID->ID() : (int) $questionObjectOrID; |
|
| 246 | + return EEM_Question_Group_Question::instance()->update( |
|
| 247 | + array('QGQ_order' => $qst_order), |
|
| 248 | + array( |
|
| 249 | + array( |
|
| 250 | + 'QST_ID' => $qst_ID, |
|
| 251 | + 'QSG_ID' => $this->ID(), |
|
| 252 | + ), |
|
| 253 | + ) |
|
| 254 | + ); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * Basically this is method just returns whether the question group has any questions with answers. This is used |
|
| 260 | + * by the admin currently to determine whether we should display the ui for deleting permanently or not b/c |
|
| 261 | + * question groups with questions that have answers should not be possible to delete permanently |
|
| 262 | + * |
|
| 263 | + * @return boolean true if has questions with answers, false if not. |
|
| 264 | + */ |
|
| 265 | + public function has_questions_with_answers() |
|
| 266 | + { |
|
| 267 | + $has_answers = false; |
|
| 268 | + $questions = $this->get_many_related('Question'); |
|
| 269 | + foreach ($questions as $question) { |
|
| 270 | + if ($question->count_related('Answer') > 0) { |
|
| 271 | + $has_answers = true; |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + return $has_answers; |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * The purpose of this method is set the question group order for this question group to be the max out of all |
|
| 280 | + * question groups |
|
| 281 | + * |
|
| 282 | + * @access public |
|
| 283 | + * @return void |
|
| 284 | + */ |
|
| 285 | + public function set_order_to_latest() |
|
| 286 | + { |
|
| 287 | + $latest_order = $this->get_model()->get_latest_question_group_order(); |
|
| 288 | + $latest_order++; |
|
| 289 | + $this->set('QSG_order', $latest_order); |
|
| 290 | + } |
|
| 291 | 291 | } |
@@ -11,86 +11,86 @@ |
||
| 11 | 11 | { |
| 12 | 12 | |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Used to reference when a registration has been checked out. |
|
| 16 | - * |
|
| 17 | - * @type int |
|
| 18 | - */ |
|
| 19 | - const status_checked_out = 0; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * Used to reference when a registration has been checked in. |
|
| 23 | - * |
|
| 24 | - * @type int |
|
| 25 | - */ |
|
| 26 | - const status_checked_in = 1; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Used to reference when a registration has never been checked in. |
|
| 30 | - * |
|
| 31 | - * @type int |
|
| 32 | - */ |
|
| 33 | - const status_checked_never = 2; |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * |
|
| 38 | - * @param array $props_n_values incoming values |
|
| 39 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be used.) |
|
| 40 | - * @param array $date_formats incoming date_formats in an array |
|
| 41 | - * where the first value is the date_format |
|
| 42 | - * and the second value is the time format |
|
| 43 | - * @return EE_Checkin |
|
| 44 | - * @throws EE_Error |
|
| 45 | - */ |
|
| 46 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 47 | - { |
|
| 48 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 49 | - return $has_object |
|
| 50 | - ? $has_object |
|
| 51 | - : new self($props_n_values, false, $timezone, $date_formats); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @param array $props_n_values incoming values from the database |
|
| 57 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 58 | - * the website will be used. |
|
| 59 | - * @return EE_Checkin |
|
| 60 | - * @throws EE_Error |
|
| 61 | - */ |
|
| 62 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 63 | - { |
|
| 64 | - return new self($props_n_values, true, $timezone); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - public function ID() |
|
| 69 | - { |
|
| 70 | - return $this->get('CHK_ID'); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - public function registration_id() |
|
| 75 | - { |
|
| 76 | - return $this->get('REG_ID'); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - public function datetime_id() |
|
| 81 | - { |
|
| 82 | - return $this->get('DTT_ID'); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - public function status() |
|
| 87 | - { |
|
| 88 | - return $this->get('CHK_in'); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - public function timestamp() |
|
| 93 | - { |
|
| 94 | - return $this->get('CHK_timestamp'); |
|
| 95 | - } |
|
| 14 | + /** |
|
| 15 | + * Used to reference when a registration has been checked out. |
|
| 16 | + * |
|
| 17 | + * @type int |
|
| 18 | + */ |
|
| 19 | + const status_checked_out = 0; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * Used to reference when a registration has been checked in. |
|
| 23 | + * |
|
| 24 | + * @type int |
|
| 25 | + */ |
|
| 26 | + const status_checked_in = 1; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Used to reference when a registration has never been checked in. |
|
| 30 | + * |
|
| 31 | + * @type int |
|
| 32 | + */ |
|
| 33 | + const status_checked_never = 2; |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * |
|
| 38 | + * @param array $props_n_values incoming values |
|
| 39 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be used.) |
|
| 40 | + * @param array $date_formats incoming date_formats in an array |
|
| 41 | + * where the first value is the date_format |
|
| 42 | + * and the second value is the time format |
|
| 43 | + * @return EE_Checkin |
|
| 44 | + * @throws EE_Error |
|
| 45 | + */ |
|
| 46 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 47 | + { |
|
| 48 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 49 | + return $has_object |
|
| 50 | + ? $has_object |
|
| 51 | + : new self($props_n_values, false, $timezone, $date_formats); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @param array $props_n_values incoming values from the database |
|
| 57 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 58 | + * the website will be used. |
|
| 59 | + * @return EE_Checkin |
|
| 60 | + * @throws EE_Error |
|
| 61 | + */ |
|
| 62 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 63 | + { |
|
| 64 | + return new self($props_n_values, true, $timezone); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + public function ID() |
|
| 69 | + { |
|
| 70 | + return $this->get('CHK_ID'); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + public function registration_id() |
|
| 75 | + { |
|
| 76 | + return $this->get('REG_ID'); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + public function datetime_id() |
|
| 81 | + { |
|
| 82 | + return $this->get('DTT_ID'); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + public function status() |
|
| 87 | + { |
|
| 88 | + return $this->get('CHK_in'); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + public function timestamp() |
|
| 93 | + { |
|
| 94 | + return $this->get('CHK_timestamp'); |
|
| 95 | + } |
|
| 96 | 96 | } |
@@ -12,180 +12,180 @@ |
||
| 12 | 12 | class EE_Currency extends EE_Base_Class |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** Currency COde @var CUR_code */ |
|
| 16 | - protected $_CUR_code = null; |
|
| 17 | - /** Currency Name Singular @var CUR_single */ |
|
| 18 | - protected $_CUR_single = null; |
|
| 19 | - /** Currency Name Plural @var CUR_plural */ |
|
| 20 | - protected $_CUR_plural = null; |
|
| 21 | - /** Currency Sign @var CUR_sign */ |
|
| 22 | - protected $_CUR_sign = null; |
|
| 23 | - /** Currency Decimal Places @var CUR_dec_plc */ |
|
| 24 | - protected $_CUR_dec_plc = null; |
|
| 25 | - /** Active? @var CUR_active */ |
|
| 26 | - protected $_CUR_active = null; |
|
| 27 | - protected $_Payment_Method; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * |
|
| 31 | - * @param array $props_n_values incoming values |
|
| 32 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 33 | - * used.) |
|
| 34 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 35 | - * date_format and the second value is the time format |
|
| 36 | - * @return EE_Attendee |
|
| 37 | - */ |
|
| 38 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 39 | - { |
|
| 40 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 41 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @param array $props_n_values incoming values from the database |
|
| 47 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 48 | - * the website will be used. |
|
| 49 | - * @return EE_Attendee |
|
| 50 | - */ |
|
| 51 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 52 | - { |
|
| 53 | - return new self($props_n_values, true, $timezone); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Gets code |
|
| 58 | - * |
|
| 59 | - * @return string |
|
| 60 | - */ |
|
| 61 | - public function code() |
|
| 62 | - { |
|
| 63 | - return $this->get('CUR_code'); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Sets code |
|
| 68 | - * |
|
| 69 | - * @param string $code |
|
| 70 | - * @return boolean |
|
| 71 | - */ |
|
| 72 | - public function set_code($code) |
|
| 73 | - { |
|
| 74 | - return $this->set('CUR_code', $code); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Gets active |
|
| 79 | - * |
|
| 80 | - * @return boolean |
|
| 81 | - */ |
|
| 82 | - public function active() |
|
| 83 | - { |
|
| 84 | - return $this->get('CUR_active'); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Sets active |
|
| 89 | - * |
|
| 90 | - * @param boolean $active |
|
| 91 | - * @return boolean |
|
| 92 | - */ |
|
| 93 | - public function set_active($active) |
|
| 94 | - { |
|
| 95 | - return $this->set('CUR_active', $active); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Gets dec_plc |
|
| 100 | - * |
|
| 101 | - * @return int |
|
| 102 | - */ |
|
| 103 | - public function dec_plc() |
|
| 104 | - { |
|
| 105 | - return $this->get('CUR_dec_plc'); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Sets dec_plc |
|
| 110 | - * |
|
| 111 | - * @param int $dec_plc |
|
| 112 | - * @return boolean |
|
| 113 | - */ |
|
| 114 | - public function set_dec_plc($dec_plc) |
|
| 115 | - { |
|
| 116 | - return $this->set('CUR_dec_plc', $dec_plc); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Gets plural |
|
| 121 | - * |
|
| 122 | - * @return string |
|
| 123 | - */ |
|
| 124 | - public function plural_name() |
|
| 125 | - { |
|
| 126 | - return $this->get('CUR_plural'); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Sets plural |
|
| 131 | - * |
|
| 132 | - * @param string $plural |
|
| 133 | - * @return boolean |
|
| 134 | - */ |
|
| 135 | - public function set_plural_name($plural) |
|
| 136 | - { |
|
| 137 | - return $this->set('CUR_plural', $plural); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Gets sign |
|
| 142 | - * |
|
| 143 | - * @return string |
|
| 144 | - */ |
|
| 145 | - public function sign() |
|
| 146 | - { |
|
| 147 | - return $this->get('CUR_sign'); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Sets sign |
|
| 152 | - * |
|
| 153 | - * @param string $sign |
|
| 154 | - * @return boolean |
|
| 155 | - */ |
|
| 156 | - public function set_sign($sign) |
|
| 157 | - { |
|
| 158 | - return $this->set('CUR_sign', $sign); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * Gets single |
|
| 163 | - * |
|
| 164 | - * @return string |
|
| 165 | - */ |
|
| 166 | - public function singular_name() |
|
| 167 | - { |
|
| 168 | - return $this->get('CUR_single'); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Sets single |
|
| 173 | - * |
|
| 174 | - * @param string $single |
|
| 175 | - * @return boolean |
|
| 176 | - */ |
|
| 177 | - public function set_singular_name($single) |
|
| 178 | - { |
|
| 179 | - return $this->set('CUR_single', $single); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Gets a prettier name |
|
| 184 | - * |
|
| 185 | - * @return string |
|
| 186 | - */ |
|
| 187 | - public function name() |
|
| 188 | - { |
|
| 189 | - return sprintf(__("%s (%s)", "event_espresso"), $this->code(), $this->plural_name()); |
|
| 190 | - } |
|
| 15 | + /** Currency COde @var CUR_code */ |
|
| 16 | + protected $_CUR_code = null; |
|
| 17 | + /** Currency Name Singular @var CUR_single */ |
|
| 18 | + protected $_CUR_single = null; |
|
| 19 | + /** Currency Name Plural @var CUR_plural */ |
|
| 20 | + protected $_CUR_plural = null; |
|
| 21 | + /** Currency Sign @var CUR_sign */ |
|
| 22 | + protected $_CUR_sign = null; |
|
| 23 | + /** Currency Decimal Places @var CUR_dec_plc */ |
|
| 24 | + protected $_CUR_dec_plc = null; |
|
| 25 | + /** Active? @var CUR_active */ |
|
| 26 | + protected $_CUR_active = null; |
|
| 27 | + protected $_Payment_Method; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * |
|
| 31 | + * @param array $props_n_values incoming values |
|
| 32 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 33 | + * used.) |
|
| 34 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 35 | + * date_format and the second value is the time format |
|
| 36 | + * @return EE_Attendee |
|
| 37 | + */ |
|
| 38 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 39 | + { |
|
| 40 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 41 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @param array $props_n_values incoming values from the database |
|
| 47 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 48 | + * the website will be used. |
|
| 49 | + * @return EE_Attendee |
|
| 50 | + */ |
|
| 51 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 52 | + { |
|
| 53 | + return new self($props_n_values, true, $timezone); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Gets code |
|
| 58 | + * |
|
| 59 | + * @return string |
|
| 60 | + */ |
|
| 61 | + public function code() |
|
| 62 | + { |
|
| 63 | + return $this->get('CUR_code'); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Sets code |
|
| 68 | + * |
|
| 69 | + * @param string $code |
|
| 70 | + * @return boolean |
|
| 71 | + */ |
|
| 72 | + public function set_code($code) |
|
| 73 | + { |
|
| 74 | + return $this->set('CUR_code', $code); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Gets active |
|
| 79 | + * |
|
| 80 | + * @return boolean |
|
| 81 | + */ |
|
| 82 | + public function active() |
|
| 83 | + { |
|
| 84 | + return $this->get('CUR_active'); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Sets active |
|
| 89 | + * |
|
| 90 | + * @param boolean $active |
|
| 91 | + * @return boolean |
|
| 92 | + */ |
|
| 93 | + public function set_active($active) |
|
| 94 | + { |
|
| 95 | + return $this->set('CUR_active', $active); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Gets dec_plc |
|
| 100 | + * |
|
| 101 | + * @return int |
|
| 102 | + */ |
|
| 103 | + public function dec_plc() |
|
| 104 | + { |
|
| 105 | + return $this->get('CUR_dec_plc'); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Sets dec_plc |
|
| 110 | + * |
|
| 111 | + * @param int $dec_plc |
|
| 112 | + * @return boolean |
|
| 113 | + */ |
|
| 114 | + public function set_dec_plc($dec_plc) |
|
| 115 | + { |
|
| 116 | + return $this->set('CUR_dec_plc', $dec_plc); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Gets plural |
|
| 121 | + * |
|
| 122 | + * @return string |
|
| 123 | + */ |
|
| 124 | + public function plural_name() |
|
| 125 | + { |
|
| 126 | + return $this->get('CUR_plural'); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Sets plural |
|
| 131 | + * |
|
| 132 | + * @param string $plural |
|
| 133 | + * @return boolean |
|
| 134 | + */ |
|
| 135 | + public function set_plural_name($plural) |
|
| 136 | + { |
|
| 137 | + return $this->set('CUR_plural', $plural); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Gets sign |
|
| 142 | + * |
|
| 143 | + * @return string |
|
| 144 | + */ |
|
| 145 | + public function sign() |
|
| 146 | + { |
|
| 147 | + return $this->get('CUR_sign'); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Sets sign |
|
| 152 | + * |
|
| 153 | + * @param string $sign |
|
| 154 | + * @return boolean |
|
| 155 | + */ |
|
| 156 | + public function set_sign($sign) |
|
| 157 | + { |
|
| 158 | + return $this->set('CUR_sign', $sign); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * Gets single |
|
| 163 | + * |
|
| 164 | + * @return string |
|
| 165 | + */ |
|
| 166 | + public function singular_name() |
|
| 167 | + { |
|
| 168 | + return $this->get('CUR_single'); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Sets single |
|
| 173 | + * |
|
| 174 | + * @param string $single |
|
| 175 | + * @return boolean |
|
| 176 | + */ |
|
| 177 | + public function set_singular_name($single) |
|
| 178 | + { |
|
| 179 | + return $this->set('CUR_single', $single); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Gets a prettier name |
|
| 184 | + * |
|
| 185 | + * @return string |
|
| 186 | + */ |
|
| 187 | + public function name() |
|
| 188 | + { |
|
| 189 | + return sprintf(__("%s (%s)", "event_espresso"), $this->code(), $this->plural_name()); |
|
| 190 | + } |
|
| 191 | 191 | } |
@@ -389,11 +389,11 @@ discard block |
||
| 389 | 389 | */ |
| 390 | 390 | public function type_obj() |
| 391 | 391 | { |
| 392 | - if (! $this->_type_obj) { |
|
| 392 | + if ( ! $this->_type_obj) { |
|
| 393 | 393 | EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
| 394 | 394 | if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) { |
| 395 | 395 | $class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type()); |
| 396 | - if (! class_exists($class_name)) { |
|
| 396 | + if ( ! class_exists($class_name)) { |
|
| 397 | 397 | throw new EE_Error( |
| 398 | 398 | sprintf( |
| 399 | 399 | __( |
@@ -402,7 +402,7 @@ discard block |
||
| 402 | 402 | ), |
| 403 | 403 | $class_name, |
| 404 | 404 | '<br />', |
| 405 | - '<a href="' . admin_url('plugins.php') . '">', |
|
| 405 | + '<a href="'.admin_url('plugins.php').'">', |
|
| 406 | 406 | '</a>' |
| 407 | 407 | ) |
| 408 | 408 | ); |
@@ -441,7 +441,7 @@ discard block |
||
| 441 | 441 | foreach ($fields as $key => $value) { |
| 442 | 442 | if (strpos($key, 'PMD_') === 0) { |
| 443 | 443 | $key_sans_model_prefix = str_replace('PMD_', '', $key); |
| 444 | - $combined_settings_array [ $key_sans_model_prefix ] = $value; |
|
| 444 | + $combined_settings_array [$key_sans_model_prefix] = $value; |
|
| 445 | 445 | } |
| 446 | 446 | } |
| 447 | 447 | $combined_settings_array = array_merge($extra_meta, $combined_settings_array); |
@@ -464,14 +464,14 @@ discard block |
||
| 464 | 464 | <div id="' |
| 465 | 465 | . $this->slug() |
| 466 | 466 | . '-payment-option-dv" class="' |
| 467 | - . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '"> |
|
| 467 | + . $payment_occurs.'-payment-gateway reg-page-payment-option-dv'.$css_class.'"> |
|
| 468 | 468 | <a id="payment-gateway-button-' . $this->slug() |
| 469 | 469 | . '" class="reg-page-payment-option-lnk" rel="' |
| 470 | - . $this->slug() . '" href="' . $url . '" > |
|
| 471 | - <img src="' . $this->button_url() . '" alt="' . sprintf( |
|
| 470 | + . $this->slug().'" href="'.$url.'" > |
|
| 471 | + <img src="' . $this->button_url().'" alt="'.sprintf( |
|
| 472 | 472 | esc_attr__('Pay using %s', 'event_espresso'), |
| 473 | 473 | $this->get_pretty('PMD_name', 'form_input') |
| 474 | - ) . '" /> |
|
| 474 | + ).'" /> |
|
| 475 | 475 | </a> |
| 476 | 476 | </div> |
| 477 | 477 | '; |
@@ -11,580 +11,580 @@ |
||
| 11 | 11 | class EE_Payment_Method extends EE_Base_Class |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Payment Method type object, which has all the info about this type of payment method, |
|
| 16 | - * including functions for processing payments, to get settings forms, etc. |
|
| 17 | - * |
|
| 18 | - * @var EE_PMT_Base |
|
| 19 | - */ |
|
| 20 | - protected $_type_obj; |
|
| 21 | - |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * @param array $props_n_values |
|
| 25 | - * @return EE_Payment_Method |
|
| 26 | - * @throws \EE_Error |
|
| 27 | - */ |
|
| 28 | - public static function new_instance($props_n_values = array()) |
|
| 29 | - { |
|
| 30 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 31 | - return $has_object ? $has_object : new self($props_n_values, false); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @param array $props_n_values |
|
| 37 | - * @return EE_Payment_Method |
|
| 38 | - * @throws \EE_Error |
|
| 39 | - */ |
|
| 40 | - public static function new_instance_from_db($props_n_values = array()) |
|
| 41 | - { |
|
| 42 | - return new self($props_n_values, true); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Checks if there is a payment method class of the given 'PMD_type', and if so returns the classname. |
|
| 49 | - * Otherwise returns a normal EE_Payment_Method |
|
| 50 | - * |
|
| 51 | - * @param array $props_n_values where 'PMD_type' is a gateway name like 'Paypal_Standard','Invoice',etc (basically |
|
| 52 | - * the classname minus 'EEPM_') |
|
| 53 | - * @return string |
|
| 54 | - */ |
|
| 55 | - // private static function _payment_method_type($props_n_values) |
|
| 56 | - // { |
|
| 57 | - // EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 58 | - // $type_string = isset($props_n_values['PMD_type']) ? $props_n_values['PMD_type'] : null; |
|
| 59 | - // if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($type_string)) { |
|
| 60 | - // return 'EEPM_' . $type_string; |
|
| 61 | - // } else { |
|
| 62 | - // return __CLASS__; |
|
| 63 | - // } |
|
| 64 | - // } |
|
| 65 | - |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Gets whether this payment method can be used anywhere at all (ie frontend cart, admin, etc) |
|
| 69 | - * |
|
| 70 | - * @return boolean |
|
| 71 | - */ |
|
| 72 | - public function active() |
|
| 73 | - { |
|
| 74 | - return array_intersect(array_keys(EEM_Payment_Method::instance()->scopes()), $this->scope()); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Sets this PM as active by making it usable within the CART scope. Offline gateways |
|
| 80 | - * are also usable from the admin-scope as well. DOES NOT SAVE it |
|
| 81 | - * |
|
| 82 | - * @throws \EE_Error |
|
| 83 | - */ |
|
| 84 | - public function set_active() |
|
| 85 | - { |
|
| 86 | - $default_scopes = array(EEM_Payment_Method::scope_cart); |
|
| 87 | - if ( |
|
| 88 | - $this->type_obj() && |
|
| 89 | - $this->type_obj()->payment_occurs() === EE_PMT_Base::offline |
|
| 90 | - ) { |
|
| 91 | - $default_scopes[] = EEM_Payment_Method::scope_admin; |
|
| 92 | - } |
|
| 93 | - $this->set_scope($default_scopes); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Makes this payment method apply to NO scopes at all. DOES NOT SAVE it. |
|
| 99 | - */ |
|
| 100 | - public function deactivate() |
|
| 101 | - { |
|
| 102 | - $this->set_scope(array()); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Gets button_url |
|
| 108 | - * |
|
| 109 | - * @return string |
|
| 110 | - */ |
|
| 111 | - public function button_url() |
|
| 112 | - { |
|
| 113 | - return $this->get('PMD_button_url'); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Sets button_url |
|
| 119 | - * |
|
| 120 | - * @param string $button_url |
|
| 121 | - */ |
|
| 122 | - public function set_button_url($button_url) |
|
| 123 | - { |
|
| 124 | - $this->set('PMD_button_url', $button_url); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Gets debug_mode |
|
| 130 | - * |
|
| 131 | - * @return boolean |
|
| 132 | - */ |
|
| 133 | - public function debug_mode() |
|
| 134 | - { |
|
| 135 | - return $this->get('PMD_debug_mode'); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Sets debug_mode |
|
| 141 | - * |
|
| 142 | - * @param boolean $debug_mode |
|
| 143 | - */ |
|
| 144 | - public function set_debug_mode($debug_mode) |
|
| 145 | - { |
|
| 146 | - $this->set('PMD_debug_mode', $debug_mode); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Gets description |
|
| 152 | - * |
|
| 153 | - * @return string |
|
| 154 | - */ |
|
| 155 | - public function description() |
|
| 156 | - { |
|
| 157 | - return $this->get('PMD_desc'); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * Sets description |
|
| 163 | - * |
|
| 164 | - * @param string $description |
|
| 165 | - */ |
|
| 166 | - public function set_description($description) |
|
| 167 | - { |
|
| 168 | - $this->set('PMD_desc', $description); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * Gets name |
|
| 174 | - * |
|
| 175 | - * @return string |
|
| 176 | - */ |
|
| 177 | - public function name() |
|
| 178 | - { |
|
| 179 | - return $this->get('PMD_name'); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * Sets name |
|
| 185 | - * |
|
| 186 | - * @param string $name |
|
| 187 | - */ |
|
| 188 | - public function set_name($name) |
|
| 189 | - { |
|
| 190 | - $this->set('PMD_name', $name); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * Gets open_by_default |
|
| 196 | - * |
|
| 197 | - * @return boolean |
|
| 198 | - */ |
|
| 199 | - public function open_by_default() |
|
| 200 | - { |
|
| 201 | - return $this->get('PMD_open_by_default'); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * Sets open_by_default |
|
| 207 | - * |
|
| 208 | - * @param boolean $open_by_default |
|
| 209 | - */ |
|
| 210 | - public function set_open_by_default($open_by_default) |
|
| 211 | - { |
|
| 212 | - $this->set('PMD_open_by_default', $open_by_default); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * Gets order |
|
| 218 | - * |
|
| 219 | - * @return int |
|
| 220 | - */ |
|
| 221 | - public function order() |
|
| 222 | - { |
|
| 223 | - return $this->get('PMD_order'); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * Sets order |
|
| 229 | - * |
|
| 230 | - * @param int $order |
|
| 231 | - */ |
|
| 232 | - public function set_order($order) |
|
| 233 | - { |
|
| 234 | - $this->set('PMD_order', $order); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * Gets slug |
|
| 240 | - * |
|
| 241 | - * @return string |
|
| 242 | - */ |
|
| 243 | - public function slug() |
|
| 244 | - { |
|
| 245 | - return $this->get('PMD_slug'); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * Sets slug |
|
| 251 | - * |
|
| 252 | - * @param string $slug |
|
| 253 | - */ |
|
| 254 | - public function set_slug($slug) |
|
| 255 | - { |
|
| 256 | - $this->set('PMD_slug', $slug); |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * Gets type |
|
| 262 | - * |
|
| 263 | - * @return string |
|
| 264 | - */ |
|
| 265 | - public function type() |
|
| 266 | - { |
|
| 267 | - return $this->get('PMD_type'); |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * Sets type |
|
| 273 | - * |
|
| 274 | - * @param string $type |
|
| 275 | - */ |
|
| 276 | - public function set_type($type) |
|
| 277 | - { |
|
| 278 | - $this->set('PMD_type', $type); |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * Gets wp_user |
|
| 284 | - * |
|
| 285 | - * @return int |
|
| 286 | - */ |
|
| 287 | - public function wp_user() |
|
| 288 | - { |
|
| 289 | - return $this->get('PMD_wp_user'); |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * Sets wp_user |
|
| 295 | - * |
|
| 296 | - * @param int $wp_user_id |
|
| 297 | - */ |
|
| 298 | - public function set_wp_user($wp_user_id) |
|
| 299 | - { |
|
| 300 | - $this->set('PMD_wp_user', $wp_user_id); |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - /** |
|
| 304 | - * Overrides parent so when PMD_type is changed we refresh the _type_obj |
|
| 305 | - * |
|
| 306 | - * @param string $field_name |
|
| 307 | - * @param mixed $field_value |
|
| 308 | - * @param boolean $use_default |
|
| 309 | - */ |
|
| 310 | - public function set($field_name, $field_value, $use_default = false) |
|
| 311 | - { |
|
| 312 | - if ($field_name === 'PMD_type') { |
|
| 313 | - // the type has probably changed, so forget about its old type object |
|
| 314 | - $this->_type_obj = null; |
|
| 315 | - } |
|
| 316 | - parent::set($field_name, $field_value, $use_default); |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * Gets admin_name |
|
| 322 | - * |
|
| 323 | - * @return string |
|
| 324 | - */ |
|
| 325 | - public function admin_name() |
|
| 326 | - { |
|
| 327 | - return $this->get('PMD_admin_name'); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - |
|
| 331 | - /** |
|
| 332 | - * Sets admin_name |
|
| 333 | - * |
|
| 334 | - * @param string $admin_name |
|
| 335 | - */ |
|
| 336 | - public function set_admin_name($admin_name) |
|
| 337 | - { |
|
| 338 | - $this->set('PMD_admin_name', $admin_name); |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * Gets admin_desc |
|
| 344 | - * |
|
| 345 | - * @return string |
|
| 346 | - */ |
|
| 347 | - public function admin_desc() |
|
| 348 | - { |
|
| 349 | - return $this->get('PMD_admin_desc'); |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - |
|
| 353 | - /** |
|
| 354 | - * Sets admin_desc |
|
| 355 | - * |
|
| 356 | - * @param string $admin_desc |
|
| 357 | - */ |
|
| 358 | - public function set_admin_desc($admin_desc) |
|
| 359 | - { |
|
| 360 | - $this->set('PMD_admin_desc', $admin_desc); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * Gets scope |
|
| 366 | - * |
|
| 367 | - * @return array |
|
| 368 | - */ |
|
| 369 | - public function scope() |
|
| 370 | - { |
|
| 371 | - return $this->get('PMD_scope'); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - |
|
| 375 | - /** |
|
| 376 | - * Sets scope |
|
| 377 | - * |
|
| 378 | - * @param array $scope |
|
| 379 | - */ |
|
| 380 | - public function set_scope($scope) |
|
| 381 | - { |
|
| 382 | - $this->set('PMD_scope', $scope); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - |
|
| 386 | - /** |
|
| 387 | - * Gets the payment method type for this payment method instance |
|
| 388 | - * |
|
| 389 | - * @return EE_PMT_Base |
|
| 390 | - * @throws EE_Error |
|
| 391 | - */ |
|
| 392 | - public function type_obj() |
|
| 393 | - { |
|
| 394 | - if (! $this->_type_obj) { |
|
| 395 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 396 | - if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) { |
|
| 397 | - $class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type()); |
|
| 398 | - if (! class_exists($class_name)) { |
|
| 399 | - throw new EE_Error( |
|
| 400 | - sprintf( |
|
| 401 | - __( |
|
| 402 | - 'An attempt to use the "%1$s" payment method failed, so it was deactivated.%2$sWas the "%1$s" Plugin recently deactivated? It can be reactivated on the %3$sPlugins Admin Page%4$s', |
|
| 403 | - 'event_espresso' |
|
| 404 | - ), |
|
| 405 | - $class_name, |
|
| 406 | - '<br />', |
|
| 407 | - '<a href="' . admin_url('plugins.php') . '">', |
|
| 408 | - '</a>' |
|
| 409 | - ) |
|
| 410 | - ); |
|
| 411 | - } |
|
| 412 | - $r = new ReflectionClass($class_name); |
|
| 413 | - $this->_type_obj = $r->newInstanceArgs(array($this)); |
|
| 414 | - } else { |
|
| 415 | - throw new EE_Error( |
|
| 416 | - sprintf( |
|
| 417 | - __( |
|
| 418 | - 'A payment method of type "%1$s" does not exist. Only ones existing are: %2$s', |
|
| 419 | - 'event_espresso' |
|
| 420 | - ), |
|
| 421 | - $this->type(), |
|
| 422 | - implode(',', EE_Payment_Method_Manager::instance()->payment_method_type_names()) |
|
| 423 | - ) |
|
| 424 | - ); |
|
| 425 | - } |
|
| 426 | - } |
|
| 427 | - return $this->_type_obj; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - |
|
| 431 | - /** |
|
| 432 | - * Returns a simple array of key-value pairs combining the payment method's fields (without the 'PMD_' prefix) |
|
| 433 | - * and the extra meta. Mostly used for passing off ot gateways. * |
|
| 434 | - * |
|
| 435 | - * @return array |
|
| 436 | - */ |
|
| 437 | - public function settings_array() |
|
| 438 | - { |
|
| 439 | - $fields = $this->model_field_array(); |
|
| 440 | - $extra_meta = $this->all_extra_meta_array(); |
|
| 441 | - // remove the model's prefix from the fields |
|
| 442 | - $combined_settings_array = array(); |
|
| 443 | - foreach ($fields as $key => $value) { |
|
| 444 | - if (strpos($key, 'PMD_') === 0) { |
|
| 445 | - $key_sans_model_prefix = str_replace('PMD_', '', $key); |
|
| 446 | - $combined_settings_array [ $key_sans_model_prefix ] = $value; |
|
| 447 | - } |
|
| 448 | - } |
|
| 449 | - $combined_settings_array = array_merge($extra_meta, $combined_settings_array); |
|
| 450 | - return $combined_settings_array; |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - |
|
| 454 | - /** |
|
| 455 | - * Gets the HTML for displaying the payment method on a page. |
|
| 456 | - * |
|
| 457 | - * @param string $url |
|
| 458 | - * @param string $css_class |
|
| 459 | - * @return string of HTML for displaying the button |
|
| 460 | - * @throws \EE_Error |
|
| 461 | - */ |
|
| 462 | - public function button_html($url = '', $css_class = '') |
|
| 463 | - { |
|
| 464 | - $payment_occurs = $this->type_obj()->payment_occurs(); |
|
| 465 | - return ' |
|
| 14 | + /** |
|
| 15 | + * Payment Method type object, which has all the info about this type of payment method, |
|
| 16 | + * including functions for processing payments, to get settings forms, etc. |
|
| 17 | + * |
|
| 18 | + * @var EE_PMT_Base |
|
| 19 | + */ |
|
| 20 | + protected $_type_obj; |
|
| 21 | + |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * @param array $props_n_values |
|
| 25 | + * @return EE_Payment_Method |
|
| 26 | + * @throws \EE_Error |
|
| 27 | + */ |
|
| 28 | + public static function new_instance($props_n_values = array()) |
|
| 29 | + { |
|
| 30 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 31 | + return $has_object ? $has_object : new self($props_n_values, false); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @param array $props_n_values |
|
| 37 | + * @return EE_Payment_Method |
|
| 38 | + * @throws \EE_Error |
|
| 39 | + */ |
|
| 40 | + public static function new_instance_from_db($props_n_values = array()) |
|
| 41 | + { |
|
| 42 | + return new self($props_n_values, true); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Checks if there is a payment method class of the given 'PMD_type', and if so returns the classname. |
|
| 49 | + * Otherwise returns a normal EE_Payment_Method |
|
| 50 | + * |
|
| 51 | + * @param array $props_n_values where 'PMD_type' is a gateway name like 'Paypal_Standard','Invoice',etc (basically |
|
| 52 | + * the classname minus 'EEPM_') |
|
| 53 | + * @return string |
|
| 54 | + */ |
|
| 55 | + // private static function _payment_method_type($props_n_values) |
|
| 56 | + // { |
|
| 57 | + // EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 58 | + // $type_string = isset($props_n_values['PMD_type']) ? $props_n_values['PMD_type'] : null; |
|
| 59 | + // if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($type_string)) { |
|
| 60 | + // return 'EEPM_' . $type_string; |
|
| 61 | + // } else { |
|
| 62 | + // return __CLASS__; |
|
| 63 | + // } |
|
| 64 | + // } |
|
| 65 | + |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Gets whether this payment method can be used anywhere at all (ie frontend cart, admin, etc) |
|
| 69 | + * |
|
| 70 | + * @return boolean |
|
| 71 | + */ |
|
| 72 | + public function active() |
|
| 73 | + { |
|
| 74 | + return array_intersect(array_keys(EEM_Payment_Method::instance()->scopes()), $this->scope()); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Sets this PM as active by making it usable within the CART scope. Offline gateways |
|
| 80 | + * are also usable from the admin-scope as well. DOES NOT SAVE it |
|
| 81 | + * |
|
| 82 | + * @throws \EE_Error |
|
| 83 | + */ |
|
| 84 | + public function set_active() |
|
| 85 | + { |
|
| 86 | + $default_scopes = array(EEM_Payment_Method::scope_cart); |
|
| 87 | + if ( |
|
| 88 | + $this->type_obj() && |
|
| 89 | + $this->type_obj()->payment_occurs() === EE_PMT_Base::offline |
|
| 90 | + ) { |
|
| 91 | + $default_scopes[] = EEM_Payment_Method::scope_admin; |
|
| 92 | + } |
|
| 93 | + $this->set_scope($default_scopes); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Makes this payment method apply to NO scopes at all. DOES NOT SAVE it. |
|
| 99 | + */ |
|
| 100 | + public function deactivate() |
|
| 101 | + { |
|
| 102 | + $this->set_scope(array()); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Gets button_url |
|
| 108 | + * |
|
| 109 | + * @return string |
|
| 110 | + */ |
|
| 111 | + public function button_url() |
|
| 112 | + { |
|
| 113 | + return $this->get('PMD_button_url'); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Sets button_url |
|
| 119 | + * |
|
| 120 | + * @param string $button_url |
|
| 121 | + */ |
|
| 122 | + public function set_button_url($button_url) |
|
| 123 | + { |
|
| 124 | + $this->set('PMD_button_url', $button_url); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Gets debug_mode |
|
| 130 | + * |
|
| 131 | + * @return boolean |
|
| 132 | + */ |
|
| 133 | + public function debug_mode() |
|
| 134 | + { |
|
| 135 | + return $this->get('PMD_debug_mode'); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Sets debug_mode |
|
| 141 | + * |
|
| 142 | + * @param boolean $debug_mode |
|
| 143 | + */ |
|
| 144 | + public function set_debug_mode($debug_mode) |
|
| 145 | + { |
|
| 146 | + $this->set('PMD_debug_mode', $debug_mode); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Gets description |
|
| 152 | + * |
|
| 153 | + * @return string |
|
| 154 | + */ |
|
| 155 | + public function description() |
|
| 156 | + { |
|
| 157 | + return $this->get('PMD_desc'); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * Sets description |
|
| 163 | + * |
|
| 164 | + * @param string $description |
|
| 165 | + */ |
|
| 166 | + public function set_description($description) |
|
| 167 | + { |
|
| 168 | + $this->set('PMD_desc', $description); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * Gets name |
|
| 174 | + * |
|
| 175 | + * @return string |
|
| 176 | + */ |
|
| 177 | + public function name() |
|
| 178 | + { |
|
| 179 | + return $this->get('PMD_name'); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * Sets name |
|
| 185 | + * |
|
| 186 | + * @param string $name |
|
| 187 | + */ |
|
| 188 | + public function set_name($name) |
|
| 189 | + { |
|
| 190 | + $this->set('PMD_name', $name); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * Gets open_by_default |
|
| 196 | + * |
|
| 197 | + * @return boolean |
|
| 198 | + */ |
|
| 199 | + public function open_by_default() |
|
| 200 | + { |
|
| 201 | + return $this->get('PMD_open_by_default'); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * Sets open_by_default |
|
| 207 | + * |
|
| 208 | + * @param boolean $open_by_default |
|
| 209 | + */ |
|
| 210 | + public function set_open_by_default($open_by_default) |
|
| 211 | + { |
|
| 212 | + $this->set('PMD_open_by_default', $open_by_default); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * Gets order |
|
| 218 | + * |
|
| 219 | + * @return int |
|
| 220 | + */ |
|
| 221 | + public function order() |
|
| 222 | + { |
|
| 223 | + return $this->get('PMD_order'); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * Sets order |
|
| 229 | + * |
|
| 230 | + * @param int $order |
|
| 231 | + */ |
|
| 232 | + public function set_order($order) |
|
| 233 | + { |
|
| 234 | + $this->set('PMD_order', $order); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * Gets slug |
|
| 240 | + * |
|
| 241 | + * @return string |
|
| 242 | + */ |
|
| 243 | + public function slug() |
|
| 244 | + { |
|
| 245 | + return $this->get('PMD_slug'); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * Sets slug |
|
| 251 | + * |
|
| 252 | + * @param string $slug |
|
| 253 | + */ |
|
| 254 | + public function set_slug($slug) |
|
| 255 | + { |
|
| 256 | + $this->set('PMD_slug', $slug); |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * Gets type |
|
| 262 | + * |
|
| 263 | + * @return string |
|
| 264 | + */ |
|
| 265 | + public function type() |
|
| 266 | + { |
|
| 267 | + return $this->get('PMD_type'); |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * Sets type |
|
| 273 | + * |
|
| 274 | + * @param string $type |
|
| 275 | + */ |
|
| 276 | + public function set_type($type) |
|
| 277 | + { |
|
| 278 | + $this->set('PMD_type', $type); |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * Gets wp_user |
|
| 284 | + * |
|
| 285 | + * @return int |
|
| 286 | + */ |
|
| 287 | + public function wp_user() |
|
| 288 | + { |
|
| 289 | + return $this->get('PMD_wp_user'); |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * Sets wp_user |
|
| 295 | + * |
|
| 296 | + * @param int $wp_user_id |
|
| 297 | + */ |
|
| 298 | + public function set_wp_user($wp_user_id) |
|
| 299 | + { |
|
| 300 | + $this->set('PMD_wp_user', $wp_user_id); |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + /** |
|
| 304 | + * Overrides parent so when PMD_type is changed we refresh the _type_obj |
|
| 305 | + * |
|
| 306 | + * @param string $field_name |
|
| 307 | + * @param mixed $field_value |
|
| 308 | + * @param boolean $use_default |
|
| 309 | + */ |
|
| 310 | + public function set($field_name, $field_value, $use_default = false) |
|
| 311 | + { |
|
| 312 | + if ($field_name === 'PMD_type') { |
|
| 313 | + // the type has probably changed, so forget about its old type object |
|
| 314 | + $this->_type_obj = null; |
|
| 315 | + } |
|
| 316 | + parent::set($field_name, $field_value, $use_default); |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * Gets admin_name |
|
| 322 | + * |
|
| 323 | + * @return string |
|
| 324 | + */ |
|
| 325 | + public function admin_name() |
|
| 326 | + { |
|
| 327 | + return $this->get('PMD_admin_name'); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + |
|
| 331 | + /** |
|
| 332 | + * Sets admin_name |
|
| 333 | + * |
|
| 334 | + * @param string $admin_name |
|
| 335 | + */ |
|
| 336 | + public function set_admin_name($admin_name) |
|
| 337 | + { |
|
| 338 | + $this->set('PMD_admin_name', $admin_name); |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * Gets admin_desc |
|
| 344 | + * |
|
| 345 | + * @return string |
|
| 346 | + */ |
|
| 347 | + public function admin_desc() |
|
| 348 | + { |
|
| 349 | + return $this->get('PMD_admin_desc'); |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + |
|
| 353 | + /** |
|
| 354 | + * Sets admin_desc |
|
| 355 | + * |
|
| 356 | + * @param string $admin_desc |
|
| 357 | + */ |
|
| 358 | + public function set_admin_desc($admin_desc) |
|
| 359 | + { |
|
| 360 | + $this->set('PMD_admin_desc', $admin_desc); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * Gets scope |
|
| 366 | + * |
|
| 367 | + * @return array |
|
| 368 | + */ |
|
| 369 | + public function scope() |
|
| 370 | + { |
|
| 371 | + return $this->get('PMD_scope'); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + |
|
| 375 | + /** |
|
| 376 | + * Sets scope |
|
| 377 | + * |
|
| 378 | + * @param array $scope |
|
| 379 | + */ |
|
| 380 | + public function set_scope($scope) |
|
| 381 | + { |
|
| 382 | + $this->set('PMD_scope', $scope); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + |
|
| 386 | + /** |
|
| 387 | + * Gets the payment method type for this payment method instance |
|
| 388 | + * |
|
| 389 | + * @return EE_PMT_Base |
|
| 390 | + * @throws EE_Error |
|
| 391 | + */ |
|
| 392 | + public function type_obj() |
|
| 393 | + { |
|
| 394 | + if (! $this->_type_obj) { |
|
| 395 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 396 | + if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) { |
|
| 397 | + $class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type()); |
|
| 398 | + if (! class_exists($class_name)) { |
|
| 399 | + throw new EE_Error( |
|
| 400 | + sprintf( |
|
| 401 | + __( |
|
| 402 | + 'An attempt to use the "%1$s" payment method failed, so it was deactivated.%2$sWas the "%1$s" Plugin recently deactivated? It can be reactivated on the %3$sPlugins Admin Page%4$s', |
|
| 403 | + 'event_espresso' |
|
| 404 | + ), |
|
| 405 | + $class_name, |
|
| 406 | + '<br />', |
|
| 407 | + '<a href="' . admin_url('plugins.php') . '">', |
|
| 408 | + '</a>' |
|
| 409 | + ) |
|
| 410 | + ); |
|
| 411 | + } |
|
| 412 | + $r = new ReflectionClass($class_name); |
|
| 413 | + $this->_type_obj = $r->newInstanceArgs(array($this)); |
|
| 414 | + } else { |
|
| 415 | + throw new EE_Error( |
|
| 416 | + sprintf( |
|
| 417 | + __( |
|
| 418 | + 'A payment method of type "%1$s" does not exist. Only ones existing are: %2$s', |
|
| 419 | + 'event_espresso' |
|
| 420 | + ), |
|
| 421 | + $this->type(), |
|
| 422 | + implode(',', EE_Payment_Method_Manager::instance()->payment_method_type_names()) |
|
| 423 | + ) |
|
| 424 | + ); |
|
| 425 | + } |
|
| 426 | + } |
|
| 427 | + return $this->_type_obj; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + |
|
| 431 | + /** |
|
| 432 | + * Returns a simple array of key-value pairs combining the payment method's fields (without the 'PMD_' prefix) |
|
| 433 | + * and the extra meta. Mostly used for passing off ot gateways. * |
|
| 434 | + * |
|
| 435 | + * @return array |
|
| 436 | + */ |
|
| 437 | + public function settings_array() |
|
| 438 | + { |
|
| 439 | + $fields = $this->model_field_array(); |
|
| 440 | + $extra_meta = $this->all_extra_meta_array(); |
|
| 441 | + // remove the model's prefix from the fields |
|
| 442 | + $combined_settings_array = array(); |
|
| 443 | + foreach ($fields as $key => $value) { |
|
| 444 | + if (strpos($key, 'PMD_') === 0) { |
|
| 445 | + $key_sans_model_prefix = str_replace('PMD_', '', $key); |
|
| 446 | + $combined_settings_array [ $key_sans_model_prefix ] = $value; |
|
| 447 | + } |
|
| 448 | + } |
|
| 449 | + $combined_settings_array = array_merge($extra_meta, $combined_settings_array); |
|
| 450 | + return $combined_settings_array; |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + |
|
| 454 | + /** |
|
| 455 | + * Gets the HTML for displaying the payment method on a page. |
|
| 456 | + * |
|
| 457 | + * @param string $url |
|
| 458 | + * @param string $css_class |
|
| 459 | + * @return string of HTML for displaying the button |
|
| 460 | + * @throws \EE_Error |
|
| 461 | + */ |
|
| 462 | + public function button_html($url = '', $css_class = '') |
|
| 463 | + { |
|
| 464 | + $payment_occurs = $this->type_obj()->payment_occurs(); |
|
| 465 | + return ' |
|
| 466 | 466 | <div id="' |
| 467 | - . $this->slug() |
|
| 468 | - . '-payment-option-dv" class="' |
|
| 469 | - . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '"> |
|
| 467 | + . $this->slug() |
|
| 468 | + . '-payment-option-dv" class="' |
|
| 469 | + . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '"> |
|
| 470 | 470 | <a id="payment-gateway-button-' . $this->slug() |
| 471 | - . '" class="reg-page-payment-option-lnk" rel="' |
|
| 472 | - . $this->slug() . '" href="' . $url . '" > |
|
| 471 | + . '" class="reg-page-payment-option-lnk" rel="' |
|
| 472 | + . $this->slug() . '" href="' . $url . '" > |
|
| 473 | 473 | <img src="' . $this->button_url() . '" alt="' . sprintf( |
| 474 | - esc_attr__('Pay using %s', 'event_espresso'), |
|
| 475 | - $this->get_pretty('PMD_name', 'form_input') |
|
| 476 | - ) . '" /> |
|
| 474 | + esc_attr__('Pay using %s', 'event_espresso'), |
|
| 475 | + $this->get_pretty('PMD_name', 'form_input') |
|
| 476 | + ) . '" /> |
|
| 477 | 477 | </a> |
| 478 | 478 | </div> |
| 479 | 479 | '; |
| 480 | - } |
|
| 481 | - |
|
| 482 | - |
|
| 483 | - /** |
|
| 484 | - * Gets all the currencies which are an option for this payment method |
|
| 485 | - * (as defined by the gateway and the currently active currencies) |
|
| 486 | - * |
|
| 487 | - * @return EE_Currency[] |
|
| 488 | - * @throws \EE_Error |
|
| 489 | - */ |
|
| 490 | - public function get_all_usable_currencies() |
|
| 491 | - { |
|
| 492 | - return EEM_Currency::instance()->get_all_currencies_usable_by($this->type_obj()); |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - |
|
| 496 | - /** |
|
| 497 | - * Reports whether or not this payment method can be used for this payment method |
|
| 498 | - * |
|
| 499 | - * @param string $currency_code currency ID (code) |
|
| 500 | - * @return boolean |
|
| 501 | - * @throws \EE_Error |
|
| 502 | - */ |
|
| 503 | - public function usable_for_currency($currency_code) |
|
| 504 | - { |
|
| 505 | - foreach ($this->get_all_usable_currencies() as $currency_obj) { |
|
| 506 | - if ($currency_obj->ID() === $currency_code) { |
|
| 507 | - return true; |
|
| 508 | - } |
|
| 509 | - } |
|
| 510 | - return false; |
|
| 511 | - } |
|
| 512 | - |
|
| 513 | - |
|
| 514 | - /** |
|
| 515 | - * Returns TRUE if this payment method's gateway is an instance of EE_Onsite_Gateway |
|
| 516 | - * |
|
| 517 | - * @return bool |
|
| 518 | - * @throws \EE_Error |
|
| 519 | - */ |
|
| 520 | - public function is_on_site() |
|
| 521 | - { |
|
| 522 | - return $this->type_obj()->payment_occurs() === EE_PMT_Base::onsite; |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - |
|
| 526 | - /** |
|
| 527 | - * Returns TRUE if this payment method's gateway is an instance of EE_Offsite_Gateway |
|
| 528 | - * |
|
| 529 | - * @return bool |
|
| 530 | - * @throws \EE_Error |
|
| 531 | - */ |
|
| 532 | - public function is_off_site() |
|
| 533 | - { |
|
| 534 | - return $this->type_obj()->payment_occurs() === EE_PMT_Base::offsite; |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - |
|
| 538 | - /** |
|
| 539 | - * Returns TRUE if this payment method does not utilize a gateway |
|
| 540 | - * |
|
| 541 | - * @return bool |
|
| 542 | - * @throws \EE_Error |
|
| 543 | - */ |
|
| 544 | - public function is_off_line() |
|
| 545 | - { |
|
| 546 | - return $this->type_obj()->payment_occurs() === EE_PMT_Base::offline; |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - /** |
|
| 550 | - * Overrides default __sleep so the object type is NOT cached. |
|
| 551 | - * This way we can rely on the normal EE_Payment_Method::type_obj() logic |
|
| 552 | - * to load the required classes, and don't need them at the time of unserialization |
|
| 553 | - * |
|
| 554 | - * @return array |
|
| 555 | - */ |
|
| 556 | - public function __sleep() |
|
| 557 | - { |
|
| 558 | - $properties = get_object_vars($this); |
|
| 559 | - unset($properties['_type_obj']); |
|
| 560 | - return array_keys($properties); |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - |
|
| 564 | - /** |
|
| 565 | - * Overrides parent to add some logging for when payment methods get deactivated |
|
| 566 | - * |
|
| 567 | - * @param array $set_cols_n_values |
|
| 568 | - * @return int @see EE_Base_Class::save() |
|
| 569 | - * @throws \EE_Error |
|
| 570 | - */ |
|
| 571 | - public function save($set_cols_n_values = array()) |
|
| 572 | - { |
|
| 573 | - $results = parent::save($set_cols_n_values); |
|
| 574 | - if ($this->get_original('PMD_scope') !== $this->get('PMD_scope')) { |
|
| 575 | - EE_Log::instance()->log( |
|
| 576 | - __FILE__, |
|
| 577 | - __FUNCTION__, |
|
| 578 | - sprintf( |
|
| 579 | - __('Set new scope on payment method %1$s to %2$s from %3$s on URL %4$s', 'event_espresso'), |
|
| 580 | - $this->name(), |
|
| 581 | - serialize($this->get_original('PMD_scope')), |
|
| 582 | - serialize($this->get('PMD_scope')), |
|
| 583 | - EE_Registry::instance()->REQ->get_current_page_permalink() |
|
| 584 | - ), |
|
| 585 | - 'payment_method_change' |
|
| 586 | - ); |
|
| 587 | - } |
|
| 588 | - return $results; |
|
| 589 | - } |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + |
|
| 483 | + /** |
|
| 484 | + * Gets all the currencies which are an option for this payment method |
|
| 485 | + * (as defined by the gateway and the currently active currencies) |
|
| 486 | + * |
|
| 487 | + * @return EE_Currency[] |
|
| 488 | + * @throws \EE_Error |
|
| 489 | + */ |
|
| 490 | + public function get_all_usable_currencies() |
|
| 491 | + { |
|
| 492 | + return EEM_Currency::instance()->get_all_currencies_usable_by($this->type_obj()); |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + |
|
| 496 | + /** |
|
| 497 | + * Reports whether or not this payment method can be used for this payment method |
|
| 498 | + * |
|
| 499 | + * @param string $currency_code currency ID (code) |
|
| 500 | + * @return boolean |
|
| 501 | + * @throws \EE_Error |
|
| 502 | + */ |
|
| 503 | + public function usable_for_currency($currency_code) |
|
| 504 | + { |
|
| 505 | + foreach ($this->get_all_usable_currencies() as $currency_obj) { |
|
| 506 | + if ($currency_obj->ID() === $currency_code) { |
|
| 507 | + return true; |
|
| 508 | + } |
|
| 509 | + } |
|
| 510 | + return false; |
|
| 511 | + } |
|
| 512 | + |
|
| 513 | + |
|
| 514 | + /** |
|
| 515 | + * Returns TRUE if this payment method's gateway is an instance of EE_Onsite_Gateway |
|
| 516 | + * |
|
| 517 | + * @return bool |
|
| 518 | + * @throws \EE_Error |
|
| 519 | + */ |
|
| 520 | + public function is_on_site() |
|
| 521 | + { |
|
| 522 | + return $this->type_obj()->payment_occurs() === EE_PMT_Base::onsite; |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + |
|
| 526 | + /** |
|
| 527 | + * Returns TRUE if this payment method's gateway is an instance of EE_Offsite_Gateway |
|
| 528 | + * |
|
| 529 | + * @return bool |
|
| 530 | + * @throws \EE_Error |
|
| 531 | + */ |
|
| 532 | + public function is_off_site() |
|
| 533 | + { |
|
| 534 | + return $this->type_obj()->payment_occurs() === EE_PMT_Base::offsite; |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + |
|
| 538 | + /** |
|
| 539 | + * Returns TRUE if this payment method does not utilize a gateway |
|
| 540 | + * |
|
| 541 | + * @return bool |
|
| 542 | + * @throws \EE_Error |
|
| 543 | + */ |
|
| 544 | + public function is_off_line() |
|
| 545 | + { |
|
| 546 | + return $this->type_obj()->payment_occurs() === EE_PMT_Base::offline; |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + /** |
|
| 550 | + * Overrides default __sleep so the object type is NOT cached. |
|
| 551 | + * This way we can rely on the normal EE_Payment_Method::type_obj() logic |
|
| 552 | + * to load the required classes, and don't need them at the time of unserialization |
|
| 553 | + * |
|
| 554 | + * @return array |
|
| 555 | + */ |
|
| 556 | + public function __sleep() |
|
| 557 | + { |
|
| 558 | + $properties = get_object_vars($this); |
|
| 559 | + unset($properties['_type_obj']); |
|
| 560 | + return array_keys($properties); |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + |
|
| 564 | + /** |
|
| 565 | + * Overrides parent to add some logging for when payment methods get deactivated |
|
| 566 | + * |
|
| 567 | + * @param array $set_cols_n_values |
|
| 568 | + * @return int @see EE_Base_Class::save() |
|
| 569 | + * @throws \EE_Error |
|
| 570 | + */ |
|
| 571 | + public function save($set_cols_n_values = array()) |
|
| 572 | + { |
|
| 573 | + $results = parent::save($set_cols_n_values); |
|
| 574 | + if ($this->get_original('PMD_scope') !== $this->get('PMD_scope')) { |
|
| 575 | + EE_Log::instance()->log( |
|
| 576 | + __FILE__, |
|
| 577 | + __FUNCTION__, |
|
| 578 | + sprintf( |
|
| 579 | + __('Set new scope on payment method %1$s to %2$s from %3$s on URL %4$s', 'event_espresso'), |
|
| 580 | + $this->name(), |
|
| 581 | + serialize($this->get_original('PMD_scope')), |
|
| 582 | + serialize($this->get('PMD_scope')), |
|
| 583 | + EE_Registry::instance()->REQ->get_current_page_permalink() |
|
| 584 | + ), |
|
| 585 | + 'payment_method_change' |
|
| 586 | + ); |
|
| 587 | + } |
|
| 588 | + return $results; |
|
| 589 | + } |
|
| 590 | 590 | } |
@@ -6,23 +6,23 @@ |
||
| 6 | 6 | class EE_Event_Venue extends EE_Base_Class |
| 7 | 7 | { |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * @param array $props_n_values |
|
| 11 | - * @return EE_Event_Venue|mixed |
|
| 12 | - */ |
|
| 13 | - public static function new_instance($props_n_values = array()) |
|
| 14 | - { |
|
| 15 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 16 | - return $has_object ? $has_object : new self($props_n_values); |
|
| 17 | - } |
|
| 9 | + /** |
|
| 10 | + * @param array $props_n_values |
|
| 11 | + * @return EE_Event_Venue|mixed |
|
| 12 | + */ |
|
| 13 | + public static function new_instance($props_n_values = array()) |
|
| 14 | + { |
|
| 15 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 16 | + return $has_object ? $has_object : new self($props_n_values); |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @param array $props_n_values |
|
| 22 | - * @return EE_Event_Venue |
|
| 23 | - */ |
|
| 24 | - public static function new_instance_from_db($props_n_values = array()) |
|
| 25 | - { |
|
| 26 | - return new self($props_n_values, true); |
|
| 27 | - } |
|
| 20 | + /** |
|
| 21 | + * @param array $props_n_values |
|
| 22 | + * @return EE_Event_Venue |
|
| 23 | + */ |
|
| 24 | + public static function new_instance_from_db($props_n_values = array()) |
|
| 25 | + { |
|
| 26 | + return new self($props_n_values, true); |
|
| 27 | + } |
|
| 28 | 28 | } |