ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilPDMailBlockGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22use ILIAS\Refinery\Factory as Refinery;
24
29{
30 public static string $block_type = 'pdmail';
31
32 private readonly GlobalHttpState $http;
33 private readonly Refinery $refinery;
37 protected array $mails = [];
38 protected int $inbox;
39 private bool $has_access = false;
40
41 public function __construct()
42 {
43 global $DIC;
44 $this->lng = $DIC->language();
45 $this->user = $DIC->user();
46 $this->ctrl = $DIC->ctrl();
47 $this->setting = $DIC->settings();
48 $this->rbacsystem = $DIC->rbac()->system();
49 $this->http = $DIC->http();
50 $this->refinery = $DIC->refinery();
51
53
54 $this->setLimit(5);
55 $this->setTitle($this->lng->txt('mail'));
56 $this->setPresentation(self::PRES_SEC_LIST);
57
58 $umail = new ilMail($this->user->getId());
59 if ($this->rbacsystem->checkAccess('internal_mail', $umail->getMailObjectReferenceId())) {
60 $this->has_access = true;
61 $this->getMails();
62 $this->setData($this->mails);
63 }
64 }
65
66 public function getBlockType(): string
67 {
68 return self::$block_type;
69 }
70
71 protected function isRepositoryObject(): bool
72 {
73 return false;
74 }
75
76 public static function getScreenMode(): string
77 {
78 global $DIC;
79 $cmd = '';
80 if ($DIC->http()->wrapper()->query()->has('cmd')) {
81 $cmd = $DIC->http()->wrapper()->query()->retrieve('cmd', $DIC->refinery()->kindlyTo()->string());
82 }
83 if ($cmd === 'showMail') {
84 return IL_SCREEN_CENTER;
85 }
86
87 return IL_SCREEN_SIDE;
88 }
89
90 public function executeCommand(): string
91 {
92 $cmd = $this->ctrl->getCmd('getHTML');
93
94 return $this->$cmd();
95 }
96
97 public function getHTML(): string
98 {
99 if (!$this->has_access) {
100 return '';
101 }
102 return parent::getHTML();
103 }
104
105 protected function getMails(): void
106 {
107 $umail = new ilMail($this->user->getId());
108 $mbox = new ilMailbox($this->user->getId());
109 $this->inbox = $mbox->getInboxFolder();
110
111 $this->mails = $umail->getMailsOfFolder(
112 $this->inbox,
113 [
114 'status' => 'unread',
115 ]
116 );
117 $this->max_count = count($this->mails);
118 }
119
120 protected function getOverview(): string
121 {
122 return '<div class="small">' . (count($this->mails)) . ' ' . $this->lng->txt('mails_pl') . '</div>';
123 }
124
125 protected function preloadData(array $data): void
126 {
127 $usr_ids = [];
128
129 foreach ($data as $mail) {
130 if ($mail['sender_id'] && $mail['sender_id'] !== ANONYMOUS_USER_ID) {
131 $usr_ids[$mail['sender_id']] = $mail['sender_id'];
132 }
133 }
134
136 }
137
138 protected function getListItemForData(array $data): ?Item
139 {
140 $f = $this->ui->factory();
141
142 $user = ilMailUserCache::getUserObjectById($data['sender_id']);
143
144 $avatar = null;
145 if ($user && $user->getId() !== ANONYMOUS_USER_ID) {
146 $avatar = $user->getAvatar();
147 $public_name_long = $user->getPublicName();
148 } elseif ($user) {
149 $avatar = $this->ui->factory()
150 ->symbol()
151 ->avatar()
152 ->picture(ilUtil::getImagePath('logo/ilias_logo_centered.png'), ilMail::_getIliasMailerName());
153 $public_name_long = ilMail::_getIliasMailerName();
154 } else {
155 $public_name_long = trim(($data['import_name'] ?? '') . ' (' . $this->lng->txt('user_deleted') . ')');
156 }
157
158 $new_mail_subj = htmlentities($data['m_subject'], ENT_NOQUOTES, 'UTF-8');
159 $this->ctrl->setParameterByClass(ilMailFolderGUI::class, 'mobj_id', $this->inbox);
160 $this->ctrl->setParameterByClass(ilMailFolderGUI::class, 'mail_id', $data['mail_id']);
161 $new_mail_link = $this->ctrl->getLinkTargetByClass([ilMailGUI::class, ilMailFolderGUI::class], 'showMail');
162 $this->ctrl->clearParametersByClass(ilMailFolderGUI::class);
163
164 $button = $f->link()->standard($new_mail_subj, $new_mail_link);
165
166 $item = $f->item()->standard($button);
167 if ($avatar !== null) {
168 $item = $item->withLeadAvatar($avatar);
169 }
170
171 $item = $item->withProperties([
172 $this->lng->txt('from') => $public_name_long,
173 $this->lng->txt('mail_sent_datetime') => ilDatePresentation::formatDate(new ilDateTime($data['send_time'], IL_CAL_DATETIME)),
174 ]);
175
176 return $item;
177 }
178
179 public function getNoItemFoundContent(): string
180 {
181 return $this->lng->txt('mail_no_mail_items');
182 }
183}
Builds data types.
Definition: Factory.php:36
const IL_SCREEN_SIDE
const IL_SCREEN_CENTER
const IL_CAL_DATETIME
This class represents a block method of a block.
setData(array $a_data)
setTitle(string $a_title)
setPresentation(int $type)
ilObjUser $user
setLimit(int $a_limit)
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
@classDescription Date and time handling
static getUserObjectById(int $usr_id)
static preloadUserObjects(array $usr_ids)
static _getIliasMailerName()
@ilCtrl_IsCalledBy ilPDMailBlockGUI: ilColumnGUI
isRepositoryObject()
Returns whether block has a corresponding repository object.
readonly GlobalHttpState $http
readonly Refinery $refinery
getListItemForData(array $data)
Get list item for data array.
preloadData(array $data)
Can be overwritten in subclasses.
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
ILIAS Setting Class.
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
const ANONYMOUS_USER_ID
Definition: constants.php:27
Interface GlobalHttpState.
Common interface to all items.
Definition: Item.php:32
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26