public static function enrol_user_with_start_and_end_date($username, $id, $roleid, $start_date, $end_date)
 {
     global $CFG, $DB;
     $params = self::validate_parameters(self::enrol_user_with_start_and_end_date_parameters(), array('username' => $username, 'id' => $id, 'roleid' => $roleid, 'start_date' => $start_date, 'end_date' => $end_date));
     $auth = new auth_plugin_joomdle();
     $id = $auth->enrol_user($username, $id, $roleid, $start_date, $end_date);
     return $id;
 }
Exemple #2
0
function joomdle_role_assigned($role)
{
    global $CFG, $DB;
    $activities = get_config('auth/joomdle', 'jomsocial_activities');
    $groups = get_config('auth/joomdle', 'jomsocial_groups');
    $enrol_parents = get_config('auth/joomdle', 'enrol_parents');
    $parent_role_id = get_config('auth/joomdle', 'parent_role_id');
    $points = get_config('auth/joomdle', 'give_points');
    $auto_mailing_lists = get_config('auth/joomdle', 'auto_mailing_lists');
    $use_kunena_forums = get_config('auth/joomdle', 'use_kunena_forums');
    $joomla_user_groups = get_config('auth/joomdle', 'joomla_user_groups');
    $auth_joomdle = new auth_plugin_joomdle();
    $context = get_context_instance_by_id($role->contextid);
    /* If a course enrolment, publish */
    if ($context->contextlevel == CONTEXT_COURSE) {
        $courseid = $context->instanceid;
        $conditions = array('id' => $courseid);
        $course = $DB->get_record('course', $conditions);
        $conditions = array('id' => $course->category);
        $cat = $DB->get_record('course_categories', $conditions);
        $conditions = array('id' => $role->userid);
        $user = $DB->get_record('user', $conditions);
        // Jomsocial activity
        if ($activities) {
            //$this->call_method ('addActivityCourseEnrolment', $user->username, (int) $courseid, $course->fullname, (int) $course->category, $cat->name);
            $auth_joomdle->call_method('addActivityCourseEnrolment', $user->username, (int) $courseid, $course->fullname, (int) $course->category, $cat->name);
        }
        // Join Jomsocial group
        if ($groups) {
            /* Join teachers as group admins, and students as regular members */
            if ($role->roleid == 3) {
                //XXX not hardcoded value?
                $auth_joomdle->call_method('addJSGroupMember', $course->fullname, $user->username, 1, (int) $courseid);
            } else {
                $auth_joomdle->call_method('addJSGroupMember', $course->fullname, $user->username, -1, (int) $courseid);
            }
        }
        // Enrol parents
        if ($enrol_parents && $parent_role_id) {
            if ($role->roleid == 5) {
                /* Get mentors for the student */
                $usercontext = get_context_instance(CONTEXT_USER, $role->userid);
                $usercontextid = $usercontext->id;
                $query = "SELECT userid\n\t\t\t\t\t    FROM\n\t\t\t\t\t\t{$CFG->prefix}role_assignments\n\t\t\t\t\t    WHERE\n\t\t\t\t\t\troleid = ? and contextid = ?\n\t\t\t\t\t\t";
                $params = array($parent_role_id, $usercontextid);
                $mentors = $DB->get_records_sql($query, $params);
                foreach ($mentors as $mentor) {
                    /* Enrol as parent into course*/
                    //role_assign($parent_role_id, $mentor->userid, $context->id );
                    $conditions = array('id' => $mentor->userid);
                    $parent_user = $DB->get_record('user', $conditions);
                    $auth_joomdle->enrol_user($parent_user->username, $courseid, $parent_role_id);
                }
            }
        }
        if ($points) {
            $auth_joomdle->call_method('addPoints', 'joomdle.enrol', $user->username, (int) $courseid, $course->fullname);
        }
        if ($auto_mailing_lists) {
            $type = '';
            if ($role->roleid == 3) {
                $type = 'course_teachers';
            } else {
                if ($role->roleid == 5) {
                    $type = 'course_students';
                    /* Get mentors for the student */
                    $usercontext = get_context_instance(CONTEXT_USER, $role->userid);
                    $usercontextid = $usercontext->id;
                    $query = "SELECT userid\n\t\t\t\t\t    FROM\n\t\t\t\t\t\t{$CFG->prefix}role_assignments\n\t\t\t\t\t    WHERE\n\t\t\t\t\t\troleid = ? and contextid = ?\n\t\t\t\t\t\t";
                    $params = array($parent_role_id, $usercontextid);
                    $mentors = $DB->get_records_sql($query, $params);
                    foreach ($mentors as $mentor) {
                        $conditions = array('id' => $mentor->userid);
                        $parent_user = $DB->get_record('user', $conditions);
                        $auth_joomdle->call_method('addMailingSub', $parent_user->username, (int) $courseid, 'course_parents');
                    }
                }
            }
            if ($type) {
                $auth_joomdle->call_method('addMailingSub', $user->username, (int) $courseid, $type);
            }
        }
        if ($joomla_user_groups) {
            $type = '';
            if ($role->roleid == 3) {
                $type = 'teachers';
            } else {
                if ($role->roleid == 5) {
                    $type = 'students';
                }
            }
            if ($type) {
                $auth_joomdle->call_method('addGroupMember', (int) $courseid, $user->username, $type);
            }
        }
        if ($use_kunena_forums) {
            if ($role->roleid == 3) {
                $auth_joomdle->call_method('addForumsModerator', (int) $courseid, $user->username);
            }
        }
    }
    return true;
}