Beispiel #1
0
function cegep_dawson_get_create_course_buttons()
{
    global $CFG, $USER;
    $items = array();
    $previous_term_str = '';
    $courseterms = array();
    $enrolments = cegep_local_get_teacher_enrolments($USER->idnumber, cegep_local_current_term());
    foreach ($enrolments as $enrolment) {
        // Skip already displayed courses
        if (in_array($enrolment['coursecode'] . $enrolment['term'], $courseterms)) {
            continue;
        }
        // Check if course title is empty
        if (!empty($enrolment['coursetitle'])) {
            $coursetitle = $enrolment['coursetitle'];
        } else {
            $coursetitle = get_string('cousetitlemissing', 'block_cegep');
        }
        // Display term string
        $current_term_str = cegep_local_term_to_string($enrolment['term']);
        if ($current_term_str != $previous_term_str) {
            $items[] = '<div style="font-weight: bold; font-size: 1.2em;">' . $current_term_str . '</div>';
        }
        $previous_term_str = $current_term_str;
        $items[] = '<form action="' . $CFG->wwwroot . '/blocks/cegep/block_cegep_createcourse.php" method="post" class="form_create">' . '<div class="coursenumber create_button">' . '<input type="hidden" name="coursecode" value="' . $enrolment['coursecode'] . '" />' . '<input type="hidden" name="term" value="' . $enrolment['term'] . '" />' . '<input type="submit" value="' . get_string('create', 'block_cegep') . '" name="submit" style="margin-right: 5px;" />' . $enrolment['coursecode'] . '</div><div class="coursetitle">' . $coursetitle . '</div></form>';
        array_push($courseterms, $enrolment['coursecode'] . $enrolment['term']);
    }
    if (count($enrolments) > 0) {
        $items[] = '<li><a target="_blank" href="' . $CFG->wwwroot . '/help/missing.course.php">Can\'t find your course?</a></li>';
    }
    return $items;
}
 private function get_available_coursegroups_list()
 {
     global $COURSE, $USER;
     $coursegroups_list = array();
     if (!($coursegroups = cegep_local_get_unenrolled_coursegroups($COURSE->idnumber, $USER->idnumber))) {
         return false;
     }
     foreach ($coursegroups as $coursegroup) {
         $coursegroups_list[$coursegroup['id']] = "{$coursegroup['coursecode']} #{$coursegroup['group']} - " . cegep_local_term_to_string($coursegroup['term']) . " ({$coursegroup['numberofstudents']} " . get_string('students', 'block_cegep') . ')';
     }
     return $coursegroups_list;
 }
function cegep_enrol()
{
    global $CFG, $DB, $USER, $COURSE, $OUTPUT, $enroldb, $sisdb;
    $currenttab = 'enrol';
    require 'block_cegep_tabs.php';
    // Set up enrolment form
    require 'block_cegep_enrol_form.php';
    $enrolform = new cegep_enrol_form('block_cegep_enrolment.php?a=enrol&id=' . $COURSE->id . '');
    // Go back to course page if cancelled
    if ($enrolform->is_cancelled()) {
        redirect($CFG->wwwroot . '/course/view.php?id=' . $COURSE->id);
    } elseif ($data = $enrolform->get_data()) {
        $students_enrolled = array();
        foreach ($data->coursegroup as $coursegroup_id) {
            // Enrol selected coursegroup(s)
            if (!($se = cegep_local_enrol_coursegroup($coursegroup_id))) {
                print_error('errorimportingstudentlist', 'block_cegep');
            }
            // Create Moodle group
            if (isset($data->creategroups) && $data->creategroups) {
                $coursegroup = cegep_local_get_coursegroup($coursegroup_id);
                $groupname = sprintf('%s gr.%d %s', $coursegroup['coursecode'], $coursegroup['group'], cegep_local_term_to_string($coursegroup['term']));
                $group = $DB->get_record('groups', array('name' => $groupname), '*');
                if (is_object($group) && isset($group->id)) {
                    $groupid = $group->id;
                } else {
                    $group = new stdClass();
                    $group->courseid = $COURSE->id;
                    $group->name = $groupname;
                    $groupid = groups_create_group($group);
                }
                foreach ($se as $username) {
                    $u = $DB->get_record('user', array('username' => $username), 'id', MUST_EXIST);
                    groups_add_member($groupid, $u->id);
                }
            }
            $students_enrolled += $se;
        }
        // Display nice confirmation with student list and buttons
        echo $OUTPUT->notification(get_string('coursegroupenrolled', 'block_cegep', implode($students_enrolled, '<br />')), 'notifysuccess');
        $linkyes = new moodle_url('block_cegep_enrolment.php', array('a' => 'enrol', 'id' => $COURSE->id));
        $linkno = new moodle_url($CFG->wwwroot . '/course/view.php', array('id' => $COURSE->id));
        echo $OUTPUT->confirm(get_string('enrolanother', 'block_cegep'), $linkyes, $linkno);
    } else {
        echo $OUTPUT->heading(get_string('enrol', 'block_cegep'), 3);
        $enrolform->display();
    }
}