ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilMassMailDeliveryJob.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
29 
31 {
32  private readonly ILIAS\DI\Container $dic;
34 
35  public function __construct()
36  {
37  global $DIC;
38  $this->dic = $DIC;
39 
40  $this->mail_json_service = new ilMailValueObjectJsonService();
41  }
42 
43  public function run(array $input, Observer $observer): Value
44  {
45  $value_objects = $this->mail_json_service->convertFromJson((string) $input[1]->getValue());
46 
47  foreach ($value_objects as $value_object) {
48  $mail = new ilMail((int) $input[0]->getValue());
49 
50  $mail->setSaveInSentbox($value_object->shouldSaveInSentBox());
51  $context_id = $input[2]->getValue();
52  $mail = $mail
53  ->withContextId((string) $context_id)
54  ->withContextParameters((array) unserialize($input[3]->getValue(), ['allowed_classes' => false]));
55 
56  $recipients = $value_object->getRecipients();
57  $recipients_cc = $value_object->getRecipientsCC();
58  $recipients_bcc = $value_object->getRecipientsBCC();
59 
60  $this->dic->logger()->mail()->info(
61  sprintf(
62  'Mail delivery to recipients: "%s" CC: "%s" BCC: "%s" From sender: "%s"',
63  $recipients,
64  $recipients_cc,
65  $recipients_bcc,
66  $value_object->getFrom()
67  )
68  );
69 
70  $mail_data = new MailDeliveryData(
71  $recipients,
72  $recipients_cc,
73  $recipients_bcc,
74  $value_object->getSubject(),
75  $value_object->getBody(),
76  $value_object->getAttachments(),
77  $value_object->isUsingPlaceholders()
78  );
79  $mail->sendMail($mail_data);
80  }
81 
82  $output = new BooleanValue();
83  $output->setValue(true);
84 
85  return $output;
86  }
87 
88  public function getInputTypes(): array
89  {
90  return [
91  new SingleType(IntegerValue::class), // User Id
92  new SingleType(StringValue::class), // JSON encoded array of ilMailValueObject
93  new SingleType(StringValue::class), // Context Id
94  new SingleType(StringValue::class), // Context Parameters
95  ];
96  }
97 
98  public function isStateless(): bool
99  {
100  return true;
101  }
102 
104  {
105  return 42; // The answer to life, universe and the rest
106  }
107 
108  public function getOutputType(): Type
109  {
110  return new SingleType(BooleanValue::class);
111  }
112 }
readonly ILIAS DI Container $dic
getValue()
Get the value that is displayed in the input client side.
Definition: Group.php:49
run(array $input, Observer $observer)
global $DIC
Definition: shib_login.php:26
readonly ilMailValueObjectJsonService $mail_json_service