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


PHP default_questiontype::save_question_options方法代码示例

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


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

示例1: stdClass

 function save_question_options($question)
 {
     global $DB;
     $result = new stdClass();
     if (!($oldanswers = $DB->get_records('question_answers', array('question' => $question->id), 'id ASC'))) {
         $oldanswers = array();
     }
     $answers = array();
     $maxfraction = -1;
     // Insert all the new answers
     foreach ($question->answer as $key => $dataanswer) {
         // Check for, and ingore, completely blank answer from the form.
         if (trim($dataanswer) == '' && $question->fraction[$key] == 0 && html_is_blank($question->feedback[$key])) {
             continue;
         }
         if ($oldanswer = array_shift($oldanswers)) {
             // Existing answer, so reuse it
             $answer = $oldanswer;
             $answer->answer = trim($dataanswer);
             $answer->fraction = $question->fraction[$key];
             $answer->feedback = $question->feedback[$key];
             $DB->update_record("question_answers", $answer);
         } else {
             // This is a completely new answer
             $answer = new stdClass();
             $answer->answer = trim($dataanswer);
             $answer->question = $question->id;
             $answer->fraction = $question->fraction[$key];
             $answer->feedback = $question->feedback[$key];
             $answer->id = $DB->insert_record("question_answers", $answer);
         }
         $answers[] = $answer->id;
         if ($question->fraction[$key] > $maxfraction) {
             $maxfraction = $question->fraction[$key];
         }
     }
     $question->answers = implode(',', $answers);
     $parentresult = parent::save_question_options($question);
     if ($parentresult !== null) {
         // Parent function returns null if all is OK
         return $parentresult;
     }
     // delete old answer records
     if (!empty($oldanswers)) {
         foreach ($oldanswers as $oa) {
             $DB->delete_records('question_answers', array('id' => $oa->id));
         }
     }
     /// Perform sanity checks on fractional grades
     if ($maxfraction != 1) {
         $maxfraction = $maxfraction * 100;
         $result->noticeyesno = get_string("fractionsnomax", "quiz", $maxfraction);
         return $result;
     } else {
         return true;
     }
 }
开发者ID:ajv,项目名称:Offline-Caching,代码行数:57,代码来源:questiontype.php

示例2: stdClass

 function save_question_options($question)
 {
     $result = new stdClass();
     $conditions = array();
     $conditions_uncleaned = explode("\r\n", $question->conditions);
     foreach ($conditions_uncleaned as $condition_uncleaned) {
         if (strlen(trim($condition_uncleaned)) > 0) {
             $conditions[] = trim($condition_uncleaned);
         }
     }
     $question->conditions = implode("\r\n", $conditions);
     $parentresult = parent::save_question_options($question);
     if ($parentresult !== null) {
         // Parent function returns null if all is OK
         return $parentresult;
     }
 }
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:17,代码来源:questiontype.php

示例3: foreach

 /**
  * Saves question-type specific options
  *
  * This is called by {@link save_question()} to save the question-type specific data from a
  * submitted form. This method takes the form data and formats into the correct format for
  * writing to the database. It then calls the parent method to actually write the data.
  *
  * @param object $question  This holds the information from the editing form,
  *                          it is not a standard question object.
  * @return object $result->error or $result->noticeyesno or $result->notice
  */
 function save_question_options($question)
 {
     // Start a try block to catch any exceptions generated when we attempt to parse and
     // then add the answers and variables to the database
     try {
         // Loop over all the answers in the question form and parse them to generate
         // a parser string. This ensures a constant formatting is stored in the database
         foreach ($question->answer as &$answer) {
             $expr = $this->parse_expression($answer);
             $answer = $expr->sage();
         }
         // Now we need to write out all the answers to the question to the database
         $answers = $this->save_question_answers($question);
         $question->answers = implode(',', $answers);
         // The next task is to write out all the variables associated with the question
         $variables = $this->save_question_variables($question);
         $question->variables = implode(',', $variables);
     } catch (Exception $e) {
         // Error when adding answers orvariables to the database so create a result class
         // and put the error string in the error member funtion and then return the class
         // This keeps us compatible with the existing save_question_options methods.
         $result = new stdClass();
         $result->error = $e->getMessage();
         return $result;
     }
     // Process the allowed functions field. This code just sets up the variable, it is saved
     // in the parent class' save_question_options method called at the end of this method
     // Look for the 'all' option. If we find it then set the string to an empty value
     if (array_key_exists('all', $question->allowedfuncs)) {
         $question->allowedfuncs = '';
     } else {
         // Create a comma separated string of the function names which are stored in the
         // keys of the array
         $question->allowedfuncs = implode(',', array_keys($question->allowedfuncs));
     }
     // Call the parent method to write the extensions fields to the database. This either returns null
     // or an error object so if we get anything then return it otherwise return our existing
     if ($res = parent::save_question_options($question)) {
         return $res;
     } else {
         return true;
     }
 }
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:54,代码来源:questiontype.php

示例4: stdClass

 function save_question_options($question)
 {
     global $DB;
     $result = new stdClass();
     $context = $question->context;
     $oldanswers = $DB->get_records('question_answers', array('question' => $question->id), 'id ASC');
     // Insert all the new answers
     $answers = array();
     $maxfraction = -1;
     foreach ($question->answer as $key => $answerdata) {
         // Check for, and ignore, completely blank answer from the form.
         if (trim($answerdata) == '' && $question->fraction[$key] == 0 && html_is_blank($question->feedback[$key]['text'])) {
             continue;
         }
         // Update an existing answer if possible.
         $answer = array_shift($oldanswers);
         if (!$answer) {
             $answer = new stdClass();
             $answer->question = $question->id;
             $answer->answer = '';
             $answer->feedback = '';
             $answer->id = $DB->insert_record('question_answers', $answer);
         }
         $answer->answer = trim($answerdata);
         $answer->fraction = $question->fraction[$key];
         $answer->feedback = $this->import_or_save_files($question->feedback[$key], $context, 'question', 'answerfeedback', $answer->id);
         $answer->feedbackformat = $question->feedback[$key]['format'];
         $DB->update_record('question_answers', $answer);
         $answers[] = $answer->id;
         if ($question->fraction[$key] > $maxfraction) {
             $maxfraction = $question->fraction[$key];
         }
     }
     // Delete any left over old answer records.
     $fs = get_file_storage();
     foreach ($oldanswers as $oldanswer) {
         $fs->delete_area_files($context->id, 'question', 'answerfeedback', $oldanswer->id);
         $DB->delete_records('question_answers', array('id' => $oldanswer->id));
     }
     $question->answers = implode(',', $answers);
     $parentresult = parent::save_question_options($question);
     if ($parentresult !== null) {
         // Parent function returns null if all is OK
         return $parentresult;
     }
     // Perform sanity checks on fractional grades
     if ($maxfraction != 1) {
         $result->noticeyesno = get_string('fractionsnomax', 'quiz', $maxfraction * 100);
         return $result;
     }
     return true;
 }
开发者ID:vuchannguyen,项目名称:web,代码行数:52,代码来源:questiontype.php


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