ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilMailValueObjectJsonService.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 {
29  public function convertToJson(array $mailValueObjects): string
30  {
31  $mailArray = [];
32  foreach ($mailValueObjects as $mailValueObject) {
33  $array = [];
34 
35  $array['from'] = $mailValueObject->getFrom();
36  $array['recipients'] = $mailValueObject->getRecipients();
37  $array['recipients_cc'] = $mailValueObject->getRecipientsCC();
38  $array['recipients_bcc'] = $mailValueObject->getRecipientsBCC();
39  $array['attachments'] = $mailValueObject->getAttachments();
40  $array['body'] = $mailValueObject->getBody();
41  $array['subject'] = $mailValueObject->getSubject();
42  $array['is_using_placholders'] = $mailValueObject->isUsingPlaceholders();
43  $array['should_save_in_sent_box'] = $mailValueObject->shouldSaveInSentBox();
44 
45  $mailArray[] = $array;
46  }
47 
48  return json_encode($mailArray, JSON_THROW_ON_ERROR);
49  }
50 
54  public function convertFromJson(string $json): array
55  {
56  $result = [];
57  $array = json_decode($json, true, 512, JSON_THROW_ON_ERROR);
58 
59  foreach ($array as $objectValues) {
60  $result[] = new ilMailValueObject(
61  $objectValues['from'],
62  $objectValues['recipients'],
63  $objectValues['recipients_cc'],
64  $objectValues['recipients_bcc'],
65  ilStr::strLen($objectValues['subject']) > 255 ? ilStr::substr($objectValues['subject'], 0, 255) : $objectValues['subject'],
66  $objectValues['body'],
67  $objectValues['attachments'],
68  $objectValues['is_using_placholders'],
69  $objectValues['should_save_in_sent_box']
70  );
71  }
72 
73  return $result;
74  }
75 }
static strLen(string $a_string)
Definition: class.ilStr.php:63