Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
folder.php
1<?php
2namespace Bitrix\Landing;
3
5{
10 public static $internalClass = 'FolderTable';
11
17 public static function deleteForSite(int $siteId): void
18 {
19 $res = self::getList([
20 'select' => [
21 'ID'
22 ],
23 'filter' => [
24 'SITE_ID' => $siteId
25 ]
26 ]);
27 while ($row = $res->fetch())
28 {
29 parent::delete($row['ID']);
30 }
31 }
32
39 public static function changeSiteIdRecursive(int $folderId, int $newSiteId)
40 {
41 // move sub folders
42 $res = self::getList([
43 'select' => [
44 'ID'
45 ],
46 'filter' => [
47 'PARENT_ID' => $folderId
48 ]
49 ]);
50 while ($row = $res->fetch())
51 {
52 $resAffected = self::update($row['ID'], [
53 'SITE_ID' => $newSiteId
54 ]);
55 if ($resAffected->isSuccess())
56 {
57 self::changeSiteIdRecursive($row['ID'], $newSiteId);
58 }
59 }
60
61 // move sub landings
62 $res = Landing::getList([
63 'select' => [
64 'ID'
65 ],
66 'filter' => [
67 'FOLDER_ID' => $folderId
68 ]
69 ]);
70 while ($row = $res->fetch())
71 {
72 Landing::update($row['ID'], [
73 'SITE_ID' => $newSiteId
74 ]);
75 }
76
77 }
78
85 public static function getSubFolderIds(int $folderId): array
86 {
87 $ids = [];
88
89 $res = self::getList([
90 'select' => ['ID'],
91 'filter' => [
92 'PARENT_ID' => $folderId,
93 ],
94 ]);
95 while ($row = $res->fetch())
96 {
97 array_push($ids, $row['ID'], ...self::getSubFolderIds($row['ID']));
98 }
99
100 return $ids;
101 }
102
109 public static function getFolderIdsForSite(int $siteId, array $additionalFilter = []): array
110 {
111 $return = [];
112 $additionalFilter['SITE_ID'] = $siteId;
113
114 $res = self::getList([
115 'select' => [
116 'ID'
117 ],
118 'filter' => $additionalFilter
119 ]);
120 while ($row = $res->fetch())
121 {
122 $return[] = $row['ID'];
123 }
124
125 return $return;
126 }
127
134 public static function getBreadCrumbs(int $folderId, ?int $siteId = null): array
135 {
136 static $cacheFolders = [];
137 $crumbs = [];
138
139 if (!$siteId)
140 {
141 $res = self::getList([
142 'select' => [
143 'SITE_ID'
144 ],
145 'filter' => [
146 'ID' => $folderId
147 ],
148 'limit' => 1
149 ]);
150 if ($row = $res->fetch())
151 {
152 $siteId = $row['SITE_ID'];
153 }
154 }
155
156 if (!$siteId)
157 {
158 return $crumbs;
159 }
160
161 // get all folder's chunks for the site
162 if (!array_key_exists($siteId, $cacheFolders))
163 {
164 $cacheFolders[$siteId] = [];
165 $res = self::getList([
166 'select' => [
167 'ID', 'TITLE', 'INDEX_ID', 'CODE',
168 'PARENT_ID', 'ACTIVE', 'DELETED'
169 ],
170 'filter' => [
171 'SITE_ID' => $siteId
172 ]
173 ]);
174 while ($row = $res->fetch())
175 {
176 $cacheFolders[$siteId][$row['ID']] = $row;
177 }
178 }
179
180 if (!$cacheFolders[$siteId])
181 {
182 return $crumbs;
183 }
184
185 // build recursively
186 $folders = $cacheFolders[$siteId];
187 do
188 {
189 if (!isset($folders[$folderId]))
190 {
191 break;
192 }
193 $crumbs[] = $folders[$folderId];
194 $folderId = $folders[$folderId]['PARENT_ID'];
195 }
196 while ($folderId);
197
198 return array_reverse($crumbs);
199 }
200
208 public static function getBreadCrumbsString(int $folderId, string $glue, ?int $siteId = null): string
209 {
210 $path = [];
211 $crumbs = self::getBreadCrumbs($folderId, $siteId);
212 foreach ($crumbs as $crumb)
213 {
214 $path[] = $crumb['TITLE'];
215 }
216 return implode($glue, $path);
217 }
218
226 public static function getFullPath(int $folderId, ?int $siteId = null, array &$lastFolder = []): string
227 {
228 $codes = [];
229
230 foreach (self::getBreadCrumbs($folderId, $siteId) as $folder)
231 {
232 $lastFolder = $folder;
233 $codes[] = $folder['CODE'];
234 }
235
236 return '/' . implode('/', $codes) . '/';
237 }
238}
static changeSiteIdRecursive(int $folderId, int $newSiteId)
Definition folder.php:39
static getFullPath(int $folderId, ?int $siteId=null, array &$lastFolder=[])
Definition folder.php:226
static getBreadCrumbs(int $folderId, ?int $siteId=null)
Definition folder.php:134
static getBreadCrumbsString(int $folderId, string $glue, ?int $siteId=null)
Definition folder.php:208
static getSubFolderIds(int $folderId)
Definition folder.php:85
static getFolderIdsForSite(int $siteId, array $additionalFilter=[])
Definition folder.php:109
static deleteForSite(int $siteId)
Definition folder.php:17
static update($primary, array $data)
Definition file.php:228
static getList(array $parameters=array())