/** * handle the form, get data of request and put in the object, handle commands if required * * @author Sebastien Piraux <*****@*****.**> * @return boolean true if form can be checked and saved, false */ public function handleForm() { // for multipage form handling if (isset($_REQUEST['step'])) { $this->step = (int) abs($_REQUEST['step']); } else { $this->step = 1; } // for answer if (isset($_REQUEST['answer'])) { $this->answerText = trim($this->answerEncode($_REQUEST['answer'])); } else { $this->answerText = ''; } // and update answerList $this->setAnswerList(); if (isset($_REQUEST['type'])) { $this->type = $_REQUEST['type']; } // else keep the value in object (default or loaded) if (isset($_REQUEST['wrongAnswerList'])) { $encoded = $this->wrongAnswerEncode($_REQUEST['wrongAnswerList']); // remove empty lines $encodedList = explode("\n", $encoded); // remove duplicated entries $this->wrongAnswerList = array_unique($encodedList); } else { $this->wrongAnswerList = ''; } if (isset($_REQUEST['grade']) && is_array($_REQUEST['grade'])) { // reinit gradeList $this->gradeList = array(); // all values must be positive foreach ($_REQUEST['grade'] as $grade) { $this->gradeList[] = abs(castToFloat($grade)); } } // else keep the value in object (default or loaded) //-- cmd if (isset($_REQUEST['cmdBack'])) { if ($this->validate()) { if ($this->step > 1) { $this->step--; } } return false; } if (isset($_REQUEST['cmdNext'])) { if ($this->validate()) { $this->step++; } return false; } // no special command return true; }
/** * handle the form, get data of request and put in the object, handle commands if required * * @author Sebastien Piraux <*****@*****.**> * @return boolean true if form can be checked and saved, false */ public function handleForm() { //-- feedbacks if (isset($_REQUEST['trueFeedback'])) { $this->trueFeedback = $_REQUEST['trueFeedback']; } if (isset($_REQUEST['falseFeedback'])) { $this->falseFeedback = $_REQUEST['falseFeedback']; } //-- correct answer if (isset($_REQUEST['correctAnswer'])) { if ($_REQUEST['correctAnswer'] == 'true') { $this->correctAnswer = 'TRUE'; } elseif ($_REQUEST['correctAnswer'] == 'false') { $this->correctAnswer = 'FALSE'; } } //-- grades $trueGrade = isset($_REQUEST['trueGrade']) ? castToFloat($_REQUEST['trueGrade']) : 0; $falseGrade = isset($_REQUEST['falseGrade']) ? castToFloat($_REQUEST['falseGrade']) : 0; if ($this->correctAnswer == 'TRUE') { $this->trueGrade = abs($trueGrade); // good answer cannot have negative score $this->falseGrade = 0 - abs($falseGrade); // bad answer cannot have positive score } elseif ($this->correctAnswer == 'FALSE') { $this->trueGrade = 0 - abs($trueGrade); // good answer cannot have negative score $this->falseGrade = abs($falseGrade); // bad answer cannot have positive score } else { $this->trueGrade = abs($trueGrade); $this->falseGrade = abs($falseGrade); } return true; }
/** * set grade * * @author Sebastien Piraux <*****@*****.**> * @param float $value */ public function setGrade($value) { $this->grade = castToFloat($value); }
/** * handle the form, get data of request and put in the object, handle commands if required * * @author Sebastien Piraux <*****@*****.**> * @return boolean true if form can be checked and saved, false */ public function handleForm() { // reinit array $this->leftList = array(); $this->rightList = array(); //-- set form value in object for ($i = 0; $i < $_REQUEST['rightCount']; $i++) { $answerNumber = $i + 1; //-- answer text $right = 'right_' . $this->questionId . '_' . $answerNumber; if (isset($_REQUEST[$right])) { $answer = trim($_REQUEST[$right]); } else { $answer = ''; } $this->addRight($answer); } // we need to have a correspondance between number of the answer in the form and code of corresponding proposal $righCodeList = array_keys($this->rightList); for ($i = 0; $i < $_REQUEST['leftCount']; $i++) { $answerNumber = $i + 1; //-- answer text $answerFieldName = 'answer_' . $this->questionId . '_' . $answerNumber; if (isset($_REQUEST[$answerFieldName])) { $answer = trim($_REQUEST[$answerFieldName]); } else { $answer = ''; } //-- matching choice $matchFieldName = 'match_' . $this->questionId . '_' . $answerNumber; if (isset($_REQUEST[$matchFieldName])) { // 'match' value is the code of the matching right answer if (isset($righCodeList[$_REQUEST[$matchFieldName]])) { $match = $righCodeList[$_REQUEST[$matchFieldName]]; } else { $match = ''; } } else { $match = ''; } //-- grade $gradeFieldName = 'grade_' . $this->questionId . '_' . $answerNumber; if (isset($_REQUEST[$gradeFieldName])) { $grade = castToFloat($_REQUEST[$gradeFieldName]); } else { $grade = ''; } $this->addLeft($answer, $match, $grade); } //-- cmd if (isset($_REQUEST['cmdRemLeft'])) { $this->remLeft(); return false; } if (isset($_REQUEST['cmdAddLeft'])) { $this->addLeft(); return false; } if (isset($_REQUEST['cmdRemRight'])) { $this->remRight(); return false; } if (isset($_REQUEST['cmdAddRight'])) { $this->addRight(); return false; } // no special command return true; }
/** * allow to import the answers, feedbacks, and grades of a question * * @param questionArray is an array that must contain all the information needed to build the question */ public function import($questionArray) { $answerArray = $questionArray['answer']; //This tick to remove examples in the answers!!!! $this->leftList = array(); $this->rightList = array(); //find right and left column $right_column = array_pop($answerArray); $left_column = array_pop($answerArray); //1- build answers foreach ($right_column as $right_key => $right_element) { $code = $this->addRight($right_element); foreach ($left_column as $left_key => $left_element) { $matched_pattern = $left_key . " " . $right_key; $matched_pattern_inverted = $right_key . " " . $left_key; if (in_array($matched_pattern, $questionArray['correct_answers']) || in_array($matched_pattern_inverted, $questionArray['correct_answers'])) { if (isset($questionArray['weighting'][$matched_pattern])) { $grade = castToFloat($questionArray['weighting'][$matched_pattern]); } else { $grade = 0; } $this->addLeft($left_element, $code, $grade); } } } $this->save(); }
/** * handle the form, get data of request and put in the object, handle commands if required * * @author Sebastien Piraux <*****@*****.**> * @return boolean true if form can be checked and saved, false */ public function handleForm() { $this->answerList = array(); // set form value in object for ($i = 0; $i < $_REQUEST['answerCount']; $i++) { $answerNumber = $i + 1; //-- answer text $answer = 'answer_' . $answerNumber; if (isset($_REQUEST[$answer])) { $this->answerList[$i]['answer'] = $_REQUEST[$answer]; } else { $this->answerList[$i]['answer'] = ''; } //-- correct answer $correct = 'correct_' . $answerNumber; if ($this->multipleAnswer) { if (isset($_REQUEST[$correct])) { $this->answerList[$i]['correct'] = 1; } else { $this->answerList[$i]['correct'] = 0; } } else { if (isset($_REQUEST['correct']) && $_REQUEST['correct'] == $correct) { $this->answerList[$i]['correct'] = 1; } else { $this->answerList[$i]['correct'] = 0; } } //-- feedbacks $comment = 'comment_' . $answerNumber; if (isset($_REQUEST[$comment])) { $this->answerList[$i]['comment'] = $_REQUEST[$comment]; } else { $this->answerList[$i]['comment'] = ''; } //-- grade $grade = 'grade_' . $answerNumber; if (isset($_REQUEST[$grade])) { if ($this->answerList[$i]['correct'] == 1) { // correct answer must have positive answer $this->answerList[$i]['grade'] = abs(castToFloat($_REQUEST[$grade])); } else { if ($this->multipleAnswer) { // if multiple answer score must be negative $this->answerList[$i]['grade'] = 0 - abs(castToFloat($_REQUEST[$grade])); } else { // if single answer score can be positive $this->answerList[$i]['grade'] = castToFloat($_REQUEST[$grade]); } } } else { $this->answerList[$i]['grade'] = 0; } } //-- cmd if (isset($_REQUEST['cmdRemAnsw'])) { $this->remAnswer(); return false; } if (isset($_REQUEST['cmdAddAnsw'])) { $this->addAnswer(); return false; } // no special command return true; }