1
0
Igor 3 سال پیش
والد
کامیت
7cd89f8f75
3فایلهای تغییر یافته به همراه156 افزوده شده و 4 حذف شده
  1. 4 0
      lang/en/iassign.php
  2. 4 0
      lang/pt_br/iassign.php
  3. 148 4
      locallib.php

+ 4 - 0
lang/en/iassign.php

@@ -368,9 +368,13 @@ $string['ilm_manager_title']              = 'Interactive Activities Manager';
 $string['ilm_type']                       = 'Select iLM type (Java or HTML5)';
 $string['ilm_type_help']                  = 'Please, select the iLM type:<br> - Java: usually a package with a JAR file<br> - HTML5: usually a package with a directory inside';
 $string['import_activity']                = 'Import activity';
+$string['import_activity_success']        = 'The activity was imported successfully!';
+$string['import_activities_success']      = 'The activities were imported successfully!';
 $string['import_file']                    = 'File Activity {$a} or compressed (zip):';
 $string['import_ilm']                     = 'Import iLM';
 $string['import_ilm_help']                = 'Import iLM';
+$string['import_statement_empty']         = 'There is no compatible acitivity in this course.';
+$string['import_statement_no_exercise']   = 'Select at least one exercise to continue';
 $string['incompatible_extension_file']    = 'File activity incompatible with the selected iLM.';
 $string['incorrect']                      = 'Incorrect';
 $string['independent_activity']           = 'Independent activity';

+ 4 - 0
lang/pt_br/iassign.php

@@ -368,9 +368,13 @@ $string['ilm_manager_title']              = 'Repositório iTarefa';
 $string['ilm_type']                       = 'Selecione o tipo de iMA (Java ou HTML5)';
 $string['ilm_type_help']                  = 'Por favor, selecione tipo do iMA:<br> - JAVA: geralmente o pacote na forma de um arquivo JAR;<br> - HTML5: geralmente um pacote TGZ ou ZIP contendo o diretório do iMA em HTML5';
 $string['import_activity']                = 'Importar atividade';
+$string['import_activity_success']        = 'A atividade foi importada com sucesso.';
+$string['import_activities_success']      = 'As atividades foram importadas com sucesso.';
 $string['import_file']                    = 'Arquivo da atividade {$a}ou arquivo compactado (zip):';
 $string['import_ilm']                     = 'Importar iMA';
 $string['import_ilm_help']                = 'Importar iMA';
+$string['import_statement_empty']         = 'Nenhuma atividade interativa foi encontrada nesse curso.';
+$string['import_statement_no_exercise']   = 'Selecione pelo menos um exercício para importar';
 $string['incompatible_extension_file']    = 'Arquivo da atividade incompatível com o iMA selecionado.';
 $string['incorrect']                      = 'Incorreto';
 $string['independent_activity']           = 'Atividade independente';

+ 148 - 4
locallib.php

@@ -314,7 +314,8 @@ class iassign {
       'get_student_submission' => '$this->get_student_submission();',
       'get_teacher_exercise' => '$this->get_teacher_exercise();',
       'post_auto_eval_result' => '$this->post_auto_eval_result();',
-      'import_activity' => '$this->import_activity();'
+      'import_activity' => '$this->import_activity();',
+      'import_activity_confirm' => '$this->import_activity_confirm();',
     );
 
     $action_iassign_restricted = array_merge($restricted, $action_iassign_limit, $action_iassign);
@@ -683,25 +684,168 @@ class iassign {
     print '</center>';
     }
 
