/**
  * Store an entire {@link question_attempt} in the database,
  * including all the question_attempt_steps that comprise it.
  * @param question_attempt $qa the question attempt to store.
  * @param object $context the context of the owning question_usage_by_activity.
  */
 public function insert_question_attempt(question_attempt $qa, $context)
 {
     $record = new stdClass();
     $record->questionusageid = $qa->get_usage_id();
     $record->slot = $qa->get_slot();
     $record->behaviour = $qa->get_behaviour_name();
     $record->questionid = $qa->get_question()->id;
     $record->variant = $qa->get_variant();
     $record->maxmark = $qa->get_max_mark();
     $record->minfraction = $qa->get_min_fraction();
     $record->flagged = $qa->is_flagged();
     $record->questionsummary = $qa->get_question_summary();
     $record->rightanswer = $qa->get_right_answer_summary();
     $record->responsesummary = $qa->get_response_summary();
     $record->timemodified = time();
     $record->id = $this->db->insert_record('question_attempts', $record);
     foreach ($qa->get_step_iterator() as $seq => $step) {
         $this->insert_question_attempt_step($step, $record->id, $seq, $context);
     }
 }
예제 #2
0
파일: datalib.php 프로젝트: covex-nn/moodle
 /**
  * Store an entire {@link question_attempt} in the database,
  * including all the question_attempt_steps that comprise it.
  * @param question_attempt $qa the question attempt to store.
  * @param context $context the context of the owning question_usage_by_activity.
  */
 public function insert_question_attempt(question_attempt $qa, $context)
 {
     $record = new stdClass();
     $record->questionusageid = $qa->get_usage_id();
     $record->slot = $qa->get_slot();
     $record->behaviour = $qa->get_behaviour_name();
     $record->questionid = $qa->get_question()->id;
     $record->variant = $qa->get_variant();
     $record->maxmark = $qa->get_max_mark();
     $record->minfraction = $qa->get_min_fraction();
     $record->maxfraction = $qa->get_max_fraction();
     $record->flagged = $qa->is_flagged();
     $record->questionsummary = $qa->get_question_summary();
     if (core_text::strlen($record->questionsummary) > question_bank::MAX_SUMMARY_LENGTH) {
         // It seems some people write very long quesions! MDL-30760
         $record->questionsummary = core_text::substr($record->questionsummary, 0, question_bank::MAX_SUMMARY_LENGTH - 3) . '...';
     }
     $record->rightanswer = $qa->get_right_answer_summary();
     $record->responsesummary = $qa->get_response_summary();
     $record->timemodified = time();
     $record->id = $this->db->insert_record('question_attempts', $record);
     $qa->set_database_id($record->id);
     foreach ($qa->get_step_iterator() as $seq => $step) {
         $this->insert_question_attempt_step($step, $record->id, $seq, $context);
     }
 }
예제 #3
0
파일: lib.php 프로젝트: mongo0se/moodle
 /**
  * Get the postdata that needs to be sent to question/toggleflag.php to change the flag state.
  * You need to append &newstate=0/1 to this.
  * @return the post data to send.
  */
 public static function get_postdata(question_attempt $qa)
 {
     $qaid = $qa->get_database_id();
     $qubaid = $qa->get_usage_id();
     $qid = $qa->get_question()->id;
     $slot = $qa->get_slot();
     $checksum = self::get_toggle_checksum($qubaid, $qid, $qaid, $slot);
     return "qaid={$qaid}&qubaid={$qubaid}&qid={$qid}&slot={$slot}&checksum={$checksum}&sesskey=" . sesskey() . '&newstate=';
 }
예제 #4
0
 /**
  * Store an entire {@link question_attempt} in the database,
  * including all the question_attempt_steps that comprise it.
  *
  * You should not call this method directly. You should use
  * @link question_engine::save_questions_usage_by_activity()}.
  *
  * @param question_attempt $qa the question attempt to store.
  * @param context $context the context of the owning question_usage_by_activity.
  * @return array of question_attempt_step_data rows, that still need to be inserted.
  */
 public function insert_question_attempt(question_attempt $qa, $context)
 {
     $record = new stdClass();
     $record->questionusageid = $qa->get_usage_id();
     $record->slot = $qa->get_slot();
     $record->behaviour = $qa->get_behaviour_name();
     $record->questionid = $qa->get_question()->id;
     $record->variant = $qa->get_variant();
     $record->maxmark = $qa->get_max_mark();
     $record->minfraction = $qa->get_min_fraction();
     $record->maxfraction = $qa->get_max_fraction();
     $record->flagged = $qa->is_flagged();
     $record->questionsummary = $qa->get_question_summary();
     if (core_text::strlen($record->questionsummary) > question_bank::MAX_SUMMARY_LENGTH) {
         // It seems some people write very long quesions! MDL-30760
         $record->questionsummary = core_text::substr($record->questionsummary, 0, question_bank::MAX_SUMMARY_LENGTH - 3) . '...';
     }
     $record->rightanswer = $qa->get_right_answer_summary();
     $record->responsesummary = $qa->get_response_summary();
     $record->timemodified = time();
     $record->id = $this->db->insert_record('question_attempts', $record);
     $qa->set_database_id($record->id);
     // Initially an array of array of question_attempt_step_objects.
     // Built as a nested array for efficiency, then flattened.
     $stepdata = array();
     foreach ($qa->get_step_iterator() as $seq => $step) {
         $stepdata[] = $this->insert_question_attempt_step($step, $record->id, $seq, $context);
     }
     return call_user_func_array('array_merge', $stepdata);
 }
예제 #5
0
 /**
  * Returns the URL for an image
  *
  * @param object $qa Question attempt object
  * @param string $filearea File area descriptor
  * @param int $itemid Item id to get
  * @return string Output url, or null if not found
  */
 protected static function get_url_for_image(question_attempt $qa, $filearea, $itemid = 0)
 {
     $question = $qa->get_question();
     $qubaid = $qa->get_usage_id();
     $slot = $qa->get_slot();
     $fs = get_file_storage();
     if ($filearea == 'bgimage') {
         $itemid = $question->id;
     }
     $componentname = $question->qtype->plugin_name();
     $draftfiles = $fs->get_area_files($question->contextid, $componentname, $filearea, $itemid, 'id');
     if ($draftfiles) {
         foreach ($draftfiles as $file) {
             if ($file->is_directory()) {
                 continue;
             }
             $url = moodle_url::make_pluginfile_url($question->contextid, $componentname, $filearea, "{$qubaid}/{$slot}/{$itemid}", '/', $file->get_filename());
             return $url->out();
         }
     }
     return null;
 }