21 if (!Loader::includeModule(
"search"))
26 $courseId = \CLearnLesson::getLinkedCourse($lessonId);
27 if ($courseId !==
false)
29 $dbCourse = \CCourse::getList(
30 [], [
"ID" => $courseId,
"ACTIVE" =>
"Y",
"ACTIVE_DATE" =>
"Y"]
33 if (!$dbCourse->fetch())
35 \CSearch::deleteIndex(
"learning",
"U\\_".$courseId.
"\\_%");
40 \CSearch::deleteIndex(
"learning",
"U\\_%",
"L".$lessonId,
null);
42 $items = static::getIndexItems($lessonId);
43 foreach ($items as $item)
46 \CSearch::index(
"learning", $item[
"ITEM_ID"], $item);
60 public static function handleReindex($nextStep = [], $callbackObject =
null, $callbackMethod =
"")
64 $indexElementType =
"C";
66 if (isset($nextStep[
"ID"]) && $nextStep[
"ID"] <>
'')
68 $indexElementType = mb_substr($nextStep[
"ID"], 0, 1);
69 $elementStartId = intval(mb_substr($nextStep[
"ID"], 1));
72 if ($indexElementType ===
"C")
74 $dbCourse = \CCourse::getList([
"ID" =>
"ASC"], [
">ID" => $elementStartId]);
75 while ($course = $dbCourse->fetch())
77 $linkedLessonId = \CCourse::courseGetLinkedLesson($course[
"ID"]);
78 if ($linkedLessonId ===
false)
84 $items = static::getIndexItems($linkedLessonId);
86 foreach ($items as $item)
90 $res &= call_user_func(array($callbackObject, $callbackMethod), $item);
100 return (
"C".$course[
"ID"]);
105 $indexElementType =
"U";
109 if ($indexElementType ===
"U")
111 $dbLessons = \CLearnLesson::getList(
112 [
"LESSON_ID" =>
"ASC"],
113 [
"LINKED_LESSON_ID" =>
"",
">LESSON_ID" => $elementStartId]
116 while ($lesson = $dbLessons->fetch())
119 $items = static::getIndexItems($lesson[
"LESSON_ID"]);
121 foreach ($items as $item)
125 $res &= call_user_func(array($callbackObject, $callbackMethod), $item);
135 return (
"U".$lesson[
"LESSON_ID"]);
140 return !empty($result) ? $result :
false;
143 private static function getLessonCourseId($lessonId)
146 $paths = \CLearnLesson::getListOfParentPathes($lessonId);
148 foreach ($paths as $path)
150 $parentLessons = $path->getPathAsArray();
151 foreach ($parentLessons as $parentLessonId)
153 $linkedCourseId = \CLearnLesson::getLinkedCourse($parentLessonId);
155 $linkedCourseId !==
false &&
156 $linkedCourseId > 0 &&
157 !\CLearnLesson::isPublishProhibited($lessonId, $parentLessonId)
160 $ids[] = $linkedCourseId;
168 private static function getIndexItems($lessonId)
170 $dbResult = \CLearnLesson::getList([], [
"=LESSON_ID" => $lessonId,
"ACTIVE" =>
"Y"]);
171 if (!$lesson = $dbResult->fetch())
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);
181 foreach ($lessonCourses as $courseId)
183 if ($lesson[
"DETAIL_TEXT_TYPE"] !==
"text")
185 $detailText = \CSearch::killTags($lesson[
"DETAIL_TEXT"]);
189 $detailText = strip_tags($lesson[
"DETAIL_TEXT"]);
192 $entityType = $isCourseEntity ?
"C" : ($lesson[
"IS_CHILDS"] ?
"H" :
"L");
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
210 private static function getCoursePaths($entityId, $entityType, $courseId)
212 static $courseToSiteCache = [];
214 $courseId = intval($courseId);
217 if (!isset($courseToSiteCache[$courseId]))
219 $rc =
$GLOBALS[
"DB"]->query(
"SELECT SITE_ID FROM b_learn_course_site WHERE COURSE_ID=".$courseId,
true);
225 $courseToSiteCache[$courseId] = [];
226 while ($courseSite = $rc->fetch())
228 $courseToSiteCache[$courseId][] = $courseSite[
"SITE_ID"];
232 if (!isset($courseToSiteCache[$courseId]))
237 $sitePaths = static::getSitePaths();
238 foreach ($courseToSiteCache[$courseId] as $siteId)
240 if (!isset($sitePaths[$siteId]) || !isset($sitePaths[$siteId][$entityType]))
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);
249 $paths[$siteId] = $url;
255 private static function getSitePaths()
264 $sites = \CLang::getList(
"ID",
"ASC", Array(
"TYPE" =>
"C"));
265 while ($site = $sites->fetch())
267 foreach ([
"C",
"H",
"L"] as $entityCode)
269 $path = \CCourse::getSitePathes($site[
"LID"], $entityCode);
270 $paths[$site[
"LID"]][$entityCode] = isset($path[0]) ? $path[0] :
"";