ILIAS  trunk Revision v11.0_alpha-1866-gfa368f7776e
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilMailAttachmentGUI Class Reference
+ Inheritance diagram for ilMailAttachmentGUI:
+ Collaboration diagram for ilMailAttachmentGUI:

Public Member Functions

 __construct ()
 
 manage ()
 
 consume ()
 
 executeCommand ()
 Since this is a ilCtrl aware UploadHandler executeCommand MUST be implemented. More...
 
 saveAttachments ()
 
 cancelSaveAttachments ()
 
 deleteAttachments ()
 
 confirmDeleteAttachments ()
 
 showAttachments ()
 
 getInfoResult (string $identifier)
 
 getInfoForExistingFiles (array $file_ids)
 
 getFileIdentifierParameterName ()
 
- Public Member Functions inherited from ILIAS\MetaData\OERExposer\OAIPMH\Handler\AbstractCtrlAwareUploadHandler
 __construct ()
 ilUIDemoFileUploadHandlerGUI constructor. More...
 
 getFileIdentifierParameterName ()
 
 getUploadURL ()
 
 getExistingFileInfoURL ()
 
 getFileRemovalURL ()
 
 executeCommand ()
 Since this is a ilCtrl aware UploadHandler executeCommand MUST be implemented. More...
 
 getInfoResult (string $identifier)
 
 getInfoForExistingFiles (array $file_ids)
 
 supportsChunkedUploads ()
 

Protected Member Functions

 getUploadResult ()
 
 getRemoveResult (string $identifier)
 
- Protected Member Functions inherited from ILIAS\MetaData\OERExposer\OAIPMH\Handler\AbstractCtrlAwareUploadHandler
 readChunkedInformation ()
 
 getUploadResult ()
 
 getRemoveResult (string $identifier)
 

Private Member Functions

 handleTableActions ()
 

Private Attributes

readonly ilGlobalTemplateInterface $tpl
 
readonly ilLanguage $lng
 
readonly ilObjUser $user
 
readonly ilFormatMail $umail
 
readonly ilFileDataMail $mfile
 
readonly Refinery $refinery
 
readonly ILIAS UI Factory $ui_factory
 
readonly ILIAS UI Renderer $ui_renderer
 
readonly ilTabsGUI $tabs
 
AttachmentManagement $mode = AttachmentManagement::MANAGE
 

Additional Inherited Members

- Data Fields inherited from ILIAS\UI\Component\Input\Field\UploadHandler
const DEFAULT_FILE_ID_PARAMETER = 'file_id'
 
- Protected Attributes inherited from ILIAS\MetaData\OERExposer\OAIPMH\Handler\AbstractCtrlAwareUploadHandler
const CMD_UPLOAD = 'upload'
 
const CMD_REMOVE = 'remove'
 
const CMD_INFO = 'info'
 
HttpServices $http
 
ilCtrl $ctrl
 
FileUpload $upload
 
bool $is_chunked = false
 
int $chunk_index = 0
 
int $amount_of_chunks = 0
 
string $chunk_id = null
 
int $chunk_total_size = 0
 

Detailed Description

Definition at line 30 of file class.ilMailAttachmentGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilMailAttachmentGUI::__construct ( )

Definition at line 43 of file class.ilMailAttachmentGUI.php.

References $DIC, ILIAS\GlobalScreen\Provider\__construct(), ILIAS\Repository\ctrl(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), ILIAS\Repository\tabs(), and ILIAS\Repository\user().

44  {
45  global $DIC;
46 
48  $this->tpl = $DIC->ui()->mainTemplate();
49  $this->lng = $DIC->language();
50  $this->user = $DIC->user();
51  $this->tabs = $DIC->tabs();
52  $this->refinery = $DIC->refinery();
53  $this->ui_factory = $DIC->ui()->factory();
54  $this->ui_renderer = $DIC->ui()->renderer();
55 
56  $this->ctrl->saveParameter($this, 'mobj_id');
57 
58  $this->umail = new ilFormatMail($DIC->user()->getId());
59  $this->mfile = new ilFileDataMail($DIC->user()->getId());
60  }
This class handles all operations on files (attachments) in directory ilias_data/mail.
global $DIC
Definition: shib_login.php:22
__construct(Container $dic, ilPlugin $plugin)
+ Here is the call graph for this function:

Member Function Documentation

◆ cancelSaveAttachments()

ilMailAttachmentGUI::cancelSaveAttachments ( )

Definition at line 137 of file class.ilMailAttachmentGUI.php.

References ILIAS\Repository\ctrl(), and ilMailFormGUI\MAIL_FORM_TYPE_ATTACH.

137  : void
138  {
139  $this->ctrl->setParameter($this, 'type', ilMailFormGUI::MAIL_FORM_TYPE_ATTACH);
140  $this->ctrl->returnToParent($this);
141  }
final const MAIL_FORM_TYPE_ATTACH
+ Here is the call graph for this function:

◆ confirmDeleteAttachments()

ilMailAttachmentGUI::confirmDeleteAttachments ( )

Definition at line 184 of file class.ilMailAttachmentGUI.php.

References ILIAS\Repository\ctrl(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), and showAttachments().

184  : void
185  {
186  $files = $this->http->wrapper()->post()->retrieve(
187  'filename',
188  $this->refinery->byTrying([
189  $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->string()),
190  $this->refinery->always([])
191  ])
192  );
193 
194  if ($files === []) {
195  $this->tpl->setOnScreenMessage('info', $this->lng->txt('mail_select_one_mail'));
196  $this->showAttachments();
197  return;
198  }
199 
200  $decodedFiles = [];
201  foreach ($files as $value) {
202  $decodedFiles[] = urldecode($value);
203  }
204 
205  $error = $this->mfile->unlinkFiles($decodedFiles);
206  if ($error !== '') {
207  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('mail_error_delete_file') . ' ' . $error, true);
208  } else {
209  $mail_data = $this->umail->retrieveFromStage();
210  if (is_array($mail_data['attachments'])) {
211  $tmp = [];
212  foreach ($mail_data['attachments'] as $attachment) {
213  if (!in_array($attachment, $decodedFiles, true)) {
214  $tmp[] = $attachment;
215  }
216  }
217  $this->umail->saveAttachments($tmp);
218  }
219 
220  $this->tpl->setOnScreenMessage('success', $this->lng->txt('mail_files_deleted'), true);
221  }
222 
223  $this->ctrl->redirect($this);
224  }
static http()
Fetches the global http state from ILIAS.
+ Here is the call graph for this function:

◆ consume()

ilMailAttachmentGUI::consume ( )

Definition at line 68 of file class.ilMailAttachmentGUI.php.

References ILIAS\Mail\Attachments\CONSUME.

68  : self
69  {
70  $this->mode = AttachmentManagement::CONSUME;
71  return $this;
72  }

◆ deleteAttachments()

ilMailAttachmentGUI::deleteAttachments ( )

Definition at line 143 of file class.ilMailAttachmentGUI.php.

References $filename, ILIAS\Repository\ctrl(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), and ilUtil\stripSlashes().

Referenced by handleTableActions().

143  : void
144  {
145  $files = $this->http->wrapper()->query()->retrieve(
146  'mail_attachments_filename',
147  $this->refinery->byTrying([
148  $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->string()),
149  $this->refinery->always([])
150  ])
151  );
152 
153  if ($files !== [] && $files[0] === 'ALL_OBJECTS') {
154  $files = array_map(static function (array $file): string {
155  return $file['name'];
156  }, $this->mfile->getUserFilesData());
157  }
158 
159  if ($files === []) {
160  $this->tpl->setOnScreenMessage('info', $this->lng->txt('select_one'), true);
161  $this->ctrl->redirect($this);
162  }
163 
164  $this->tpl->setTitle($this->lng->txt('mail'));
165 
166  $confirmation = new ilConfirmationGUI();
167  $confirmation->setFormAction($this->ctrl->getFormAction($this, 'confirmDeleteAttachments'));
168  $confirmation->setConfirm($this->lng->txt('confirm'), 'confirmDeleteAttachments');
169  $confirmation->setCancel($this->lng->txt('cancel'), 'showAttachments');
170  $confirmation->setHeaderText($this->lng->txt('mail_sure_delete_file'));
171 
172  foreach ($files as $filename) {
173  $confirmation->addItem(
174  'filename[]',
175  ilUtil::stripSlashes($filename),
176  ilUtil::stripSlashes(urldecode($filename))
177  );
178  }
179 
180  $this->tpl->setContent($confirmation->getHTML());
181  $this->tpl->printToStdout();
182  }
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
static http()
Fetches the global http state from ILIAS.
$filename
Definition: buildRTE.php:78
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ executeCommand()

