Beispiel #1
0
/**
 * Get course/profile right
 *
 * @param integer $profileId profile identifier
 * @param integer $courseId course identifier
 * @return array ['tool_id']['action_name'] value
 */
function claro_get_course_profile_right($profileId = null, $courseId = null)
{
    $courseProfileRightList = null;
    static $cachedProfileId = null;
    static $cachedCourseId = null;
    static $cachedCourseProfileRightList = null;
    // load courseId
    if (is_null($courseId)) {
        if (claro_is_in_a_course()) {
            $courseId = claro_get_current_course_id();
        } else {
            return false;
        }
    }
    // load profile id
    if (is_null($profileId)) {
        if (!empty($GLOBALS['_profileId'])) {
            $profileId = $GLOBALS['_profileId'];
        } else {
            return false;
        }
    }
    if (!empty($cachedCourseProfileRightList) && $cachedProfileId == $profileId && $cachedCourseId == $courseId) {
        $courseProfileRightList = $cachedCourseProfileRightList;
    }
    if (empty($courseProfileRightList)) {
        $profile = new RightProfile();
        if ($profile->load($profileId)) {
            $courseProfileToolRight = new RightCourseProfileToolRight();
            $courseProfileToolRight->setCourseId($courseId);
            $courseProfileToolRight->load($profile);
            $courseProfileRightList = $courseProfileToolRight->getToolActionList();
            // cache for the next time ...
            $cachedProfileId = $profileId;
            $cachedCourseId = $courseId;
            $cachedCourseProfileRightList = $courseProfileRightList;
        } else {
            return false;
        }
    }
    return $courseProfileRightList;
}
Beispiel #2
0
//=================================
// Main section
//=================================
$cmd = isset($_REQUEST['cmd']) ? $_REQUEST['cmd'] : null;
$display_profile = isset($_REQUEST['display_profile']) ? $_REQUEST['display_profile'] : null;
$profile_id = isset($_REQUEST['profile_id']) ? $_REQUEST['profile_id'] : null;
$tool_id = isset($_REQUEST['tool_id']) ? $_REQUEST['tool_id'] : null;
$right_value = isset($_REQUEST['right_value']) ? $_REQUEST['right_value'] : null;
if (!empty($profile_id)) {
    // load profile
    $profile = new RightProfile();
    if ($profile->load($profile_id)) {
        // load profile tool right
        $courseProfileRight = new RightCourseProfileToolRight();
        $courseProfileRight->setCourseId(claro_get_current_course_id());
        $courseProfileRight->load($profile);
        if (!$profile->isLocked()) {
            if ($cmd == 'set_right' && !empty($tool_id)) {
                $courseProfileRight->setToolRight($tool_id, $right_value);
                $courseProfileRight->save();
            }
        }
    } else {
        $profile_id = null;
    }
}
//---------------------------------
// Build list of profile to display
//---------------------------------
$display_profile_list = array();
$display_profile_url_param = null;