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


PHP qtype_multianswer_extract_question函数代码示例

本文整理汇总了PHP中qtype_multianswer_extract_question函数的典型用法代码示例。如果您正苦于以下问题:PHP qtype_multianswer_extract_question函数的具体用法?PHP qtype_multianswer_extract_question怎么用?PHP qtype_multianswer_extract_question使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: readquestions

 protected function readquestions($lines)
 {
     // For this class the method has been simplified as
     // there can never be more than one question for a
     // multianswer import
     $questions = array();
     $questiontext = array();
     $questiontext['text'] = implode('', $lines);
     $questiontext['format'] = 0;
     $questiontext['itemid'] = '';
     $question = qtype_multianswer_extract_question($questiontext);
     $question->questiontext = $question->questiontext['text'];
     $question->questiontextformat = 0;
     $question->qtype = MULTIANSWER;
     $question->generalfeedback = '';
     $question->course = $this->course;
     if (!empty($question)) {
         $name = html_to_text(implode(' ', $lines));
         $name = preg_replace('/{[^}]*}/', '', $name);
         $name = trim($name);
         if ($name) {
             $question->name = shorten_text($name, 45);
         } else {
             // We need some name, so use the current time, since that will be
             // reasonably unique.
             $question->name = userdate(time());
         }
         $questions[] = $question;
     }
     return $questions;
 }
开发者ID:sebastiansanio,项目名称:tallerdeprogramacion2fiuba,代码行数:31,代码来源:format.php

