示例#1
0
 /**
  * Retrieve the computed response analysis from the question_response_analysis table.
  *
  * @param \qubaid_condition $qubaids    load the analysis of which question usages?
  * @param string            $whichtries load the analysis of which tries?
  * @return analysis_for_question|boolean analysis or false if no cached analysis found.
  */
 public function load_cached($qubaids, $whichtries)
 {
     global $DB;
     $timemodified = time() - self::TIME_TO_CACHE;
     // Variable name 'analyses' is the plural of 'analysis'.
     $responseanalyses = $DB->get_records_select('question_response_analysis', 'hashcode = ? AND whichtries = ? AND questionid = ? AND timemodified > ?', array($qubaids->get_hash_code(), $whichtries, $this->questiondata->id, $timemodified));
     if (!$responseanalyses) {
         return false;
     }
     $analysisids = array();
     foreach ($responseanalyses as $responseanalysis) {
         $analysisforsubpart = $this->analysis->get_analysis_for_subpart($responseanalysis->variant, $responseanalysis->subqid);
         $class = $analysisforsubpart->get_response_class($responseanalysis->aid);
         $class->add_response($responseanalysis->response, $responseanalysis->credit);
         $analysisids[] = $responseanalysis->id;
     }
     list($sql, $params) = $DB->get_in_or_equal($analysisids);
     $counts = $DB->get_records_select('question_response_count', "analysisid {$sql}", $params);
     foreach ($counts as $count) {
         $responseanalysis = $responseanalyses[$count->analysisid];
         $analysisforsubpart = $this->analysis->get_analysis_for_subpart($responseanalysis->variant, $responseanalysis->subqid);
         $class = $analysisforsubpart->get_response_class($responseanalysis->aid);
         $class->set_response_count($responseanalysis->response, $count->try, $count->rcount);
     }
     return $this->analysis;
 }
示例#2
0
 /**
  * Retrieve the computed response analysis from the question_response_analysis table.
  *
  * @param \qubaid_condition $qubaids which attempts to get cached response analysis for.
  * @return analysis_for_question|boolean analysis or false if no cached analysis found.
  */
 public function load_cached($qubaids)
 {
     global $DB;
     $timemodified = time() - self::TIME_TO_CACHE;
     $rows = $DB->get_records_select('question_response_analysis', 'hashcode = ? AND questionid = ? AND timemodified > ?', array($qubaids->get_hash_code(), $this->questiondata->id, $timemodified));
     if (!$rows) {
         return false;
     }
     foreach ($rows as $row) {
         $class = $this->analysis->get_subpart($row->subqid)->get_response_class($row->aid);
         $class->add_response_and_count($row->response, $row->credit, $row->rcount);
     }
     return $this->analysis;
 }