ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilMailExplorer.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 
28 {
29  private readonly GlobalHttpState $http;
30  private readonly Refinery $refinery;
31  private int $currentFolderId = 0;
32  private readonly 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 {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' => $userId,
55  ]
56  );
57  }
58 
59  parent::__construct('mail_exp', $parentObject, '', $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  $folderId = $this->http->wrapper()->post()->retrieve('mobj_id', $this->refinery->kindlyTo()->int());
72  } elseif ($this->http->wrapper()->query()->has('mobj_id')) {
73  $folderId = $this->http->wrapper()->query()->retrieve('mobj_id', $this->refinery->kindlyTo()->int());
74  } else {
75  $folderId = $this->refinery->byTrying([
76  $this->refinery->kindlyTo()->int(),
77  $this->refinery->always($this->currentFolderId),
78  ])->transform(ilSession::get('mobj_id'));
79  }
80 
81  $this->currentFolderId = $folderId;
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->currentFolderId === (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  $iconType = $a_node['m_type'];
168  if ($a_node['m_type'] === 'user_folder') {
169  $iconType = 'local';
170  }
171 
172  $icon = ilUtil::getImagePath('standard/icon_' . $iconType . '.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 }
static get(string $a_var)
This describes a Tree Node.
Definition: Node.php:30
build(Factory $factory, $record, $environment=null)
static prepareFormOutput($a_str, bool $a_strip=false)
__construct(ilMailGUI $parentObject, int $userId)
withHighlighted(bool $expanded)
Set $highlighted to true to have this node highlighted on loading.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
readonly GlobalHttpState $http
static http()
Fetches the global http state from ILIAS.
Mail Box class Base class for creating and handling mail boxes.
readonly int $root_folder_id
readonly Refinery $refinery
global $DIC
Definition: shib_login.php:22
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
getNodeId($a_node)
Get id for node.
getNodeStateToggleCmdClasses($record)
This describes a Tree Control.
Definition: Tree.php:28
repairRootNode(array $root)
Workaround for: https://mantis.ilias.de/view.php?id=40716.
Explorer class that works on tree objects (Services/Tree)
__construct(Container $dic, ilPlugin $plugin)
setOrderField(string $a_val, bool $a_numeric=false)