예제 #1
0
 /**
  * Perform all necessary tasks to add a student enrolment to the system.
  *
  * @param array $checks what checks to perform before adding enrolling the
  * user.  e.g. array('prereq' => 1, 'waitlist' => 1) will check that
  * prerequisites are satisfied, and that the class is not full
  * @param boolean $notify whether or not notifications should be sent if a
  * check fails
  */
 function add($checks = array(), $notify = false)
 {
     global $CURMAN, $CFG, $USER;
     $status = true;
     if ($CURMAN->db->record_exists(STUTABLE, 'userid', $this->userid, 'classid', $this->classid)) {
         // already enrolled -- pretend we succeeded
         return true;
     }
     // check that the student can be enrolled first
     if (!empty($checks['prereq'])) {
         // check prerequisites
         $cmclass = new cmclass($this->classid);
         // get all the curricula that the user is in
         $curricula = curriculumstudent::get_curricula($this->userid);
         foreach ($curricula as $curriculum) {
             $curcrs = new curriculumcourse();
             $curcrs->courseid = $cmclass->courseid;
             $curcrs->curriculumid = $curriculum->curid;
             if (!$curcrs->prerequisites_satisfied($this->userid)) {
                 // prerequisites not satisfied
                 if ($notify) {
                     $data = new stdClass();
                     $data->userid = $this->userid;
                     $data->classid = $this->classid;
                     //$data->trackid = $trackid;
                     events_trigger('crlm_prereq_unsatisfied', $data);
                 }
                 $status = new Object();
                 $status->message = get_string('unsatisfiedprereqs', 'block_curr_admin');
                 $status->code = 'unsatisfiedprereqs';
                 return $status;
             }
         }
     }
     if (!empty($checks['waitlist'])) {
         // check class enrolment limit
         $cmclass = new cmclass($this->classid);
         $limit = $cmclass->maxstudents;
         if (!empty($limit) && $limit <= student::count_enroled($this->classid)) {
             // class is full
             // put student on wait list
             $wait_list = new waitlist($this);
             $wait_list->timecreated = time();
             $wait_list->position = 0;
             $wait_list->add();
             if ($notify) {
                 $subject = get_string('user_waitlisted', 'block_curr_admin');
                 $a = new object();
                 $a->user = $this->user->idnumber;
                 $a->cmclass = $cmclass->idnumber;
                 $message = get_string('user_waitlisted_msg', 'block_curr_admin', $a);
                 $from = $user = get_admin();
                 notification::notify($message, $user, $from);
                 email_to_user($user, $from, $subject, $message);
             }
             $status = new Object();
             $status->message = get_string('user_waitlisted', 'block_curr_admin');
             $status->code = 'user_waitlisted';
             return $status;
         }
     }
     //set end time based on class duration
     $studentclass = new cmclass($this->classid);
     if (empty($this->endtime)) {
         if (isset($studentclass->duration) && $studentclass->duration) {
             $this->endtime = $this->enrolmenttime + $studentclass->duration;
         } else {
             // no class duration -> no end time
             $this->endtime = 0;
         }
     }
     $status = $this->data_insert_record();
     // TBD: we should check this!
     /// Get the Moodle user ID or create a new account for this user.
     if (!($muserid = cm_get_moodleuserid($this->userid))) {
         $user = new user($this->userid);
         if (!($muserid = $user->synchronize_moodle_user(true, true))) {
             $status = new Object();
             $status->message = get_string('errorsynchronizeuser', 'block_curr_admin');
             $muserid = false;
         }
     }
     /// Enrol them into the Moodle class.
     if ($moodlecourseid = moodle_get_course($this->classid)) {
         if ($mcourse = get_record('course', 'id', $moodlecourseid)) {
             $enrol = $mcourse->enrol;
             if (!$enrol) {
                 $enrol = $CFG->enrol;
             }
             if ($CURMAN->config->restrict_to_elis_enrolment_plugin && $enrol != 'elis') {
                 $status = new Object();
                 $status->message = get_string('error_not_using_elis_enrolment', 'block_curr_admin');
                 return $status;
             }
             $timestart = $this->enrolmenttime;
             $timeend = $this->endtime;
             if ($role = get_default_course_role($mcourse)) {
                 $context = get_context_instance(CONTEXT_COURSE, $mcourse->id);
                 if (!empty($muserid)) {
                     if (!role_assign($role->id, $muserid, 0, $context->id, $timestart, $timeend, 0, 'manual')) {
                         $status = new Object();
                         $status->message = get_string('errorroleassign', 'block_curr_admin');
                     }
                 }
             }
         }
     } else {
         if (!empty($muserid)) {
             $sturole = $CURMAN->config->enrolment_role_sync_student_role;
             // ELIS-2776: must still trigger events for notifications
             $ra = new stdClass();
             $ra->roleid = !empty($sturole) ? $sturole : get_field('role', 'id', 'shortname', 'student');
             $ra->contextid = context_level_base::get_custom_context_level('class', 'block_curr_admin');
             // TBD
             $ra->userid = $muserid;
             $ra->component = '';
             // TBD: 'enrol_elis'
             $ra->itemid = $this->classid;
             // TBD
             $ra->timemodified = time();
             $ra->modifierid = empty($USER->id) ? 0 : $USER->id;
             events_trigger('role_assigned', $ra);
         }
     }
     return $status;
 }
