Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
mailboxdirectorystorage.php
1<?php
2
4
7
9{
10 private $mailboxId = null;
11 private $data = [];
12
13 public function __construct($mailboxId)
14 {
15 $this->mailboxId = $mailboxId;
16
17 $this->init();
18 }
19
20 public function init()
21 {
22 $items = MailboxDirectory::fetchAll($this->mailboxId);
23
24 $this->set($items);
25 }
26
27 public function set(array $items)
28 {
29 $this->group($items);
30 }
31
32 public function get(string $key, $default = null)
33 {
34 return $this->getData($key, $default);
35 }
36
37 public function getByHash(string $key)
38 {
39 $list = $this->get('hashed', []);
40 return isset($list[$key]) ? $list[$key] : null;
41 }
42
43 public function getByPath(string $key)
44 {
45 $key = Emoji::decode($key);
46 $list = $this->get('all', []);
47 return isset($list[$key]) ? $list[$key] : null;
48 }
49
50 private function has(string $key)
51 {
52 return isset($this->data[$key]);
53 }
54
55 private function remove(string $key)
56 {
57 if (isset($this->data[$key]))
58 {
59 unset($this->data[$key]);
60 }
61 }
62
63 private function reset()
64 {
65 $this->data = [];
66 }
67
68 private function getData(string $key, $default = null)
69 {
70 return $this->has($key) ? $this->data[$key] : $default;
71 }
72
73 private function setData($name, $value)
74 {
75 $this->data[$name] = $value;
76 }
77
78 private function group($items)
79 {
80 $all = [];
81 $income = [];
82 $outcome = [];
83 $spam = [];
84 $trash = [];
85 $draft = [];
86 $hashed = [];
87
88 foreach ($items as $item)
89 {
90 $all[$item->getPath()] = $item;
91 $hashed[$item->getDirMd5()] = $item;
92
93 if ($item->isIncome())
94 {
95 $income[] = $item;
96 }
97
98 if ($item->isOutcome())
99 {
100 $outcome[] = $item;
101 }
102
103 if ($item->isSpam())
104 {
105 $spam[] = $item;
106 }
107
108 if ($item->isDraft())
109 {
110 $draft[] = $item;
111 }
112
113 if ($item->isTrash())
114 {
115 $trash[] = $item;
116 }
117 }
118
119 $this->reset();
120 $this->setData('all', $all);
121 $this->setData('income', $income);
122 $this->setData('outcome', $outcome);
123 $this->setData('spam', $spam);
124 $this->setData('trash', $trash);
125 $this->setData('draft', $draft);
126 $this->setData('hashed', $hashed);
127 }
128}