ilMailAttachmentGUI::executeCommand ( )

Since this is a ilCtrl aware UploadHandler executeCommand MUST be implemented.

The Implementation MUST make sure, the Upload and the Removal Command are handled correctly

Implements ILIAS\MetaData\OERExposer\OAIPMH\Handler\ilCtrlAwareUploadHandler.

Definition at line 74 of file class.ilMailAttachmentGUI.php.

References ILIAS\Repository\ctrl().

74  : void
75  {
76  if (!($cmd = $this->ctrl->getCmd())) {
77  $cmd = 'showAttachments';
78  }
79 
80  match ($cmd) {
81  AbstractCtrlAwareUploadHandler::CMD_UPLOAD,
82  AbstractCtrlAwareUploadHandler::CMD_INFO,
83  AbstractCtrlAwareUploadHandler::CMD_REMOVE => parent::executeCommand(),
84  default => $this->$cmd()
85  };
86  }
+ Here is the call graph for this function:

◆ getFileIdentifierParameterName()

ilMailAttachmentGUI::getFileIdentifierParameterName ( )
Returns
string defaults to self::DEFAULT_FILE_ID_PARAMETER

Implements ILIAS\UI\Component\Input\Field\UploadHandler.

Definition at line 361 of file class.ilMailAttachmentGUI.php.

Referenced by getUploadResult().

361  : string
362  {
363  return 'userfile';
364  }
+ Here is the caller graph for this function:

◆ getInfoForExistingFiles()

ilMailAttachmentGUI::getInfoForExistingFiles ( array  $file_ids)
Parameters
array$file_ids
Returns
BasicFileInfoResult[]

Implements ILIAS\UI\Component\Input\Field\UploadHandler.

Definition at line 356 of file class.ilMailAttachmentGUI.php.

356  : array
357  {
358  throw new DomainException('Not necessary for this handler');
359  }

◆ getInfoResult()

ilMailAttachmentGUI::getInfoResult ( string  $identifier)
Returns
null|FileInfoResult for the file with the given identifier or null if the file does not exist.

Implements ILIAS\UI\Component\Input\Field\UploadHandler.

Definition at line 351 of file class.ilMailAttachmentGUI.php.

351  : ?FileInfoResult
352  {
353  throw new DomainException('Not necessary for this handler');
354  }

◆ getRemoveResult()

ilMailAttachmentGUI::getRemoveResult ( string  $identifier)
protected

Definition at line 346 of file class.ilMailAttachmentGUI.php.

346  : HandlerResult
347  {
348  throw new DomainException('Not necessary for this handler');
349  }

◆ getUploadResult()

ilMailAttachmentGUI::getUploadResult ( )
protected

Definition at line 326 of file class.ilMailAttachmentGUI.php.

References $message, getFileIdentifierParameterName(), ILIAS\FileUpload\DTO\UploadResult\isOK(), ILIAS\Repository\lng(), and ILIAS\Repository\upload().

326  : HandlerResult
327  {
328  $this->upload->process();
329  $array = $this->upload->getResults();
330  $result = end($array);
331 
332  if ($result instanceof UploadResult && $result->isOK()) {
333  $identifier = $this->mfile->storeUploadedFile($result);
334  $status = HandlerResult::STATUS_OK;
335  $message = $this->lng->txt('saved_successfully');
336  $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'), true);
337  } else {
338  $status = HandlerResult::STATUS_FAILED;
339  $identifier = '';
340  $message = $result->getStatus()->getMessage();
341  }
342 
343  return new BasicHandlerResult($this->getFileIdentifierParameterName(), $status, $identifier, $message);
344  }
$message
Definition: xapiexit.php:31
+ Here is the call graph for this function:

◆ handleTableActions()

ilMailAttachmentGUI::handleTableActions ( )
private

Definition at line 311 of file class.ilMailAttachmentGUI.php.

