public static function extract_archive($archive_path, $to_path = '')
 {
     $to_path = empty($to_path) ? MoodleUtil::create_temp_directory() : $to_path;
     $zipper = new zip_packer();
     if ($zipper->extract_to_pathname($archive_path, $to_path)) {
         return $to_path;
     } else {
         return false;
     }
 }
 public function process_archive($filename, $realfilename)
 {
     if ($this->is_archive($realfilename)) {
         if ($this->base_temp = MoodleUtil::extract_archive($filename)) {
             $result = $this->process_directory($this->base_temp);
         } else {
             $result = false;
         }
     } else {
         $result = $this->process_file($filename);
     }
     return $result;
 }
 protected function add_assessment_item(ImsQtiWriter $writer, $question)
 {
     $identifier = self::question_identifier($question);
     $lang = MoodleUtil::get_current_language();
     $label = $question->qtype;
     $toolname = self::get_tool_name();
     $toolversion = Qti::get_tool_version();
     $result = $writer->add_assessmentItem($identifier, $question->name, true, false, $label, $lang, $toolname, $toolversion);
     return $result;
 }
 protected function add_question_metadata(ImsXmlWriter $item, $question)
 {
     $result = $item->add_metadata('lom', '1.0');
     $lom = new LomWriter($result, 'lom');
     $general = $lom->add_general();
     $general->add_title($question->name);
     $general->add_identifier(MoodleUtil::get_catalog_name(), $question->id);
     $lifecycle = $lom->add_lifecycle();
     $lifecycle->add_status();
     return $result;
 }
 protected function answer($percent, $text, $feedback)
 {
     $feedback = $this->html_to_text($feedback);
     $text = $this->html_to_text($text);
     $percent = MoodleUtil::round_to_nearest_grade($percent);
     $percent = $percent * 100;
     $result = "%{$percent}%{$text}#{$feedback}";
     return $result;
 }
 protected function get_fraction($item, $interaction, $answer, $default_grade)
 {
     $default_grade = empty($default_grade) ? 1 : $default_grade;
     $score = $this->get_score($item, $interaction, $answer);
     $result = MoodleUtil::round_to_nearest_grade($score / $default_grade);
     return $result;
 }