예제 #2
0
 /**
  * Test check_for_completed_nags function with completion time in the past.
  */
 public function test_checkforcompletednagsdate()
 {
     global $DB;
     $dataset = $this->createCsvDataSet(array(user::TABLE => elispm::file('tests/fixtures/pmuser.csv'), curriculum::TABLE => elispm::file('tests/fixtures/curriculum.csv'), curriculumstudent::TABLE => elispm::file('tests/fixtures/curriculum_student.csv'), course::TABLE => elispm::file('tests/fixtures/pmcourse.csv'), curriculumcourse::TABLE => elispm::file('tests/fixtures/curriculum_course.csv'), pmclass::TABLE => elispm::file('tests/fixtures/pmclass.csv'), student::TABLE => elispm::file('tests/fixtures/student.csv')));
     $this->loadDataSet($dataset);
     // Set the course to be required in the program.
     $sql = "UPDATE {" . curriculumcourse::TABLE . "} SET required = 1 WHERE curriculumid = 1 AND courseid = 100";
     $DB->execute($sql);
     // Set the completion time to a month ago and status to completed on the class enrolment.
     $completetime = time() - 2592000;
     $sql = 'UPDATE {' . student::TABLE . '} SET completetime = ' . $completetime . ', completestatusid = 2 WHERE userid = 103 AND classid = 100';
     $DB->execute($sql);
     // Execute check_for_completed_nags.
     $curriculum = new curriculum(1);
     $curriculum->load();
     $result = $curriculum->check_for_completed_nags();
     // Verify completion time in program assignment table.
     $recordset = curriculumstudent::get_curricula(103);
     foreach ($recordset as $record) {
         $this->assertEquals(1, $record->curid);
         $this->assertEquals($completetime, $record->timecompleted);
     }
 }
예제 #3
0
 /**
  * curriculum overview menu
  *
  * @uses $OUTPUT
  * @uses $PAGE
  * @uses $USER
  */
 function display_available()
 {
     // action_available()
     global $OUTPUT, $PAGE, $USER;
     /// This is for a Moodle user, so get the Curriculum user id.
     $cuserid = cm_get_crlmuserid($USER->id);
     $usercurs = curriculumstudent::get_curricula($cuserid);
     if (count($usercurs) > elis::$config->local_elisprogram->catalog_collapse_count) {
         $buttonLabel = get_string('show');
         $extraclass = ' hide';
     } else {
         $buttonLabel = get_string('hide');
         $extraclass = '';
     }
     // Needed for the hide buttons
     $this->include_js();
     // Process this user's curricula in turn, outputting the courses within each.
     if ($usercurs) {
         foreach ($usercurs as $usercur) {
             echo $OUTPUT->heading('<div class="clearfix"></div><div class="headermenu"><script id="curriculum' . $usercur->curid . 'script" type="text/javascript">toggleVisibleInit("curriculum' . $usercur->curid . 'script", "curriculum' . $usercur->curid . 'button", "' . $buttonLabel . '", "Hide", "Show", "curriculum' . $usercur->curid . '");</script></div>' . $usercur->name . ' (' . $usercur->idnumber . ')');
             echo '<div id="curriculum' . $usercur->curid . "\" {$this->div_attrs} " . '" class="yui-skin-sam' . $extraclass . '">';
             if ($courses = user::get_user_course_curriculum($cuserid, $usercur->curid)) {
                 echo "<div id=\"{$usercur->id}\"></div>";
                 $table = new availablecoursetable($courses, $cuserid);
                 $table->print_yui_table('curriculum' . $usercur->curid);
             } else {
                 echo '<p>' . get_string('nocoursesinthiscurriculum', 'local_elisprogram') . '</p>';
             }
             echo '</div>';
         }
     } else {
         echo $OUTPUT->heading(get_string('nocoursesinthiscurriculum', 'local_elisprogram'));
     }
     echo '<br/>';
     echo $OUTPUT->box(get_string('lp_curriculum_instructions', 'local_elisprogram'), 'generalbox lp_instructions');
 }
 /**
  * curriculum overview menu
  *
  * @global object $CFG
  * @global object $USER
  * @global object $CURMAN
  */
 function action_available()
 {
     global $CFG, $USER, $CURMAN;
     /// This is for a Moodle user, so get the Curriculum user id.
     $cuserid = cm_get_crlmuserid($USER->id);
     $usercurs = curriculumstudent::get_curricula($cuserid);
     if (count($usercurs) > $CURMAN->config->catalog_collapse_count) {
         $buttonLabel = get_string('show', 'block_curr_admin');
         $extraclass = ' hide';
     } else {
         $buttonLabel = get_string('hide', 'block_curr_admin');
         $extraclass = '';
     }
     require_js($CFG->wwwroot . '/curriculum/js/util.js');
     $this->include_yui();
     // Process this user's curricula in turn, outputting the courses within each.
     if ($usercurs) {
         foreach ($usercurs as $usercur) {
             print_heading('<div class="clearfix"></div><div class="headermenu"><script id="curriculum' . $usercur->curid . 'script" type="text/javascript">toggleVisibleInit("curriculum' . $usercur->curid . 'script", "curriculum' . $usercur->curid . 'button", "' . $buttonLabel . '", "Hide", "Show", "curriculum' . $usercur->curid . '");</script></div>' . $usercur->name . ' (' . $usercur->idnumber . ')');
             echo '<div id="curriculum' . $usercur->curid . '" class="yui-skin-sam ' . $extraclass . '">';
             if ($courses = user::get_user_course_curriculum($cuserid, $usercur->curid)) {
                 echo "<div id=\"{$usercur->id}\"></div>";
                 $table = new availablecoursetable($courses);
                 $table->print_yui_table($usercur->id);
             } else {
                 echo '<p>' . get_string('nocoursesinthiscurriculum', 'block_curr_admin') . '</p>';
             }
             echo '</div>';
         }
     } else {
         print_heading(get_string('nocoursesinthiscurriculum', 'block_curr_admin'));
     }
     echo '<br/>';
     print_box(get_string('lp_curriculum_instructions', 'block_curr_admin'), 'generalbox lp_instructions');
 }