ILIAS  trunk Revision v12.0_alpha-1338-g8f7e531aa3c
MailGlobalScreenToolProvider.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
32use ILIAS\HTTP\Wrapper\WrapperFactory as HttpWrapper;
35use ILIAS\UI\Component\Link\Bulky as BulkyLink;
37use ILIAS\UI\Component\Legacy\Content as LegacyContent;
40use ILIAS\UI\Factory as UIFactory;
41use ILIAS\UI\Renderer as UIRenderer;
42use ilLanguage;
44use ilMailbox;
47use ilMailGUI;
49use ilObjUser;
50use ilUtil;
51
53{
54 final public const string SHOW_MAIL_FOLDERS_TOOL = 'show_mail_folders_tool';
55
56 private readonly UIFactory $ui_factory;
57 private readonly UIRenderer $ui_renderer;
58 private readonly ilMailbox $mbox;
59 private readonly ilObjUser $user;
60 private readonly ?ilCtrlInterface $ctrl;
61 private readonly HttpWrapper $http_wrapper;
62 private readonly Refinery $refinery;
63 private readonly ilLanguage $lng;
64 private readonly IconFactory $icon_factory;
65
66 public function __construct(
68 ?UIFactory $ui_factory = null,
69 ?UIRenderer $ui_renderer = null,
70 ?ilObjUser $user = null,
71 ?ilCtrlInterface $ctrl = null,
72 ?HttpWrapper $http_wrapper = null,
73 ?Refinery $refinery = null,
74 ?ilLanguage $lng = null,
75 ?IconFactory $icon_factory = null
76 ) {
78 $this->ui_factory = $ui_factory ?? $this->dic->ui()->factory();
79 $this->ui_renderer = $ui_renderer ?? $this->dic->ui()->renderer();
80 $this->user = $user ?? $this->dic->user();
81 $this->ctrl = $ctrl ?? $this->dic->ctrl();
82 $this->http_wrapper = $http_wrapper ?? $this->dic->http()->wrapper();
83 $this->refinery = $refinery ?? $this->dic->refinery();
84 $this->lng = $lng ?? $this->dic->language();
85 $this->icon_factory = $icon_factory ?? $this->ui_factory->symbol()->icon();
86
87 $this->mbox = new ilMailbox($this->user->getId());
88 }
89
91 {
92 return $this->context_collection->main()->repository()->administration();
93 }
94
95 public function getToolsForContextStack(CalledContexts $called_contexts): array
96 {
97 $identification = fn($id): IdentificationInterface => $this->identification_provider->contextAwareIdentifier($id);
98
99 $tools = [];
100
101 $additional_data = $called_contexts->getLast()->getAdditionalData();
102 if ($additional_data->exists(self::SHOW_MAIL_FOLDERS_TOOL) &&
103 $additional_data->get(self::SHOW_MAIL_FOLDERS_TOOL) === true) {
104
105 $tools[] = $this->factory
106 ->tool($identification('mail_folders_tree'))
107 ->withTitle($this->lng->txt('mail'))
108 ->withSymbol($this->icon_factory->standard('mail', $this->lng->txt('mail')))
109 ->withContentWrapper(function (): LegacyContent {
110 $current_folder_id = $this->http_wrapper->query()->retrieve(
111 'mobj_id',
112 $this->refinery->kindlyTo()->int()
113 );
114
115 $this->ctrl->setParameterByClass(ilMailFormGUI::class, 'type', ilMailFormGUI::MAIL_FORM_TYPE_NEW);
116
117 $sub_items = [
118 $this->buildItem(
119 $this->lng->txt('mail_new'),
120 'mail',
121 $this->buildFolderLink($current_folder_id, ilMailFormGUI::class)
122 ),
123 ...$this->buildSubItems(),
124 $this->buildItem(
125 $this->lng->txt('mail_attachments'),
126 'attach',
127 $this->buildFolderLink($current_folder_id, [ilMailGUI::class, ilMailAttachmentGUI::class])
128 )
129 ];
130
131 if ($this->dic->settings()->get('show_mail_settings', '0')) {
132 $sub_items[] = $this->buildItem(
133 $this->lng->txt('mail_options'),
134 'adm',
135 $this->buildFolderLink($current_folder_id, ilMailOptionsGUI::class)
136 );
137 }
138
139 $item = $this->ui_factory->menu()->drilldown(
140 $this->lng->txt('mail'),
141 $sub_items
142 );
143
144 return $this->ui_factory->legacy()->content(
145 $this->ui_renderer->render($item)
146 );
147 });
148 }
149
150 return $tools;
151 }
152
156 private function buildSubItems(): array
157 {
158 $items = [];
159
160 $folders = $this->mbox->getSubFolders();
161 usort(
162 $folders,
163 static fn(MailFolderData $a, MailFolderData $b): int => $a->isTrash() && !$b->isUserLocalFolder() ? 1 : 0
164 );
165 $user_folders = $this->filterUserFolders($folders);
166
167 foreach ($folders as $folder) {
168 if ($folder->isUserLocalFolder() && $user_folders !== []) {
169 $icon_name = $folder->getType()->value;
170 $items[] = $this->ui_factory->menu()->sub(
171 $folder->getTitle(),
172 [
173 $this->buildItem(
174 $this->lng->txt('mail_main_folder'),
175 $icon_name,
176 $this->buildFolderLink($folder->getFolderId(), ilMailFolderGUI::class)
177 ),
178 ...array_map(
179 function (MailFolderData $folder) use ($icon_name): BulkyLink {
180 return $this->buildItem(
181 $folder->getTitle(),
182 $icon_name,
183 $this->buildFolderLink($folder->getFolderId(), ilMailFolderGUI::class)
184 );
185 },
186 $user_folders
187 ),
188 ]
189 );
190 continue;
191 }
192
193 $items[] = $this->buildItem(
194 $folder->getTitle(),
195 $folder->getType()->value,
196 $this->buildFolderLink($folder->getFolderId(), ilMailFolderGUI::class)
197 );
198 }
199
200 return $items;
201 }
202
207 private function buildFolderLink(int $folderId, string|array $class, ?string $cmd = null): string
208 {
209 $this->ctrl->setParameterByClass(is_array($class) ? current($class) : $class, 'mobj_id', $folderId);
210 $url = $this->ctrl->getLinkTargetByClass($class, $cmd);
211 $this->ctrl->setParameterByClass(is_array($class) ? current($class) : $class, 'mob_id', null);
212
213 return $url;
214 }
215
216 private function buildItem(string $title, string $icon_name, string $link): BulkyLink
217 {
218 return $this->ui_factory->link()->bulky(
219 $this->buildIcon($title, $icon_name),
220 $title,
221 new URI(ILIAS_HTTP_PATH . '/' . $link)
222 );
223 }
224
225 private function buildIcon(string $title, string $type): CustomIcon
226 {
227 return $this->icon_factory->custom(
228 ilUtil::getImagePath("standard/icon_$type.svg"),
229 $title
230 );
231 }
232
237 private function filterUserFolders(array &$folders): array
238 {
239 $user_folders = [];
240 $filtered_folders = [];
241
242 foreach ($folders as $folder) {
243 if ($folder->isUserFolder()) {
244 $user_folders[] = $folder;
245 continue;
246 }
247
248 $filtered_folders[] = $folder;
249 }
250 $folders = $filtered_folders;
251
252 return $user_folders;
253 }
254}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
factory()
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
__construct(Container $dic, ?UIFactory $ui_factory=null, ?UIRenderer $ui_renderer=null, ?ilObjUser $user=null, ?ilCtrlInterface $ctrl=null, ?HttpWrapper $http_wrapper=null, ?Refinery $refinery=null, ?ilLanguage $lng=null, ?IconFactory $icon_factory=null)
buildItem(string $title, string $icon_name, string $link)
buildFolderLink(int $folderId, string|array $class, ?string $cmd=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
language handling
@ilCtrl_Calls ilMailFolderGUI: ILIAS\User\Profile\PublicProfileGUI
@ilCtrl_Calls ilMailFormGUI: ilMailAttachmentGUI, ilMailSearchGUI, ilMailSearchCoursesGUI,...
final const string MAIL_FORM_TYPE_NEW
@ilCtrl_Calls ilMailGUI: ilMailFolderGUI, ilMailFormGUI, ilContactGUI, ilMailOptionsGUI,...
User class.
Util class various functions, usage as namespace.
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
This describes the behavior of an custom icon.
Definition: Custom.php:27
This is how a factory for icons looks like.
Definition: Factory.php:27
An entity that renders components to a string output.
Definition: Renderer.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$dic
Definition: ltiresult.php:33
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
if(!file_exists('../ilias.ini.php'))
$url
Definition: shib_logout.php:70