ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilPDMailBlockGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once 'Services/Block/classes/class.ilBlockGUI.php';
5include_once 'Services/Mail/classes/class.ilMailUserCache.php';
6
14{
15 public static $block_type = 'pdmail';
16
20 protected $lng;
21
25 protected $user;
26
30 protected $ctrl;
31
35 protected $rbacsystem;
36
40 protected $setting;
41
45 protected $mails = array();
46
50 protected $inbox;
51
55 public function __construct()
56 {
57 global $DIC;
58
59 $this->lng = $DIC->language();
60 $this->user = $DIC->user();
61 $this->ctrl = $DIC->ctrl();
62 $this->setting = $DIC->settings();
63 $this->rbacsystem = $DIC->rbac()->system();
64
65 include_once 'Services/User/classes/class.ilObjUser.php';
66 include_once 'Services/Mail/classes/class.ilMailbox.php';
67 include_once 'Services/Mail/classes/class.ilMail.php';
68
70
71 $this->setLimit(5);
72 $this->setTitle($this->lng->txt('mail'));
73 $this->setPresentation(self::PRES_SEC_LIST);
74 }
75
79 public function getBlockType() : string
80 {
81 return self::$block_type;
82 }
83
87 protected function isRepositoryObject() : bool
88 {
89 return false;
90 }
91
95 public static function getScreenMode()
96 {
97 switch ($_GET['cmd']) {
98 case 'showMail':
99 return IL_SCREEN_CENTER;
100 break;
101
102 default:
103 return IL_SCREEN_SIDE;
104 break;
105 }
106 }
107
111 public function executeCommand()
112 {
113 $cmd = $this->ctrl->getCmd('getHTML');
114
115 return $this->$cmd();
116 }
117
118 public function getHTML()
119 {
120 $umail = new ilMail($this->user->getId());
121 if (!$this->rbacsystem->checkAccess('internal_mail', $umail->getMailObjectReferenceId())) {
122 return '';
123 }
124
125 $this->getMails();
126 $this->setData($this->mails);
127
128 return parent::getHTML();
129 }
130
134 protected function getMails()
135 {
136 require_once 'Services/Mail/classes/class.ilObjMail.php';
137
138 $umail = new ilMail($this->user->getId());
139 $mbox = new ilMailbox($this->user->getId());
140 $this->inbox = $mbox->getInboxFolder();
141
142 $this->mails = $umail->getMailsOfFolder(
143 $this->inbox,
144 array(
145 'status' => 'unread'
146 )
147 );
148 }
149
153 public function fillDataSection()
154 {
155 $this->getMails();
156 $this->setData($this->mails);
157
158 if (count($this->mails) > 0) {
159 $this->setRowTemplate("tpl.pd_mail_row.html", "Services/Mail");
160 parent::fillDataSection();
161 } else {
162 $this->setEnableNumInfo(false);
163 $this->setDataSection($this->getOverview());
164 }
165 }
166
170 public function fillRow($mail)
171 {
172 $user = ilMailUserCache::getUserObjectById($mail['sender_id']);
173
174 $this->tpl->touchBlock('usr_image_space');
175 if ($user && $user->getId() != ANONYMOUS_USER_ID) {
176 $this->tpl->setVariable('PUBLIC_NAME_LONG', $user->getPublicName());
177 $this->tpl->setVariable('IMG_SENDER', $user->getPersonalPicturePath('xxsmall'));
178 $this->tpl->setVariable('ALT_SENDER', htmlspecialchars($user->getPublicName()));
179 } elseif (!$user) {
180 $this->tpl->setVariable('PUBLIC_NAME_LONG', $mail['import_name'] . ' (' . $this->lng->txt('user_deleted') . ')');
181
182 $this->tpl->setCurrentBlock('image_container');
183 $this->tpl->touchBlock('image_container');
184 $this->tpl->parseCurrentBlock();
185 } else {
186 $this->tpl->setVariable('PUBLIC_NAME_LONG', ilMail::_getIliasMailerName());
187 $this->tpl->setVariable('IMG_SENDER', ilUtil::getImagePath('HeaderIconAvatar.svg'));
188 $this->tpl->setVariable('ALT_SENDER', htmlspecialchars(ilMail::_getIliasMailerName()));
189 }
190
191 $this->tpl->setVariable('NEW_MAIL_DATE', ilDatePresentation::formatDate(new ilDate($mail['send_time'], IL_CAL_DATE)));
192
193 $this->tpl->setVariable('NEW_MAIL_SUBJ', htmlentities($mail['m_subject'], ENT_NOQUOTES, 'UTF-8'));
194 $this->ctrl->setParameter($this, 'mobj_id', $this->inbox);
195 $this->ctrl->setParameter($this, 'mail_id', $mail['mail_id']);
196 $this->tpl->setVariable('NEW_MAIL_LINK_READ', $this->ctrl->getLinkTarget($this, 'showMail'));
197 $this->ctrl->clearParameters($this);
198 }
199
203 protected function getOverview()
204 {
205 return '<div class="small">' . ((int) count($this->mails)) . " " . $this->lng->txt("mails_pl") . "</div>";
206 }
207
211 protected function showMail()
212 {
213 include_once("./Services/Mail/classes/class.ilPDMailGUI.php");
214 $mail_gui = new ilPDMailGUI();
215
216 $content_block = new ilDashboardContentBlockGUI();
217 $content_block->setContent($mail_gui->getPDMailHTML(
218 $_GET["mail_id"],
219 $_GET["mobj_id"]
220 ));
221 $content_block->setTitle($this->lng->txt("message"));
222
223 $content_block->addBlockCommand(
224 "ilias.php?baseClass=ilMailGUI&mail_id=" .
225 $_GET["mail_id"] . "&mobj_id=" . $_GET["mobj_id"] . "&type=reply",
226 $this->lng->txt("reply")
227 );
228 $content_block->addBlockCommand(
229 "ilias.php?baseClass=ilMailGUI&mail_id=" .
230 $_GET["mail_id"] . "&mobj_id=" . $_GET["mobj_id"] . "&type=read",
231 $this->lng->txt("inbox")
232 );
233
234 $this->ctrl->setParameter($this, 'mail_id', (int) $_GET['mail_id']);
235 $content_block->addBlockCommand($this->ctrl->getLinkTarget($this, 'deleteMail'), $this->lng->txt('delete'));
236
237 return $content_block->getHTML();
238 }
239
243 public function deleteMail()
244 {
245 $this->lng->loadLanguageModule('mail');
246
247 $umail = new ilMail($this->user->getId());
248 $mbox = new ilMailbox($this->user->getId());
249
250 if (!$_GET['mobj_id']) {
251 $_GET['mobj_id'] = $mbox->getInboxFolder();
252 }
253
254 if ($umail->moveMailsToFolder(array((int) $_GET['mail_id']), (int) $mbox->getTrashFolder())) {
255 \ilUtil::sendInfo($this->lng->txt('mail_moved_to_trash'), true);
256 } else {
257 \ilUtil::sendInfo($this->lng->txt('mail_move_error'), true);
258 }
259 $this->ctrl->redirectByClass('ildashboardgui', 'show');
260 }
261
265 protected function preloadData(array $data)
266 {
267 $usr_ids = array();
268
269 foreach ($data as $mail) {
270 if ($mail['sender_id'] && $mail['sender_id'] != ANONYMOUS_USER_ID) {
271 $usr_ids[$mail['sender_id']] = $mail['sender_id'];
272 }
273 }
274
276 }
277
278 //
279 // New rendering
280 //
281
282 protected $new_rendering = true;
283
284
288 protected function getListItemForData(array $mail) : \ILIAS\UI\Component\Item\Item
289 {
290 $f = $this->ui->factory();
291
292 $user = ilMailUserCache::getUserObjectById($mail['sender_id']);
293
294 if ($user && $user->getId() != ANONYMOUS_USER_ID) {
295 $public_name_long = $user->getPublicName();
296 $img_sender = $user->getPersonalPicturePath('xxsmall');
297 $alt_sender = htmlspecialchars($user->getPublicName());
298 } elseif (!$user) {
299 $public_name_long = $mail['import_name'] . ' (' . $this->lng->txt('user_deleted') . ')';
300 $img_sender = "";
301 $alt_sender = "";
302 } else {
303 $public_name_long = ilMail::_getIliasMailerName();
304 $img_sender = ilUtil::getImagePath('HeaderIconAvatar.svg');
305 $alt_sender = htmlspecialchars(ilMail::_getIliasMailerName());
306 }
307
308 $new_mail_date = ilDatePresentation::formatDate(new ilDate($mail['send_time'], IL_CAL_DATE));
309 $new_mail_subj = htmlentities($mail['m_subject'], ENT_NOQUOTES, 'UTF-8');
310 $this->ctrl->setParameter($this, 'mobj_id', $this->inbox);
311 $this->ctrl->setParameter($this, 'mail_id', $mail['mail_id']);
312 $new_mail_link = $this->ctrl->getLinkTarget($this, 'showMail', "", false, false);
313 $this->ctrl->clearParameters($this);
314
315
316 $button = $f->button()->shy($new_mail_subj, $new_mail_link);
317
318 $item = $f->item()->standard($button)->withDescription($new_mail_date);
319 if ($img_sender != "") {
320 $item = $item->withLeadImage($f->image()->standard($img_sender, $alt_sender));
321 }
322
323 return $item;
324 }
325}
user()
Definition: user.php:4
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
const IL_SCREEN_SIDE
const IL_SCREEN_CENTER
const IL_CAL_DATE
This class represents a block method of a block.
setRowTemplate($a_rowtemplatename, $a_rowtemplatedir="")
Set Row Template Name.
setLimit($a_limit)
Set Limit.
setData($a_data)
Set Data.
setPresentation(int $type)
Set presentation.
setDataSection($a_content)
Call this from overwritten fillDataSection(), if standard row based data is not used.
setTitle($a_title)
Set Title.
setEnableNumInfo($a_enablenuminfo)
Set Enable Item Number Info.
BlockGUI class for (centered) Content on Personal Desktop.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
Class for single dates.
static getUserObjectById($usr_id)
static preloadUserObjects(array $usr_ids)
Mail Box class Base class for creating and handling mail boxes.
BlockGUI class for Personal Desktop Mail block.
isRepositoryObject()
Returns whether block has a corresponding repository object.bool
fillDataSection()
Fill data section.
fillRow($mail)
get flat list for personal desktop
static getScreenMode()
Get Screen Mode for current command.
executeCommand()
execute command
getListItemForData(array $mail)
Get list item for data array.null|\ILIAS\UI\Component\Item\Item
Mail User Interface class.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
ui()
Definition: ui.php:5
$DIC
Definition: xapitoken.php:46