コード例 #1
0
/**
 * A convenience function to take care of the common case where you
 * just want to enrol someone using the default role into a course
 *
 * @param object $course
 * @param object $user
 * @param string $enrol - the plugin used to do this enrolment
 */
function enrol_into_course($course, $user, $enrol)
{
    $timestart = time();
    // remove time part from the timestamp and keep only the date part
    $timestart = make_timestamp(date('Y', $timestart), date('m', $timestart), date('d', $timestart), 0, 0, 0);
    if ($course->enrolperiod) {
        $timeend = $timestart + $course->enrolperiod;
    } else {
        $timeend = 0;
    }
    if ($role = get_default_course_role($course)) {
        $context = get_context_instance(CONTEXT_COURSE, $course->id);
        if (!role_assign($role->id, $user->id, 0, $context->id, $timestart, $timeend, 0, $enrol)) {
            return false;
        }
        // force accessdata refresh for users visiting this context...
        mark_context_dirty($context->path);
        email_welcome_message_to_user($course, $user);
        add_to_log($course->id, 'course', 'enrol', 'view.php?id=' . $course->id, $course->id);
        return true;
    }
    return false;
}
コード例 #2
0
ファイル: accesslib.php プロジェクト: veritech/pare-project
/**
 * A convenience function to take care of the common case where you
 * just want to enrol someone using the default role into a course
 *
 * @param object $course
 * @param object $user
 * @param string $enrol - the plugin used to do this enrolment
 */
function enrol_into_course($course, $user, $enrol)
{
    if ($course->enrolperiod) {
        $timestart = time();
        $timeend = time() + $course->enrolperiod;
    } else {
        $timestart = $timeend = 0;
    }
    if ($role = get_default_course_role($course)) {
        $context = get_context_instance(CONTEXT_COURSE, $course->id);
        if (!role_assign($role->id, $user->id, 0, $context->id, $timestart, $timeend, 0, $enrol)) {
            return false;
        }
        email_welcome_message_to_user($course, $user);
        add_to_log($course->id, 'course', 'enrol', 'view.php?id=' . $course->id, $user->id);
        return true;
    }
    return false;
}