function OnSearchReindex($NS = array(), $oCallback = null, $callback_method = '') { global $DB; $arResult = array(); $arAllSitesPathes = array(); $oPath = new CLearnPath(); $elementStartId = 0; $indexElementType = 'C'; // start reindex from courses $by = $order = ''; $lastProcessedCourseId = false; $sites = CLang::GetList($by, $order, array('TYPE' => 'C')); while ($site = $sites->Fetch()) { $arAllSitesPathes[$site['LID']] = array('C' => CCourse::GetSitePathes($site['LID'], 'C'), 'H' => CCourse::GetSitePathes($site['LID'], 'H'), 'L' => CCourse::GetSitePathes($site['LID'], 'L')); } $arCoursesFilter = array(); $arLessonsFilter = array('LINKED_LESSON_ID' => ''); if ($NS['MODULE'] === 'learning' && strlen($NS['ID']) > 0) { $indexElementType = substr($NS['ID'], 0, 1); $elementStartId = (int) substr($NS['ID'], 1); if (strlen($NS['SITE_ID']) > 0) { $arCoursesFilter['SITE_ID'] = $NS['SITE_ID']; } } $arCoursesFilter['>ID'] = $elementStartId; if ($indexElementType === 'C') { $rsCourse = CCourse::GetList(array('ID' => 'ASC'), $arCoursesFilter); while ($arCourse = $rsCourse->Fetch()) { try { $arCourse["SITE_ID"] = CCourse::GetSiteId($arCourse['ID']); $arPathes = $arAllSitesPathes[$arCourse['SITE_ID']]['C']; $linkedLessonId = CCourse::CourseGetLinkedLesson($arCourse['ID']); $arGroupPermissions = CLearnAccess::GetSymbolsAccessibleToLesson($linkedLessonId, CLearnAccess::OP_LESSON_READ); } catch (LearnException $e) { continue; // skip indexation of this item } $arSiteIds = array(); foreach ($arPathes as $k => $path) { $arCourse["PATH"] = $path; $Url = str_replace("#COURSE_ID#", $arCourse["ID"], $arCourse["PATH"]); $arSiteIds[$arCourse['SITE_ID']] = $Url; } $lastProcessedCourseId = $arCourse['ID']; $detailText = ''; if ($arCourse["DETAIL_TEXT_TYPE"] !== 'text') { $detailText = CSearch::KillTags($arCourse['DETAIL_TEXT']); } else { $detailText = strip_tags($arCourse['DETAIL_TEXT']); } $dataBody = ''; if (strlen($detailText) > 0) { $dataBody = $detailText; } else { $dataBody = $arCourse['NAME']; } $Result = array("ID" => "C" . $arCourse["ID"], "LAST_MODIFIED" => $arCourse["TIMESTAMP_X"], "TITLE" => $arCourse["NAME"], "BODY" => $dataBody, "SITE_ID" => $arSiteIds, "PERMISSIONS" => $arGroupPermissions, "COURSE_ID" => "C" . $arCourse["ID"]); if ($oCallback) { $res = call_user_func(array($oCallback, $callback_method), $Result); if (!$res) { return "C" . $arCourse["ID"]; } } else { $arResult[] = $Result; } } // Reindex of courses finished. Let's reindex lessons now. $indexElementType = 'U'; $elementStartId = 0; } $arLessonsFilter['>LESSON_ID'] = $elementStartId; if ($indexElementType === 'U') { $rsLessons = CLearnLesson::GetList(array('LESSON_ID' => 'ASC'), $arLessonsFilter); $arLessonsWithCourse = array(); // list of lessons in context of some course while ($arLesson = $rsLessons->Fetch()) { $arOParentPathes = CLearnLesson::GetListOfParentPathes($arLesson['LESSON_ID']); foreach ($arOParentPathes as $oParentPath) { $mostParentLesson = $oParentPath->GetTop(); $linkedCourseId = CLearnLesson::GetLinkedCourse($mostParentLesson); if ($linkedCourseId !== false) { $arLessonsWithCourse[] = array_merge($arLesson, array('PARENT_COURSE_ID' => $linkedCourseId)); } } } foreach ($arLessonsWithCourse as $arLesson) { try { $arGroupPermissions = CLearnAccess::GetSymbolsAccessibleToLesson($arLesson['LESSON_ID'], CLearnAccess::OP_LESSON_READ); $arSiteIds = array(); $lessonType = 'L'; if ($arLesson['IS_CHILDS']) { $lessonType = 'H'; } foreach ($arAllSitesPathes as $siteId => $arSitePathesByLessonType) { foreach ($arSitePathesByLessonType as $someLessonType => $arPathes) { // skip wrong types of lessons if ($lessonType !== $someLessonType) { continue; } foreach ($arPathes as $k => $path) { $oPath->SetPath($arLesson['LESSON_ID']); if ($lessonType == 'H') { $Url = str_replace("#CHAPTER_ID#", '0' . $arLesson['LESSON_ID'], $path); } else { $Url = str_replace("#LESSON_ID#", $arLesson['LESSON_ID'], $path); } $Url = str_replace("#COURSE_ID#", $arLesson['PARENT_COURSE_ID'], $Url); $arSiteIds[$siteId] = $Url; } } } } catch (LearnException $e) { continue; // skip indexation of this item } $detailText = ''; if ($arLesson["DETAIL_TEXT_TYPE"] !== 'text') { $detailText = CSearch::KillTags($arLesson['DETAIL_TEXT']); } else { $detailText = strip_tags($arLesson['DETAIL_TEXT']); } $dataBody = ''; if (strlen($detailText) > 0) { $dataBody = $detailText; } else { $dataBody = $arLesson['NAME']; } $Result = array("ID" => 'U' . $arLesson['LESSON_ID'], "LAST_MODIFIED" => $arLesson['TIMESTAMP_X'], "TITLE" => $arLesson['NAME'], "BODY" => $dataBody, "SITE_ID" => $arSiteIds, "PERMISSIONS" => $arGroupPermissions); if ($oCallback) { $res = call_user_func(array($oCallback, $callback_method), $Result); if (!$res) { return 'U' . $arLesson['LESSON_ID']; } } else { $arResult[] = $Result; } } } if ($oCallback) { $rc = false; } else { $rc = $arResult; } return $rc; }