1
0
Просмотр исходного кода

Fixed bug in files and notifications

Igor 3 лет назад
Родитель
Сommit
1678fa40bd
2 измененных файлов с 31 добавлено и 19 удалено
  1. 1 1
      ilm_handlers/html5.php
  2. 30 18
      locallib.php

+ 1 - 1
ilm_handlers/html5.php

@@ -190,7 +190,7 @@ class html5 implements ilm_handle {
     if ($view_teacherfileversion) { // get the exercise in Moodle data (teacher file)
       $fileid = "";
       $fs = get_file_storage();
-      $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->filesid); // iassign_statement_activity_item = table 'iassign_statement'
+      $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->id); // iassign_statement_activity_item = table 'iassign_statement'
       if ($files) {
         foreach ($files as $value) {
           if ($value->get_filename() != '.')

+ 30 - 18
locallib.php

@@ -361,7 +361,7 @@ class iassign {
     $iassign_statement = $DB->get_record("iassign_statement", array("id" => $ilmid));
     $fs = get_file_storage(); // Get reference to all files in Moodle data
 
-    $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
+    $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->id);
 
     foreach ($files as $file) {
       if ($file->get_filename() != ".") {
@@ -1368,7 +1368,7 @@ var exercises = [ '; // '
       
       $context = context_module::instance($USER->cm);
 
-      $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
+      $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->id);
 
       foreach ($files as $value) {
         
@@ -1383,7 +1383,7 @@ var exercises = [ '; // '
           
           $updateentry = new stdClass();
           $updateentry->id = $iassign_id;
-          $updateentry->filesid = $newfile->get_itemid();
+          $updateentry->filesid = $iassign_id;
 
           $DB->update_record("iassign_statement", $updateentry);
 
@@ -1412,6 +1412,7 @@ var exercises = [ '; // '
     $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassignid));
 
     // Remove the current id of activity
+    $id_source_copy = $iassign_statement->id;
     $iassign_statement->id=0;
 
     // Include prefix (Copy of ...)
@@ -1427,17 +1428,17 @@ var exercises = [ '; // '
 
       // Duplicate activity file
       $fs = get_file_storage(); // Get reference to all files in Moodle data
-      $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
+      $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $id_source_copy);
 
       foreach ($files as $value) {
         if ($value->get_filename() != ".") {
           $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
 
-          $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
+          $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $id_), $value);
 
           $updateentry = new stdClass();
           $updateentry->id = $id_;
-          $updateentry->filesid = $newfile->get_itemid();
+          $updateentry->filesid = $id_;
 
           // Update the duplicated iLM iAssign with new file id
           $DB->update_record("iassign_statement", $updateentry);
@@ -2186,7 +2187,7 @@ var exercises = [ '; // '
     $param->action = $this->action; // hidden
     $param->id = $id; // hidden
 
-$param->special_param1 = 0; // 'special_param1 == 1' => script of iGeom
+    $param->special_param1 = 0; // 'special_param1 == 1' => script of iGeom
 
     $COURSE->cm = $id;
     $COURSE->iassignid = $iassignid;
@@ -2352,7 +2353,7 @@ $param->special_param1 = 0; // 'special_param1 == 1' => script of iGeom
 
         $fs = get_file_storage(); // Get reference to all files in Moodle data
 
-        $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->filesid);
+        $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->id);
         if ($files) {
           foreach ($files as $file) {
             if ($file->get_filename() != '.') {
@@ -2702,7 +2703,7 @@ $param->special_param1 = 0; // 'special_param1 == 1' => script of iGeom
     if ($iassign_submission)
       $this->update_comment($iassign_submission->id);
 
-    $file = $iassign_statement_activity_item->filesid;
+    $file = $iassign_statement_activity_item->id;
 
     // 1 when open previous file; 2 when the activity is redone!; 3 when the teacher enter in the activity
     // 1 => locallib.php: view_iassign_current(): action=view will set write_solution=0!!!!!
@@ -4179,11 +4180,21 @@ $param->special_param1 = 0; // 'special_param1 == 1' => script of iGeom
 
   function get_total_notifications () {
     global $DB, $USER, $COURSE;
-    
-    $params = array('userid' => $USER->id, 'course' => $COURSE->id);
-    
-    $total_messages = $DB->get_record_sql("SELECT COUNT(*) AS total FROM {iassign_submission_comment} AS c, {iassign_submission} AS s, {iassign_statement} AS st, {iassign} AS ias "
-        . " WHERE c.return_status=0 AND c.receiver=:userid AND c.iassign_submissionid=s.id AND s.iassign_statementid=st.id AND st.iassignid=ias.id AND ias.course=:course", $params);
+
+    $total_messages = 0;
+
+    if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
+      $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '1');
+
+      $total_messages = $DB->get_record_sql("SELECT COUNT(*) AS total FROM {iassign_submission_comment} AS c, {iassign_submission} AS s, {iassign_statement} AS st, {iassign} AS ias "
+        . " WHERE c.return_status=0 AND c.receiver=:receiver AND c.iassign_submissionid=s.id AND s.iassign_statementid=st.id AND st.iassignid=ias.id AND ias.course=:course", $params);
+    }
+    else {
+      $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '2');
+
+      $total_messages = $DB->get_record_sql("SELECT COUNT(*) AS total FROM {iassign_submission_comment} AS c, {iassign_submission} AS s, {iassign_statement} AS st, {iassign} AS ias "
+        . " WHERE c.return_status=0 AND c.receiver=:receiver AND c.iassign_submissionid=s.id AND s.userid=:userid AND s.iassign_statementid=st.id AND st.iassignid=ias.id AND ias.course=:course", $params);
+    }
 
     return $total_messages->total;
   }
@@ -4201,6 +4212,8 @@ $param->special_param1 = 0; // 'special_param1 == 1' => script of iGeom
   }
 
   function print_main_menu () {
+    global $USER;
+
     $id = $this->cm->id;
 
     $actual_action = optional_param('action', '', PARAM_TEXT);
@@ -4616,9 +4629,7 @@ $param->special_param1 = 0; // 'special_param1 == 1' => script of iGeom
           $action_links .= $link_duplicate_activity . $link_move_activity;
           } // if ($USER->iassignEdit == 1 && has_capability('mod/iassign:editiassign', $this->context, $USER->id))
 
-        $action_links .= '</ul></nav>';
-
-        print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $links . '</td><td class="align-middle">'.$action_links.'</td></tr>' . "\n";
+        print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $links . '</td><td class="align-middle"></td></tr>' . "\n";
         }
         print '</tbody></table>';
       } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
@@ -5305,6 +5316,7 @@ class activity {
         }
 
       if (!$fs->file_exists($param->context->id, $component, $filearea, $file->get_itemid(), $file->get_filepath(), $file->get_filename())) {
+
         $itemid = $file->get_itemid() + $param->iassign_id;
 
         $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
@@ -7636,7 +7648,7 @@ class ilm_manager {
       foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
         $cm = get_coursemodule_from_instance("iassign", $iassign->id, $courseid);
         $context = context_module::instance($cm->id);
-        $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->filesid);
+        $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->id);
         if ($files) {
           foreach ($files as $value) {
             $extension = explode(".", $value->get_filename());