3-customers-converter.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace cx_newsletter;
  3. class customers_converter
  4. extends database_converter
  5. implements database_converter_interface {
  6. public function get_array() : array {
  7. $this->check_target();
  8. $result = [];
  9. $result['company'] = $this->target->company;
  10. $result['name'] = $this->target->name;
  11. $result['surname'] = $this->target->surname;
  12. $result['comments'] = $this->target->comments;
  13. $result['email'] = $this->target->email;
  14. $result['phone_number'] = $this->target->phone_number;
  15. $result['tester'] = $this->target->tester;
  16. if ($this->target->group !== null) {
  17. $result['grouped'] = $this->target->group->get_id();
  18. } else {
  19. $result['grouped'] = null;
  20. }
  21. if ($this->target->has_id()) {
  22. $result['id'] = $this->target->get_id();
  23. }
  24. return $result;
  25. }
  26. public function load_array(array $target) : self {
  27. $this->check_all_exists($target, [
  28. 'company',
  29. 'name',
  30. 'surname',
  31. 'comments',
  32. 'email',
  33. 'phone_number',
  34. 'tester',
  35. 'grouped'
  36. ]);
  37. $this->target = new customer($this->id_or_null($target));
  38. $this->target->company = $target['company'];
  39. $this->target->name = $target['name'];
  40. $this->target->surname = $target['surname'];
  41. $this->target->comments = $target['comments'];
  42. $this->target->email = $target['email'];
  43. $this->target->phone_number = $target['phone_number'];
  44. $this->target->tester = $target['tester'];
  45. if ($target['grouped'] === null) {
  46. $this->target->group = null;
  47. } else {
  48. $this->target->group = new group(intval($target['grouped']));
  49. }
  50. return $this;
  51. }
  52. }