当前位置: 首页>>代码示例>>PHP>>正文


PHP lesson_page::check_answer方法代码示例

本文整理汇总了PHP中lesson_page::check_answer方法的典型用法代码示例。如果您正苦于以下问题:PHP lesson_page::check_answer方法的具体用法?PHP lesson_page::check_answer怎么用?PHP lesson_page::check_answer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lesson_page的用法示例。


在下文中一共展示了lesson_page::check_answer方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: check_answer

 public function check_answer()
 {
     global $DB, $CFG;
     $formattextdefoptions = new stdClass();
     $formattextdefoptions->noclean = true;
     $formattextdefoptions->para = false;
     $answers = $this->get_answers();
     shuffle($answers);
     $params = array('answers' => $answers, 'lessonid' => $this->lesson->id, 'contents' => $this->get_contents());
     $mform = new lesson_display_answer_form_truefalse($CFG->wwwroot . '/mod/lesson/continue.php', $params);
     $data = $mform->get_data();
     require_sesskey();
     $result = parent::check_answer();
     if (empty($data->answerid)) {
         $result->noanswer = true;
         return $result;
     }
     $result->answerid = $data->answerid;
     $answer = $DB->get_record("lesson_answers", array("id" => $result->answerid), '*', MUST_EXIST);
     if ($this->lesson->jumpto_is_correct($this->properties->id, $answer->jumpto)) {
         $result->correctanswer = true;
     }
     if ($this->lesson->custom) {
         if ($answer->score > 0) {
             $result->correctanswer = true;
         } else {
             $result->correctanswer = false;
         }
     }
     $result->newpageid = $answer->jumpto;
     $result->response = format_text($answer->response, $answer->responseformat, $formattextdefoptions);
     $result->studentanswer = $result->userresponse = $answer->answer;
     return $result;
 }
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:34,代码来源:truefalse.php

示例2: check_answer

 public function check_answer()
 {
     global $PAGE, $CFG;
     $result = parent::check_answer();
     $result->isessayquestion = true;
     $mform = new lesson_display_answer_form_essay($CFG->wwwroot . '/mod/lesson/continue.php', array('contents' => $this->get_contents()));
     $data = $mform->get_data();
     require_sesskey();
     if (!$data) {
         redirect(new moodle_url('/mod/lesson/view.php', array('id' => $PAGE->cm->id, 'pageid' => $this->properties->id)));
     }
     $studentanswer = $data->answer['text'];
     if (trim($studentanswer) === '') {
         $result->noanswer = true;
         return $result;
     }
     $answers = $this->get_answers();
     foreach ($answers as $answer) {
         $result->answerid = $answer->id;
         $result->newpageid = $answer->jumpto;
     }
     $userresponse = new stdClass();
     $userresponse->sent = 0;
     $userresponse->graded = 0;
     $userresponse->score = 0;
     $userresponse->answer = $studentanswer;
     $userresponse->response = "";
     $result->userresponse = serialize($userresponse);
     $result->studentanswer = s($studentanswer);
     return $result;
 }
开发者ID:vuchannguyen,项目名称:web,代码行数:31,代码来源:essay.php

示例3: check_answer

    public function check_answer() {
        global $CFG;
        $result = parent::check_answer();

        $mform = new lesson_display_answer_form_shortanswer($CFG->wwwroot.'/mod/lesson/continue.php', array('contents'=>$this->get_contents()));
        $data = $mform->get_data();
        require_sesskey();

        $formattextdefoptions = new stdClass();
        $formattextdefoptions->noclean = true;
        $formattextdefoptions->para = false;

        // set defaults
        $result->response = '';
        $result->newpageid = 0;

        if (!isset($data->answer) || !is_numeric($data->answer)) {
            $result->noanswer = true;
            return $result;
        } else {
            // Just doing default PARAM_RAW, not doing PARAM_INT because it could be a float.
            $result->useranswer = (float)$data->answer;
        }
        $result->studentanswer = $result->userresponse = $result->useranswer;
        $answers = $this->get_answers();
        foreach ($answers as $answer) {
            $answer = parent::rewrite_answers_urls($answer);
            if (strpos($answer->answer, ':')) {
                // there's a pairs of values
                list($min, $max) = explode(':', $answer->answer);
                $minimum = (float) $min;
                $maximum = (float) $max;
            } else {
                // there's only one value
                $minimum = (float) $answer->answer;
                $maximum = $minimum;
            }
            if (($result->useranswer >= $minimum) && ($result->useranswer <= $maximum)) {
                $result->newpageid = $answer->jumpto;
                $result->response = format_text($answer->response, $answer->responseformat, $formattextdefoptions);
                if ($this->lesson->jumpto_is_correct($this->properties->id, $result->newpageid)) {
                    $result->correctanswer = true;
                }
                if ($this->lesson->custom) {
                    if ($answer->score > 0) {
                        $result->correctanswer = true;
                    } else {
                        $result->correctanswer = false;
                    }
                }
                $result->answerid = $answer->id;
                return $result;
            }
        }
        return $result;
    }
