2-messages_converter.php 810 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace cx_newsletter;
  3. class messages_converter
  4. extends database_converter
  5. implements database_converter_interface {
  6. public function get_array() : array {
  7. $this->check_target();
  8. $result = [];
  9. $result['title'] = $this->target->title;
  10. $result['content'] = base64_encode($this->target->content);
  11. if ($this->target->has_id()) {
  12. $result['id'] = $this->target->get_id();
  13. }
  14. return $result;
  15. }
  16. public function load_array(array $target) : self {
  17. $this->check_all_exists($target, [ 'title', 'content' ]);
  18. $this->target = new message($this->id_or_null($target));
  19. $this->target->title = $target['title'];
  20. $this->target->content = base64_decode($target['content']);
  21. return $this;
  22. }
  23. }