Пример #1
0
 /**
  * Check question's form data for valid response. Override this is type has specific format requirements.
  *
  * @param object $responsedata The data entered into the response.
  * @return boolean
  */
 public function response_valid($responsedata)
 {
     if (isset($responsedata->{'q' . $this->id})) {
         $checkdateresult = '';
         if ($responsedata->{'q' . $this->id} != '') {
             $checkdateresult = questionnaire_check_date($responsedata->{'q' . $this->id});
         }
         return substr($checkdateresult, 0, 5) != 'wrong';
     } else {
         return parent::response_valid($responsedata);
     }
 }
Пример #2
0
 /**
  * Check question's form data for valid response. Override this is type has specific format requirements.
  *
  * @param object $responsedata The data entered into the response.
  * @return boolean
  */
 public function response_valid($responsedata)
 {
     $num = 0;
     $nbchoices = count($this->choices);
     $na = get_string('notapplicable', 'questionnaire');
     foreach ($this->choices as $cid => $choice) {
         // In case we have named degrees on the Likert scale, count them to substract from nbchoices.
         $nameddegrees = 0;
         $content = $choice->content;
         if (preg_match("/^[0-9]{1,3}=/", $content)) {
             $nameddegrees++;
         } else {
             $str = 'q' . "{$this->id}_{$cid}";
             if (isset($responsedata->{$str}) && $responsedata->{$str} == $na) {
                 $responsedata->{$str} = -1;
             }
             // If choice value == -999 this is a not yet answered choice.
             $num += isset($responsedata->{$str}) && $responsedata->{$str} != -999;
         }
         $nbchoices -= $nameddegrees;
     }
     // If nodupes and nb choice restricted, nbchoices may be > actual choices, so limit it to $question->length.
     $isrestricted = $this->length < count($this->choices) && $this->precise == 2;
     if ($isrestricted) {
         $nbchoices = min($nbchoices, $this->length);
     }
     if ($num != $nbchoices && $num != 0) {
         return false;
     } else {
         return parent::response_valid($responsedata);
     }
 }
 /**
  * Check question's form data for valid response. Override this is type has specific format requirements.
  *
  * @param object $responsedata The data entered into the response.
  * @return boolean
  */
 public function response_valid($responsedata)
 {
     $valid = true;
     if (isset($responsedata->{'q' . $this->id})) {
         $nbrespchoices = 0;
         foreach ($responsedata->{'q' . $this->id} as $resp) {
             if (strpos($resp, 'other_') !== false) {
                 // ..."other" choice is checked but text box is empty.
                 $othercontent = "q" . $this->id . substr($resp, 5);
                 if (empty($responsedata->{$othercontent})) {
                     $valid = false;
                     break;
                 }
                 $nbrespchoices++;
             } else {
                 if (is_numeric($resp)) {
                     $nbrespchoices++;
                 }
             }
         }
         $nbquestchoices = count($this->choices);
         $min = $this->length;
         $max = $this->precise;
         if ($max == 0) {
             $max = $nbquestchoices;
         }
         if ($min > $max) {
             $min = $max;
             // Sanity check.
         }
         $min = min($nbquestchoices, $min);
         if ($nbrespchoices && ($nbrespchoices < $min || $nbrespchoices > $max)) {
             // Number of ticked boxes is not within min and max set limits.
             $valid = false;
         }
     } else {
         $valid = parent::response_valid($responsedata);
     }
     return $valid;
 }