示例2: readquestions

 public function readquestions($lines)
 {
     question_bank::get_qtype('multianswer');
     // Ensure the multianswer code is loaded.
     // For this class the method has been simplified as
     // there can never be more than one question for a
     // multianswer import.
     $questions = array();
     $questiontext = array();
     $questiontext['text'] = implode('', $lines);
     $questiontext['format'] = FORMAT_MOODLE;
     $questiontext['itemid'] = '';
     $question = qtype_multianswer_extract_question($questiontext);
     $question->questiontext = $question->questiontext['text'];
     $question->questiontextformat = 0;
     $question->qtype = 'multianswer';
     $question->generalfeedback = '';
     $question->generalfeedbackformat = FORMAT_MOODLE;
     $question->length = 1;
     $question->penalty = 0.3333333;
     if (!empty($question)) {
         $question->name = $this->create_default_question_name($question->questiontext, get_string('questionname', 'question'));
         $questions[] = $question;
     }
     return $questions;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:26,代码来源:format.php

示例3: definition_inner

 function definition_inner(&$mform)
 {
     $question_type_names = question_type_menu();
     $mform->addRule('questiontext', null, 'required', null, 'client');
     // Remove meaningless defaultgrade field.
     $mform->removeElement('defaultgrade');
     // display the questions from questiontext;
     if ("" != optional_param('questiontext', '', PARAM_RAW)) {
         $this->questiondisplay = fullclone(qtype_multianswer_extract_question(optional_param('questiontext', '', PARAM_RAW)));
     } else {
         $this->questiondisplay = "";
     }
     if (isset($this->questiondisplay->options->questions) && is_array($this->questiondisplay->options->questions)) {
         $countsubquestions = 0;
         foreach ($this->questiondisplay->options->questions as $subquestion) {
             if (!empty($subquestion)) {
                 $countsubquestions++;
             }
         }
     } else {
         $countsubquestions = 0;
     }
     $mform->addElement('submit', 'analyzequestion', get_string('decodeverifyquestiontext', 'qtype_multianswer'));
     $mform->registerNoSubmitButton('analyzequestion');
     for ($sub = 1; $sub <= $countsubquestions; $sub++) {
         $this->editas[$sub] = 'unknown type';
         if (isset($this->questiondisplay->options->questions[$sub]->qtype)) {
             $this->editas[$sub] = $this->questiondisplay->options->questions[$sub]->qtype;
         } else {
             if (optional_param('sub_' . $sub . "_" . 'qtype', '', PARAM_RAW) != '') {
                 $this->editas[$sub] = optional_param('sub_' . $sub . "_" . 'qtype', '', PARAM_RAW);
             }
         }
         $mform->addElement('header', 'subhdr', get_string('questionno', 'quiz', '{#' . $sub . '}') . '&nbsp;' . $question_type_names[$this->questiondisplay->options->questions[$sub]->qtype]);
         $mform->addElement('static', 'sub_' . $sub . "_" . 'questiontext', get_string('questiondefinition', 'qtype_multianswer'), array('cols' => 60, 'rows' => 3));
         if (isset($this->questiondisplay->options->questions[$sub]->questiontext)) {
             $mform->setDefault('sub_' . $sub . "_" . 'questiontext', $this->questiondisplay->options->questions[$sub]->questiontext);
         }
         $mform->addElement('static', 'sub_' . $sub . "_" . 'defaultgrade', get_string('defaultgrade', 'quiz'));
         $mform->setDefault('sub_' . $sub . "_" . 'defaultgrade', $this->questiondisplay->options->questions[$sub]->defaultgrade);
         if ($this->questiondisplay->options->questions[$sub]->qtype == 'shortanswer') {
             $mform->addElement('static', 'sub_' . $sub . "_" . 'usecase', get_string('casesensitive', 'quiz'));
         }
         if ($this->questiondisplay->options->questions[$sub]->qtype == 'multichoice') {
             $mform->addElement('static', 'sub_' . $sub . "_" . 'layout', get_string('layout', 'qtype_multianswer'), array('cols' => 60, 'rows' => 1));
             //, $gradeoptions);
         }
         foreach ($this->questiondisplay->options->questions[$sub]->answer as $key => $ans) {
             $mform->addElement('static', 'sub_' . $sub . "_" . 'answer[' . $key . ']', get_string('answer', 'quiz'), array('cols' => 60, 'rows' => 1));
             if ($this->questiondisplay->options->questions[$sub]->qtype == 'numerical' && $key == 0) {
                 $mform->addElement('static', 'sub_' . $sub . "_" . 'tolerance[' . $key . ']', get_string('acceptederror', 'quiz'));
                 //, $gradeoptions);
             }
             $mform->addElement('static', 'sub_' . $sub . "_" . 'fraction[' . $key . ']', get_string('grade'));
             //, $gradeoptions);
             $mform->addElement('static', 'sub_' . $sub . "_" . 'feedback[' . $key . ']', get_string('feedback', 'quiz'));
         }
     }
 }
开发者ID:edwinphillips,项目名称:moodle-485cb39,代码行数:59,代码来源:edit_multianswer_form.php

示例4: readquestions

 function readquestions($lines)
 {
     // Parses an array of lines into an array of questions.
     // For this class the method has been simplified as
     // there can never be more than one question for a
     // multianswer import
     $questions = array();
     $thequestion = qtype_multianswer_extract_question(addslashes(implode('', $lines)));
     $thequestion->qtype = MULTIANSWER;
     $thequestion->course = $this->course;
     if (!empty($thequestion)) {
         $thequestion->name = addslashes($lines[0]);
         $questions[] = $thequestion;
     }
     return $questions;
 }
开发者ID:nadavkav,项目名称:MoodleTAO,代码行数:16,代码来源:format.php

示例5: build_moodle

 /**
  * Build questions using moodle serialized data. Used for reimport, i.e. from Moodle to Moodle.
  * Used to process data not supported by QTI and to improve performances.
  *
  * @param QtiImportSettings $data
  * @return object|null
  */
 public function build_moodle(QtiImportSettings $settings)
 {
     $result = parent::build_moodle($settings);
     $data = $settings->get_data();
     $text = $data->questiontext;
     foreach ($data->options->questions as $key => $q) {
         $text = str_replace('{#' . $key . '}', $q->questiontext, $text);
     }
     $result = qtype_multianswer_extract_question($text);
     $result->resources = array();
     $result->questiontextformat = FORMAT_HTML;
     $result->name = $data->name;
     $result->generalfeedback = $data->generalfeedback;
     $result->penalty = $data->penalty;
     return $result;
 }
开发者ID:jmvedrine,项目名称:moodle-qformat_imsqti21,代码行数:23,代码来源:cloze_builder.class.php

示例6: readquestions

    public function readquestions($lines) {
        question_bank::get_qtype('multianswer'); // Ensure the multianswer code is loaded.

        // For this class the method has been simplified as
        // there can never be more than one question for a
        // multianswer import.
        $questions = array();

        $questiontext = array();
        $questiontext['text'] = implode('', $lines);
        $questiontext['format'] = FORMAT_MOODLE;
        $questiontext['itemid'] = '';
        $question = qtype_multianswer_extract_question($questiontext);
        $question->questiontext = $question->questiontext['text'];
        $question->questiontextformat = 0;

        $question->qtype = 'multianswer';
        $question->generalfeedback = '';
        $question->generalfeedbackformat = FORMAT_MOODLE;
        $question->length = 1;
        $question->penalty = 0.3333333;

        if (!empty($question)) {
            $name = html_to_text(implode(' ', $lines));
            $name = preg_replace('/{[^}]*}/', '', $name);
            $name = trim($name);

            if ($name) {
                $question->name = shorten_text($name, 45);
            } else {
                // We need some name, so use the current time, since that will be
                // reasonably unique.
                $question->name = userdate(time());
            }

            $questions[] = $question;
        }

        return $questions;
    }
开发者ID:netspotau,项目名称:moodle-mod_assign,代码行数:40,代码来源:format.php

示例7: import_multianswer

 /**
  * import cloze type question
  * @param array question question array from xml tree
  * @return object question object
  */
 function import_multianswer($questions)
 {
     $questiontext = $questions['#']['questiontext'][0]['#']['text'];
     $qo = qtype_multianswer_extract_question($this->import_text($questiontext));
     // 'header' parts particular to multianswer
     $qo->qtype = MULTIANSWER;
     $qo->course = $this->course;
     $qo->generalfeedback = $this->getpath($questions, array('#', 'generalfeedback', 0, '#', 'text', 0, '#'), '', true);
     if (!empty($questions)) {
         $qo->name = $this->import_text($questions['#']['name'][0]['#']['text']);
     }
     return $qo;
 }
开发者ID:veritech,项目名称:pare-project,代码行数:18,代码来源:format.php

示例8: import_multianswer

 /**
  * Import cloze type question
  * @param array question question array from xml tree
  * @return object question object
  */
 public function import_multianswer($question)
 {
     global $USER;
     question_bank::get_qtype('multianswer');
     $questiontext = $this->import_text_with_files($question, array('#', 'questiontext', 0));
     $qo = qtype_multianswer_extract_question($questiontext);
     // Header parts particular to multianswer.
     $qo->qtype = 'multianswer';
     $qo->course = $this->course;
     $qo->name = $this->clean_question_name($this->import_text($question['#']['name'][0]['#']['text']));
     $qo->questiontextformat = $questiontext['format'];
     $qo->questiontext = $qo->questiontext['text'];
     if (!empty($questiontext['itemid'])) {
         $qo->questiontextitemid = $questiontext['itemid'];
     }
     // Backwards compatibility, deal with the old image tag.
     $filedata = $this->getpath($question, array('#', 'image_base64', '0', '#'), null, false);
     $filename = $this->getpath($question, array('#', 'image', '0', '#'), null, false);
     if ($filedata && $filename) {
         $fs = get_file_storage();
         if (empty($qo->questiontextitemid)) {
             $qo->questiontextitemid = file_get_unused_draft_itemid();
         }
         $filename = clean_param(str_replace('/', '_', $filename), PARAM_FILE);
         $filerecord = array('contextid' => context_user::instance($USER->id)->id, 'component' => 'user', 'filearea' => 'draft', 'itemid' => $qo->questiontextitemid, 'filepath' => '/', 'filename' => $filename);
         $fs->create_file_from_string($filerecord, base64_decode($filedata));
         $qo->questiontext .= ' <img src="@@PLUGINFILE@@/' . $filename . '" />';
     }
     // Restore files in generalfeedback.
     $generalfeedback = $this->import_text_with_files($question, array('#', 'generalfeedback', 0), $qo->generalfeedback, $this->get_format($qo->questiontextformat));
     $qo->generalfeedback = $generalfeedback['text'];
     $qo->generalfeedbackformat = $generalfeedback['format'];
     if (!empty($generalfeedback['itemid'])) {
         $qo->generalfeedbackitemid = $generalfeedback['itemid'];
     }
     $qo->penalty = $this->getpath($question, array('#', 'penalty', 0, '#'), $this->defaultquestion()->penalty);
     // Fix problematic rounding from old files.
     if (abs($qo->penalty - 0.3333333) < 0.005) {
         $qo->penalty = 0.3333333;
     }
     $this->import_hints($qo, $question, true, false, $this->get_format($qo->questiontextformat));
     return $qo;
 }
开发者ID:helenagarcia90,项目名称:moodle,代码行数:48,代码来源:format.php

示例9: validation

 public function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     $questiondisplay = qtype_multianswer_extract_question($data['questiontext']);
     if (isset($questiondisplay->options->questions)) {
         $subquestions = fullclone($questiondisplay->options->questions);
         if (count($subquestions)) {
             $sub = 1;
             foreach ($subquestions as $subquestion) {
                 $prefix = 'sub_' . $sub . '_';
                 $answercount = 0;
                 $maxgrade = false;
                 $maxfraction = -1;
                 foreach ($subquestion->answer as $key => $answer) {
                     if (is_array($answer)) {
                         $answer = $answer['text'];
                     }
                     $trimmedanswer = trim($answer);
                     if ($trimmedanswer !== '') {
                         $answercount++;
                         if ($subquestion->qtype == 'numerical' && !($this->is_valid_number($trimmedanswer) || $trimmedanswer == '*')) {
                             $errors[$prefix . 'answer[' . $key . ']'] = get_string('answermustbenumberorstar', 'qtype_numerical');
                         }
                         if ($subquestion->fraction[$key] == 1) {
                             $maxgrade = true;
                         }
                         if ($subquestion->fraction[$key] > $maxfraction) {
                             $maxfraction = $subquestion->fraction[$key];
                         }
                     }
                 }
                 if ($answercount == 0) {
                     if ($subquestion->qtype == 'multichoice') {
                         $errors[$prefix . 'answer[0]'] = get_string('notenoughanswers', 'qtype_multichoice', 2);
                     } else {
                         $errors[$prefix . 'answer[0]'] = get_string('notenoughanswers', 'question', 1);
                     }
                 }
                 if ($maxgrade == false) {
                     $errors[$prefix . 'fraction[0]'] = get_string('fractionsnomax', 'question');
                 }
                 $sub++;
             }
         } else {
             $errors['questiontext'] = get_string('questionsmissing', 'qtype_multianswer');
         }
     }
     if (($this->negativediff > 0 || $this->usedinquiz && ($this->negativediff > 0 || $this->negativediff < 0 || $this->qtypechange)) && !$this->confirm) {
         $errors['confirm'] = get_string('confirmsave', 'qtype_multianswer', $this->negativediff);
     }
     return $errors;
 }
