ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
MailGlobalScreenToolProvider.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
31use ILIAS\HTTP\Wrapper\WrapperFactory as HttpWrapper;
34use ILIAS\UI\Component\Button\Bulky as BulkyButton;
36use ILIAS\UI\Component\Legacy\Content as LegacyContent;
39use ILIAS\UI\Factory as UIFactory;
40use ILIAS\UI\Renderer as UIRenderer;
41use ilLanguage;
43use ilMailbox;
46use ilMailGUI;
48use ilObjUser;
49use ilUtil;
50
52{
53 final public const string SHOW_MAIL_FOLDERS_TOOL = 'show_mail_folders_tool';
54
55 private readonly UIFactory $ui_factory;
56 private readonly UIRenderer $ui_renderer;
57 private readonly ilMailbox $mbox;
58 private readonly ilObjUser $user;
59 private readonly ?ilCtrlInterface $ctrl;
60 private readonly HttpWrapper $http_wrapper;
61 private readonly Refinery $refinery;
62 private readonly ilLanguage $lng;
63 private readonly IconFactory $icon_factory;
64
65 public function __construct(
67 ?UIFactory $ui_factory = null,
68 ?UIRenderer $ui_renderer = null,
69 ?ilObjUser $user = null,
70 ?ilCtrlInterface $ctrl = null,
71 ?HttpWrapper $http_wrapper = null,
72 ?Refinery $refinery = null,
73 ?ilLanguage $lng = null,
74 ?IconFactory $icon_factory = null
75 ) {
77 $this->ui_factory = $ui_factory ?? $this->dic->ui()->factory();
78 $this->ui_renderer = $ui_renderer ?? $this->dic->ui()->renderer();
79 $this->user = $user ?? $this->dic->user();
80 $this->ctrl = $ctrl ?? $this->dic->ctrl();
81 $this->http_wrapper = $http_wrapper ?? $this->dic->http()->wrapper();
82 $this->refinery = $refinery ?? $this->dic->refinery();
83 $this->lng = $lng ?? $this->dic->language();
84 $this->icon_factory = $icon_factory ?? $this->ui_factory->symbol()->icon();
85
86 $this->mbox = new ilMailbox($this->user->getId());
87 }
88
90 {
91 return $this->context_collection->main()->repository()->administration();
92 }
93
94 public function getToolsForContextStack(CalledContexts $called_contexts): array
95 {
96 $identification = fn($id): IdentificationInterface => $this->identification_provider->contextAwareIdentifier($id);
97
98 $tools = [];
99
100 $additional_data = $called_contexts->getLast()->getAdditionalData();
101 if ($additional_data->exists(self::SHOW_MAIL_FOLDERS_TOOL) &&
102 $additional_data->get(self::SHOW_MAIL_FOLDERS_TOOL) === true) {
103
104 $tools[] = $this->factory
105 ->tool($identification('mail_folders_tree'))
106 ->withTitle($this->lng->txt('mail'))
107 ->withSymbol($this->icon_factory->standard('mail', $this->lng->txt('mail')))
108 ->withContentWrapper(function (): LegacyContent {
109 $current_folder_id = $this->http_wrapper->query()->retrieve(
110 'mobj_id',
111 $this->refinery->kindlyTo()->int()
112 );
113
114 $this->ctrl->setParameterByClass(ilMailFormGUI::class, 'type', ilMailFormGUI::MAIL_FORM_TYPE_NEW);
115
116 $sub_items = [
117 $this->buildItem(
118 $this->lng->txt('mail_new'),
119 'mail',
120 $this->buildFolderLink($current_folder_id, ilMailFormGUI::class)
121 ),
122 ...$this->buildSubItems(),
123 $this->buildItem(
124 $this->lng->txt('mail_attachments'),
125 'attach',
126 $this->buildFolderLink($current_folder_id, [ilMailGUI::class, ilMailAttachmentGUI::class])
127 )
128 ];
129
130 if ($this->dic->settings()->get('show_mail_settings', '0')) {
131 $sub_items[] = $this->buildItem(
132 $this->lng->txt('mail_options'),
133 'adm',
134 $this->buildFolderLink($current_folder_id, ilMailOptionsGUI::class)
135 );
136 }
137
138 $item = $this->ui_factory->menu()->drilldown(
139 $this->lng->txt('mail'),
140 $sub_items
141 );
142
143 return $this->ui_factory->legacy()->content(
144 $this->ui_renderer->render($item)
145 );
146 });
147 }
148
149 return $tools;
150 }
151
155 private function buildSubItems(): array
156 {
157 $items = [];
158
159 $folders = $this->mbox->getSubFolders();
160 usort(
161 $folders,
162 static fn(MailFolderData $a, MailFolderData $b): int => $a->isTrash() && !$b->isUserLocalFolder() ? 1 : 0
163 );
164 $user_folders = $this->filterUserFolders($folders);
165
166 foreach ($folders as $folder) {
167 if ($folder->isUserLocalFolder() && $user_folders !== []) {
168 $icon_name = $folder->getType()->value;
169 $items[] = $this->ui_factory->menu()->sub(
170 $folder->getTitle(),
171 [
172 $this->buildItem(
173 $this->lng->txt('mail_main_folder'),
174 $icon_name,
175 $this->buildFolderLink($folder->getFolderId(), ilMailFolderGUI::class)
176 ),
177 ...array_map(
178 function (MailFolderData $folder) use ($icon_name): BulkyButton {
179 return $this->buildItem(
180 $folder->getTitle(),
181 $icon_name,
182 $this->buildFolderLink($folder->getFolderId(), ilMailFolderGUI::class)
183 );
184 },
185 $user_folders
186 ),
187 ]
188 );
189 continue;
190 }
191
192 $items[] = $this->buildItem(
193 $folder->getTitle(),
194 $folder->getType()->value,
195 $this->buildFolderLink($folder->getFolderId(), ilMailFolderGUI::class)
196 );
197 }
198
199 return $items;
200 }
201
206 private function buildFolderLink(int $folderId, string|array $class, ?string $cmd = null): string
207 {
208 $this->ctrl->setParameterByClass(is_array($class) ? current($class) : $class, 'mobj_id', $folderId);
209 $url = $this->ctrl->getLinkTargetByClass($class, $cmd);
210 $this->ctrl->setParameterByClass(is_array($class) ? current($class) : $class, 'mob_id', null);
211
212 return $url;
213 }
214
215 private function buildItem(string $title, string $icon_name, string $link): BulkyButton
216 {
217 return $this->ui_factory->button()->bulky(
218 $this->buildIcon($title, $icon_name),
219 $title,
220 $link
221 );
222 }
223
224 private function buildIcon(string $title, string $type): CustomIcon
225 {
226 return $this->icon_factory->custom(
227 ilUtil::getImagePath("standard/icon_$type.svg"),
228 $title
229 );
230 }
231
236 private function filterUserFolders(array &$folders): array
237 {
238 $user_folders = [];
239 $filtered_folders = [];
240
241 foreach ($folders as $folder) {
242 if ($folder->isUserFolder()) {
243 $user_folders[] = $folder;
244 continue;
245 }
246
247 $filtered_folders[] = $folder;
248 }
249 $folders = $filtered_folders;
250
251 return $user_folders;
252 }
253}
$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
__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 a bulky button.
Definition: Bulky.php:29
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:68