ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilMailValueObjectJsonService.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 {
26  public function convertToJson(array $mail_value_objects): string
27  {
28  $records = [];
29  foreach ($mail_value_objects as $mail_value_object) {
30  $mail_data = [];
31  $mail_data['from'] = $mail_value_object->getFrom();
32  $mail_data['recipients'] = $mail_value_object->getRecipients();
33  $mail_data['recipients_cc'] = $mail_value_object->getRecipientsCC();
34  $mail_data['recipients_bcc'] = $mail_value_object->getRecipientsBCC();
35  $mail_data['attachments'] = $mail_value_object->getAttachments();
36  $mail_data['body'] = $mail_value_object->getBody();
37  $mail_data['subject'] = $mail_value_object->getSubject();
38  $mail_data['is_using_placholders'] = $mail_value_object->isUsingPlaceholders();
39  $mail_data['should_save_in_sent_box'] = $mail_value_object->shouldSaveInSentBox();
40 
41  $records[] = $mail_data;
42  }
43 
44  return json_encode($records, JSON_THROW_ON_ERROR);
45  }
46 
50  public function convertFromJson(string $json): array
51  {
52  $result = [];
53  $array = json_decode($json, true, 512, JSON_THROW_ON_ERROR);
54 
55  foreach ($array as $object_values) {
56  $result[] = new ilMailValueObject(
57  $object_values['from'],
58  $object_values['recipients'],
59  $object_values['recipients_cc'],
60  $object_values['recipients_bcc'],
61  ilStr::strLen($object_values['subject']) > 255 ? ilStr::substr($object_values['subject'], 0, 255) : $object_values['subject'],
62  $object_values['body'],
63  $object_values['attachments'],
64  $object_values['is_using_placholders'],
65  $object_values['should_save_in_sent_box']
66  );
67  }
68 
69  return $result;
70  }
71 }
static strLen(string $a_string)
Definition: class.ilStr.php:60