开发者ID:rushi963,项目名称:moodle,代码行数:52,代码来源:edit_multianswer_form.php

示例10: import_multianswer

 /**
  * import cloze type question
  * @param array question question array from xml tree
  * @return object question object
  */
 function import_multianswer($questions)
 {
     $questiontext = array();
     $questiontext['text'] = $this->import_text($questions['#']['questiontext'][0]['#']['text']);
     $questiontext['format'] = '1';
     $questiontext['itemid'] = '';
     $qo = qtype_multianswer_extract_question($questiontext);
     // 'header' parts particular to multianswer
     $qo->qtype = MULTIANSWER;
     $qo->course = $this->course;
     $qo->generalfeedback = '';
     // restore files in generalfeedback
     $qo->generalfeedback = $this->getpath($questions, array('#', 'generalfeedback', 0, '#', 'text', 0, '#'), $qo->generalfeedback, true);
     $qo->generalfeedbackfiles = array();
     $qo->generalfeedbackformat = $this->trans_format($this->getpath($questions, array('#', 'generalfeedback', 0, '@', 'format'), 'moodle_auto_format'));
     $files = $this->getpath($questions, array('#', 'generalfeedback', 0, '#', 'file'), array(), false);
     foreach ($files as $file) {
         $data = new stdclass();
         $data->content = $file['#'];
         $data->encoding = $file['@']['encoding'];
         $data->name = $file['@']['name'];
         $qo->generalfeedbackfiles[] = $data;
     }
     if (!empty($questions)) {
         $qo->name = $this->import_text($questions['#']['name'][0]['#']['text']);
     }
     $qo->questiontext = $qo->questiontext['text'];
     $qo->questiontextformat = '';
     return $qo;
 }
