ソースを参照

Bug fixed in import and restore files

Igor 3 年 前
コミット
6bac722656
4 ファイル変更80 行追加13 行削除
  1. 3 1
      backup/moodle2/backup_iassign_stepslib.php
  2. 1 1
      ilm_handlers/html5.php
  3. 15 3
      ilm_manager.php
  4. 61 8
      locallib.php

+ 3 - 1
backup/moodle2/backup_iassign_stepslib.php

@@ -70,7 +70,9 @@ class backup_iassign_activity_structure_step extends backup_activity_structure_s
       'max_experiment',
       'dependency',
       'automatic_evaluate',
-      'show_answer'));
+      'show_answer',
+      'store_all_submissions',
+      'filesid'));
 
     $iassign_submissions = new backup_nested_element('iassign_submissions');
 

+ 1 - 1
ilm_handlers/html5.php

@@ -167,7 +167,7 @@ class html5 implements ilm_handle {
     $('.expand_button').addClass('disabled');
   }
 }</script>";
-    $html .= "<div style='width: 800px;text-align: right;'><div onClick='full_screen()' style='color: blue; cursor: pointer; display: contents;'>".get_string('full_screen', 'iassign')."</div></div>";
+    $html .= "<div id='fullscreen' style='width: 800px;text-align: right;'><div onClick='full_screen()' style='color: blue; cursor: pointer; display: contents;'>".get_string('full_screen', 'iassign')."</div></div>";
 
     return $html;
   }

+ 15 - 3
ilm_manager.php

