Esempio n. 1
0
 /**
  * Test datedelta methods: validate() & is_zero()
  * @dataProvider dataprovider_datedelta
  * @param string $instr The input string.
  * @param bool $isvalid Whether the input string is valid.
  * @param bool $iszero Whether the input string is zero.
  */
 public function test_datedelta($instr, $isvalid, $iszero)
 {
     $this->assertEquals($isvalid, datedelta::validate($instr));
     if ($isvalid === true) {
         $dd = new datedelta($instr);
         $this->assertEquals($iszero, $dd->is_zero());
     }
 }
Esempio n. 2
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;
 }