- Модуль: learning
- Путь к файлу: ~/bitrix/modules/learning/classes/general/clearnaccess.php
- Класс: CLearnAccess
- Вызов: CLearnAccess::SetBasePermissions
public function SetBasePermissions ($in_arPermPairs)
{
global $DB, $USER;
// Check args
if ( ! is_array($in_arPermPairs) )
{
throw new LearnException ('',
LearnException::EXC_ERR_ALL_ACCESS_DENIED
| LearnException::EXC_ERR_ALL_PARAMS);
}
// Check & escape for SQL
$arPermPairs = array();
foreach ($in_arPermPairs as $in_subject_id => $in_task_id)
{
$subject_id = $DB->ForSQL($in_subject_id);
$task_id = self::StrictlyCastToInteger($in_task_id);
$arPermPairs[$subject_id] = $task_id;
}
// Check rights (we can access only if is admin and logged in)
if ( ! (self::IsLoggedUserCanAccessModuleSettings()
&& ( ((int) $USER->GetID()) === $this->userId) )
)
{
throw new LearnException ('',
LearnException::EXC_ERR_ALL_ACCESS_DENIED);
}
// Yes, I know - most of products on MyISAM. So, In God We Trust.
$DB->StartTransaction();
$rc = $DB->Query(
"DELETE FROM b_learn_rights_all
WHERE 1=1", 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_all (SUBJECT_ID, TASK_ID)
VALUES ('" . $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();
}