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


PHP match_grade_options函数代码示例

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


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

示例1: test_match_grade_options

 public function test_match_grade_options()
 {
     $gradeoptions = question_bank::fraction_options_full();
     $this->assertEquals(0.3333333, match_grade_options($gradeoptions, 0.3333333, 'error'));
     $this->assertEquals(0.3333333, match_grade_options($gradeoptions, 0.333333, 'error'));
     $this->assertEquals(0.3333333, match_grade_options($gradeoptions, 0.33333, 'error'));
     $this->assertFalse(match_grade_options($gradeoptions, 0.3333, 'error'));
     $this->assertEquals(0.3333333, match_grade_options($gradeoptions, 0.3333333, 'nearest'));
     $this->assertEquals(0.3333333, match_grade_options($gradeoptions, 0.333333, 'nearest'));
     $this->assertEquals(0.3333333, match_grade_options($gradeoptions, 0.33333, 'nearest'));
     $this->assertEquals(0.3333333, match_grade_options($gradeoptions, 0.33, 'nearest'));
     $this->assertEquals(-0.1428571, match_grade_options($gradeoptions, -0.15, 'nearest'));
 }
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:13,代码来源:questionlib_test.php

示例2: importprocess

    /**
     * Process the file
     * This method should not normally be overidden
     * @param object $category
     * @return bool success
     */
    public function importprocess($category) {
        global $USER, $CFG, $DB, $OUTPUT;

        $context = $category->context;
        $this->importcontext = $context;

        // reset the timer in case file upload was slow
        set_time_limit(0);

        // STAGE 1: Parse the file
        echo $OUTPUT->notification(get_string('parsingquestions', 'question'), 'notifysuccess');

        if (! $lines = $this->readdata($this->filename)) {
            echo $OUTPUT->notification(get_string('cannotread', 'question'));
            return false;
        }

        if (!$questions = $this->readquestions($lines, $context)) {   // Extract all the questions
            echo $OUTPUT->notification(get_string('noquestionsinfile', 'question'));
            return false;
        }

        // STAGE 2: Write data to database
        echo $OUTPUT->notification(get_string('importingquestions', 'question',
                $this->count_questions($questions)), 'notifysuccess');

        // check for errors before we continue
        if ($this->stoponerror and ($this->importerrors>0)) {
            echo $OUTPUT->notification(get_string('importparseerror', 'question'));
            return true;
        }

        // get list of valid answer grades
        $gradeoptionsfull = question_bank::fraction_options_full();

        // check answer grades are valid
        // (now need to do this here because of 'stop on error': MDL-10689)
        $gradeerrors = 0;
        $goodquestions = array();
        foreach ($questions as $question) {
            if (!empty($question->fraction) and (is_array($question->fraction))) {
                $fractions = $question->fraction;
                $answersvalid = true; // in case they are!
                foreach ($fractions as $key => $fraction) {
                    $newfraction = match_grade_options($gradeoptionsfull, $fraction,
                            $this->matchgrades);
                    if ($newfraction === false) {
                        $answersvalid = false;
                    } else {
                        $fractions[$key] = $newfraction;
                    }
                }
                if (!$answersvalid) {
                    echo $OUTPUT->notification(get_string('invalidgrade', 'question'));
                    ++$gradeerrors;
                    continue;
                } else {
                    $question->fraction = $fractions;
                }
            }
            $goodquestions[] = $question;
        }
        $questions = $goodquestions;

        // check for errors before we continue
        if ($this->stoponerror && $gradeerrors > 0) {
            return false;
        }

        // count number of questions processed
        $count = 0;

        foreach ($questions as $question) {   // Process and store each question

            // reset the php timeout
            set_time_limit(0);

            // check for category modifiers
            if ($question->qtype == 'category') {
                if ($this->catfromfile) {
                    // find/create category object
                    $catpath = $question->category;
                    $newcategory = $this->create_category_path($catpath);
                    if (!empty($newcategory)) {
                        $this->category = $newcategory;
                    }
                }
                continue;
            }
            $question->context = $context;

            $count++;

            echo "<hr /><p><b>$count</b>. ".$this->format_question_text($question)."</p>";
//.........这里部分代码省略.........
开发者ID:nigeldaley,项目名称:moodle,代码行数:101,代码来源:format.php

示例3: importprocess

 /**
  * Process the file
  * This method should not normally be overidden
  * @return boolean success
  */
 function importprocess()
 {
     global $USER;
     // reset the timer in case file upload was slow
     @set_time_limit();
     // STAGE 1: Parse the file
     notify(get_string('parsingquestions', 'quiz'));
     if (!($lines = $this->readdata($this->filename))) {
         notify(get_string('cannotread', 'quiz'));
         return false;
     }
     if (!($questions = $this->readquestions($lines))) {
         // Extract all the questions
         notify(get_string('noquestionsinfile', 'quiz'));
         return false;
     }
     // STAGE 2: Write data to database
     notify(get_string('importingquestions', 'quiz', $this->count_questions($questions)));
     // check for errors before we continue
     if ($this->stoponerror and $this->importerrors > 0) {
         notify(get_string('importparseerror', 'quiz'));
         return true;
     }
     // get list of valid answer grades
     $grades = get_grade_options();
     $gradeoptionsfull = $grades->gradeoptionsfull;
     // check answer grades are valid
     // (now need to do this here because of 'stop on error': MDL-10689)
     $gradeerrors = 0;
     $goodquestions = array();
     foreach ($questions as $question) {
         if (!empty($question->fraction) and is_array($question->fraction)) {
             $fractions = $question->fraction;
             $answersvalid = true;
             // in case they are!
             foreach ($fractions as $key => $fraction) {
                 $newfraction = match_grade_options($gradeoptionsfull, $fraction, $this->matchgrades);
                 if ($newfraction === false) {
                     $answersvalid = false;
                 } else {
                     $fractions[$key] = $newfraction;
                 }
             }
             if (!$answersvalid) {
                 notify(get_string('matcherror', 'quiz'));
                 ++$gradeerrors;
                 continue;
             } else {
                 $question->fraction = $fractions;
             }
         }
         $goodquestions[] = $question;
     }
     $questions = $goodquestions;
     // check for errors before we continue
     if ($this->stoponerror and $gradeerrors > 0) {
         return false;
     }
     // count number of questions processed
     $count = 0;
     foreach ($questions as $question) {
         // Process and store each question
         // reset the php timeout
         @set_time_limit();
         // check for category modifiers
         if ($question->qtype == 'category') {
             if ($this->catfromfile) {
                 // find/create category object
                 $catpath = $question->category;
                 $newcategory = $this->create_category_path($catpath, '/');
                 if (!empty($newcategory)) {
                     $this->category = $newcategory;
                 }
             }
             continue;
         }
         $count++;
         echo "<hr /><p><b>{$count}</b>. " . $this->format_question_text($question) . "</p>";
         $question->category = $this->category->id;
         $question->stamp = make_unique_id_code();
         // Set the unique code (not to be changed)
         $question->createdby = $USER->id;
         $question->timecreated = time();
         if (!($question->id = insert_record("question", $question))) {
             error(get_string('cannotinsert', 'quiz'));
         }
         $this->questionids[] = $question->id;
         // Now to save all the answers and type-specific options
         global $QTYPES;
         $result = $QTYPES[$question->qtype]->save_question_options($question);
         if (!empty($result->error)) {
             notify($result->error);
             return false;
         }
         if (!empty($result->notice)) {
//.........这里部分代码省略.........
开发者ID:kai707,项目名称:ITSA-backup,代码行数:101,代码来源:format.php

示例4: importprocess

 /**
  * Process the file
  * This method should not normally be overidden
  * @param object $category
  * @return bool success
  */
 public function importprocess($category)
 {
     global $USER, $CFG, $DB, $OUTPUT;
     // Raise time and memory, as importing can be quite intensive.
     core_php_time_limit::raise();
     raise_memory_limit(MEMORY_EXTRA);
     // STAGE 1: Parse the file
     echo $OUTPUT->notification(get_string('parsingquestions', 'question'), 'notifysuccess');
     if (!($lines = $this->readdata($this->filename))) {
         echo $OUTPUT->notification(get_string('cannotread', 'question'));
         return false;
     }
     if (!($questions = $this->readquestions($lines))) {
         // Extract all the questions
         echo $OUTPUT->notification(get_string('noquestionsinfile', 'question'));
         return false;
     }
     // STAGE 2: Write data to database
     echo $OUTPUT->notification(get_string('importingquestions', 'question', $this->count_questions($questions)), 'notifysuccess');
     // check for errors before we continue
     if ($this->stoponerror and $this->importerrors > 0) {
         echo $OUTPUT->notification(get_string('importparseerror', 'question'));
         return true;
     }
     // get list of valid answer grades
     $gradeoptionsfull = question_bank::fraction_options_full();
     // check answer grades are valid
     // (now need to do this here because of 'stop on error': MDL-10689)
     $gradeerrors = 0;
     $goodquestions = array();
     foreach ($questions as $question) {
         if (!empty($question->fraction) and is_array($question->fraction)) {
             $fractions = $question->fraction;
             $invalidfractions = array();
             foreach ($fractions as $key => $fraction) {
                 $newfraction = match_grade_options($gradeoptionsfull, $fraction, $this->matchgrades);
                 if ($newfraction === false) {
                     $invalidfractions[] = $fraction;
                 } else {
                     $fractions[$key] = $newfraction;
                 }
             }
             if ($invalidfractions) {
                 echo $OUTPUT->notification(get_string('invalidgrade', 'question', implode(', ', $invalidfractions)));
                 ++$gradeerrors;
                 continue;
             } else {
                 $question->fraction = $fractions;
             }
         }
         $goodquestions[] = $question;
     }
     $questions = $goodquestions;
     // check for errors before we continue
     if ($this->stoponerror && $gradeerrors > 0) {
         return false;
     }
     // count number of questions processed
     $count = 0;
     foreach ($questions as $question) {
         // Process and store each question
         $transaction = $DB->start_delegated_transaction();
         // reset the php timeout
         core_php_time_limit::raise();
         // check for category modifiers
         if ($question->qtype == 'category') {
             if ($this->catfromfile) {
                 // find/create category object
                 $catpath = $question->category;
                 $newcategory = $this->create_category_path($catpath);
                 if (!empty($newcategory)) {
                     $this->category = $newcategory;
                 }
             }
             $transaction->allow_commit();
             continue;
         }
         $question->context = $this->importcontext;
         $count++;
         echo "<hr /><p><b>{$count}</b>. " . $this->format_question_text($question) . "</p>";
         $question->category = $this->category->id;
         $question->stamp = make_unique_id_code();
         // Set the unique code (not to be changed)
         $question->createdby = $USER->id;
         $question->timecreated = time();
         $question->modifiedby = $USER->id;
         $question->timemodified = time();
         $fileoptions = array('subdirs' => true, 'maxfiles' => -1, 'maxbytes' => 0);
         $question->id = $DB->insert_record('question', $question);
         if (isset($question->questiontextitemid)) {
             $question->questiontext = file_save_draft_area_files($question->questiontextitemid, $this->importcontext->id, 'question', 'questiontext', $question->id, $fileoptions, $question->questiontext);
         } else {
             if (isset($question->questiontextfiles)) {
                 foreach ($question->questiontextfiles as $file) {
//.........这里部分代码省略.........
开发者ID:alanaipe2015,项目名称:moodle,代码行数:101,代码来源:format.php


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