Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
search.php
1<?
2
4
6
7class Search
8{
19 public static function indexLesson($lessonId)
20 {
21 if (!Loader::includeModule("search"))
22 {
23 return;
24 }
25
26 $courseId = \CLearnLesson::getLinkedCourse($lessonId);
27 if ($courseId !== false)
28 {
29 $dbCourse = \CCourse::getList(
30 [], ["ID" => $courseId, "ACTIVE" => "Y", "ACTIVE_DATE" => "Y"]
31 );
32
33 if (!$dbCourse->fetch())
34 {
35 \CSearch::deleteIndex("learning", "U\\_".$courseId."\\_%");
36 return;
37 }
38 }
39
40 \CSearch::deleteIndex("learning", "U\\_%", "L".$lessonId, null);
41
42 $items = static::getIndexItems($lessonId);
43 foreach ($items as $item)
44 {
45 unset($item["ID"]); //CSearchCallback uses ID, but CSearch::index throws a MYSQL Error
46 \CSearch::index("learning", $item["ITEM_ID"], $item);
47 }
48 }
49
60 public static function handleReindex($nextStep = [], $callbackObject = null, $callbackMethod = "")
61 {
62 $result = array();
63 $elementStartId = 0;
64 $indexElementType = "C"; // start reindex from courses
65
66 if (isset($nextStep["ID"]) && $nextStep["ID"] <> '')
67 {
68 $indexElementType = mb_substr($nextStep["ID"], 0, 1);
69 $elementStartId = intval(mb_substr($nextStep["ID"], 1));
70 }
71
72 if ($indexElementType === "C")
73 {
74 $dbCourse = \CCourse::getList(["ID" => "ASC"], [">ID" => $elementStartId]);
75 while ($course = $dbCourse->fetch())
76 {
77 $linkedLessonId = \CCourse::courseGetLinkedLesson($course["ID"]);
78 if ($linkedLessonId === false)
79 {
80 continue;
81 }
82
83 $res = true;
84 $items = static::getIndexItems($linkedLessonId);
85
86 foreach ($items as $item)
87 {
88 if ($callbackObject)
89 {
90 $res &= call_user_func(array($callbackObject, $callbackMethod), $item);
91 }
92 else
93 {
94 $result[] = $item;
95 }
96 }
97
98 if (!$res)
99 {
100 return ("C".$course["ID"]);
101 }
102 }
103
104 // Reindex of courses finished. Let's reindex lessons now.
105 $indexElementType = "U";
106 $elementStartId = 0;
107 }
108
109 if ($indexElementType === "U")
110 {
111 $dbLessons = \CLearnLesson::getList(
112 ["LESSON_ID" => "ASC"],
113 ["LINKED_LESSON_ID" => "", ">LESSON_ID" => $elementStartId]
114 );
115
116 while ($lesson = $dbLessons->fetch())
117 {
118 $res = true;
119 $items = static::getIndexItems($lesson["LESSON_ID"]);
120
121 foreach ($items as $item)
122 {
123 if ($callbackObject)
124 {
125 $res &= call_user_func(array($callbackObject, $callbackMethod), $item);
126 }
127 else
128 {
129 $result[] = $item;
130 }
131 }
132
133 if (!$res)
134 {
135 return ("U".$lesson["LESSON_ID"]);
136 }
137 }
138 }
139
140 return !empty($result) ? $result : false;
141 }
142
143 private static function getLessonCourseId($lessonId)
144 {
145 $ids = [];
146 $paths = \CLearnLesson::getListOfParentPathes($lessonId);
147
148 foreach ($paths as $path)
149 {
150 $parentLessons = $path->getPathAsArray();
151 foreach ($parentLessons as $parentLessonId)
152 {
153 $linkedCourseId = \CLearnLesson::getLinkedCourse($parentLessonId);
154 if (
155 $linkedCourseId !== false &&
156 $linkedCourseId > 0 &&
157 !\CLearnLesson::isPublishProhibited($lessonId, $parentLessonId)
158 )
159 {
160 $ids[] = $linkedCourseId;
161 }
162 }
163 }
164
165 return $ids;
166 }
167
168 private static function getIndexItems($lessonId)
169 {
170 $dbResult = \CLearnLesson::getList([], ["=LESSON_ID" => $lessonId, "ACTIVE" => "Y"]);
171 if (!$lesson = $dbResult->fetch())
172 {
173 return [];
174 }
175
176 $permissions = \CLearnAccess::getSymbolsAccessibleToLesson($lessonId, \CLearnAccess::OP_LESSON_READ);
177 $isCourseEntity = intval($lesson["LINKED_LESSON_ID"]) > 0;
178 $lessonCourses = $isCourseEntity ? [$lesson["COURSE_ID"]] : static::getLessonCourseId($lessonId);
179
180 $result = [];
181 foreach ($lessonCourses as $courseId)
182 {
183 if ($lesson["DETAIL_TEXT_TYPE"] !== "text")
184 {
185 $detailText = \CSearch::killTags($lesson["DETAIL_TEXT"]);
186 }
187 else
188 {
189 $detailText = strip_tags($lesson["DETAIL_TEXT"]);
190 }
191
192 $entityType = $isCourseEntity ? "C" : ($lesson["IS_CHILDS"] ? "H" : "L");
193 $result[] = [
194 "ID" => "U_".$courseId."_".$lesson["LESSON_ID"],
195 "ITEM_ID" => "U_".$courseId."_".$lesson["LESSON_ID"],
196 "PARAM1" => "L".$lesson["LESSON_ID"],
197 "PARAM2" => "C".$courseId,
198 "LAST_MODIFIED" => $lesson["TIMESTAMP_X"],
199 "TITLE" => $lesson["NAME"],
200 "BODY" => $detailText <> '' ? $detailText : $lesson["NAME"],
201 "SITE_ID" => static::getCoursePaths($lesson["LESSON_ID"], $entityType, $courseId),
202 "PERMISSIONS" => $permissions
203 ];
204
205 }
206
207 return $result;
208 }
209
210 private static function getCoursePaths($entityId, $entityType, $courseId)
211 {
212 static $courseToSiteCache = [];
213
214 $courseId = intval($courseId);
215 $paths = [];
216
217 if (!isset($courseToSiteCache[$courseId]))
218 {
219 $rc = $GLOBALS["DB"]->query("SELECT SITE_ID FROM b_learn_course_site WHERE COURSE_ID=".$courseId, true);
220 if ($rc === false)
221 {
222 return $paths;
223 }
224
225 $courseToSiteCache[$courseId] = [];
226 while ($courseSite = $rc->fetch())
227 {
228 $courseToSiteCache[$courseId][] = $courseSite["SITE_ID"];
229 }
230 }
231
232 if (!isset($courseToSiteCache[$courseId]))
233 {
234 return $paths;
235 }
236
237 $sitePaths = static::getSitePaths();
238 foreach ($courseToSiteCache[$courseId] as $siteId)
239 {
240 if (!isset($sitePaths[$siteId]) || !isset($sitePaths[$siteId][$entityType]))
241 {
242 continue;
243 }
244
245 $url = str_replace("#COURSE_ID#", $courseId, $sitePaths[$siteId][$entityType]);
246 $url = str_replace("#CHAPTER_ID#", "0".$entityId, $url);
247 $url = str_replace("#LESSON_ID#", $entityId, $url);
248
249 $paths[$siteId] = $url;
250 }
251
252 return $paths;
253 }
254
255 private static function getSitePaths()
256 {
257 static $paths = [];
258
259 if (!empty($paths))
260 {
261 return $paths;
262 }
263
264 $sites = \CLang::getList("ID", "ASC", Array("TYPE" => "C"));
265 while ($site = $sites->fetch())
266 {
267 foreach (["C", "H", "L"] as $entityCode)
268 {
269 $path = \CCourse::getSitePathes($site["LID"], $entityCode);
270 $paths[$site["LID"]][$entityCode] = isset($path[0]) ? $path[0] : "";
271 }
272 }
273
274 return $paths;
275 }
276}
static handleReindex($nextStep=[], $callbackObject=null, $callbackMethod="")
Definition search.php:60
static indexLesson($lessonId)
Definition search.php:19
$GLOBALS['____1979065141']
Definition mutator.php:1