ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
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 preloadData(array $data): void
129  {
130  $usr_ids = [];
131 
132  foreach ($data as $mail) {
133  if ($mail['sender_id'] && $mail['sender_id'] !== ANONYMOUS_USER_ID) {
134  $usr_ids[$mail['sender_id']] = $mail['sender_id'];
135  }
136  }
137 
139  }
140 
141  protected function getListItemForData(array $data): ?Item
142  {
143  $f = $this->ui->factory();
144 
145  $user = ilMailUserCache::getUserObjectById($data['sender_id']);
146 
147  $avatar = null;
148  if ($user && $user->getId() !== ANONYMOUS_USER_ID) {
149  $avatar = $user->getAvatar();
150  $public_name_long = $user->getPublicName();
151  } elseif ($user) {
152  $avatar = $this->ui->factory()
153  ->symbol()
154  ->avatar()
155  ->picture(ilUtil::getImagePath('logo/ilias_logo_centered.png'), ilMail::_getIliasMailerName());
156  $public_name_long = ilMail::_getIliasMailerName();
157  } else {
158  $public_name_long = trim(($data['import_name'] ?? '') . ' (' . $this->lng->txt('user_deleted') . ')');
159  }
160 
161  $new_mail_subj = htmlentities($data['m_subject'], ENT_NOQUOTES, 'UTF-8');
162  $this->ctrl->setParameterByClass(ilMailFolderGUI::class, 'mobj_id', $this->inbox);
163  $this->ctrl->setParameterByClass(ilMailFolderGUI::class, 'mail_id', $data['mail_id']);
164  $new_mail_link = $this->ctrl->getLinkTargetByClass([ilMailGUI::class, ilMailFolderGUI::class], 'showMail');
165  $this->ctrl->clearParametersByClass(ilMailFolderGUI::class);
166 
167  $button = $f->link()->standard($new_mail_subj, $new_mail_link);
168 
169  $item = $f->item()->standard($button);
170  if ($avatar !== null) {
171  $item = $item->withLeadAvatar($avatar);
172  }
173 
174  $item = $item->withProperties([
175  $this->lng->txt('from') => $public_name_long,
176  $this->lng->txt('mail_sent_datetime') => ilDatePresentation::formatDate(new ilDateTime($data['send_time'], IL_CAL_DATETIME)),
177  ]);
178 
179  return $item;
180  }
181 
182  public function getNoItemFoundContent(): string
183  {
184  return $this->lng->txt('mail_no_mail_items');
185  }
186 }
ilObjUser $user
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ilObjUser $user=null,)
const IL_CAL_DATETIME
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=[])
BlockGUI class for Personal Desktop Mail block.
static _getIliasMailerName()
getPublicName()
returns firstname lastname and login if profile is public, login otherwise
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
global $DIC
Definition: shib_login.php:25
static preloadUserObjects(array $usr_ids)
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
readonly GlobalHttpState $http
const IL_SCREEN_CENTER
__construct(Container $dic, ilPlugin $plugin)
setTitle(string $a_title)
This class represents a block method of a block.
setData(array $a_data)
const IL_SCREEN_SIDE
setPresentation(int $type)