ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilPDMailBlockGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
31 {
32  public static string $block_type = 'pdmail';
33 
34  private readonly GlobalHttpState $http;
35  private readonly Refinery $refinery;
36  private int $requestMailObjId = 0;
38  protected ilSetting $setting;
40  protected array $mails = [];
41  protected int $inbox;
42  private bool $has_access = false;
43 
44  public function __construct()
45  {
46  global $DIC;
47  $this->lng = $DIC->language();
48  $this->user = $DIC->user();
49  $this->ctrl = $DIC->ctrl();
50  $this->setting = $DIC->settings();
51  $this->rbacsystem = $DIC->rbac()->system();
52  $this->http = $DIC->http();
53  $this->refinery = $DIC->refinery();
54 
56 
57  $this->setLimit(5);
58  $this->setTitle($this->lng->txt('mail'));
59  $this->setPresentation(self::PRES_SEC_LIST);
60 
61  $umail = new ilMail($this->user->getId());
62  if ($this->rbacsystem->checkAccess('internal_mail', $umail->getMailObjectReferenceId())) {
63  $this->has_access = true;
64  $this->getMails();
65  $this->setData($this->mails);
66  }
67  }
68 
69  public function getBlockType(): string
70  {
71  return self::$block_type;
72  }
73 
74  protected function isRepositoryObject(): bool
75  {
76  return false;
77  }
78 
79  public static function getScreenMode(): string
80  {
81  global $DIC;
82  $cmd = "";
83  if ($DIC->http()->wrapper()->query()->has('cmd')) {
84  $cmd = $DIC->http()->wrapper()->query()->retrieve('cmd', $DIC->refinery()->kindlyTo()->string());
85  }
86  if ($cmd === 'showMail') {
87  return IL_SCREEN_CENTER;
88  }
89 
90  return IL_SCREEN_SIDE;
91  }
92 
93  public function executeCommand(): string
94  {
95  $cmd = $this->ctrl->getCmd('getHTML');
96 
97  return $this->$cmd();
98  }
99 
100  public function getHTML(): string
101  {
102  if (!$this->has_access) {
103  return '';
104  }
105  return parent::getHTML();
106  }
107 
108  protected function getMails(): void
109  {
110  $umail = new ilMail($this->user->getId());
111  $mbox = new ilMailbox($this->user->getId());
112  $this->inbox = $mbox->getInboxFolder();
113 
114  $this->mails = $umail->getMailsOfFolder(
115  $this->inbox,
116  [
117  'status' => 'unread',
118  ]
119  );
120  $this->max_count = count($this->mails);
121  }
122 
123  protected function getOverview(): string
124  {
125  return '<div class="small">' . (count($this->mails)) . " " . $this->lng->txt("mails_pl") . "</div>";
126  }
127 
128  protected function showMail(): string
129  {
130  $mail_gui = new ilPDMailGUI();
131 
132  $content_block = new ilDashboardContentBlockGUI();
133  $mailId = 0;
134  if ($this->http->wrapper()->query()->has('mail_id')) {
135  $mailId = $this->http->wrapper()->query()->retrieve('mail_id', $this->refinery->kindlyTo()->int());
136  }
137  $mobjId = $this->requestMailObjId;
138  if ($this->http->wrapper()->query()->has('mobj_id')) {
139  $mobjId = $this->http->wrapper()->query()->retrieve('mobj_id', $this->refinery->kindlyTo()->int());
140  }
141  $content_block->setContent($mail_gui->getPDMailHTML(
142  $mailId,
143  $mobjId
144  ));
145  $content_block->setTitle($this->lng->txt("message"));
146 
147  $content_block->addBlockCommand(
148  "ilias.php?baseClass=ilMailGUI&mail_id=" .
149  $mailId . "&mobj_id="
150  . $mobjId . "&type=reply",
151  $this->lng->txt("reply")
152  );
153  $content_block->addBlockCommand(
154  "ilias.php?baseClass=ilMailGUI&mail_id=" .
155  $mailId . "&mobj_id="
156  . $mobjId . "&type=read",
157  $this->lng->txt("inbox")
158  );
159 
160  $this->ctrl->setParameter($this, 'mail_id', $mailId);
161  $content_block->addBlockCommand(
162  $this->ctrl->getLinkTarget($this, 'deleteMail'),
163  $this->lng->txt('delete')
164  );
165 
166  return $content_block->getHTML();
167  }
168 
169  public function deleteMail(): void
170  {
171  $this->lng->loadLanguageModule('mail');
172 
173  $umail = new ilMail($this->user->getId());
174  $mbox = new ilMailbox($this->user->getId());
175 
176  $mailId = 0;
177  if ($this->http->wrapper()->query()->has('mail_id')) {
178  $mailId = $this->http->wrapper()->query()->retrieve('mail_id', $this->refinery->kindlyTo()->int());
179  }
180  $mobjId = 0;
181  if ($this->http->wrapper()->query()->has('mobj_id')) {
182  $mobjId = $this->http->wrapper()->query()->retrieve('mobj_id', $this->refinery->kindlyTo()->int());
183  }
184 
185  if ($mobjId) {
186  $this->requestMailObjId = $mbox->getInboxFolder();
187  }
188 
189  if ($umail->moveMailsToFolder(
190  [$mailId],
191  $mbox->getTrashFolder()
192  )) {
193  $this->main_tpl->setOnScreenMessage('info', $this->lng->txt('mail_moved_to_trash'), true);
194  } else {
195  $this->main_tpl->setOnScreenMessage('info', $this->lng->txt('mail_move_error'), true);
196  }
197  $this->ctrl->redirectByClass(ilDashboardGUI::class, 'show');
198  }
199 
200  protected function preloadData(array $data): void
201  {
202  $usr_ids = [];
203 
204  foreach ($data as $mail) {
205  if ($mail['sender_id'] && $mail['sender_id'] !== ANONYMOUS_USER_ID) {
206  $usr_ids[$mail['sender_id']] = $mail['sender_id'];
207  }
208  }
209 
211  }
212 
213  protected function getListItemForData(array $data): ?Item
214  {
215  $f = $this->ui->factory();
216 
217  $user = ilMailUserCache::getUserObjectById($data['sender_id']);
218 
219  if ($user && $user->getId() !== ANONYMOUS_USER_ID) {
220  $public_name_long = $user->getPublicName();
221  $img_sender = $user->getPersonalPicturePath('xxsmall');
222  $alt_sender = htmlspecialchars($user->getPublicName());
223  } elseif (!$user instanceof ilObjUser) {
224  $public_name_long = trim(($data['import_name'] ?? '') . ' (' . $this->lng->txt('user_deleted') . ')');
225  $img_sender = "";
226  $alt_sender = "";
227  } else {
228  $public_name_long = ilMail::_getIliasMailerName();
229  $img_sender = ilUtil::getImagePath('logo/HeaderIconAvatar.svg');
230  $alt_sender = htmlspecialchars(ilMail::_getIliasMailerName());
231  }
232 
233  $new_mail_date = ilDatePresentation::formatDate(new ilDate($data['send_time'], IL_CAL_DATE));
234  $new_mail_subj = htmlentities($data['m_subject'], ENT_NOQUOTES, 'UTF-8');
235  $this->ctrl->setParameter($this, 'mobj_id', $this->inbox);
236  $this->ctrl->setParameter($this, 'mail_id', $data['mail_id']);
237  $new_mail_link = $this->ctrl->getLinkTarget($this, 'showMail');
238  $this->ctrl->clearParameters($this);
239 
240 
241  $button = $f->button()->shy($new_mail_subj, $new_mail_link);
242 
243  $item = $f->item()->standard($button)->withDescription($new_mail_date);
244  if ($img_sender !== "") {
245  $item = $item->withLeadImage($f->image()->standard($img_sender, $alt_sender));
246  }
247 
248  return $item;
249  }
250 }
Interface GlobalHttpState.
ilObjUser $user
const ANONYMOUS_USER_ID
Definition: constants.php:27
static getUserObjectById(int $usr_id)
setLimit(int $a_limit)
readonly Refinery $refinery
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)
static _getIliasMailerName()
getPublicName()
returns firstname lastname and login if profile is public, login otherwise
global $DIC
Definition: feed.php:28
Mail User Interface class.
static http()
Fetches the global http state from ILIAS.
__construct(VocabulariesInterface $vocabularies)
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)
readonly GlobalHttpState $http
const IL_SCREEN_CENTER
getPersonalPicturePath(string $a_size="small", bool $a_force_pic=false)
const IL_CAL_DATE
setTitle(string $a_title)
This class represents a block method of a block.
setData(array $a_data)
const IL_SCREEN_SIDE
setPresentation(int $type)