ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilMailValueObjectJsonService.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
8 {
9 
14  public function convertToJson(array $mailValueObjects)
15  {
16  $mailArray = array();
17  foreach ($mailValueObjects as $mailValueObject) {
18  $array = array();
19 
20  $array['from'] = $mailValueObject->getFrom();
21  $array['recipients'] = $mailValueObject->getRecipients();
22  $array['recipients_cc'] = $mailValueObject->getRecipientsCC();
23  $array['recipients_bcc'] = $mailValueObject->getRecipientsBCC();
24  $array['attachments'] = $mailValueObject->getAttachments();
25  $array['body'] = $mailValueObject->getBody();
26  $array['subject'] = $mailValueObject->getSubject();
27  $array['is_using_placholders'] = $mailValueObject->isUsingPlaceholders();
28  $array['should_save_in_sent_box'] = $mailValueObject->shouldSaveInSentBox();
29 
30  $mailArray[] = $array;
31  }
32 
33  return json_encode($mailArray);
34  }
35 
40  public function convertFromJson(string $json)
41  {
42  $result = array();
43  $array = json_decode($json, true);
44 
45  foreach ($array as $objectValues) {
46  $result[] = new ilMailValueObject(
47  $objectValues['from'],
48  $objectValues['recipients'],
49  $objectValues['recipients_cc'],
50  $objectValues['recipients_bcc'],
51  $objectValues['subject'],
52  $objectValues['body'],
53  $objectValues['attachments'],
54  $objectValues['is_using_placholders'],
55  $objectValues['should_save_in_sent_box']
56  );
57  }
58 
59  return $result;
60  }
61 }
$result