Beispiel #1
0
/**
 * Notifies that students have not passed their classes via the notifications where applicable,
 * setting enrolment status to failed where applicable
 *
 * @param int $pmuserid  optional userid to update, default(0) updates all users
 */
function pm_update_student_enrolment($pmuserid = 0)
{
    global $DB;
    require_once elispm::lib('data/student.class.php');
    require_once elispm::lib('notifications.php');
    //look for all enrolments where status is incomplete / in progress and end time has passed
    $select = 'completestatusid = :status AND endtime > 0 AND endtime < :time';
    $params = array('status' => STUSTATUS_NOTCOMPLETE, 'time' => time());
    if ($pmuserid) {
        $select .= ' AND userid = :userid';
        $params['userid'] = $pmuserid;
    }
    $students = $DB->get_recordset_select(student::TABLE, $select, $params);
    if (!empty($students)) {
        foreach ($students as $s) {
            // Send notification, if enabled.
            $sendnotification = !empty(elis::$config->local_elisprogram->notify_incompletecourse_user) ? true : false;
            if ($sendnotification === true) {
                $a = $DB->get_field(pmclass::TABLE, 'idnumber', array('id' => $s->classid));
                $message = get_string('incomplete_course_message', 'local_elisprogram', $a);
                $cuser = new user($s->userid);
                $from = get_admin();
                notification::notify($message, $cuser, $from);
            }
            //set status to failed
            $s->completetime = time();
            $s->completestatusid = STUSTATUS_FAILED;
            $stu = new student($s->id);
            $stu->set_from_data($s);
            $stu->update();
        }
    }
    return true;
}
 /**
  *
  */
 function action_updatemultiple()
 {
     global $CURMAN;
     $clsid = $this->required_param('id', PARAM_INT);
     $users = $this->optional_param('users', array());
     foreach ($users as $uid => $user) {
         $sturecord = array();
         $sturecord['id'] = $user['association_id'];
         $sturecord['classid'] = $clsid;
         $sturecord['userid'] = $uid;
         $startyear = $user['startyear'];
         $startmonth = $user['startmonth'];
         $startday = $user['startday'];
         $sturecord['enrolmenttime'] = mktime(0, 0, 0, $startmonth, $startday, $startyear);
         $endyear = $user['endyear'];
         $endmonth = $user['endmonth'];
         $endday = $user['endday'];
         $sturecord['completetime'] = mktime(0, 0, 0, $endmonth, $endday, $endyear);
         $sturecord['completestatusid'] = $user['completestatusid'];
         $sturecord['grade'] = $user['grade'];
         $sturecord['credits'] = $user['credits'];
         $sturecord['locked'] = !empty($user['locked']) ? 1 : 0;
         $stu = new student($sturecord);
         if ($stu->completestatusid == STUSTATUS_PASSED && $CURMAN->db->get_field(STUTABLE, 'completestatusid', 'id', $stu->id) != STUSTATUS_PASSED) {
             $stu->complete();
         } else {
             if (($status = $stu->update()) !== true) {
                 echo cm_error('Record not updated.  Reason: ' . $status->message);
             }
         }
         // Now once we've done all this, delete the student if we've been asked to
         if (isset($user['unenrol']) && cmclasspage::can_enrol_into_class($clsid)) {
             $stu_delete = new student($user['association_id']);
             if (!$stu_delete->delete()) {
                 echo cm_error('Student "name: ' . cm_fullname($stu->user) . '" not unenrolled.');
             }
         }
     }
     $this->action_default();
 }