Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
213 changes: 199 additions & 14 deletions components/ILIAS/Mail/classes/Provider/MailGlobalScreenToolProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,47 +20,232 @@

namespace ILIAS\Mail\Provider;

use ILIAS\GlobalScreen\Scope\Tool\Provider\AbstractDynamicToolProvider;
use ILIAS\GlobalScreen\ScreenContext\Stack\ContextCollection;
use ilCtrlException;
use ilCtrlInterface;
use ILIAS\DI\Container;
use ILIAS\GlobalScreen\Identification\IdentificationInterface;
use ILIAS\GlobalScreen\Scope\Tool\Factory\Tool;
use ILIAS\GlobalScreen\Scope\Tool\Provider\AbstractDynamicToolProvider;
use ILIAS\GlobalScreen\ScreenContext\Stack\CalledContexts;
use ILIAS\UI\Component\Legacy\Content;
use ilMailExplorer;
use ILIAS\GlobalScreen\ScreenContext\Stack\ContextCollection;
use ILIAS\HTTP\Wrapper\WrapperFactory as HttpWrapper;
use ILIAS\Mail\Folder\MailFolderData;
use ILIAS\Refinery\Factory as Refinery;
use ILIAS\UI\Component\Button\Bulky as BulkyButton;
use ILIAS\UI\Component\Clickable;
use ILIAS\UI\Component\Legacy\Content as LegacyContent;
use ILIAS\UI\Component\Symbol\Icon\Custom as CustomIcon;
use ILIAS\UI\Component\Symbol\Icon\Factory as IconFactory;
use ILIAS\UI\Factory as UIFactory;
use ILIAS\UI\Renderer as UIRenderer;
use ilLanguage;
use ilMailAttachmentGUI;
use ilMailbox;
use ilMailFolderGUI;
use ilMailFormGUI;
use ilMailGUI;
use ilMailOptionsGUI;
use ilObjUser;
use ilUtil;

class MailGlobalScreenToolProvider extends AbstractDynamicToolProvider
{
final public const string SHOW_MAIL_FOLDERS_TOOL = 'show_mail_folders_tool';

private UIFactory $ui_factory;
private UIRenderer $ui_renderer;
private ilMailbox $mbox;
private ilObjUser $user;
private ?ilCtrlInterface $ctrl;
private HttpWrapper $http_wrapper;
private Refinery $refinery;
private ilLanguage $lng;
private IconFactory $icon_factory;

public function __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
) {
parent::__construct($dic);
$this->ui_factory = $ui_factory ?? $this->dic->ui()->factory();
$this->ui_renderer = $ui_renderer ?? $this->dic->ui()->renderer();
$this->user = $user ?? $this->dic->user();
$this->ctrl = $ctrl ?? $this->dic->ctrl();
$this->http_wrapper = $http_wrapper ?? $this->dic->http()->wrapper();
$this->refinery = $refinery ?? $this->dic->refinery();
$this->lng = $lng ?? $this->dic->language();
$this->icon_factory = $icon_factory ?? $this->ui_factory->symbol()->icon();

$this->mbox = new ilMailbox($this->user->getId());
}

public function isInterestedInContexts(): ContextCollection
{
return $this->context_collection->main()->repository()->administration();
}

public function getToolsForContextStack(
CalledContexts $called_contexts
): array {
public function getToolsForContextStack(CalledContexts $called_contexts): array
{
$identification = fn($id): IdentificationInterface => $this->identification_provider->contextAwareIdentifier($id);

$tools = [];

$additional_data = $called_contexts->getLast()->getAdditionalData();
if ($additional_data->exists(self::SHOW_MAIL_FOLDERS_TOOL) &&
$additional_data->get(self::SHOW_MAIL_FOLDERS_TOOL) === true) {
$title = $this->dic->language()->txt('mail_folders');
$icon = $this->dic->ui()->factory()->symbol()->icon()->standard('mail', $title);

$tools[] = $this->factory
->tool($identification('mail_folders_tree'))
->withTitle($title)
->withSymbol($icon)
->withContentWrapper(function (): Content {
$exp = new ilMailExplorer(new ilMailGUI(), $this->dic->user()->getId());
->withTitle($this->lng->txt('mail'))
->withSymbol($this->icon_factory->standard('mail', $this->lng->txt('mail')))
->withContentWrapper(function (): LegacyContent {
$current_folder_id = $this->http_wrapper->query()->retrieve(
'mobj_id',
$this->refinery->kindlyTo()->int()
);

return $this->dic->ui()->factory()->legacy()->content($exp->getHTML(true));
$this->ctrl->setParameterByClass(ilMailFormGUI::class, 'type', ilMailFormGUI::MAIL_FORM_TYPE_NEW);

$sub_items = [
$this->buildItem(
$this->lng->txt('mail_new'),
'mail',
$this->buildFolderLink($current_folder_id, ilMailFormGUI::class)
),
...$this->buildSubItems(),
$this->buildItem(
$this->lng->txt('mail_attachments'),
'fils',
$this->buildFolderLink($current_folder_id, [ilMailGUI::class, ilMailAttachmentGUI::class])
)
];

if ($this->dic->settings()->get('show_mail_settings', '0')) {
$sub_items[] = $this->buildItem(
$this->lng->txt("mail_options"),
"adm",
$this->buildFolderLink($current_folder_id, ilMailOptionsGUI::class)
);
}

$item = $this->ui_factory->menu()->drilldown(
$this->lng->txt('mail'),
$sub_items
);
return $this->ui_factory->legacy()->content(
$this->ui_renderer->render($item)
);
});
}

return $tools;
}

/**
* @return Clickable[]
*/
private function buildSubItems(): array
{
$items = [];

$folders = $this->mbox->getSubFolders();
usort(
$folders,
static fn(MailFolderData $a, MailFolderData $b): int => $a->isTrash() && !$b->isUserLocalFolder() ? 1 : 0
);
$user_folders = $this->filterUserFolders($folders);

foreach ($folders as $folder) {
if ($folder->isUserLocalFolder() && $user_folders !== []) {
$icon_name = $folder->getType()->value;
$items[] = $this->ui_factory->menu()->sub(
$folder->getTitle(),
[
$this->buildItem(
$this->lng->txt("mail_main_folder"),
$icon_name,
$this->buildFolderLink($folder->getFolderId(), ilMailFolderGUI::class)
),
...array_map(
function (MailFolderData $folder) use ($icon_name): BulkyButton {
return $this->buildItem(
$folder->getTitle(),
$icon_name,
$this->buildFolderLink($folder->getFolderId(), ilMailFolderGUI::class)
);
},
$user_folders
),
]
);
continue;
}

$items[] = $this->buildItem(
$folder->getTitle(),
$folder->getType()->value,
$this->buildFolderLink($folder->getFolderId(), ilMailFolderGUI::class)
);
}
return $items;
}

/**
* @param class-string|list<class-string> $class
* @throws ilCtrlException
*/
private function buildFolderLink(int $folderId, string|array $class, ?string $cmd = null): string
{
$this->ctrl->setParameterByClass(is_array($class) ? current($class) : $class, 'mobj_id', $folderId);
$url = $this->ctrl->getLinkTargetByClass($class, $cmd);
$this->ctrl->setParameterByClass(is_array($class) ? current($class) : $class, 'mob_id', null);

return $url;
}

private function buildItem(string $title, string $icon_name, string $link): BulkyButton
{
return $this->ui_factory->button()->bulky(
$this->buildIcon($title, $icon_name),
$title,
$link
);
}

private function buildIcon(string $title, string $type): CustomIcon
{
return $this->icon_factory->custom(
ilUtil::getImagePath("standard/icon_$type.svg"),
$title
);
}

/**
* @param MailFolderData[] $folders
* @return MailFolderData[]
*/
private function filterUserFolders(array &$folders): array
{
$user_folders = [];
$filtered_folders = [];

foreach ($folders as $folder) {
if ($folder->isUserFolder()) {
$user_folders[] = $folder;
continue;
}

$filtered_folders[] = $folder;
}
$folders = $filtered_folders;

return $user_folders;
}
}
4 changes: 2 additions & 2 deletions components/ILIAS/Mail/classes/class.ilMailAttachmentGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private function confirmDeleteAttachments(): void
$this->ctrl->redirect($this);
}

$this->tpl->setTitle($this->lng->txt('mail'));
$this->tpl->setTitle($this->lng->txt('mail_attachments'));

$confirmation = new ilConfirmationGUI();
$confirmation->setFormAction($this->ctrl->getFormAction($this, self::CMD_DELETE_ATTACHMENTS));
Expand Down Expand Up @@ -242,7 +242,7 @@ private function deleteAttachmentsCommand(): void

private function showAttachmentsCommand(): void
{
$this->tpl->setTitle($this->lng->txt('mail'));
$this->tpl->setTitle($this->lng->txt('mail_attachments'));

if ($this->mode === AttachmentManagement::CONSUME) {
$this->tabs->clearTargets();
Expand Down
Loading