References ILIAS\Repository\ctrl(), deleteAttachments(), ILIAS\FileDelivery\http(), ILIAS\Repository\refinery(), and saveAttachments().

311  : void
312  {
313  $query = $this->http->wrapper()->query();
314  if (!$query->has('mail_attachments_table_action')) {
315  return;
316  }
317 
318  $action = $query->retrieve('mail_attachments_table_action', $this->refinery->to()->string());
319  match ($action) {
320  'saveAttachments' => $this->saveAttachments(),
321  'deleteAttachments' => $this->deleteAttachments(),
322  default => $this->ctrl->redirect($this),
323  };
324  }
static http()
Fetches the global http state from ILIAS.
+ Here is the call graph for this function:

◆ manage()

ilMailAttachmentGUI::manage ( )

Definition at line 62 of file class.ilMailAttachmentGUI.php.

62  : self
63  {
64  $this->mode = AttachmentManagement::MANAGE;
65  return $this;
66  }

◆ saveAttachments()

ilMailAttachmentGUI::saveAttachments ( )

Definition at line 88 of file class.ilMailAttachmentGUI.php.

References ILIAS\Repository\ctrl(), ilUtil\formatSize(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), null, ILIAS\Repository\refinery(), showAttachments(), and ILIAS\Repository\user().

Referenced by handleTableActions().

88  : void
89  {
90  $files = [];
91 
92  // Important: Do not check for uploaded files here,
93  // otherwise it is no more possible to remove files (please ignore bug reports like 10137)
94 
95  $sizeOfSelectedFiles = 0;
96  $filesOfRequest = $this->http->wrapper()->query()->retrieve(
97  'mail_attachments_filename',
98  $this->refinery->byTrying([
99  $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->string()),
100  $this->refinery->always([])
101  ])
102  );
103 
104  if ($filesOfRequest !== [] && $filesOfRequest[0] === 'ALL_OBJECTS') {
105  $filesOfRequest = array_map(static function (array $file): string {
106  return $file['name'];
107  }, $this->mfile->getUserFilesData());
108  }
109 
110  foreach ($filesOfRequest as $file) {
111  if (is_file($this->mfile->getMailPath() . '/' . basename($this->user->getId() . '_' . urldecode($file)))) {
112  $files[] = urldecode($file);
113  $sizeOfSelectedFiles += filesize(
114  $this->mfile->getMailPath() . '/' .
115  basename($this->user->getId() . '_' . urldecode($file))
116  );
117  }
118  }
119 
120  if ($files !== [] &&
121  null !== $this->mfile->getAttachmentsTotalSizeLimit() &&
122  $sizeOfSelectedFiles > $this->mfile->getAttachmentsTotalSizeLimit()) {
123  $this->tpl->setOnScreenMessage(
124  'failure',
125  $this->lng->txt('mail_max_size_attachments_total_error') . ' ' .
126  ilUtil::formatSize((int) $this->mfile->getAttachmentsTotalSizeLimit())
127  );
128  $this->showAttachments();
129  return;
130  }
131 
132  $this->umail->saveAttachments($files);
133 
134  $this->ctrl->returnToParent($this);
135  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static http()
Fetches the global http state from ILIAS.
static formatSize(int $size, string $a_mode='short', ?ilLanguage $a_lng=null)
Returns the specified file size value in a human friendly form.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ showAttachments()

ilMailAttachmentGUI::showAttachments ( )

Definition at line 226 of file class.ilMailAttachmentGUI.php.

References $components, $mode, ILIAS\Mail\Attachments\CONSUME, ILIAS\Repository\ctrl(), ILIAS\FileDelivery\http(), ILIAS\Repository\int(), ILIAS\Repository\lng(), ILIAS\Repository\tabs(), and ILIAS\Repository\user().

Referenced by confirmDeleteAttachments(), and saveAttachments().

