1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
clearnlessontree.php
См. документацию.
1<?php
3{
4 protected $arTree = NULL;
5 protected $arLessonsInTree = array(); // Array of ids of lessons already pushed to tree
6 protected $arLessonsAsList = array(); // Lessons' tree in list mode (with depth)
7 protected $arLessonsAsListOldMode = array(); // Lessons' tree in list mode (with depth) - in old compatibility mode
8 protected $arPublishProhibitedLessons = array(); // Lessons that are prohibited for publish (setted only if publishProhibitionMode enabled)
9
22 public function __construct ($rootLessonId, $arOrder = null, $arFilter = array(), $publishProhibitionMode = true, $arSelectFields = array())
23 {
24 $this->EnsureStrictlyCastableToInt ($rootLessonId); // throws an exception on error
25 if ($arOrder === null)
26 $arOrder = array ('EDGE_SORT' => 'asc');
27
28 if (is_array($arSelectFields) && (count($arSelectFields) > 0))
29 {
30 $arFieldsMustBeSelected = array ('LESSON_ID', 'EDGE_SORT', 'IS_CHILDS');
31 foreach ($arFieldsMustBeSelected as $fieldName)
32 {
33 if ( ! in_array($fieldName, $arSelectFields) )
34 $arSelectFields[] = $fieldName;
35 }
36 }
37
38 $publishProhibitionContext = false;
39
40 if ($publishProhibitionMode)
41 {
42 $publishProhibitionContext = (int) $rootLessonId;
43
44 global $DB;
45 $rc = $DB->Query (
46 "SELECT PROHIBITED_LESSON_ID
47 FROM b_learn_publish_prohibition
48 WHERE COURSE_LESSON_ID = $publishProhibitionContext",
49 true // ignore errors
50 );
51
52 if ($rc === false)
53 throw new LearnException ('EA_SQLERROR', LearnException::EXC_ERR_ALL_GIVEUP);
54
55 while ($arData = $rc->Fetch())
56 $this->arPublishProhibitedLessons[] = (int) $arData['PROHIBITED_LESSON_ID'];
57 }
58
59 $arCurrentPath = array($rootLessonId);
60 $this->arTree = $this->BuildTreeRecursive(
61 $rootLessonId,
62 $arOrder,
63 $arFilter,
64 0,
65 NULL,
66 $arSelectFields,
67 $arCurrentPath
68 );
69 }
70
97 public function GetTree ()
98 {
99 return ($this->arTree);
100 }
101
126 public function GetTreeAsList()
127 {
128 return ($this->arLessonsAsList);
129 }
130
131
137 public function GetTreeAsListOldMode()
138 {
139 return ($this->arLessonsAsListOldMode);
140 }
141
142
148 public function GetLessonsIdListInTree()
149 {
150 return ($this->arLessonsInTree);
151 }
152
153
159 protected function BuildTreeRecursive ($rootLessonId, $arOrder, $arFilter, $depth = 0, $parentChapterId = NULL, $arSelectFields, $arRootPath)
160 {
161 $oPath = new CLearnPath();
162 $arLessons = array();
163
164 $CDBResult = CLearnLesson::GetListOfImmediateChilds($rootLessonId, $arOrder, $arFilter, $arSelectFields);
165 while (($arData = $CDBResult->Fetch()) !== false)
166 {
167 // Skip lessons that are already in tree (prevent cycling)
168 if ( in_array($arData['LESSON_ID'], $this->arLessonsInTree) )
169 continue;
170
171 // Skip lessons prohibited for publishing
172 if (in_array( (int) $arData['LESSON_ID'], $this->arPublishProhibitedLessons, true))
173 continue;
174
175 // Path as array for current LESSON_ID
176 $arCurrentLessonPath = $arRootPath;
177 $arCurrentLessonPath[] = (int) $arData['LESSON_ID'];
178 $oPath->SetPathFromArray($arCurrentLessonPath);
179 $strUrlencodedCurrentLessonPath = $oPath->ExportUrlencoded();
180
181
182 // Register lesson
183 $this->arLessonsInTree[] = $arData['LESSON_ID'];
184 $this->arLessonsAsList[] = array_merge(
185 $arData,
186 array(
187 '#DEPTH_IN_TREE' => $depth,
188 '#LESSON_PATH' => $strUrlencodedCurrentLessonPath
189 )
190 );
191
192 // hack: we don't know yet, what index name must be for element in array.
193 // And we must preserve order in array elements (for compatibility).
194 // But we will know index name after BuildTreeRecursive will be called, which
195 // adds to array new elements. So create bother elements, and after remove unneeded.
196 $this->arLessonsAsListOldMode['LE' . $arData['LESSON_ID']] = array();
197 $this->arLessonsAsListOldMode['CH' . $arData['LESSON_ID']] = array();
198
199 $item = $arData;
200 $item['#childs'] = array();
201 $lessonType_oldDataModel = 'LE';
202
203 if ($arData['IS_CHILDS'])
204 {
205 $lessonType_oldDataModel = 'CH';
206 $item['#childs'] = $this->BuildTreeRecursive (
207 $arData['LESSON_ID'],
208 $arOrder,
209 $arFilter,
210 $depth + 1,
211 $arData['LESSON_ID'],
212 $arSelectFields,
213 $arCurrentLessonPath
214 );
215
216 // It still can be zero childs due to $arFilter, publish prohibition or prevent cycling instead of non-zero $arData['IS_CHILDS']
217 if (count($item['#childs']) == 0)
218 $lessonType_oldDataModel = 'LE';
219 }
220
221 // remove unneeded element caused by hack above
222 if ($lessonType_oldDataModel === 'LE')
223 unset($this->arLessonsAsListOldMode['CH' . $arData['LESSON_ID']]);
224 else
225 unset($this->arLessonsAsListOldMode['LE' . $arData['LESSON_ID']]);
226
227 $this->arLessonsAsListOldMode[$lessonType_oldDataModel . $arData['LESSON_ID']] = array_merge(
228 $arData,
229 array(
230 'ID' => $arData['LESSON_ID'],
231 'CHAPTER_ID' => $parentChapterId,
232 'SORT' => $arData['EDGE_SORT'],
233 'TYPE' => $lessonType_oldDataModel,
234 'DEPTH_LEVEL' => $depth + 1,
235 '#LESSON_PATH' => $strUrlencodedCurrentLessonPath
236 )
237 );
238
239 $arLessons[] = $item;
240 }
241
242 return ($arLessons);
243 }
244
245 protected function EnsureStrictlyCastableToInt ($i)
246 {
247 if ( ( ! is_numeric($i) )
248 || ( ! is_int($i + 0) )
249 )
250 {
251 throw new LearnException ('Non-strictly casts to integer: ' . htmlspecialcharsbx($i),
254 }
255 }
256}
static GetListOfImmediateChilds($lessonId, $arOrder=array(), $arFilter=array(), $arSelectFields=array(), $arNavParams=array())
Определения clearnlesson.php:1855
$arLessonsAsListOldMode
Определения clearnlessontree.php:7
GetLessonsIdListInTree()
Определения clearnlessontree.php:148
GetTree()
Определения clearnlessontree.php:97
GetTreeAsList()
Определения clearnlessontree.php:126
EnsureStrictlyCastableToInt($i)
Определения clearnlessontree.php:245
$arLessonsInTree
Определения clearnlessontree.php:5
__construct($rootLessonId, $arOrder=null, $arFilter=array(), $publishProhibitionMode=true, $arSelectFields=array())
Определения clearnlessontree.php:22
GetTreeAsListOldMode()
Определения clearnlessontree.php:137
$arLessonsAsList
Определения clearnlessontree.php:6
BuildTreeRecursive($rootLessonId, $arOrder, $arFilter, $depth=0, $parentChapterId=NULL, $arSelectFields, $arRootPath)
Определения clearnlessontree.php:159
$arPublishProhibitedLessons
Определения clearnlessontree.php:8
Определения clearnpath.php:79
Определения learnexception.php:4
const EXC_ERR_ALL_PARAMS
Определения learnexception.php:7
const EXC_ERR_ALL_LOGIC
Определения learnexception.php:5
const EXC_ERR_ALL_GIVEUP
Определения learnexception.php:6
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
global $DB
Определения cron_frame.php:29
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701
$i
Определения factura.php:643
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$arFilter
Определения user_search.php:106