开发者ID:esyacelga,项目名称:sisadmaca,代码行数:35,代码来源:format.php

示例11: import_multianswer

 /**
  * Import cloze type question
  * @param array question question array from xml tree
  * @return object question object
  */
 public function import_multianswer($question)
 {
     question_bank::get_qtype('multianswer');
     $questiontext['text'] = $this->import_text($question['#']['questiontext'][0]['#']['text']);
     $questiontext['format'] = FORMAT_HTML;
     $questiontext['itemid'] = '';
     $qo = qtype_multianswer_extract_question($questiontext);
     // 'header' parts particular to multianswer
     $qo->qtype = 'multianswer';
     $qo->course = $this->course;
     $qo->generalfeedback = '';
     $qo->name = $this->clean_question_name($this->import_text($question['#']['name'][0]['#']['text']));
     $qo->questiontextformat = $questiontext['format'];
     $qo->questiontext = $qo->questiontext['text'];
     $itemid = $this->import_files($this->getpath($question, array('#', 'questiontext', 0, '#', 'file'), array(), false));
     if (!empty($itemid)) {
         $qo->questiontextitemid = $itemid;
     }
     // Backwards compatibility, deal with the old image tag.
     $filedata = $this->getpath($question, array('#', 'image_base64', '0', '#'), null, false);
     $filename = $this->getpath($question, array('#', 'image', '0', '#'), null, false);
     if ($filedata && $filename) {
         $data = new stdClass();
         $data->content = $filedata;
         $data->encoding = 'base64';
         // Question file areas don't support subdirs, so convert path to filename if necessary.
         $data->name = clean_param(str_replace('/', '_', $filename), PARAM_FILE);
         $qo->questiontextfiles[] = $data;
         $qo->questiontext .= ' <img src="@@PLUGINFILE@@/' . $data->name . '" />';
     }
     // restore files in generalfeedback
     $generalfeedback = $this->import_text_with_files($question, array('#', 'generalfeedback', 0), $qo->generalfeedback, $this->get_format($qo->questiontextformat));
     $qo->generalfeedback = $generalfeedback['text'];
     $qo->generalfeedbackformat = $generalfeedback['format'];
     if (!empty($generalfeedback['itemid'])) {
         $qo->generalfeedbackitemid = $generalfeedback['itemid'];
     }
     $qo->penalty = $this->getpath($question, array('#', 'penalty', 0, '#'), $this->defaultquestion()->penalty);
     // Fix problematic rounding from old files:
     if (abs($qo->penalty - 0.3333333) < 0.005) {
         $qo->penalty = 0.3333333;
     }
     $this->import_hints($qo, $question, false, false, $this->get_format($qo->questiontextformat));
     return $qo;
 }
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:50,代码来源:format.php

