/**
  * Load the needed users.xml file to backup_ids table for future reference
  *
  * @param string $restoreid Restore id
  * @param string $usersfile File path
  * @param \core\progress\base $progress Progress tracker
  */
 public static function load_users_to_tempids($restoreid, $usersfile, \core\progress\base $progress = null)
 {
     if (!file_exists($usersfile)) {
         // Shouldn't happen ever, but...
         throw new backup_helper_exception('missing_users_xml_file', $usersfile);
     }
     // Set up progress tracking (indeterminate).
     if (!$progress) {
         $progress = new \core\progress\null();
     }
     $progress->start_progress('Loading users into temporary table');
     // Let's parse, custom processor will do its work, sending info to DB
     $xmlparser = new progressive_parser();
     $xmlparser->set_file($usersfile);
     $xmlprocessor = new restore_users_parser_processor($restoreid);
     $xmlparser->set_processor($xmlprocessor);
     $xmlparser->set_progress($progress);
     $xmlparser->process();
     // Finish progress.
     $progress->end_progress();
 }
Ejemplo n.º 2
0
 /**
  * Analyse responses for an array of questions or sub questions.
  *
  * @param object[] $questions  as returned by self::load_and_initialise_questions_for_calculations.
  * @param qubaid_condition $qubaids the question usages whose responses to analyse.
  * @param string $whichtries which tries to analyse \question_attempt::FIRST_TRY, LAST_TRY or ALL_TRIES.
  * @param null|\core\progress\base $progress Used to indicate progress of task.
  * @param int[] $done array keys are ids of questions that have been analysed before calling method.
  * @return array array keys are ids of questions that were analysed after this method call.
  */
 protected function analyse_responses_for_questions($questions, $qubaids, $whichtries, $progress = null, $done = array())
 {
     $countquestions = count($questions);
     if (!$countquestions) {
         return array();
     }
     if ($progress === null) {
         $progress = new \core\progress\null();
     }
     $progress->start_progress('', $countquestions, $countquestions);
     foreach ($questions as $question) {
         $progress->increment_progress();
         if (question_bank::get_qtype($question->qtype, false)->can_analyse_responses() && !isset($done[$question->id])) {
             $responesstats = new \core_question\statistics\responses\analyser($question, $whichtries);
             if ($responesstats->get_last_analysed_time($qubaids, $whichtries) === false) {
                 $responesstats->calculate($qubaids, $whichtries);
             }
         }
         $done[$question->id] = 1;
     }
     $progress->end_progress();
     return $done;
 }