+  function import_activity_confirm () {
+    global $USER, $DB;
+
+    if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
+      exit;
+
+    if (!isset($_REQUEST['statements'])) exit;
+
+    $iassign_destiny = $this->iassign->id;
+    $activities_list = $_REQUEST['statements'];
+
+    foreach($activities_list as $activity) {
+
+      $activity_source = $DB->get_record('iassign_statement', array('id' => $activity));
+
+      $activity_source->id = 0;
+
+      $iassign_id_from = $activity_source->iassignid;
+      $filesid_from = $activity_source->filesid;
+
+      $activity_source->iassignid = $iassign_destiny;
+
+      $author = $DB->get_record("user", array('id' => $USER->id));
+      $activity_source->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
+      $activity_source->author_modified = $activity_source->author_modified_name;
+      
+      if ($id_ = $DB->insert_record("iassign_statement", $activity_source)) {
+
+        $fs = get_file_storage(); 
+        // Duplicate activity file
+        $files_ids = $DB->get_records_sql('SELECT id FROM {files} WHERE component="mod_iassign" AND itemid=' . $filesid_from);
+
+        print 'Arquivos a serem copiados: ';
+        print_r($files_ids);
+        
+        foreach ($files_ids as $fileid) {
+          $source_file = $fs->get_file_by_id($fileid->id);
+
+          $newfile = $fs->create_file_from_storedfile(array('contextid' =>  $this->context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $id_), $source_file);
+
+            $updateentry = new stdClass();
+            $updateentry->id = $id_;
+            $updateentry->filesid = $id_;
+
+            // Update the duplicated iLM iAssign with new file id
+            $DB->update_record("iassign_statement", $updateentry);
+        }
+
+      }
+
+    }
+
+    $destiny_url = new moodle_url('/mod/iassign/view.php', array('id' => $this->context->id));
+
+    $str_index = count($activities_list) > 1 ? 'import_activities_success' : 'import_activity_success';
+
+    redirect($this->return, get_string($str_index, 'iassign'), null, \core\output\notification::NOTIFY_SUCCESS);
+    exit;
+  }
+
   function import_activity () {
     global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
 
     if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
       exit;
 
+    print '<script>
+    function verify_selection () {
+      document.getElementById("msg-error").classList.add("d-none");
+
+      var checkboxes = document.getElementsByName("statements[]");
+      for(var i = 0; i < checkboxes.length; i++)
+        if (checkboxes[i].checked) return true;
+        
+      document.getElementById("msg-error").classList.remove("d-none");
+      return false;
+    }
+    </script>';
+
+    $destiny_url = new moodle_url('/mod/iassign/view.php', array('id' => $this->cm->id, 'action' => 'import_activity_confirm'));
+
     print $OUTPUT->header();
 
     $this->print_main_menu();
 
-    print '<br>';
+    print '<h2 class="m-b-2 mt-4">' . get_string('import_activity', 'iassign') . '</h2>';
+
+    print '<form action="'.$destiny_url.'" method="post" onsubmit="return verify_selection()">';
+    
+    $courses_as_teacher = $this->get_courses_enroled_as_teacher($USER->id);
+
+    foreach ($courses_as_teacher as $course) {
+
+      print '<a href="#item-'.$course->id.'" class="list-group-item list-group-item-action h5" style="margin-top: 1rem;" data-toggle="collapse" onclick=\'$(".fa-caret-right, .fa-caret-down", this).toggleClass("fa-caret-right").toggleClass("fa-caret-down");\' > <i class="fa fa-caret-right"></i> ' . $course->fullname . ' </a>';
+
+      print '<div class="collapse" style="padding: 0 1.5rem;" id="item-'.$course->id.'">';
+
+      $iassigns = $this->get_iassign_items_by_course($course->id);
+
+      if ($iassigns) {
+        foreach ($iassigns as $iassign) {
+          print '<a href="#item-'.$course->id.'-'.$iassign->id.'" class="list-group-item list-group-item-action" data-toggle="collapse" onclick=\'$(".fa-caret-right, .fa-caret-down", this).toggleClass("fa-caret-right").toggleClass("fa-caret-down");\'><i class="fa fa-caret-right"></i> '.$iassign->name.'</a>';
+
+          print '<div class="collapse" style="padding: 0 1.5rem;" id="item-'.$course->id.'-'.$iassign->id.'">';
+          
+          $statements = $this->get_iassign_statement_by_iassign($iassign->id);
+
+          print '<table class="table table-hover">';
+
+          if ($statements) {
+            foreach ($statements as $statement) {
+              print '<tr><td> <div class="form-check"> <input class="form-check-input" name="statements[]" type="checkbox" value="'.$statement->id.'" id="statement-' . $statement->id . '">';
+              print '<label class="form-check-label w-100" for="statement-' . $statement->id . '">' . $statement->name;  
+              print '</label></div></td></tr>';
+            }
+          }
+          else {
+            print '<tr><td>' . get_string('no_activity', 'iassign') . '</td></tr>';
+          }
+          
+          print '</table></div>';
+        }
+      }
+      else {
+        print '<div class="p-2">' . get_string('import_statement_empty', 'iassign').'</div>';
+      }
+      print '</div>';
+    }
+    print '<div class="text-center"><button type="submit" class="btn btn-primary mt-2">Confirmar</button></div>';
+    print '<div class="text-center text-danger d-none" id="msg-error">'.get_string('import_statement_no_exercise', 'iassign').'</div>';
     
-    $return = enrol_get_users_courses(2);
 
-    print_r($return);
+    print '</form>';
 
     print $OUTPUT->footer();
   }
 
+  function get_iassign_items_by_course ($courseid) {
+    global $DB;
+
+    return $DB->get_records("iassign", array("course" => $courseid));
+  }
+
+  function get_iassign_statement_by_iassign ($iassignid) {
+    global $DB;
+
+    return $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
+  }
+
+  function get_courses_enroled_as_teacher($userid) {
+    $all_enroled = enrol_get_users_courses($userid);
+    $return = array();
+    foreach ($all_enroled as $enroled) {
+      $context_course = context_course::instance($enroled->id);
+
+      if (has_capability('mod/iassign:runautoevaluate', $context_course, $userid, false) ) {
+        array_push($return, $enroled);
+      }
+    }
+    return $return;
+  }
+
   /// Manage all submissions in exercises to table iassign_allsubmissions
   function all_submissions () {
     global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;