ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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 $mailValueObjects): string
27  {
28  $mailArray = [];
29  foreach ($mailValueObjects as $mailValueObject) {
30  $array = [];
31 
32  $array['from'] = $mailValueObject->getFrom();
33  $array['recipients'] = $mailValueObject->getRecipients();
34  $array['recipients_cc'] = $mailValueObject->getRecipientsCC();
35  $array['recipients_bcc'] = $mailValueObject->getRecipientsBCC();
36  $array['attachments'] = $mailValueObject->getAttachments();
37  $array['body'] = $mailValueObject->getBody();
38  $array['subject'] = $mailValueObject->getSubject();
39  $array['is_using_placholders'] = $mailValueObject->isUsingPlaceholders();
40  $array['should_save_in_sent_box'] = $mailValueObject->shouldSaveInSentBox();
41 
42  $mailArray[] = $array;
43  }
44 
45  return json_encode($mailArray, JSON_THROW_ON_ERROR);
46  }
47 
51  public function convertFromJson(string $json): array
52  {
53  $result = [];
54  $array = json_decode($json, true, 512, JSON_THROW_ON_ERROR);
55 
56  foreach ($array as $objectValues) {
57  $result[] = new ilMailValueObject(
58  $objectValues['from'],
59  $objectValues['recipients'],
60  $objectValues['recipients_cc'],
61  $objectValues['recipients_bcc'],
62  ilStr::strLen($objectValues['subject']) > 255 ? ilStr::substr($objectValues['subject'], 0, 255) : $objectValues['subject'],
63  $objectValues['body'],
64  $objectValues['attachments'],
65  $objectValues['is_using_placholders'],
66  $objectValues['should_save_in_sent_box']
67  );
68  }
69 
70  return $result;
71  }
72 }
static strLen(string $a_string)
Definition: class.ilStr.php:63