示例#1
0
 public function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     if (!empty($data['timetocomplete'])) {
         if (!datedelta::validate($data['timetocomplete'])) {
             $errors['timetocomplete'] = get_string('error_not_timeformat', 'local_elisprogram');
         } else {
             $datedelta = new datedelta($data['timetocomplete']);
             if ($datedelta->is_zero() || !$datedelta->getDateString()) {
                 $errors['timetocomplete'] = get_string('error_invalid_timeperiod', 'local_elisprogram');
             }
         }
     }
     if (!empty($data['frequency'])) {
         if (!datedelta::validate($data['frequency'])) {
             $errors['frequency'] = get_string('error_not_timeformat', 'local_elisprogram');
         } else {
             $datedelta = new datedelta($data['frequency']);
             if ($datedelta->is_zero() || !$datedelta->getDateString()) {
                 $errors['frequency'] = get_string('error_invalid_timeperiod', 'local_elisprogram');
             }
         }
     }
     if (!empty($data['idnumber'])) {
         if (!$this->check_unique(curriculum::TABLE, 'idnumber', $data['idnumber'], $data['id'])) {
             $errors['idnumber'] = get_string('badidnumber', 'local_elisprogram');
         }
     }
     $errors += parent::validate_custom_fields($data, 'curriculum');
     return $errors;
 }
示例#2
0
 public function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     $errors += parent::validate_custom_fields($data, 'cluster');
     return $errors;
 }
示例#3
0
 /**
  *  make sure the start time is before the end time and the start date is before the end date for the class
  * @param array $data
  * @param mixed $files
  * @return array
  */
 function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     if (!empty($data['idnumber'])) {
         if (!$this->check_unique(track::TABLE, 'idnumber', $data['idnumber'], $data['id'])) {
             $errors['idnumber'] = get_string('badidnumber', 'local_elisprogram');
         }
     }
     if (!empty($data['startdate']) && !empty($data['enddate']) && !empty($data['disablestart']) && !empty($data['disableend'])) {
         if ($data['startdate'] > $data['enddate']) {
             $errors['startdate'] = get_string('error_date_range', 'local_elisprogram');
         }
     }
     $errors += parent::validate_custom_fields($data, 'track');
     return $errors;
 }
示例#4
0
 /**
  *  make sure the start time is before the end time and the start date is before the end date for the class
  * @param array $data
  * @param mixed $files
  * @return array
  */
 function validation($data, $files)
 {
     global $DB;
     $errors = parent::validation($data, $files);
     $sql = 'idnumber = ?';
     $params = array($data['idnumber']);
     if ($data['id']) {
         $sql .= ' AND id != ?';
         $params[] = $data['id'];
     }
     if ($DB->record_exists_select(pmclass::TABLE, $sql, $params)) {
         $errors['idnumber'] = get_string('idnumber_already_used', 'local_elisprogram');
     }
     if (isset($data['starttime']) && isset($data['endtime'])) {
         if ($data['starttime'] > $data['endtime']) {
             $errors['starttime'] = get_string('error_duration', 'local_elisprogram');
         }
         if (!empty($data['startdate']) && !empty($data['enddate']) && !empty($data['disablestart']) && !empty($data['disableend'])) {
             if ($data['startdate'] > $data['enddate']) {
                 $errors['start'] = get_string('error_date_range', 'local_elisprogram');
             }
         }
     }
     if (!empty($this->_customdata['obj']) && !empty($this->_customdata['obj']->maxstudents)) {
         if ($data['maxstudents'] < $this->_customdata['obj']->maxstudents && $data['maxstudents'] < student::count_enroled($this->_customdata['obj']->id)) {
             $context = context_system::instance();
             if (!has_capability('local/elisprogram:overrideclasslimit', $context)) {
                 $errors['maxstudents'] = get_string('error_n_overenrol', 'local_elisprogram');
             }
         }
     }
     $errors += parent::validate_custom_fields($data, 'class');
     return $errors;
 }
示例#5
0
 function validation($data, $files)
 {
     global $CFG, $DB;
     $errors = parent::validation($data, $files);
     // Use a default for 'id' if we're doing an add
     if (!$data['id']) {
         $data['id'] = 0;
     }
     if (!empty($data['username'])) {
         if (!$this->check_unique(user::TABLE, 'username', $data['username'], $data['id'])) {
             $errors['username_group'] = get_string('badusername', 'local_elisprogram');
         }
     } else {
         if (!$data['id'] && empty($data['id_same_user'])) {
             $errors['username_group'] = get_string('required');
         }
     }
     if (!empty($data['idnumber'])) {
         if (!$this->check_unique(user::TABLE, 'idnumber', $data['idnumber'], $data['id'])) {
             $errors['idnumber'] = get_string('badidnumber', 'local_elisprogram');
         } else {
             //make sure we don't set up an idnumber that is related to a non-linked Moodle user
             require_once elispm::lib('data/usermoodle.class.php');
             if (!($muserid = $DB->get_field(usermoodle::TABLE, 'muserid', array('cuserid' => $data['id'])))) {
                 $muserid = 0;
             }
             if (!$this->check_unique('user', 'idnumber', $data['idnumber'], $muserid)) {
                 $errors['idnumber'] = get_string('badidnumbermoodle', 'local_elisprogram');
             }
         }
     }
     // Validate the supplied email addresses as best we can...
     if (!empty($data['email'])) {
         if (!$this->check_unique(user::TABLE, 'email', $data['email'], $data['id'])) {
             $errors['email'] = get_string('emailexists');
         }
     }
     if (!empty($data['email2'])) {
         if (!$this->check_unique(user::TABLE, 'email', $data['email2'], $data['id'])) {
             $errors['email2'] = get_string('emailexists');
         }
     }
     if (!empty($data['contactemail'])) {
         if (!$this->check_unique(user::TABLE, 'email', $data['contactemail'], $data['id'])) {
             $errors['contactemail'] = get_string('emailexists');
         }
     }
     $errors += parent::validate_custom_fields($data, 'user');
     return $errors;
 }
示例#6
0
 function validation($data, $files)
 {
     global $DB;
     $errors = parent::validation($data, $files);
     $params = array($data['idnumber']);
     $sql = 'idnumber = ?';
     if ($data['id']) {
         $sql .= ' AND id != ?';
         $params[] = $data['id'];
     }
     if ($DB->record_exists_select(course::TABLE, $sql, $params)) {
         $errors['idnumber'] = get_string('idnumber_already_used', 'local_elisprogram');
     }
     $errors += parent::validate_custom_fields($data, 'course');
     return $errors;
 }