@@ -267,18 +267,30 @@ if (has_capability('mod/iassign:editiassign', $context, $USER->id)) {
       if (strtolower($file_extension) != 'zip') {
         $filename = $newfilename;
 
-        $files_course = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
+        $files_course = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, '/', false, true, 'filename');
 
         if ($files_course) {
           foreach ($files_course as $value) {
-            if ($value->get_filename() == iassign_utils::format_filename($newfilename))
+            if ($value->get_filename() == $newfilename) {
               $filename = iassign_utils::version_filename($value->get_filename());
+              }
             }
           }
+          
 
         $ilm_extensions = explode(",", $iassign_ilm->extension);
         if (in_array($file_extension, $ilm_extensions))
-          $file = $mform->save_stored_file('file', $context->id, 'mod_iassign', 'activity', 0, $dir_base, iassign_utils::format_filename($filename), 0, $USER->id);
+          $file = $mform->save_stored_file(
+              'file', 
+              $context->id, 
+              'mod_iassign', 
+              'activity', 
+              0, 
+              '/', 
+              $filename,
+              0,
+              $USER->id);
+
         else if ($from == 'block' || $from == 'tinymce' || $from == 'atto')
           $file = $mform->save_stored_file('file', $context->id, 'mod_iassign', 'activity', 0, $dir_base, iassign_utils::format_filename($filename), 0, $USER->id);
         else

+ 61 - 8
locallib.php

@@ -451,13 +451,33 @@ class iassign {
 
     //2021 $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR;
     //TODO: tem que criar moodledata/temp/iassign_files
+    // Create $CFG->dataroot/temp/iassign_files
+
+    $tempfilespath = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp';
+    if (!file_exists($tempfilespath)) {
+      mkdir($tempfilespath, 0777, true);
+      }
+    $iassignfilespath = $tempfilespath . DIRECTORY_SEPARATOR . 'iassign_files';
+    if (!file_exists($iassignfilespath)) {
+      mkdir($iassignfilespath, 0777, true);
+      }
+
     $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' 
      . DIRECTORY_SEPARATOR . 'iassign_files' . DIRECTORY_SEPARATOR;
+    
+    if (!file_exists($diretorio)) {
+      echo 'Não foi possível criar o diretório para preparar o arquivo com as submissões. Possivelmente o caminho está bloqueado para escrita.';
+      exit;
+    }
 
     $zip_filename = $diretorio . 'package_iassign_'.time().'.zip';
 
     $zip = new zip_archive(); // create ZIP
-    $zip->open($zip_filename);
+    if (!$zip->open($zip_filename)) {
+      echo 'Não foi possível criar o arquivo zip com as submissões dos alunos, pois o diretório no servidor está bloqueado para escrita: ' . $diretorio;
+      exit;
+    }
+    ;
 
     foreach ($exercises_list as $exercise) {
       $dir_ex = iassign_utils::format_filename($exercise->name);
@@ -2491,7 +2511,7 @@ $param->special_param1 = 0; // 'special_param1 == 1' => script of iGeom
       $this->activity->view_dates();
       $USER->iassignEdit = $this->bottonPost;
       $this->activity->show_info_iassign();
-
+      
       if ($iassign_submission) {
         //xxx $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
         $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
@@ -2945,6 +2965,7 @@ $param->special_param1 = 0; // 'special_param1 == 1' => script of iGeom
           print '</tr></table>' . "\n";
 
           // Presents the iLM
+          
           print '<table width=100% border=0 valign="top">' . "\n";
           print '<td width=80% align="left">';
           print '<strong>' . $last_iassign . ' ' . get_string('repeat_msg', 'iassign') . '</strong></td>' . "\n"; // If you want to do this activity from the beginning again, use the \"Redo button\".
@@ -5082,14 +5103,14 @@ class activity {
   /// Show information of activity
   function show_info_iassign () {
     global $DB, $OUTPUT;
+    $output = '';
 
-    $output = '<p><strong>' . get_string('proposition', 'iassign') . ':</strong>&nbsp;' . $this->activity->proposition . '</p>' . "\n";
     if ($this->activity->type_iassign == 3) {
       if ($this->activity->dependency == 0) {
-        $output .= '<p><strong>' . get_string('independent_activity', 'iassign') . '</strong></p>' . "\n";
+        $output .= '<p style="margin-top: -1rem;"><strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
         } else {
         $dependencys = explode(';', $this->activity->dependency);
-        $output .= '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>';
+        $output .= '<p style="margin-top: -1rem;"><strong>' . get_string('dependency', 'iassign') . '</strong>';
         foreach ($dependencys as $dependency) {
             $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
             if ($dependencyiassign)
@@ -5097,12 +5118,44 @@ class activity {
           } // foreach ($dependencys as $dependency)
         } // if ($iassign_statement_activity_item->dependency == 0)
       if ($this->activity->max_experiment == 0)
-        $output .= '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . get_string('ilimit', 'iassign');
+        $output .= '<strong style="margin-left: 3rem;">' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . get_string('ilimit', 'iassign');
       else
-        $output .= '<p><strong>' . get_string('experiment_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->max_experiment . "\n";
-      $output .= '&nbsp;&nbsp;&nbsp;<strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->grade . '</p>' . "\n";
+        $output .= '<strong style="margin-left: 3rem;">' . get_string('experiment_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->max_experiment . "\n";
+      $output .= '<strong style="margin-left: 3rem;">' . get_string('grade_iassign', 'iassign') . ':</strong>&nbsp;' . $this->activity->grade . '</p>' . "\n";
       } // if ($iassign_statement_activity_item->type_iassign == 3)
 
+    $output .= '<script>
+    function toLeft () {
+
+      document.getElementsByClassName("proposition")[0].style.cssFloat = "left";
+      document.getElementsByClassName("proposition")[0].style.width = "40%";
+      document.getElementById("fullscreen").style.marginTop = "-3rem";
+      document.getElementById("columnsbutton").style.color = "#1da075";
+    }
+    function toDefault () {
+
+      document.getElementsByClassName("proposition")[0].style.cssFloat = "none";
+      document.getElementsByClassName("proposition")[0].style.width = "100%";
+      document.getElementById("fullscreen").style.marginTop = "0";
+      document.getElementById("columnsbutton").style.color = "#343a40";
+    }
+    
+    var activate = false;
+    function toggleColumns () {
+      if (activate) {
+        activate = false;
+        toDefault();
+      } else {
+        activate = true;
+        toLeft();
+      }
+    }
+    </script>';
+    
+    $output .= '<span style="float: right"> <i id="columnsbutton" onclick="toggleColumns()" class="fa fa-columns" style="font-size: 1.5rem;" aria-hidden="true" role="button"></i></span>';
+
+    $output .= '<p><strong>' . get_string('proposition', 'iassign') . ':</p>&nbsp;<div class="proposition">' . $this->activity->proposition . '</div>' . "\n";
+    
     print $OUTPUT->box($output);
     } // function show_info_iassign()