ILIAS  release_8 Revision v8.24
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{
30 private Refinery $refinery;
31 private int $currentFolderId = 0;
32 private int $root_folder_id;
33 private int $root_node_id;
34
35 public function __construct(ilMailGUI $parentObject, int $userId)
36 {
37 global $DIC;
38
39 $this->http = $DIC->http();
40 $this->refinery = $DIC->refinery();
41
42 $this->tree = new ilTree($userId);
43 $this->tree->setTableNames('mail_tree', 'mail_obj_data');
44
45 $this->root_folder_id = (new ilMailbox($userId))->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 $this->root_folder_id does not match root node id $this->root_node_id for user $userId"
51 );
52 }
53
54 parent::__construct('mail_exp', $parentObject, '', $this->tree);
55
56 $this->initFolder();
57
58 $this->setSkipRootNode(true);
59 $this->setAjax(false);
60 $this->setOrderField('title,m_type');
61 }
62
63 protected function initFolder(): void
64 {
65 if ($this->http->wrapper()->post()->has('mobj_id')) {
66 $folderId = $this->http->wrapper()->post()->retrieve('mobj_id', $this->refinery->kindlyTo()->int());
67 } elseif ($this->http->wrapper()->query()->has('mobj_id')) {
68 $folderId = $this->http->wrapper()->query()->retrieve('mobj_id', $this->refinery->kindlyTo()->int());
69 } else {
70 $folderId = $this->refinery->byTrying([
71 $this->refinery->kindlyTo()->int(),
72 $this->refinery->always($this->currentFolderId),
73 ])->transform(ilSession::get('mobj_id'));
74 }
75
76 $this->currentFolderId = $folderId;
77 }
78
84 private function repairRootNode(array $root): array
85 {
86 if (!isset($root['child']) && $this->root_node_id !== $this->root_folder_id) {
87 $root['child'] = $this->root_node_id;
88 $root['obj_id'] = $this->root_node_id;
89 $root['parent'] = 0;
90 $root['depth'] = 1;
91 $root['title'] = 'a_root';
92 $root['m_type'] = 'root';
93 $root['lft'] = 1;
94 $root['rgt'] = PHP_INT_MAX;
95 $root['user_id'] = $this->tree->getTreeId();
96 }
97
98 return $root;
99 }
100
101 public function getTreeLabel(): string
102 {
103 return $this->lng->txt("mail_folders");
104 }
105
106 public function getTreeComponent(): Tree
107 {
108 $f = $this->ui->factory();
109
110 return $f->tree()
111 ->expandable($this->getTreeLabel(), $this)
112 ->withData($this->tree->getChilds($this->root_node_id))
113 ->withHighlightOnNodeClick(false);
114 }
115
116 public function build(
118 $record,
119 $environment = null
120 ): Node {
121 return parent::build($factory, $record, $environment)
122 ->withHighlighted(
123 $this->currentFolderId === (int) $record['child']
124 );
125 }
126
127 protected function getNodeStateToggleCmdClasses($record): array
128 {
129 return [
130 ilMailGUI::class,
131 ];
132 }
133
134 public function getRootNode(): array
135 {
136 return $this->repairRootNode(parent::getRootNode());
137 }
138
139 public function getNodeContent($a_node): string
140 {
141 $content = ilLegacyFormElementsUtil::prepareFormOutput($a_node['title']);
142
143 if ((int) $a_node['child'] === (int) $this->getNodeId($this->getRootNode())) {
144 $content = $this->lng->txt('mail_folders');
145 } elseif ($a_node['depth'] < 3) {
146 $content = $this->lng->txt('mail_' . $a_node['title']);
147 }
148
149 return $content;
150 }
151
152 public function getNodeIconAlt($a_node): string
153 {
154 return $this->getNodeContent($a_node);
155 }
156
157 public function getNodeIcon($a_node): string
158 {
159 if ((int) $a_node['child'] === (int) $this->getNodeId($this->getRootNode())) {
160 $icon = ilUtil::getImagePath('icon_mail.svg');
161 } else {
162 $iconType = $a_node['m_type'];
163 if ($a_node['m_type'] === 'user_folder') {
164 $iconType = 'local';
165 }
166
167 $icon = ilUtil::getImagePath('icon_' . $iconType . '.svg');
168 }
169
170 return $icon;
171 }
172
173 public function getNodeHref($a_node): string
174 {
175 if ((int) $a_node['child'] === (int) $this->getNodeId($this->getRootNode())) {
176 $a_node['child'] = 0;
177 }
178
179 $this->ctrl->setParameterByClass(ilMailFolderGUI::class, 'mobj_id', $a_node['child']);
180 $href = $this->ctrl->getLinkTargetByClass([ilMailGUI::class, ilMailFolderGUI::class]);
181 $this->ctrl->clearParametersByClass(ilMailFolderGUI::class);
182
183 return $href;
184 }
185}
Builds data types.
Definition: Factory.php:21
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.
build(Factory $factory, $record, $environment=null)
getNodeContent($a_node)
Get content of a node.
GlobalHttpState $http
__construct(ilMailGUI $parentObject, int $userId)
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...
getRootNode()
Get root node.
Mail Box class Base class for creating and handling mail boxes.
static get(string $a_var)
Explorer class that works on tree objects (Services/Tree)
setOrderField(string $a_val, bool $a_numeric=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
global $DIC
Definition: feed.php:28
Interface GlobalHttpState.
This describes a Tree Node.
Definition: Node.php:31
This describes a Tree Control.
Definition: Tree.php:29
$factory
Definition: metadata.php:75
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc