Ejemplo n.º 1
0
 /**
  * Enrols a user in a track.
  *
  * @param int $userid The user id
  * @param int $trackid The track id
  */
 static function enrol($userid, $trackid)
 {
     global $CURMAN;
     // make sure we don't double-enrol
     if ($CURMAN->db->record_exists(USRTRKTABLE, 'userid', $userid, 'trackid', $trackid)) {
         return false;
     }
     $record = new usertrack();
     $record->userid = $userid;
     $record->trackid = $trackid;
     $record->data_insert_record();
     $user = new user($userid);
     $track = new track($trackid);
     // add the student to the associated curriculum, if they're not already
     // enrolled
     if (!$CURMAN->db->record_exists(CURASSTABLE, 'userid', $userid, 'curriculumid', $track->curid)) {
         $curstu = new curriculumstudent();
         $curstu->userid = $userid;
         $curstu->curriculumid = $track->curid;
         $curstu->completed = 0;
         $curstu->credits = 0;
         $curstu->locked = 0;
         $curstu->add();
     }
     events_trigger('track_assigned', $record);
     /**
      * Get autoenrollable classes in the track.  Classes are autoenrollable
      * if:
      * - the autoenrol flag is set
      * - it is the only class in that course slot for the track
      */
     $sql = 'SELECT classid, courseid ' . 'FROM ' . $CURMAN->db->prefix_table(TRACKCLASSTABLE) . ' ' . 'WHERE trackid = \'' . $trackid . '\' ' . 'GROUP BY courseid ' . 'HAVING COUNT(*) = 1 AND MAX(autoenrol) = 1';
     $classes = $CURMAN->db->get_records_sql($sql);
     if (!empty($classes)) {
         foreach ($classes as $class) {
             // enrol user in each autoenrolable class
             $stu_record = new object();
             $stu_record->userid = $userid;
             $stu_record->classid = $class->classid;
             $stu_record->enrolmenttime = time();
             $enrolment = new student($stu_record);
             // check prerequisites and enrolment limits
             $enrolment->add(array('prereq' => 1, 'waitlist' => 1), true);
         }
     }
     return true;
 }
 protected function process_assignment($data)
 {
     $context = $this->get_context();
     $curid = $data->id;
     foreach ($data->_selection as $userid) {
         $stucur = new curriculumstudent(array('userid' => $userid, 'curriculumid' => $curid));
         $stucur->add();
     }
     $tmppage = $this->get_basepage();
     $tmppage->params['_assign'] = 'assign';
     redirect($tmppage->get_url(), get_string('num_users_assigned', 'block_curr_admin', count($data->_selection)));
 }