示例12: test_questiontext_extraction_of_multiplechoice_subquestions_variants

 /**
  *  Verify that the multiplechoice variants parameters are correctly interpreted from
  *  the question text
  *
  *
  */
 public function test_questiontext_extraction_of_multiplechoice_subquestions_variants()
 {
     $questiontext = array();
     $questiontext['format'] = FORMAT_HTML;
     $questiontext['itemid'] = '';
     $questiontext['text'] = '<p>Match the following cities with the correct state:</p>
         <ul>
         <li>1 San Francisco:{1:MULTICHOICE:=California#OK~Arizona#Wrong}</li>
         <li>2 Tucson:{1:MC:%0%California#Wrong~=Arizona#OK}</li>
         <li>3 Los Angeles:{1:MULTICHOICE_S:=California#OK~Arizona#Wrong}</li>
         <li>4 Phoenix:{1:MCS:%0%California#Wrong~=Arizona#OK}</li>
         <li>5 San Francisco:{1:MULTICHOICE_H:=California#OK~Arizona#Wrong}</li>
         <li>6 Tucson:{1:MCH:%0%California#Wrong~=Arizona#OK}</li>
         <li>7 Los Angeles:{1:MULTICHOICE_HS:=California#OK~Arizona#Wrong}</li>
         <li>8 Phoenix:{1:MCHS:%0%California#Wrong~=Arizona#OK}</li>
         <li>9 San Francisco:{1:MULTICHOICE_V:=California#OK~Arizona#Wrong}</li>
         <li>10 Tucson:{1:MCV:%0%California#Wrong~=Arizona#OK}</li>
         <li>11 Los Angeles:{1:MULTICHOICE_VS:=California#OK~Arizona#Wrong}</li>
         <li>12 Phoenix:{1:MCVS:%0%California#Wrong~=Arizona#OK}</li>
         </ul>';
     $q = qtype_multianswer_extract_question($questiontext);
     foreach ($q->options->questions as $key => $sub) {
         $this->assertSame($sub->qtype, 'multichoice');
         if ($key == 1 || $key == 2 || $key == 5 || $key == 6 || $key == 9 || $key == 10) {
             $this->assertSame($sub->shuffleanswers, 0);
         } else {
             $this->assertSame($sub->shuffleanswers, 1);
         }
         if ($key == 1 || $key == 2 || $key == 3 || $key == 4) {
             $this->assertSame($sub->layout, qtype_multichoice_base::LAYOUT_DROPDOWN);
         } else {
             if ($key == 5 || $key == 6 || $key == 7 || $key == 8) {
                 $this->assertSame($sub->layout, qtype_multichoice_base::LAYOUT_HORIZONTAL);
             } else {
                 if ($key == 9 || $key == 10 || $key == 11 || $key == 12) {
                     $this->assertSame($sub->layout, qtype_multichoice_base::LAYOUT_VERTICAL);
                 }
             }
         }
     }
 }
开发者ID:evltuma,项目名称:moodle,代码行数:47,代码来源:questiontype_test.php

示例13: import_multianswer

 /**
  * Import cloze type question
  * @param array question question array from xml tree
  * @return object question object
  */
 public function import_multianswer($questions)
 {
     question_bank::get_qtype('multianswer');
     $questiontext = array();
     $questiontext['text'] = $this->import_text($questions['#']['questiontext'][0]['#']['text']);
     $questiontext['format'] = '1';
     $questiontext['itemid'] = '';
     $qo = qtype_multianswer_extract_question($questiontext);
     // 'header' parts particular to multianswer
     $qo->qtype = MULTIANSWER;
     $qo->course = $this->course;
     $qo->generalfeedback = '';
     // restore files in generalfeedback
     $qo->generalfeedback = $this->getpath($questions, array('#', 'generalfeedback', 0, '#', 'text', 0, '#'), $qo->generalfeedback, true);
     $qo->generalfeedbackformat = $this->trans_format($this->getpath($questions, array('#', 'generalfeedback', 0, '@', 'format'), 'moodle_auto_format'));
     $qo->generalfeedbackfiles = $this->import_files($this->getpath($questions, array('#', 'generalfeedback', 0, '#', 'file'), array(), false));
     if (!empty($questions)) {
         $qo->name = $this->import_text($questions['#']['name'][0]['#']['text']);
     }
     $qo->questiontext = $qo->questiontext['text'];
     $qo->questiontextformat = '';
     $this->import_hints($qo, $questions, true);
     return $qo;
 }
开发者ID:sebastiansanio,项目名称:tallerdeprogramacion2fiuba,代码行数:29,代码来源:format.php

示例14: wrsqz_qtype_multianswer_extract_question

function wrsqz_qtype_multianswer_extract_question($form){
    global $CFG;
    //include($CFG->dirroot . '/question/type/multianswer/questiontype.php');
    $text = $form->questiontext;

    $question = qtype_multianswer_extract_question($text);
    
    //if ( isset($form->hiddenCASValue) && !wrsqz_isEmptySession($form->hiddenCASValue)){
        $question->qtype = 'multianswerwiris';
        foreach($question->options->questions as $key=>$wrapped){
            if(($wrapped->qtype == 'shortanswer' || $wrapped->qtype == 'multichoice')
                && strpos($wrapped->questiontext,'#')!==false){
                $wrapped->qtype .= 'wiris';
            }
            $question->options->questions[$key] = $wrapped;
        }
   // }
    return $question;
}
开发者ID:nagyistoce,项目名称:moodle-Teach-Pilot,代码行数:19,代码来源:libquestiontype.php

示例15: validation

 function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     $questiondisplay = qtype_multianswer_extract_question($data['questiontext']);
     //                   echo "<p> questiondisplay ".$data['questiontext']['text']." <pre>";print_r($questiondisplay);echo "</pre></p>";
     if (isset($questiondisplay->options->questions)) {
         $subquestions = fullclone($questiondisplay->options->questions);
         if (count($subquestions)) {
             $sub = 1;
             foreach ($subquestions as $subquestion) {
                 $prefix = 'sub_' . $sub . '_';
                 $answercount = 0;
                 $maxgrade = false;
                 $maxfraction = -1;
                 if (isset($this->savedquestiondisplay->options->questions[$sub]->qtype) && $this->savedquestiondisplay->options->questions[$sub]->qtype != $questiondisplay->options->questions[$sub]->qtype) {
                     $storemess = " STORED QTYPE " . $question_type_names[$this->savedquestiondisplay->options->questions[$sub]->qtype];
                 }
                 foreach ($subquestion->answer as $key => $answer) {
                     $trimmedanswer = trim($answer);
                     if ($trimmedanswer !== '') {
                         $answercount++;
                         if ($subquestion->qtype == 'numerical' && !(is_numeric($trimmedanswer) || $trimmedanswer == '*')) {
                             $errors[$prefix . 'answer[' . $key . ']'] = get_string('answermustbenumberorstar', 'qtype_numerical');
                         }
                         if ($subquestion->fraction[$key] == 1) {
                             $maxgrade = true;
                         }
                         if ($subquestion->fraction[$key] > $maxfraction) {
                             $maxfraction = $subquestion->fraction[$key];
                         }
                     }
                 }
                 if ($answercount == 0) {
                     if ($subquestion->qtype == 'multichoice') {
                         $errors[$prefix . 'answer[0]'] = get_string('notenoughanswers', 'qtype_multichoice', 2);
                     } else {
                         $errors[$prefix . 'answer[0]'] = get_string('notenoughanswers', 'quiz', 1);
                     }
                 }
                 if ($maxgrade == false) {
                     $errors[$prefix . 'fraction[0]'] = get_string('fractionsnomax', 'question');
                 }
                 $sub++;
             }
         } else {
             $errors['questiontext'] = get_string('questionsmissing', 'qtype_multianswer');
         }
     }
     // $question = qtype_multianswer_extract_question($data['questiontext']);
     //  if (isset $question->options->questions
     if (($this->negative_diff > 0 || $this->used_in_quiz && ($this->negative_diff > 0 || $this->negative_diff < 0 || $this->qtype_change)) && $this->confirm == 0) {
         $errors['confirm'] = get_string('confirmsave', 'qtype_multianswer', $this->negative_diff);
     }
     return $errors;
 }
开发者ID:esyacelga,项目名称:sisadmaca,代码行数:55,代码来源:edit_multianswer_form.php


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