ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
MailImplementation.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ILIAS\ResourceStorage\Services as ResourceStorage;
25
26class MailImplementation implements Mail
27{
28 private string $temp_file_path;
29 public function __construct(
30 private readonly string $lang_code,
31 private readonly string $subject = '',
32 private readonly string $body = '',
33 private readonly string $salutation_none_specific = '',
34 private readonly string $salutation_male = '',
35 private readonly string $salutation_female = '',
36 private readonly ?string $attachment_rid = null,
37 private readonly ?string $legacy_attachment_filename = null
38 ) {
39 $this->temp_file_path = CLIENT_DATA_DIR . '/temp/namas/';
40 }
41
42 public function getLangCode(): string
43 {
44 return $this->lang_code;
45 }
46
47 public function getSubject(): string
48 {
49 return $this->subject;
50 }
51
52 public function getBody(): string
53 {
54 return $this->body;
55 }
56
57 public function getSalutationNoneSpecific(): string
58 {
59 return $this->salutation_none_specific;
60 }
61
62 public function getSalutationMale(): string
63 {
64 return $this->salutation_male;
65 }
66
67 public function getSalutationFemale(): string
68 {
69 return $this->salutation_female;
70 }
71
72 public function getAttachmentRid(): ?string
73 {
74 return $this->attachment_rid;
75 }
76
77 public function getAttachment(ResourceStorage $irss): ?array
78 {
79 if ($this->attachment_rid !== null) {
80 $rid = $irss->manage()->find($this->attachment_rid);
81 if ($rid === null) {
82 return null;
83 }
84 $this->ensureAttachmentFileExists($irss, $rid);
85 return [
86 $this->temp_file_path . $this->lang_code,
87 $irss->manage()->getCurrentRevision($rid)->getTitle()
88 ];
89 }
90
91 if ($this->legacy_attachment_filename !== null) {
92 $path = '/' . implode(
93 '/',
94 array_map(
95 static fn(string $path_part): string => trim($path_part, '/'),
96 [
97 CLIENT_DATA_DIR . '/ilReg/reg_' . USER_FOLDER_ID,
98 $this->lang_code,
99 ]
100 )
101 );
102
103 return [$path, $this->legacy_attachment_filename];
104 }
105
106 return null;
107 }
108
109 public function deleteAttachmentTempFile(): void
110 {
111 if (file_exists($this->temp_file_path . $this->lang_code)) {
112 unlink($this->temp_file_path . $this->lang_code);
113 }
114 }
115
116 public function toStorage(): array
117 {
118 return [
119 'subject' => [\ilDBConstants::T_TEXT, $this->subject],
120 'body' => [\ilDBConstants::T_TEXT, $this->body],
121 'sal_f' => [\ilDBConstants::T_TEXT, $this->salutation_female],
122 'sal_m' => [\ilDBConstants::T_TEXT, $this->salutation_male],
123 'sal_g' => [\ilDBConstants::T_TEXT, $this->salutation_none_specific],
124 'att_rid' => [\ilDBConstants::T_TEXT, $this->attachment_rid]
125 ];
126 }
127
129 ResourceStorage $irss,
131 ): void {
132 if (file_exists($this->temp_file_path . $this->lang_code)) {
133 return;
134 }
135
136 if (!file_exists($this->temp_file_path)) {
137 mkdir($this->temp_file_path);
138 }
139
140 file_put_contents(
141 $this->temp_file_path . $this->lang_code,
142 $irss->consume()->stream($rid)->getStream()->getContents()
143 );
144 }
145}
__construct(private readonly string $lang_code, private readonly string $subject='', private readonly string $body='', private readonly string $salutation_none_specific='', private readonly string $salutation_male='', private readonly string $salutation_female='', private readonly ?string $attachment_rid=null, private readonly ?string $legacy_attachment_filename=null)
ensureAttachmentFileExists(ResourceStorage $irss, ResourceIdentification $rid)
const USER_FOLDER_ID
Definition: constants.php:33
const CLIENT_DATA_DIR
Definition: constants.php:46
$path
Definition: ltiservices.php:30
RFC 822 Email address list validation Utility.
if(!file_exists('../ilias.ini.php'))