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


PHP question_edit_form::set_data方法代码示例

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


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

示例1: array

 function set_data($question)
 {
     if (!empty($question->options->trueanswer)) {
         $trueanswer = $question->options->answers[$question->options->trueanswer];
         $draftid = file_get_submitted_draft_itemid('trueanswer');
         $answerid = $question->options->trueanswer;
         $text = $trueanswer->feedback;
         $question->correctanswer = $trueanswer->fraction != 0;
         $question->feedbacktrue = array();
         $question->feedbacktrue['text'] = $trueanswer->feedback;
         $question->feedbacktrue['format'] = $trueanswer->feedbackformat;
         $question->feedbacktrue['text'] = file_prepare_draft_area($draftid, $this->context->id, 'question', 'answerfeedback', !empty($answerid) ? (int) $answerid : null, $this->fileoptions, $text);
         $question->feedbacktrue['itemid'] = $draftid;
     }
     if (!empty($question->options->falseanswer)) {
         $falseanswer = $question->options->answers[$question->options->falseanswer];
         $draftid = file_get_submitted_draft_itemid('falseanswer');
         $answerid = $question->options->falseanswer;
         $text = $falseanswer->feedback;
         $question->feedbackfalse = array();
         $question->feedbackfalse['text'] = $falseanswer->feedback;
         $question->feedbackfalse['format'] = $falseanswer->feedbackformat;
         $question->feedbackfalse['text'] = file_prepare_draft_area($draftid, $this->context->id, 'question', 'answerfeedback', !empty($answerid) ? (int) $answerid : null, $this->fileoptions, $text);
         $question->feedbackfalse['itemid'] = $draftid;
     }
     parent::set_data($question);
 }
开发者ID:vuchannguyen,项目名称:web,代码行数:27,代码来源:edit_truefalse_form.php

示例2:

 function set_data($question)
 {
     if (empty($question->name)) {
         $question->name = get_string("random", "quiz");
     }
     parent::set_data($question);
 }
开发者ID:veritech,项目名称:pare-project,代码行数:7,代码来源:edit_random_form.php

示例3: reset

 function set_data($question)
 {
     if (!empty($question->options) && !empty($question->options->answers)) {
         $answer = reset($question->options->answers);
         $question->feedback = $answer->feedback;
     }
     $question->penalty = 0;
     parent::set_data($question);
 }
开发者ID:kai707,项目名称:ITSA-backup,代码行数:9,代码来源:edit_essay_form.php

示例4:

 function set_data($question)
 {
     if (!empty($question->options->trueanswer)) {
         $trueanswer = $question->options->answers[$question->options->trueanswer];
         $question->correctanswer = $trueanswer->fraction != 0;
         $question->feedbacktrue = $trueanswer->feedback;
         $question->feedbackfalse = $question->options->answers[$question->options->falseanswer]->feedback;
     }
     parent::set_data($question);
 }
开发者ID:JackCanada,项目名称:moodle-hacks,代码行数:10,代码来源:edit_truefalse_form.php

示例5: reset

 function set_data($question)
 {
     if (!empty($question->options)) {
         $question->essay = $question->options->essay;
         $question->maxbytes = $question->options->maxbytes;
         if (!empty($question->options->answers)) {
             $answer = reset($question->options->answers);
             $question->feedback = $answer->feedback;
         }
     }
     $question->penalty = 0;
     parent::set_data($question);
 }
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:13,代码来源:edit_imagedit_form.php