226  : void
227  {
228  $this->tpl->setTitle($this->lng->txt('mail'));
229 
230  if ($this->mode === AttachmentManagement::CONSUME) {
231  $this->tabs->clearTargets();
232  $this->tabs->setBackTarget(
233  $this->lng->txt('mail_manage_attachments_back_to_compose'),
234  $this->ctrl->getLinkTarget($this, 'cancelSaveAttachments')
235  );
236  }
237 
238  $components = [];
239  if ($this->mode === AttachmentManagement::MANAGE) {
240  $dropzone = $this->ui_factory
241  ->dropzone()
242  ->file()
243  ->standard(
244  $this->lng->txt('mail_manage_attachments'),
245  $this->lng->txt('mail_manage_attachments_drop_files_msg'),
246  '#',
247  $this->ui_factory->input()->field()->file(
248  $this,
249  $this->lng->txt('file')
250  )->withMaxFiles(42) // The answer to life, universe and the rest
251  )
252  ->withBulky(true)
253  ->withUploadButton(
254  $this->ui_factory->button()->shy(
255  $this->lng->txt('upload'),
256  '#'
257  )
258  );
259  $components[] = $dropzone;
260  }
261 
262  $mail_data = $this->umail->retrieveFromStage();
263  $files = $this->mfile->getUserFilesData();
264  $records = [];
265  $checked_items = [];
266  foreach ($files as $file) {
267  if (is_array($mail_data['attachments']) && in_array($file['name'], $mail_data['attachments'], true)) {
268  $checked_items[] = urlencode($file['name']);
269  }
270 
271  $records[] = [
272  'filename' => $file['name'],
273  'filesize' => (int) $file['size'],
274  'filecreatedate' => (int) $file['ctime'],
275  ];
276  }
277 
278  $table = new MailAttachmentTableGUI(
279  $this,
280  $this->user,
281  $records,
282  $this->ui_factory,
283  $this->ui_renderer,
284  $this->lng,
285  $this->ctrl,
286  $this->http->request(),
287  new ILIAS\Data\Factory(),
288  'handleTableActions',
290  );
291  $components[] = $table->get();
292 
293  $this->tpl->setContent($this->ui_renderer->render($components));
294 
295  if ($this->mode === AttachmentManagement::CONSUME) {
296  // The table above has to be rendered first, because it deselects all checkboxes
297  $this->tpl->addOnLoadCode('
298  const checked_items = ' . json_encode($checked_items, JSON_THROW_ON_ERROR) . ';
299  for (const item of checked_items) {
300  const checkbox = document.querySelector("input[type=\'checkbox\'][value=\'" + item + "\']");
301  if (checkbox) {
302  checkbox.checked = true;
303  }
304  }
305  ');
306  }
307 
308  $this->tpl->printToStdout();
309  }
AttachmentManagement $mode
$components
static http()
Fetches the global http state from ILIAS.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $lng

readonly ilLanguage ilMailAttachmentGUI::$lng
private

Definition at line 33 of file class.ilMailAttachmentGUI.php.

◆ $mfile

readonly ilFileDataMail ilMailAttachmentGUI::$mfile
private

Definition at line 36 of file class.ilMailAttachmentGUI.php.

◆ $mode

AttachmentManagement ilMailAttachmentGUI::$mode = AttachmentManagement::MANAGE
private

Definition at line 41 of file class.ilMailAttachmentGUI.php.

Referenced by showAttachments().

◆ $refinery

readonly Refinery ilMailAttachmentGUI::$refinery
private

Definition at line 37 of file class.ilMailAttachmentGUI.php.

◆ $tabs

readonly ilTabsGUI ilMailAttachmentGUI::$tabs
private

Definition at line 40 of file class.ilMailAttachmentGUI.php.

◆ $tpl

readonly ilGlobalTemplateInterface ilMailAttachmentGUI::$tpl
private

Definition at line 32 of file class.ilMailAttachmentGUI.php.

◆ $ui_factory

readonly ILIAS UI Factory ilMailAttachmentGUI::$ui_factory
private

Definition at line 38 of file class.ilMailAttachmentGUI.php.

◆ $ui_renderer

readonly ILIAS UI Renderer ilMailAttachmentGUI::$ui_renderer
private

Definition at line 39 of file class.ilMailAttachmentGUI.php.

◆ $umail

readonly ilFormatMail ilMailAttachmentGUI::$umail
private

Definition at line 35 of file class.ilMailAttachmentGUI.php.

◆ $user

readonly ilObjUser ilMailAttachmentGUI::$user
private

Definition at line 34 of file class.ilMailAttachmentGUI.php.


The documentation for this class was generated from the following file: