ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMailExplorer.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25use ILIAS\Refinery\Factory as Refinery;
26
28{
29 private readonly GlobalHttpState $http;
30 private readonly Refinery $refinery;
31 private int $current_folder_id = 0;
32 private readonly int $root_folder_id;
33 private readonly int $root_node_id;
34
35 public function __construct(ilMailGUI $parent_object, int $usr_id)
36 {
37 global $DIC;
38
39 $this->http = $DIC->http();
40 $this->refinery = $DIC->refinery();
41
42 $this->tree = new ilTree($usr_id);
43 $this->tree->setTableNames('mail_tree', 'mail_obj_data');
44
45 $this->root_folder_id = (new ilMailbox($usr_id))->getRooFolder();
46 $this->root_node_id = $this->tree->readRootId();
47
48 if ($this->root_folder_id !== $this->root_node_id) {
49 $DIC->logger()->mail()->error(
50 'Root folder id {root_folder_id} does not match root node id {root_node_id} for user {usr_id}',
51 [
52 'root_folder_id' => $this->root_folder_id,
53 'root_node_id' => $this->root_node_id,
54 'usr_id' => $usr_id,
55 ]
56 );
57 }
58
59 parent::__construct('mail_exp', $parent_object, '', $this->tree);
60
61 $this->initFolder();
62
63 $this->setSkipRootNode(true);
64 $this->setAjax(false);
65 $this->setOrderField('title,m_type');
66 }
67
68 protected function initFolder(): void
69 {
70 if ($this->http->wrapper()->post()->has('mobj_id')) {
71 $folder_id = $this->http->wrapper()->post()->retrieve('mobj_id', $this->refinery->kindlyTo()->int());
72 } elseif ($this->http->wrapper()->query()->has('mobj_id')) {
73 $folder_id = $this->http->wrapper()->query()->retrieve('mobj_id', $this->refinery->kindlyTo()->int());
74 } else {
75 $folder_id = $this->refinery->byTrying([
76 $this->refinery->kindlyTo()->int(),
77 $this->refinery->always($this->current_folder_id),
78 ])->transform(ilSession::get('mobj_id'));
79 }
80
81 $this->current_folder_id = $folder_id;
82 }
83
89 private function repairRootNode(array $root): array
90 {
91 if (!isset($root['child']) && $this->root_node_id !== $this->root_folder_id) {
92 $root['child'] = $this->root_node_id;
93 $root['obj_id'] = $this->root_node_id;
94 $root['parent'] = 0;
95 $root['depth'] = 1;
96 $root['title'] = 'a_root';
97 $root['m_type'] = 'root';
98 $root['lft'] = 1;
99 $root['rgt'] = PHP_INT_MAX;
100 $root['user_id'] = $this->tree->getTreeId();
101 }
102
103 return $root;
104 }
105
106 public function getTreeLabel(): string
107 {
108 return $this->lng->txt("mail_folders");
109 }
110
111 public function getTreeComponent(): Tree
112 {
113 $f = $this->ui->factory();
114
115 return $f->tree()
116 ->expandable($this->getTreeLabel(), $this)
117 ->withData($this->tree->getChilds($this->root_node_id))
118 ->withHighlightOnNodeClick(false);
119 }
120
121 public function build(
122 Factory $factory,
123 $record,
124 $environment = null
125 ): Node {
126 return parent::build($factory, $record, $environment)
127 ->withHighlighted(
128 $this->current_folder_id === (int) $record['child']
129 );
130 }
131
132 protected function getNodeStateToggleCmdClasses($record): array
133 {
134 return [
135 ilMailGUI::class,
136 ];
137 }
138
139 public function getRootNode(): array
140 {
141 return $this->repairRootNode(parent::getRootNode());
142 }
143
144 public function getNodeContent($a_node): string
145 {
146 $content = ilLegacyFormElementsUtil::prepareFormOutput($a_node['title']);
147
148 if ((int) $a_node['child'] === (int) $this->getNodeId($this->getRootNode())) {
149 $content = $this->lng->txt('mail_folders');
150 } elseif ($a_node['depth'] < 3) {
151 $content = $this->lng->txt('mail_' . $a_node['title']);
152 }
153
154 return $content;
155 }
156
157 public function getNodeIconAlt($a_node): string
158 {
159 return $this->getNodeContent($a_node);
160 }
161
162 public function getNodeIcon($a_node): string
163 {
164 if ((int) $a_node['child'] === (int) $this->getNodeId($this->getRootNode())) {
165 $icon = ilUtil::getImagePath('standard/icon_mail.svg');
166 } else {
167 $icon_type = $a_node['m_type'];
168 if ($a_node['m_type'] === 'user_folder') {
169 $icon_type = 'local';
170 }
171
172 $icon = ilUtil::getImagePath('standard/icon_' . $icon_type . '.svg');
173 }
174
175 return $icon;
176 }
177
178 public function getNodeHref($a_node): string
179 {
180 if ((int) $a_node['child'] === (int) $this->getNodeId($this->getRootNode())) {
181 $a_node['child'] = 0;
182 }
183
184 $this->ctrl->setParameterByClass(ilMailFolderGUI::class, 'mobj_id', $a_node['child']);
185 $href = $this->ctrl->getLinkTargetByClass([ilMailGUI::class, ilMailFolderGUI::class]);
186 $this->ctrl->clearParametersByClass(ilMailFolderGUI::class);
187
188 return $href;
189 }
190}
Builds data types.
Definition: Factory.php:36
static prepareFormOutput($a_str, bool $a_strip=false)
repairRootNode(array $root)
Workaround for: https://mantis.ilias.de/view.php?id=40716.
getNodeHref($a_node)
Get href for node.
getNodeIcon($a_node)
Get node icon path.
readonly Refinery $refinery
build(Factory $factory, $record, $environment=null)
getNodeContent($a_node)
Get content of a node.
__construct(ilMailGUI $parent_object, int $usr_id)
getNodeIconAlt($a_node)
Get node icon alt attribute.
getNodeStateToggleCmdClasses($record)
Should return an array of ilCtrl-enabled command classes which should be used to build the URL for th...
readonly int $root_folder_id
getRootNode()
Get root node.
readonly GlobalHttpState $http
readonly int $root_node_id
@ilCtrl_Calls ilMailGUI: ilMailFolderGUI, ilMailFormGUI, ilContactGUI, ilMailOptionsGUI,...
static get(string $a_var)
Explorer class that works on tree objects (Services/Tree)
setOrderField(string $a_val, bool $a_numeric=false)
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface GlobalHttpState.
This describes a Tree Node.
Definition: Node.php:31
This describes a Tree Control.
Definition: Tree.php:29
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26