示例6: set_data

 public function set_data($question)
 {
     if (isset($question->options) && is_array($question->options->answers)) {
         $answers = $question->options->answers;
         $default_values = array();
         $key = 0;
         foreach ($answers as $answer) {
             $default_values['answer[' . $key . ']'] = $answer->answer;
             $default_values['fraction[' . $key . ']'] = $answer->fraction;
             $default_values['feedback[' . $key . ']'] = $answer->feedback;
             $key++;
         }
         $question = (object) ((array) $question + $default_values);
     }
     parent::set_data($question);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:16,代码来源:edit_missingtype_form.php

示例7: foreach

 function set_data($question)
 {
     if (isset($question->options)) {
         $subquestions = $question->options->subquestions;
         if (count($subquestions)) {
             $key = 0;
             foreach ($subquestions as $subquestion) {
                 $default_values['subanswers[' . $key . ']'] = $subquestion->answertext;
                 $default_values['subquestions[' . $key . ']'] = $subquestion->questiontext;
                 $key++;
             }
         }
         $default_values['shuffleanswers'] = $question->options->shuffleanswers;
         $question = (object) ((array) $question + $default_values);
     }
     parent::set_data($question);
 }
开发者ID:JackCanada,项目名称:moodle-hacks,代码行数:17,代码来源:edit_match_form.php

示例8: foreach

 function set_data($question)
 {
     if (isset($question->options)) {
         $answers = $question->options->answers;
         if (count($answers)) {
             $key = 0;
             foreach ($answers as $answer) {
                 $default_values['answer[' . $key . ']'] = $answer->answer;
                 $default_values['fraction[' . $key . ']'] = $answer->fraction;
                 $default_values['feedback[' . $key . ']'] = $answer->feedback;
                 $key++;
             }
         }
         $default_values['usecase'] = $question->options->usecase;
         $question = (object) ((array) $question + $default_values);
     }
     parent::set_data($question);
 }
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:18,代码来源:edit_shortanswer_form.php

示例9: foreach

 function set_data($question)
 {
     if (isset($question->options)) {
         $answers = $question->options->answers;
         if (count($answers)) {
             $key = 0;
             foreach ($answers as $answer) {
                 $default_values['answer[' . $key . ']'] = $answer->answer;
                 $default_values['fraction[' . $key . ']'] = $answer->fraction;
                 $default_values['feedback[' . $key . ']'] = $answer->feedback;
                 $key++;
             }
         }
         $default_values['single'] = $question->options->single;
         $default_values['shuffleanswers'] = $question->options->shuffleanswers;
         $default_values['correctfeedback'] = $question->options->correctfeedback;
         $default_values['partiallycorrectfeedback'] = $question->options->partiallycorrectfeedback;
         $default_values['incorrectfeedback'] = $question->options->incorrectfeedback;
         $question = (object) ((array) $question + $default_values);
     }
     parent::set_data($question);
 }
开发者ID:veritech,项目名称:pare-project,代码行数:22,代码来源:edit_multichoice_form.php

示例10: empty

 function set_data($question)
 {
     $is_new = empty($question->id) || empty($question->options->rows);
     if (!$is_new) {
         $options = $question->options;
         $question->multiple = $options->multiple ? '1' : '0';
         $question->grademethod = $options->grademethod;
         $question->rowshort = array();
         $question->rowlong = array();
         $question->rowfeedback = array();
         $question->rowid = array();
         foreach ($options->rows as $row) {
             $question->rowshort[] = $row->shorttext;
             $question->rowlong[] = $row->description;
             $question->rowfeedback[] = $row->feedback;
             $question->rowid[] = $row->id;
         }
         $question->colshort = array();
         $question->collong = array();
         $question->colid = array();
         foreach ($options->cols as $col) {
             $question->colshort[] = $col->shorttext;
             $question->collong[] = $col->description;
             $question->colid[] = $col->id;
         }
         //$question->matrix = array();
         $row_index = 0;
         foreach ($options->rows as $row) {
             $col_index = 0;
             foreach ($options->cols as $col) {
                 $cell_name = qtype_matrix_grading::cell_name($row_index, $col_index, $options->multiple);
                 $weight = $options->weights[$row->id][$col->id];
                 if ($options->multiple) {
                     $value = $weight > 0 ? 'on' : '';
                     $question->{$cell_name} = $value;
                 } else {
                     if ($weight > 0) {
                         $question->{$cell_name} = $col_index;
                         break;
                     }
                 }
                 $col_index++;
             }
             $row_index++;
         }
     }
     /* set data should be called on new questions to set up course id, etc
      * after setting up values for question
      */
     parent::set_data($question);
 }
开发者ID:sunilwebaccess,项目名称:moodle-question-matrix,代码行数:51,代码来源:edit_matrix_form.php

示例11: array

 function set_data($question)
 {
     global $DB;
     $default_values = array();
     if (isset($question->id) and $question->id and $question->qtype and $question->questiontext) {
         foreach ($question->options->questions as $key => $wrapped) {
             if (!empty($wrapped)) {
                 // The old way of restoring the definitions is kept to gradually
                 // update all multianswer questions
                 if (empty($wrapped->questiontext)) {
                     $parsableanswerdef = '{' . $wrapped->defaultgrade . ':';
                     switch ($wrapped->qtype) {
                         case 'multichoice':
                             $parsableanswerdef .= 'MULTICHOICE:';
                             break;
                         case 'shortanswer':
                             $parsableanswerdef .= 'SHORTANSWER:';
                             break;
                         case 'numerical':
                             $parsableanswerdef .= 'NUMERICAL:';
                             break;
                         default:
                             print_error('unknownquestiontype', 'question', '', $wrapped->qtype);
                     }
                     $separator = '';
                     foreach ($wrapped->options->answers as $subanswer) {
                         $parsableanswerdef .= $separator . '%' . round(100 * $subanswer->fraction) . '%';
                         $parsableanswerdef .= $subanswer->answer;
                         if (!empty($wrapped->options->tolerance)) {
                             // Special for numerical answers:
                             $parsableanswerdef .= ":{$wrapped->options->tolerance}";
                             // We only want tolerance for the first alternative, it will
                             // be applied to all of the alternatives.
                             unset($wrapped->options->tolerance);
                         }
                         if ($subanswer->feedback) {
                             $parsableanswerdef .= "#{$subanswer->feedback}";
                         }
                         $separator = '~';
                     }
                     $parsableanswerdef .= '}';
                     // Fix the questiontext fields of old questions
                     $DB->set_field('question', 'questiontext', $parsableanswerdef, array('id' => $wrapped->id));
                 } else {
                     $parsableanswerdef = str_replace('&#', '&\\#', $wrapped->questiontext);
                 }
                 $question->questiontext = str_replace("{#{$key}}", $parsableanswerdef, $question->questiontext);
             }
         }
     }
     // set default to $questiondisplay questions elements
     if ($this->reload) {
         if (isset($this->questiondisplay->options->questions)) {
             $subquestions = fullclone($this->questiondisplay->options->questions);
             if (count($subquestions)) {
                 $sub = 1;
                 foreach ($subquestions as $subquestion) {
                     $prefix = 'sub_' . $sub . '_';
                     // validate parameters
                     $answercount = 0;
                     $maxgrade = false;
                     $maxfraction = -1;
                     if ($subquestion->qtype == 'shortanswer') {
                         switch ($subquestion->usecase) {
                             case '1':
                                 $default_values[$prefix . 'usecase'] = get_string('caseyes', 'quiz');
                                 break;
                             case '0':
                             default:
                                 $default_values[$prefix . 'usecase'] = get_string('caseno', 'quiz');
                         }
                     }
                     if ($subquestion->qtype == 'multichoice') {
                         $default_values[$prefix . 'layout'] = $subquestion->layout;
                         switch ($subquestion->layout) {
                             case '0':
                                 $default_values[$prefix . 'layout'] = get_string('layoutselectinline', 'qtype_multianswer');
                                 break;
                             case '1':
                                 $default_values[$prefix . 'layout'] = get_string('layoutvertical', 'qtype_multianswer');
                                 break;
                             case '2':
                                 $default_values[$prefix . 'layout'] = get_string('layouthorizontal', 'qtype_multianswer');
                                 break;
                             default:
                                 $default_values[$prefix . 'layout'] = get_string('layoutundefined', 'qtype_multianswer');
                         }
                     }
                     foreach ($subquestion->answer as $key => $answer) {
                         if ($subquestion->qtype == 'numerical' && $key == 0) {
                             $default_values[$prefix . 'tolerance[' . $key . ']'] = $subquestion->tolerance[0];
                         }
                         $trimmedanswer = trim($answer);
                         if ($trimmedanswer !== '') {
                             $answercount++;
                             if ($subquestion->qtype == 'numerical' && !(is_numeric($trimmedanswer) || $trimmedanswer == '*')) {
                                 $this->_form->setElementError($prefix . 'answer[' . $key . ']', get_string('answermustbenumberorstar', 'qtype_numerical'));
                             }
                             if ($subquestion->fraction[$key] == 1) {
                                 $maxgrade = true;
//.........这里部分代码省略.........
开发者ID:esyacelga,项目名称:sisadmaca,代码行数:101,代码来源:edit_multianswer_form.php

示例12: array

 function set_data($question)
 {
     if (isset($question->options)) {
         // added by Harry - beginn
         $default_values['arrangemedia'] = $question->options->arrangemedia;
         $default_values['placemedia'] = $question->options->placemedia;
         // added by Harry - end
         $default_values['backgroundmedia'] = $question->options->backgroundmedia->media;
         $default_values['globalfeedbackgrade'] = $question->options->feedbackfraction;
         $default_values['feedbackok'] = $question->options->feedbackok;
         $default_values['feedbackmissed'] = $question->options->feedbackmissed;
         $oldmedia = $question->options->media;
         if (count($oldmedia)) {
             $key = 0;
             $dbmediaids = array();
             // maps the db ids of the dragdrop objects to the html slots
             $dbhsids = array();
             // maps the db ids of the primary hot spots to the html slots
             foreach ($oldmedia as $omedia) {
                 $default_values['ddtext[' . $key . ']'] = $omedia->questiontext;
                 $default_values['ddmedia[' . $key . ']'] = $omedia->media;
                 $default_values['ddmediatargetx[' . $key . ']'] = $omedia->targetx;
                 $default_values['ddmediatargety[' . $key . ']'] = $omedia->targety;
                 $default_values['ddmediadisplaywidth[' . $key . ']'] = $omedia->displaywidth;
                 $default_values['ddmediadisplayheight[' . $key . ']'] = $omedia->displayheight;
                 if ($omedia->primary_hotspot != 0) {
                     $hotspot = $omedia->hotspots[$omedia->primary_hotspot];
                     $default_values['ddhotspotx[' . $key . ']'] = $hotspot->x;
                     $default_values['ddhotspoty[' . $key . ']'] = $hotspot->y;
                     $default_values['ddhotspotwidth[' . $key . ']'] = $hotspot->width;
                     $default_values['ddhotspotheight[' . $key . ']'] = $hotspot->height;
                 } else {
                     $default_values['ddhotspotgroup[' . $key . '][ddhotspotx]'] = 0;
                     $default_values['ddhotspotgroup[' . $key . '][ddhotspoty]'] = 0;
                     $default_values['ddhotspotgroup[' . $key . '][ddhotspotwidth]'] = 0;
                     $default_values['ddhotspotgroup[' . $key . '][ddhotspotheight]'] = 0;
                 }
                 $dbmediaids[$omedia->id] = $key + 1;
                 $dbhsids[$omedia->primary_hotspot] = $key + 1;
                 $key++;
             }
             // map the db ids to html "alternate hot spots" fields
             foreach ($dbmediaids as $dbmediaid => $htmlslot) {
                 if (count($oldmedia[$dbmediaid]->hotspots) > 1) {
                     $hotspotids = array();
                     foreach ($oldmedia[$dbmediaid]->hotspots as $id => $hs) {
                         if ($id != $oldmedia[$dbmediaid]->primary_hotspot) {
                             $hotspotids[] = $dbhsids[$id];
                         }
                     }
                     $hotspotids = implode(',', $hotspotids);
                     $default_values['althotspots[' . ($htmlslot - 1) . ']'] = $hotspotids;
                 }
             }
         }
         $question = (object) ((array) $question + $default_values);
     }
     parent::set_data($question);
 }
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:59,代码来源:edit_dragdrop_form.php

示例13: set_data

 /** Patch up data from the database before a user edits it in the form. */
 public function set_data($question)
 {
     if (!empty($question->questiontext)) {
         $question->questiontext = $this->convert_legacy_fact_sheets($question->questiontext);
     }
     if (!empty($question->generalfeedback)) {
         $question->generalfeedback = $this->convert_legacy_fact_sheets($question->generalfeedback);
     }
     if (!empty($question->specificfeedback)) {
         $question->specificfeedback = $this->convert_legacy_fact_sheets($question->specificfeedback);
     }
     if (!empty($question->prts)) {
         foreach ($question->prts as $prtname => $prt) {
             if (!empty($prt->nodes)) {
                 foreach ($prt->nodes as $nodename => $node) {
                     $node->truefeedback = $this->convert_legacy_fact_sheets($node->truefeedback);
                     $node->falsefeedback = $this->convert_legacy_fact_sheets($node->falsefeedback);
                 }
             }
         }
     }
     parent::set_data($question);
 }
开发者ID:sanyaade-teachings,项目名称:moodle-qtype_stack,代码行数:24,代码来源:edit_stack_form.php

示例14: array

 function set_data($question)
 {
     $answer = $this->answer;
     $default_values = array();
     if (count($answer)) {
         $key = 0;
         foreach ($answer as $answer) {
             $default_values['answer[' . $key . ']'] = $answer->answer;
             $default_values['fraction[' . $key . ']'] = $answer->fraction;
             $default_values['tolerance[' . $key . ']'] = $answer->tolerance;
             $default_values['tolerancetype[' . $key . ']'] = $answer->tolerancetype;
             $default_values['correctanswerlength[' . $key . ']'] = $answer->correctanswerlength;
             $default_values['correctanswerformat[' . $key . ']'] = $answer->correctanswerformat;
             $default_values['feedback[' . $key . ']'] = $answer->feedback;
             $key++;
         }
     }
     if (isset($question->options)) {
         $units = array_values($question->options->units);
         // make sure the default unit is at index 0
         usort($units, create_function('$a, $b', 'if (1.0 === (float)$a->multiplier) { return -1; } else ' . 'if (1.0 === (float)$b->multiplier) { return 1; } else { return 0; }'));
         if (count($units)) {
             $key = 0;
             foreach ($units as $unit) {
                 $default_values['unit[' . $key . ']'] = $unit->unit;
                 $default_values['multiplier[' . $key . ']'] = $unit->multiplier;
                 $key++;
             }
         }
     }
     $key = 0;
     $formdata = array();
     $fromform = new stdClass();
     //this should be done before the elements are created and stored as $this->formdata ;
     //fill out all data sets and also the fields for the next item to add.
     /*      if(!empty($this->datasetdefs)){
             $j = $this->noofitems * count($this->datasetdefs);
              for ($itemnumber = $this->noofitems; $itemnumber >= 1; $itemnumber--){
                 $data = array();
                 foreach ($this->datasetdefs as $defid => $datasetdef){
                     if (isset($datasetdef->items[$itemnumber])){
                         $formdata["number[$j]"] = $datasetdef->items[$itemnumber]->value;
                         $formdata["definition[$j]"] = $defid;
                         $formdata["itemid[$j]"] = $datasetdef->items[$itemnumber]->id;
                         $data[$datasetdef->name] = $datasetdef->items[$itemnumber]->value;
                     }
                     $j--;
                 }
         //                 echo "<p>answers avant  comment <pre>";print_r($answer);echo"</pre></p>";
         //                 echo "<p>data avant  comment <pre>";print_r($data);echo"</pre></p>";
                          
                 if($this->noofitems != 0 ) {
                     if(!isset($question->id)) $question->id = 0 ;
                 $comment = $this->qtypeobj->comment_on_datasetitems($question->id,$this->nonemptyanswer, $data, $itemnumber);//$this->
                  if ($comment->outsidelimit) {
                      $this->outsidelimit=$comment->outsidelimit ;
                 }
                 $totalcomment='';
            //              echo "<p> comment <pre>";print_r($comment);echo"</pre></p>";
     
                 foreach ($this->nonemptyanswer as $key => $answer) {
                     $totalcomment .= $comment->stranswers[$key].'<br/>';
                 }
     
                 $formdata['answercomment['.$itemnumber.']'] = $totalcomment ;
             }
             }
         //    $formdata['reload'] = '1';
           //  $formdata['nextpageparam[forceregeneration]'] = $this->regenerate;
             $formdata['selectdelete'] = '1';
             $formdata['selectadd'] = '1';
             $j = $this->noofitems * count($this->datasetdefs)+1;
             $data = array(); // data for comment_on_datasetitems later
                $idx =1 ;
                 foreach ($this->datasetdefs as $defid => $datasetdef){
                    $formdata["datasetdef[$idx]"] = $defid;
                     $idx++;
                 }
             $formdata = $this->qtypeobj->custom_generator_set_data($this->datasetdefs, $formdata);
         }*/
     $question = (object) ((array) $question + $default_values + $this->formdata);
     parent::set_data($question);
 }
开发者ID:ajv,项目名称:Offline-Caching,代码行数:83,代码来源:edit_calculatedsimple_form.php

示例15: foreach

 function set_data($question)
 {
     if (isset($question->options)) {
         $answers = $question->options->answers;
         if (count($answers)) {
             $key = 0;
             foreach ($answers as $answer) {
                 $default_values['answer[' . $key . ']'] = $answer->answer;
                 $default_values['fraction[' . $key . ']'] = $answer->fraction;
                 $default_values['tolerance[' . $key . ']'] = $answer->tolerance;
                 $default_values['tolerancetype[' . $key . ']'] = $answer->tolerancetype;
                 $default_values['correctanswerlength[' . $key . ']'] = $answer->correctanswerlength;
                 $default_values['correctanswerformat[' . $key . ']'] = $answer->correctanswerformat;
                 $default_values['feedback[' . $key . ']'] = $answer->feedback;
                 $key++;
             }
         }
         $units = array_values($question->options->units);
         // make sure the default unit is at index 0
         usort($units, create_function('$a, $b', 'if (1.0 === (float)$a->multiplier) { return -1; } else ' . 'if (1.0 === (float)$b->multiplier) { return 1; } else { return 0; }'));
         if (count($units)) {
             $key = 0;
             foreach ($units as $unit) {
                 $default_values['unit[' . $key . ']'] = $unit->unit;
                 $default_values['multiplier[' . $key . ']'] = $unit->multiplier;
                 $key++;
             }
         }
     }
     $default_values['submitbutton'] = get_string('nextpage', 'qtype_calculated');
     $default_values['makecopy'] = get_string('makecopynextpage', 'qtype_calculated');
     /* set the wild cards category display given that on loading the category element is
        unselected when processing this function but have a valid value when processing the
        update category button. The value can be obtain by
         $qu->category =$this->_form->_elements[$this->_form->_elementIndex['category']]->_values[0];
         but is coded using existing functions
        */
     $qu = new stdClass();
     $el = new stdClass();
     /* no need to call elementExists() here */
     if ($this->_form->elementExists('category')) {
         $el = $this->_form->getElement('category');
     } else {
         $el = $this->_form->getElement('categorymoveto');
     }
     if ($value = $el->getSelected()) {
         $qu->category = $value[0];
     } else {
         $qu->category = $question->category;
         // on load  $question->category is set by question.php
     }
     $html2 = $this->qtypeobj->print_dataset_definitions_category($qu);
     $this->_form->_elements[$this->_form->_elementIndex['listcategory']]->_text = $html2;
     $question = (object) ((array) $question + $default_values);
     parent::set_data($question);
 }
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:56,代码来源:edit_calculated_form.php


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