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