Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
mailboxdirectory.php
1<?php
2
4
7use Bitrix\Mail\MailboxDirectory as MailboxDirectoryManager;
11use JsonSerializable;
12
13class MailboxDirectory extends \Bitrix\Mail\Internals\EO_MailboxDirectory implements JsonSerializable
14{
15 private $children = [];
16
17 public function isSync()
18 {
19 if ((int)$this->getIsSync() === (int)MailboxDirectoryTable::ACTIVE)
20 {
21 return true;
22 }
23
24 return false;
25 }
26
27 public function isDisabled()
28 {
29 if ((int)$this->getIsDisabled() === (int)MailboxDirectoryTable::ACTIVE)
30 {
31 return true;
32 }
33
34 return false;
35 }
36
37 public function isHiddenSystemFolder()
38 {
39 if($this->isDisabled())
40 {
41 if(in_array($this->getPath(),[
42 '[Gmail]',
43 ]))
44 {
45 return true;
46 }
47 }
48
49 return false;
50 }
51
52 public function isSpam()
53 {
54 if ((int)$this->getIsSpam() === (int)MailboxDirectoryTable::ACTIVE)
55 {
56 return true;
57 }
58
59 return false;
60 }
61
62 public function isTrash()
63 {
64 if ((int)$this->getIsTrash() === (int)MailboxDirectoryTable::ACTIVE)
65 {
66 return true;
67 }
68
69 return false;
70 }
71
72 public function isDraft()
73 {
74 if ((int)$this->getIsDraft() === (int)MailboxDirectoryTable::ACTIVE)
75 {
76 return true;
77 }
78
79 return false;
80 }
81
82 public function isOutcome()
83 {
84 if ((int)$this->getIsOutcome() === (int)MailboxDirectoryTable::ACTIVE)
85 {
86 return true;
87 }
88
89 return false;
90 }
91
92 public function isInvisibleToCounters()
93 {
94 if($this->isTrash() || $this->isSpam() || $this->isDraft() || $this->isOutcome())
95 {
96 return true;
97 }
98
99 return false;
100 }
101
102 public function isIncome()
103 {
104 if ((int)$this->getIsIncome() === (int)MailboxDirectoryTable::ACTIVE)
105 {
106 return true;
107 }
108
109 return false;
110 }
111
112 public function hasChildren()
113 {
114 return !empty($this->children);
115 }
116
117 public function getChildren()
118 {
119 return $this->children;
120 }
121
122 public function addChild($dir)
123 {
124 $this->children[] = $dir;
125
126 return $this;
127 }
128
129 public function getCountChildren()
130 {
131 $count = 0;
132
133 foreach ($this->children as $child)
134 {
135 $count++;
136
137 if ($child->hasChildren())
138 {
139 $count += $child->getCountChildren();
140 }
141 }
142
143 return $count;
144 }
145
146 public function getCountSyncChildren()
147 {
148 $count = 0;
149
150 foreach ($this->children as $child)
151 {
152 if ($child->isSync())
153 {
154 $count++;
155 }
156
157 $count += $child->getCountSyncChildren();
158 }
159
160 return $count;
161 }
162
163 public function getFormattedName()
164 {
165 if ($this->getLevel() === 1)
166 {
167 return $this->getName();
168 }
169
170 $path = explode($this->getDelimiter(), $this->getPath());
171
172 return join(' / ', $path);
173 }
174
175 public function getPath($emojiEncode = false)
176 {
177 if(!$emojiEncode)
178 {
179 return parent::getPath();
180 }
181 return Emoji::encode(parent::getPath());
182 }
183
184 public function getName()
185 {
186 $name = $this->sysGetValue('NAME');
187 $level = $this->getLevel();
188
189 if (mb_strtolower($name) == 'inbox' && $level === 1)
190 {
191 return Loc::getMessage('MAIL_CLIENT_INBOX_ALIAS');
192 }
193
194 return $name;
195 }
196
197 public function isSyncLock()
198 {
199 if ($this->getSyncLock() > time() - Mailbox::getTimeout())
200 {
201 return true;
202 }
203
204 return false;
205 }
206
207 public function startSyncLock()
208 {
209 $this->setSyncLock(time());
210
211 if (MailboxDirectoryManager::setSyncLock($this->getId(), $this->getSyncLock()) > 0)
212 {
213 return true;
214 }
215
216 return false;
217 }
218
219 public function stopSyncLock()
220 {
221 $this->unsetSyncLock();
222 $this->setSyncLock(null);
223
224 $this->save();
225 }
226
230 public function jsonSerialize()
231 {
232 return [
233 'ID' => $this->getId(),
234 'MAILBOX_ID' => $this->getMailboxId(),
235 'NAME' => $this->getName(),
236 'FORMATTED_NAME' => $this->getFormattedName(),
237 'PATH' => $this->getPath(),
238 'FLAGS' => $this->getFlags(),
239 'DELIMITER' => $this->getDelimiter(),
240 'DIR_MD5' => $this->getDirMd5(),
241 'LEVEL' => $this->getLevel(),
242 'IS_DISABLED' => $this->isDisabled(),
243 'CHILDREN' => Json::decode(Json::encode($this->getChildren()))
244 ];
245 }
246}
static setSyncLock(int $id, int $time)
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29