ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilPDMailBlockGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
24 
31 {
32  public static string $block_type = 'pdmail';
35  private int $requestMailObjId = 0;
37  protected ilSetting $setting;
39  protected array $mails = [];
40  protected int $inbox;
41 
42  public function __construct()
43  {
44  global $DIC;
45  $this->lng = $DIC->language();
46  $this->user = $DIC->user();
47  $this->ctrl = $DIC->ctrl();
48  $this->setting = $DIC->settings();
49  $this->rbacsystem = $DIC->rbac()->system();
50  $this->http = $DIC->http();
51  $this->refinery = $DIC->refinery();
52 
54 
55  $this->setLimit(5);
56  $this->setTitle($this->lng->txt('mail'));
57  $this->setPresentation(self::PRES_SEC_LIST);
58  }
59 
60  public function getBlockType(): string
61  {
62  return self::$block_type;
63  }
64 
65  protected function isRepositoryObject(): bool
66  {
67  return false;
68  }
69 
70  public static function getScreenMode(): string
71  {
72  global $DIC;
73  $cmd = "";
74  if ($DIC->http()->wrapper()->query()->has('cmd')) {
75  $cmd = $DIC->http()->wrapper()->query()->retrieve('cmd', $DIC->refinery()->kindlyTo()->string());
76  }
77  if ($cmd === 'showMail') {
78  return IL_SCREEN_CENTER;
79  }
80 
81  return IL_SCREEN_SIDE;
82  }
83 
84  public function executeCommand(): string
85  {
86  $cmd = $this->ctrl->getCmd('getHTML');
87 
88  return $this->$cmd();
89  }
90 
91  public function getHTML(): string
92  {
93  $umail = new ilMail($this->user->getId());
94  if (!$this->rbacsystem->checkAccess('internal_mail', $umail->getMailObjectReferenceId())) {
95  return '';
96  }
97 
98  $this->getMails();
99  $this->setData($this->mails);
100 
101  return parent::getHTML();
102  }
103 
104  protected function getMails(): void
105  {
106  $umail = new ilMail($this->user->getId());
107  $mbox = new ilMailbox($this->user->getId());
108  $this->inbox = $mbox->getInboxFolder();
109 
110  $this->mails = $umail->getMailsOfFolder(
111  $this->inbox,
112  [
113  'status' => 'unread',
114  ]
115  );
116  }
117 
118  public function fillDataSection(): void
119  {
120  $this->getMails();
121  $this->setData($this->mails);
122 
123  if (count($this->mails) > 0) {
124  $this->setRowTemplate("tpl.pd_mail_row.html", "Services/Mail");
125  parent::fillDataSection();
126  } else {
127  $this->setEnableNumInfo(false);
128  $this->setDataSection($this->getOverview());
129  }
130  }
131 
132  public function fillRow(array $a_set): void
133  {
134  $user = ilMailUserCache::getUserObjectById((int) $a_set['sender_id']);
135 
136  $this->tpl->touchBlock('usr_image_space');
137  if ($user && $user->getId() !== ANONYMOUS_USER_ID) {
138  $this->tpl->setVariable('PUBLIC_NAME_LONG', $user->getPublicName());
139  $this->tpl->setVariable('IMG_SENDER', $user->getPersonalPicturePath('xxsmall'));
140  $this->tpl->setVariable('ALT_SENDER', htmlspecialchars($user->getPublicName()));
141  } elseif (!$user) {
142  $this->tpl->setVariable(
143  'PUBLIC_NAME_LONG',
144  trim(($a_set['import_name'] ?? '') . ' (' . $this->lng->txt('user_deleted') . ')')
145  );
146 
147  $this->tpl->setCurrentBlock('image_container');
148  $this->tpl->touchBlock('image_container');
149  $this->tpl->parseCurrentBlock();
150  } else {
151  $this->tpl->setVariable('PUBLIC_NAME_LONG', ilMail::_getIliasMailerName());
152  $this->tpl->setVariable('IMG_SENDER', ilUtil::getImagePath('HeaderIconAvatar.svg'));
153  $this->tpl->setVariable('ALT_SENDER', htmlspecialchars(ilMail::_getIliasMailerName()));
154  }
155 
156  $this->tpl->setVariable(
157  'NEW_MAIL_DATE',
158  ilDatePresentation::formatDate(new ilDate($a_set['send_time'], IL_CAL_DATE))
159  );
160 
161  $this->tpl->setVariable(
162  'NEW_MAIL_SUBJ',
163  htmlentities($a_set['m_subject'], ENT_NOQUOTES, 'UTF-8')
164  );
165  $this->ctrl->setParameter($this, 'mobj_id', $this->inbox);
166  $this->ctrl->setParameter($this, 'mail_id', $a_set['mail_id']);
167  $this->tpl->setVariable('NEW_MAIL_LINK_READ', $this->ctrl->getLinkTarget($this, 'showMail'));
168  $this->ctrl->clearParameters($this);
169  }
170 
171  protected function getOverview(): string
172  {
173  return '<div class="small">' . (count($this->mails)) . " " . $this->lng->txt("mails_pl") . "</div>";
174  }
175 
176  protected function showMail(): string
177  {
178  $mail_gui = new ilPDMailGUI();
179 
180  $content_block = new ilDashboardContentBlockGUI();
181  $mailId = 0;
182  if ($this->http->wrapper()->query()->has('mail_id')) {
183  $mailId = $this->http->wrapper()->query()->retrieve('mail_id', $this->refinery->kindlyTo()->int());
184  }
185  $mobjId = $this->requestMailObjId;
186  if ($this->http->wrapper()->query()->has('mobj_id')) {
187  $mobjId = $this->http->wrapper()->query()->retrieve('mobj_id', $this->refinery->kindlyTo()->int());
188  }
189  $content_block->setContent($mail_gui->getPDMailHTML(
190  $mailId,
191  $mobjId
192  ));
193  $content_block->setTitle($this->lng->txt("message"));
194 
195  $content_block->addBlockCommand(
196  "ilias.php?baseClass=ilMailGUI&mail_id=" .
197  $mailId . "&mobj_id="
198  . $mobjId . "&type=reply",
199  $this->lng->txt("reply")
200  );
201  $content_block->addBlockCommand(
202  "ilias.php?baseClass=ilMailGUI&mail_id=" .
203  $mailId . "&mobj_id="
204  . $mobjId . "&type=read",
205  $this->lng->txt("inbox")
206  );
207 
208  $this->ctrl->setParameter($this, 'mail_id', $mailId);
209  $content_block->addBlockCommand(
210  $this->ctrl->getLinkTarget($this, 'deleteMail'),
211  $this->lng->txt('delete')
212  );
213 
214  return $content_block->getHTML();
215  }
216 
217  public function deleteMail(): void
218  {
219  $this->lng->loadLanguageModule('mail');
220 
221  $umail = new ilMail($this->user->getId());
222  $mbox = new ilMailbox($this->user->getId());
223 
224  $mailId = 0;
225  if ($this->http->wrapper()->query()->has('mail_id')) {
226  $mailId = $this->http->wrapper()->query()->retrieve('mail_id', $this->refinery->kindlyTo()->int());
227  }
228  $mobjId = 0;
229  if ($this->http->wrapper()->query()->has('mobj_id')) {
230  $mobjId = $this->http->wrapper()->query()->retrieve('mobj_id', $this->refinery->kindlyTo()->int());
231  }
232 
233  if ($mobjId) {
234  $this->requestMailObjId = $mbox->getInboxFolder();
235  }
236 
237  if ($umail->moveMailsToFolder(
238  [$mailId],
239  $mbox->getTrashFolder()
240  )) {
241  $this->main_tpl->setOnScreenMessage('info', $this->lng->txt('mail_moved_to_trash'), true);
242  } else {
243  $this->main_tpl->setOnScreenMessage('info', $this->lng->txt('mail_move_error'), true);
244  }
245  $this->ctrl->redirectByClass(ilDashboardGUI::class, 'show');
246  }
247 
248  protected function preloadData(array $data): void
249  {
250  $usr_ids = [];
251 
252  foreach ($data as $mail) {
253  if ($mail['sender_id'] && $mail['sender_id'] !== ANONYMOUS_USER_ID) {
254  $usr_ids[$mail['sender_id']] = $mail['sender_id'];
255  }
256  }
257 
259  }
260 
261  //
262  // New rendering
263  //
264 
265  protected bool $new_rendering = true;
266 
267  protected function getListItemForData(array $data): ?Item
268  {
269  $f = $this->ui->factory();
270 
271  $user = ilMailUserCache::getUserObjectById($data['sender_id']);
272 
273  if ($user && $user->getId() !== ANONYMOUS_USER_ID) {
274  $public_name_long = $user->getPublicName();
275  $img_sender = $user->getPersonalPicturePath('xxsmall');
276  $alt_sender = htmlspecialchars($user->getPublicName());
277  } elseif (!$user) {
278  $public_name_long = trim(($data['import_name'] ?? '') . ' (' . $this->lng->txt('user_deleted') . ')');
279  $img_sender = "";
280  $alt_sender = "";
281  } else {
282  $public_name_long = ilMail::_getIliasMailerName();
283  $img_sender = ilUtil::getImagePath('HeaderIconAvatar.svg');
284  $alt_sender = htmlspecialchars(ilMail::_getIliasMailerName());
285  }
286 
287  $new_mail_date = ilDatePresentation::formatDate(new ilDate($data['send_time'], IL_CAL_DATE));
288  $new_mail_subj = htmlentities($data['m_subject'], ENT_NOQUOTES, 'UTF-8');
289  $this->ctrl->setParameter($this, 'mobj_id', $this->inbox);
290  $this->ctrl->setParameter($this, 'mail_id', $data['mail_id']);
291  $new_mail_link = $this->ctrl->getLinkTarget($this, 'showMail');
292  $this->ctrl->clearParameters($this);
293 
294 
295  $button = $f->button()->shy($new_mail_subj, $new_mail_link);
296 
297  $item = $f->item()->standard($button)->withDescription($new_mail_date);
298  if ($img_sender !== "") {
299  $item = $item->withLeadImage($f->image()->standard($img_sender, $alt_sender));
300  }
301 
302  return $item;
303  }
304 }
Interface GlobalHttpState.
ilObjUser $user
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const ANONYMOUS_USER_ID
Definition: constants.php:27
static getUserObjectById(int $usr_id)
setLimit(int $a_limit)
setDataSection(string $a_content)
Call this from overwritten fillDataSection(), if standard row based data is not used.
setEnableNumInfo(bool $a_enablenuminfo)
getMailsOfFolder(int $a_folder_id, array $filter=[])
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
BlockGUI class for Personal Desktop Mail block.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
getPublicName()
returns firstname lastname and login if profile is public, login otherwise
global $DIC
Definition: feed.php:28
setRowTemplate(string $a_rowtemplatename, string $a_rowtemplatedir="")
Set Row Template Name.
Mail User Interface class.
static http()
Fetches the global http state from ILIAS.
Mail Box class Base class for creating and handling mail boxes.
Common interface to all items.
Definition: Item.php:31
static preloadUserObjects(array $usr_ids)
const IL_SCREEN_CENTER
getPersonalPicturePath(string $a_size="small", bool $a_force_pic=false)
const IL_CAL_DATE
__construct(Container $dic, ilPlugin $plugin)
setTitle(string $a_title)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a block method of a block.
setData(array $a_data)
const IL_SCREEN_SIDE
setPresentation(int $type)