Beispiel #1
0
 /**
  * Constructor.
  * @param question_usage_by_activity $quba the question usage we will be picking variants for.
  * @param qubaid_condition $qubaids ids of the usages to consider when counting previous uses of each variant.
  */
 public function __construct(\question_usage_by_activity $quba, \qubaid_condition $qubaids)
 {
     $questionidtoseed = array();
     foreach ($quba->get_attempt_iterator() as $qa) {
         $question = $qa->get_question();
         if ($question->get_num_variants() > 1) {
             $questionidtoseed[$question->id] = $question->get_variants_selection_seed();
         }
     }
     if (empty($questionidtoseed)) {
         return;
     }
     $this->variantsusecounts = array_fill_keys($questionidtoseed, array());
     $variantsused = \question_engine::load_used_variants(array_keys($questionidtoseed), $qubaids);
     foreach ($variantsused as $questionid => $usagecounts) {
         $seed = $questionidtoseed[$questionid];
         foreach ($usagecounts as $variant => $count) {
             if (isset($this->variantsusecounts[$seed][$variant])) {
                 $this->variantsusecounts[$seed][$variant] += $count;
             } else {
                 $this->variantsusecounts[$seed][$variant] = $count;
             }
         }
     }
 }
Beispiel #2
0
 /**
  * Store an entire {@link question_usage_by_activity} in the database,
  * including all the question_attempts that comprise it.
  * @param question_usage_by_activity $quba the usage to store.
  */
 public function insert_questions_usage_by_activity(question_usage_by_activity $quba)
 {
     $record = new stdClass();
     $record->contextid = $quba->get_owning_context()->id;
     $record->component = $quba->get_owning_component();
     $record->preferredbehaviour = $quba->get_preferred_behaviour();
     $newid = $this->db->insert_record('question_usages', $record);
     $quba->set_id_from_database($newid);
     foreach ($quba->get_attempt_iterator() as $qa) {
         $this->insert_question_attempt($qa, $quba->get_owning_context());
     }
 }
Beispiel #3
0
 /**
  * Store an entire {@link question_usage_by_activity} in the database,
  * including all the question_attempts that comprise it.
  *
  * You should not call this method directly. You should use
  * @link question_engine::save_questions_usage_by_activity()}.
  *
  * @param question_usage_by_activity $quba the usage to store.
  */
 public function insert_questions_usage_by_activity(question_usage_by_activity $quba)
 {
     $record = new stdClass();
     $record->contextid = $quba->get_owning_context()->id;
     $record->component = $quba->get_owning_component();
     $record->preferredbehaviour = $quba->get_preferred_behaviour();
     $newid = $this->db->insert_record('question_usages', $record);
     $quba->set_id_from_database($newid);
     // Initially an array of array of question_attempt_step_objects.
     // Built as a nested array for efficiency, then flattened.
     $stepdata = array();
     foreach ($quba->get_attempt_iterator() as $qa) {
         $stepdata[] = $this->insert_question_attempt($qa, $quba->get_owning_context());
     }
     $stepdata = call_user_func_array('array_merge', $stepdata);
     if ($stepdata) {
         $this->insert_all_step_data($stepdata);
     }
 }