- Модуль: learning
- Путь к файлу: ~/bitrix/modules/learning/classes/general/clearnaccess.php
- Класс: CLearnAccess
- Вызов: CLearnAccess::SetLessonsPermissions
public function SetLessonsPermissions ($in_arPermissions)
{
global $DB;
// Check args
if ( ! is_array($in_arPermissions) )
{
throw new LearnException ('',
LearnException::EXC_ERR_ALL_ACCESS_DENIED
| LearnException::EXC_ERR_ALL_PARAMS);
}
// First request for rights will not use cache (this will refresh cache)
$isUseCacheForRights = false;
$arPermissions = array();
foreach ($in_arPermissions as $in_lessonId => $arPermPairs)
{
if ( ! is_array($arPermPairs) )
{
throw new LearnException ('',
LearnException::EXC_ERR_ALL_ACCESS_DENIED
| LearnException::EXC_ERR_ALL_PARAMS);
}
$lesson_id = self::StrictlyCastToInteger($in_lessonId);
// Ensure, that for all requested lessons there is rights for changing rights.
if ( ! $this->IsLessonAccessible($lesson_id, self::OP_LESSON_MANAGE_RIGHTS, $isUseCacheForRights) )
throw new LearnException ('', LearnException::EXC_ERR_ALL_ACCESS_DENIED);
$isUseCacheForRights = true; // use cache for every next request for rights
// Check params & escape for SQL
$arPermissions[$lesson_id] = array();
foreach ($arPermPairs as $in_subject_id => $in_task_id)
{
$subject_id = $DB->ForSQL($in_subject_id);
$task_id = self::StrictlyCastToInteger($in_task_id);
$arPermissions[$lesson_id][$subject_id] = $task_id;
}
}
// Yes, I know - most of products on MyISAM. So, In God We Trust.
$DB->StartTransaction();
// Process setting permissions
foreach ($arPermissions as $lesson_id => $arPermPairs)
{
$subject_id = $arPerm[0];
$task_id = $arPerm[1];
$rc = $DB->Query(
"DELETE FROM b_learn_rights
WHERE LESSON_ID = $lesson_id", true);
if ($rc === false)
{
$DB->Rollback();
throw new LearnException ('EA_SQLERROR',
LearnException::EXC_ERR_ALL_ACCESS_DENIED
| LearnException::EXC_ERR_ALL_GIVEUP);
}
foreach ($arPermPairs as $subject_id => $task_id)
{
// All data already escaped above!
$rc = $DB->Query(
"INSERT INTO b_learn_rights (LESSON_ID, SUBJECT_ID, TASK_ID)
VALUES (" . $lesson_id . ", '" . $subject_id . "', " . $task_id . ")", true);
if ($rc === false)
{
$DB->Rollback();
throw new LearnException ('EA_SQLERROR',
LearnException::EXC_ERR_ALL_ACCESS_DENIED
| LearnException::EXC_ERR_ALL_GIVEUP);
}
}
}
// Amen
$DB->Commit();
CLearnCacheOfLessonTreeComponent::MarkAsDirty();
}