开发者ID:rezaies,项目名称:moodle,代码行数:56,代码来源:numerical.php

示例4: check_answer

 public function check_answer()
 {
     global $CFG;
     $result = parent::check_answer();
     $mform = new lesson_display_answer_form_shortanswer($CFG->wwwroot . '/mod/lesson/continue.php', array('contents' => $this->get_contents()));
     $data = $mform->get_data();
     require_sesskey();
     $studentanswer = trim($data->answer);
     if ($studentanswer === '') {
         $result->noanswer = true;
         return $result;
     }
     $i = 0;
     $answers = $this->get_answers();
     foreach ($answers as $answer) {
         $answer = parent::rewrite_answers_urls($answer, false);
         $i++;
         // Applying PARAM_TEXT as it is applied to the answer submitted by the user.
         $expectedanswer = clean_param($answer->answer, PARAM_TEXT);
         $ismatch = false;
         $markit = false;
         $useregexp = $this->qoption;
         if ($useregexp) {
             //we are using 'normal analysis', which ignores case
             $ignorecase = '';
             if (substr($expectedanswer, -2) == '/i') {
                 $expectedanswer = substr($expectedanswer, 0, -2);
                 $ignorecase = 'i';
             }
         } else {
             $expectedanswer = str_replace('*', '#####', $expectedanswer);
             $expectedanswer = preg_quote($expectedanswer, '/');
             $expectedanswer = str_replace('#####', '.*', $expectedanswer);
         }
         // see if user typed in any of the correct answers
         if (!$this->lesson->custom && $this->lesson->jumpto_is_correct($this->properties->id, $answer->jumpto) or $this->lesson->custom && $answer->score > 0) {
             if (!$useregexp) {
                 // we are using 'normal analysis', which ignores case
                 if (preg_match('/^' . $expectedanswer . '$/i', $studentanswer)) {
                     $ismatch = true;
                 }
             } else {
                 if (preg_match('/^' . $expectedanswer . '$/' . $ignorecase, $studentanswer)) {
                     $ismatch = true;
                 }
             }
             if ($ismatch == true) {
                 $result->correctanswer = true;
             }
         } else {
             if (!$useregexp) {
                 //we are using 'normal analysis'
                 // see if user typed in any of the wrong answers; don't worry about case
                 if (preg_match('/^' . $expectedanswer . '$/i', $studentanswer)) {
                     $ismatch = true;
                 }
             } else {
                 // we are using regular expressions analysis
                 $startcode = substr($expectedanswer, 0, 2);
                 switch ($startcode) {
                     //1- check for absence of required string in $studentanswer (coded by initial '--')
                     case "--":
                         $expectedanswer = substr($expectedanswer, 2);
                         if (!preg_match('/^' . $expectedanswer . '$/' . $ignorecase, $studentanswer)) {
                             $ismatch = true;
                         }
                         break;
                         //2- check for code for marking wrong strings (coded by initial '++')
                     //2- check for code for marking wrong strings (coded by initial '++')
                     case "++":
                         $expectedanswer = substr($expectedanswer, 2);
                         $markit = true;
                         //check for one or several matches
                         if (preg_match_all('/' . $expectedanswer . '/' . $ignorecase, $studentanswer, $matches)) {
                             $ismatch = true;
                             $nb = count($matches[0]);
                             $original = array();
                             $marked = array();
                             $fontStart = '<span class="incorrect matches">';
                             $fontEnd = '</span>';
                             for ($i = 0; $i < $nb; $i++) {
                                 array_push($original, $matches[0][$i]);
                                 array_push($marked, $fontStart . $matches[0][$i] . $fontEnd);
                             }
                             $studentanswer = str_replace($original, $marked, $studentanswer);
                         }
                         break;
                         //3- check for wrong answers belonging neither to -- nor to ++ categories
                     //3- check for wrong answers belonging neither to -- nor to ++ categories
                     default:
                         if (preg_match('/^' . $expectedanswer . '$/' . $ignorecase, $studentanswer, $matches)) {
                             $ismatch = true;
                         }
                         break;
                 }
                 $result->correctanswer = false;
             }
         }
         if ($ismatch) {
             $result->newpageid = $answer->jumpto;
//.........这里部分代码省略.........
开发者ID:pzhu2004,项目名称:moodle,代码行数:101,代码来源:shortanswer.php

示例5: check_answer

 public function check_answer()
 {
     global $CFG, $PAGE;
     $formattextdefoptions = new stdClass();
     $formattextdefoptions->noclean = true;
     $formattextdefoptions->para = false;
     $result = parent::check_answer();
     $mform = $this->make_answer_form();
     $data = $mform->get_data();
     require_sesskey();
     if (!$data) {
         redirect(new moodle_url('/mod/lesson/view.php', array('id' => $PAGE->cm->id, 'pageid' => $this->properties->id)));
     }
     $response = $data->response;
     $getanswers = $this->get_answers();
     foreach ($getanswers as $key => $answer) {
         $getanswers[$key] = parent::rewrite_answers_urls($answer);
     }
     $correct = array_shift($getanswers);
     $wrong = array_shift($getanswers);
     $answers = array();
     foreach ($getanswers as $key => $answer) {
         if ($answer->answer !== '' or $answer->response !== '') {
             $answers[$answer->id] = $answer;
         }
     }
     // get the user's exact responses for record keeping
     $hits = 0;
     $userresponse = array();
     foreach ($response as $id => $value) {
         if ($value == '') {
             $result->noanswer = true;
             return $result;
         }
         $value = htmlspecialchars_decode($value);
         $userresponse[] = $value;
         // Make sure the user's answer exists in question's answer
         if (array_key_exists($id, $answers)) {
             $answer = $answers[$id];
             $result->studentanswer .= '<br />' . format_text($answer->answer, $answer->answerformat, $formattextdefoptions) . ' = ' . $value;
             if (trim($answer->response) == trim($value)) {
                 $hits++;
             }
         }
     }
     $result->userresponse = implode(",", $userresponse);
     if ($hits == count($answers)) {
         $result->correctanswer = true;
         $result->response = format_text($correct->answer, $correct->answerformat, $formattextdefoptions);
         $result->answerid = $correct->id;
         $result->newpageid = $correct->jumpto;
     } else {
         $result->correctanswer = false;
         $result->response = format_text($wrong->answer, $wrong->answerformat, $formattextdefoptions);
         $result->answerid = $wrong->id;
         $result->newpageid = $wrong->jumpto;
     }
     return $result;
 }
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:59,代码来源:matching.php

示例6: check_answer

 public function check_answer()
 {
     global $DB, $CFG, $PAGE;
     $result = parent::check_answer();
     $formattextdefoptions = new stdClass();
     $formattextdefoptions->noclean = true;
     $formattextdefoptions->para = false;
     $answers = $this->get_used_answers();
     shuffle($answers);
     $action = $CFG->wwwroot . '/mod/lesson/continue.php';
     $params = array('answers' => $answers, 'lessonid' => $this->lesson->id, 'contents' => $this->get_contents());
     if ($this->properties->qoption) {
         $mform = new lesson_display_answer_form_multichoice_multianswer($action, $params);
     } else {
         $mform = new lesson_display_answer_form_multichoice_singleanswer($action, $params);
     }
     $data = $mform->get_data();
     require_sesskey();
     if (!$data) {
         redirect(new moodle_url('/mod/lesson/view.php', array('id' => $PAGE->cm->id, 'pageid' => $this->properties->id)));
     }
     if ($this->properties->qoption) {
         // MULTIANSWER allowed, user's answer is an array
         if (empty($data->answer) || !is_array($data->answer)) {
             $result->noanswer = true;
             return $result;
         }
         $studentanswers = array();
         foreach ($data->answer as $key => $value) {
             $studentanswers[] = (int) $key;
         }
         // get what the user answered
         $result->userresponse = implode(",", $studentanswers);
         // get the answers in a set order, the id order
         $answers = $this->get_used_answers();
         $ncorrect = 0;
         $nhits = 0;
         $correctresponse = '';
         $wrongresponse = '';
         $correctanswerid = 0;
         $wronganswerid = 0;
         // store student's answers for displaying on feedback page
         $result->studentanswer = '';
         foreach ($answers as $answer) {
             foreach ($studentanswers as $answerid) {
                 if ($answerid == $answer->id) {
                     $result->studentanswer .= '<br />' . format_text($answer->answer, $answer->answerformat, $formattextdefoptions);
                 }
             }
         }
         $correctpageid = null;
         $wrongpageid = null;
         // this is for custom scores.  If score on answer is positive, it is correct
         if ($this->lesson->custom) {
             $ncorrect = 0;
             $nhits = 0;
             foreach ($answers as $answer) {
                 if ($answer->score > 0) {
                     $ncorrect++;
                     foreach ($studentanswers as $answerid) {
                         if ($answerid == $answer->id) {
                             $nhits++;
                         }
                     }
                     // save the first jumpto page id, may be needed!...
                     if (!isset($correctpageid)) {
                         // leave in its "raw" state - will converted into a proper page id later
                         $correctpageid = $answer->jumpto;
                     }
                     // save the answer id for scoring
                     if ($correctanswerid == 0) {
                         $correctanswerid = $answer->id;
                     }
                     // ...also save any response from the correct answers...
                     if (trim(strip_tags($answer->response))) {
                         $correctresponse = format_text($answer->response, $answer->responseformat, $formattextdefoptions);
                     }
                 } else {
                     // save the first jumpto page id, may be needed!...
                     if (!isset($wrongpageid)) {
                         // leave in its "raw" state - will converted into a proper page id later
                         $wrongpageid = $answer->jumpto;
                     }
                     // save the answer id for scoring
                     if ($wronganswerid == 0) {
                         $wronganswerid = $answer->id;
                     }
                     // ...and from the incorrect ones, don't know which to use at this stage
                     if (trim(strip_tags($answer->response))) {
                         $wrongresponse = format_text($answer->response, $answer->responseformat, $formattextdefoptions);
                     }
                 }
             }
         } else {
             foreach ($answers as $answer) {
                 if ($this->lesson->jumpto_is_correct($this->properties->id, $answer->jumpto)) {
                     $ncorrect++;
                     foreach ($studentanswers as $answerid) {
                         if ($answerid == $answer->id) {
                             $nhits++;
//.........这里部分代码省略.........
开发者ID:vuchannguyen,项目名称:web,代码行数:101,代码来源:multichoice.php

示例7: check_answer

 public function check_answer()
 {
     global $CFG, $PAGE;
     $formattextdefoptions = new stdClass();
     $formattextdefoptions->noclean = true;
     $formattextdefoptions->para = false;
     $result = parent::check_answer();
     $mform = $this->make_answer_form();
     $data = $mform->get_data();
     require_sesskey();
     if (!$data) {
         redirect(new moodle_url('/mod/lesson/view.php', array('id' => $PAGE->cm->id, 'pageid' => $this->properties->id)));
     }
     $response = $data->response;
     if (!is_array($response)) {
         $result->noanswer = true;
         return $result;
     }
     $answers = $this->get_answers();
     $correct = array_shift($answers);
     $wrong = array_shift($answers);
     foreach ($answers as $key => $answer) {
         if ($answer->answer === '' or $answer->response === '') {
             // incomplete option!
             unset($answers[$key]);
         }
     }
     // get he users exact responses for record keeping
     $hits = 0;
     $userresponse = array();
     foreach ($response as $key => $value) {
         foreach ($answers as $answer) {
             if ($value === $answer->response) {
                 $userresponse[] = $answer->id;
             }
             if ((int) $answer->id === (int) $key) {
                 $result->studentanswer .= '<br />' . format_text($answer->answer, $answer->answerformat, $formattextdefoptions) . ' = ' . $value;
             }
             if ((int) $answer->id === (int) $key and $value === $answer->response) {
                 $hits++;
             }
         }
     }
     $result->userresponse = implode(",", $userresponse);
     if ($hits == count($answers)) {
         $result->correctanswer = true;
         $result->response = format_text($correct->answer, $correct->answerformat, $formattextdefoptions);
         $result->answerid = $correct->id;
         $result->newpageid = $correct->jumpto;
     } else {
         $result->correctanswer = false;
         $result->response = format_text($wrong->answer, $wrong->answerformat, $formattextdefoptions);
         $result->answerid = $wrong->id;
         $result->newpageid = $wrong->jumpto;
     }
     return $result;
 }
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:57,代码来源:matching.php


注:本文中的lesson_page::check_answer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。