Browse Source

teacher view partially done

bernardo 4 years ago
parent
commit
609296d84a
7 changed files with 185 additions and 101 deletions
  1. 9 0
      db/access.php
  2. 10 1
      lang/en/gradeimporter.php
  3. 9 1
      lang/pt_br/gradeimporter.php
  4. 2 4
      lib.php
  5. 144 49
      locallib.php
  6. 1 1
      version.php
  7. 10 45
      view.php

+ 9 - 0
db/access.php

@@ -37,6 +37,15 @@
                     )
         ),
 
+        /*'mod/gradeimporter:teacherview' => array(
+            'captype' => 'write',
+            'contextlevel' => CONTEXT_MODULE,
+            'archetypes' => array(
+                'editingteacher' => CAP_ALLOW,
+                'manager' => CAP_ALLOW,
+                'teacher' => CAP_ALLOW
+            )
+),*/
         
         'mod/gradeimporter:student'=> array(
             'captype'=> 'read',

+ 10 - 1
lang/en/gradeimporter.php

@@ -73,4 +73,13 @@ $string['newsubmission'] = "Add new submission";
 //events string
     $string['eventmodelsubmissioncreated'] = 'Submission created';
 
-$string['downloadconfigcsv'] = 'Download config CSV';
+$string['downloadconfigcsv'] = 'Download config CSV';
+
+//view - table presentation
+$string['student']      = 'Student';
+$string['type']         = 'Type';
+$string['submission']   = 'Submission';
+$string['comment']      = 'Comment';
+$string['grade']        = 'Grade';
+$string['file']         = 'File';
+$string['nameCol']      = 'Name';

+ 9 - 1
lang/pt_br/gradeimporter.php

@@ -73,4 +73,12 @@ $string['newsubmission'] = 'Nova Submissão';
 //events string
     $string['eventmodelsubmissioncreated'] = 'Submissão criada';
 
-$string['downloadconfigcsv'] = 'Descarregar modelo do CSV de configuração';
+$string['downloadconfigcsv'] = 'Descarregar modelo do CSV de configuração';
+
+//view - table presentation
+$string['student']      = 'Aluno';
+$string['type']         = 'Tipo';
+$string['submission']   = 'Submissão';
+$string['comment']      = 'Comentário';
+$string['grade']        = 'Nota';
+$string['file']         = 'Arquivo';

+ 2 - 4
lib.php

@@ -121,9 +121,7 @@ function gradeimporter_check_for_zips ($context, $cm, $submission){
               array_shift($csv); // remove column header
               for ($i = 0; $i< sizeof($csv); $i++){
                 foreach ($tempfiles as $storedfile) {
-                  if ($storedfile->get_filename() == $csv[$i]['file']){
-
-                    
+                  if ($storedfile->get_filename() == $csv[$i]['file']){                   
 
                     $dbentry = new stdClass();
                     $dbentry->id = null;
@@ -149,7 +147,7 @@ function gradeimporter_check_for_zips ($context, $cm, $submission){
                       'filename'        =>  $csv[$i]['file']
                     );
 
-                    $storedfile = $fs->create_file_from_storedfile($fileinfo, $storedfile);
+                    $fs->create_file_from_storedfile($fileinfo, $storedfile);
                     break;
                   }
                 }

+ 144 - 49
locallib.php

@@ -1,13 +1,10 @@
 <?php
 
-namespace gradeimporter{
+function get_comments($cmid, $id){
+  global $DB, $USER, $CFG;
+  $tp = $CFG->prefix; // gets moodle tables prefix, not everyone uses mdl_
 
-  class feedback {
-      public static function get_comments($cmid, $id) {
-          global $DB, $USER, $CFG;
-          $tp = $CFG->prefix; // gets moodle tables prefix, not everyone uses mdl_
-
-          $sql = "
+  $sql = "
           SELECT gf.id gf_id,
                 gf.grade,
                 gf.comment gf_comment,
@@ -25,61 +22,159 @@ namespace gradeimporter{
             JOIN ".$tp."gradeimporter_submissiontype gst
               ON gs.type = gst.id
           WHERE gf.studentid = ?";
-          $comments = array();
-          $records = $DB->get_records_sql($sql, array('studentid'=>$USER->id));
-
-          $data = array();
-          if (count($records)) {
-            foreach ($records as $key => $value) {
-              if (!array_key_exists($value->gst_name, $data)) $data[$value->gst_name] = array();
-              
-                
-                $fileurl = buildurl ($cmid, $id, $value->gf_id, $value->gf_name);
-                
-                $data[$value->gst_name][] = array($value->gs_name, $value->grade, $value->gf_comment, $fileurl);
-            }
-          }
-
-          return $data;
-      }
+
+  $records = $DB->get_records_sql($sql, array('studentid' => $USER->id));
+
+  $data = array();
+  if (count($records)) {
+    foreach ($records as $value) {
+      if (!array_key_exists($value->gst_name, $data)) $data[$value->gst_name] = array();
+
+
+      $fileurl = buildurl($cmid, $value->gf_id, $value->gf_name);
+
+      $data[$value->gst_name][] = array($value->gs_name, $value->grade, $value->gf_comment, $fileurl);
+    }
   }
 
+  return $data;
 }
 
-namespace{
-  require_once($CFG->libdir.'/filelib.php');
-  require_once("$CFG->libdir/csvlib.class.php");
+function get_teacher_view($cmid, $gradeimporterid, $enrolledusers){
+  global $DB, $CFG;
+  
+  $tp = $CFG->prefix; // gets moodle tables prefix, not everyone uses mdl_
+
+  $table = new html_table();
+  $table->attributes['class'] = 'generaltable mod_index';
+  $table->align = array();
+  //creates table head
+  /*$subrow = new html_table_row();
+  $subrow->cells[] = new html_table_cell(get_string('nameCol', 'gradeimporter'));
+*/
+ $subrow = array(get_string('nameCol', 'gradeimporter'));
+ $table->align[] = 'center';
 
+  $submissionsSQL = "SELECT id, name 
+                      FROM mdl_gradeimporter_submission 
+                      WHERE gradeimporterid = 1
+                      ORDER BY id";
+  $submissions = $DB->get_records_sql($submissionsSQL);
+  foreach ($submissions as $submission){
+    $subrow[] = $submission->name;
+    $table->align[] = 'center';
+  }
+  $table->head = $subrow;
+  
+  //all submissions names are on the table
+  
+  $sql = " SELECT gs.id gs_id,
+                  gs.gradeimporterid gs_gradeimporterid,
+                  gs.type gs_type,
+                  gs.name gs_name, 
+                  gst.name  gst_name,
+                  gf.id gf_id,
+                  gf.studentid  gf_studentid,
+                  gf.grade  gf_grade,
+                  gf.fileid gf_fileid,
+                  gf.contextid  gf_contextid,
+                  gf.name gf_name,
+                  user.firstname  user_firstname,
+                  user.lastname user_lastname
+                  FROM ".$tp."gradeimporter_feedback gf
+                  JOIN ".$tp."user user
+                      ON user.id = gf.studentid
+                  JOIN ".$tp."gradeimporter_submission gs
+                      ON gs.id = gf.submissionid
+                  JOIN ".$tp."gradeimporter_submissiontype gst
+                      ON gst.id = gs.type
+                  WHERE gs.gradeimporterid = $gradeimporterid
+                  ORDER BY user.firstname, user.lastname, gs.id, gf.id";
+  $records = $DB->get_recordset_sql($sql);
+  
+  $usersList = array();
+  foreach ($enrolledusers as $user){
+    $usersList[$user->id] = array('name'=>$user->firstname." ".$user->lastname);
+  }
+  ksort($usersList);
 
-  function buildurl($cmid, $id, $fileid, $filename){
+  foreach ($records as $record){
+    echo "passou userid $record->gf_studentid  fileid $record->gf_fileid <br>";
+    $url = buildurl($cmid, $record->gf_id, $record->gf_name);
+    $usersList[$record->gf_studentid][$record->gs_id] = array('grade'=>$record->gf_grade, 'file'=>$url);
+  }
+  
+  foreach($usersList as $user){
+    $row = new html_table_row();
+    $cell = new html_table_cell($user['name']);
+    $row->cells[] = $cell;
+    foreach ($submissions as $submission){
+      if (array_key_exists($submission->id, $user)){
+        $url = $user[$submission->id]['file'];
+        $grade = $user[$submission->id]['grade'];
+      } else{
+        $url = '-';
+        $grade = '-';
+      }
+      $cell = new html_table_cell ($grade);
+      $row->cells[] = $cell;
 
-    $fileurl = new moodle_url("/mod/gradeimporter/view.php", array('cmid'=>$cmid, 'id'=>$id, 'fileid'=>$fileid, 'filename'=>$filename, 'action'=>1));
-    return "<a href=$fileurl> $filename</a>";
-    /*$fs = get_file_storage();
-    $file = $fs->get_file($contextid, 'mod_gradeimporter', 'gradeimporter_feedback', $fileid, '/', $filename);
-    if ($file){
-      send_stored_file($file, 86400, 0, true);
+      $cell = new html_table_cell ($url);
+      $row->cells[] = $cell;
     }
-    return moodle_url::make_pluginfile_url($contextid, 'mod_gradeimporter', 'gradeimporter_feedback', $fileid, '/', $filename, $forcedownload);*/
+    $table->data[] = $row;
   }
+  
+  //gets all submission types relative to the gradeimporter instance
+  /*$subtype_array = $DB->get_records("gradeimporter_submissiontype", array('gradeimporterid' => $gradeimporterid), 'id', '*');
 
-  function exportCSV($context){
-    $enrolledusers = get_enrolled_users ($context, 'mod/gradeimporter:student');
-    $data = array();
-    $header = array('id', 'name', 'email', 'grade', 'comment', 'file');
+  foreach ($subtype_array as $subtype) {
+    //gets all submissions from a subtype;
+    $submission_array = $DB->get_records("gradeimporter_submission", array('type' => $subtype->id), 'id', '*');
 
-    $csvexport = new csv_export_writer();
-    $csvexport->set_filename('config');
-    $csvexport->add_data($header);
+    foreach ($submission_array as $submission) {
+      //gets all feedbacks from a submission
+      $feedback_array = $DB->get_records("gradeimporter_feedback", array('submissionid' => $submission->id), 'id', '*');
+      $cell = new html_table_cell($submission->name);
+      $cell->colspan = 2;
+      $subrow->cells[] = $cell;
 
-    foreach ($enrolledusers as $value){
-      $name = $value->firstname.' '.$value->lastname;
-      $studententry = array($value->id, $name, $value->email,'','','');
-      $csvexport->add_data($studententry);
+      foreach ($feedback_array as $feedback) {
+          //for each feedback add it to the correspondent user list in $enrolledusers
+      }
     }
+    $table->data[] = $subrow;
+  }*/
+  
+  echo html_writer::table($table);
+}
+
+
+require_once($CFG->libdir . '/filelib.php');
+require_once("$CFG->libdir/csvlib.class.php");
+
+
+function buildurl($cmid, $fileid, $filename){
 
-    $csvexport->download_file();
-    //$dlfile = $csvexporter->download_array('config', $data);
+  $fileurl = new moodle_url("/mod/gradeimporter/view.php", array('id' => $cmid, 'fileid' => $fileid, 'filename' => $filename, 'action' => 1));
+  return "<a href=$fileurl> $filename</a>";
+}
+
+function exportCSV($context){
+  $enrolledusers = get_enrolled_users($context, 'mod/gradeimporter:student');
+  $header = array('id', 'name', 'email', 'grade', 'comment', 'file');
+
+  $csvexport = new csv_export_writer();
+  $csvexport->set_filename('config');
+  $csvexport->add_data($header);
 
+  foreach ($enrolledusers as $value) {
+    $name = $value->firstname . ' ' . $value->lastname;
+    $studententry = array($value->id, $name, $value->email, '', '', '');
+    $csvexport->add_data($studententry);
   }
-}
+
+  $csvexport->download_file();
+  //$dlfile = $csvexporter->download_array('config', $data);
+
+}

+ 1 - 1
version.php

@@ -2,7 +2,7 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$plugin->version = 20191119;
+$plugin->version = 20200210;
 $plugin->requires = 2014021100;
 $plugin->release = 'v1.0';
 $plugin->component = 'mod_gradeimporter';

+ 10 - 45
view.php

@@ -11,7 +11,7 @@
     $id = optional_param('id', 0, PARAM_INT); // course_module ID, or
     $g  = optional_param('g', 0, PARAM_INT);  // gradeimporter instance ID, should be named as the first character of the module
     $action = optional_param('action', 0, PARAM_INT);
-    $cmid = optional_param('cmid', 0, PARAM_INT);
+    //$cmid = optional_param('cmid', 0, PARAM_INT);
     $id       = optional_param('id', 0, PARAM_INT);
     $fileid     = optional_param('fileid', 0, PARAM_INT);
     $filename   = optional_param('filename', 'a', PARAM_TEXT);
@@ -105,58 +105,22 @@ if (has_capability('mod/gradeimporter:edit', $context)) {
 
 require_once($CFG->libdir . '/tablelib.php');
 require_once(dirname(__FILE__).'/locallib.php');
-use \gradeimporter\feedback;
 
-$data = feedback::get_comments($cm->id, $id);
+
 
 if (has_capability('mod/gradeimporter:edit', $context)){
   //loads teacher view
-  $table = new html_table();
-  $table->attributes['class'] = 'generaltable mod_index';
-  $table->head  = array ("Aluno", "Tipo", "Nome", "Nota", "Arquivos");
-  $table->align = array ('center', 'center', 'center', 'center', 'center');
-
-  if (count($data)) {
-    $currentAluno = "";
-    foreach ($data as $aluno => $datas) {
-      if ($currentAluno != "" && $currentAluno != $aluno) {
-        $row = new html_table_row();
-        $cell = new html_table_cell();
-        $cell->colspan = 6;
-        $row->cells[] = $cell;
-        $table->data[] = $row;
-      }
-      $t = count($datas);
-      foreach ($datas as $tipo => $cells) {$t += count($cells);};
-      $currentAluno = $aluno;
-      $row = new html_table_row();
-      $cell = new html_table_cell($aluno);
-      $cell->rowspan = $t+1;
-      $row->cells[] = $cell;
-      $table->data[] = $row;
-
-      foreach ($datas as $tipo => $cells) {
-        $row = new html_table_row();
-        $cell = new html_table_cell($tipo);
-        $cell->rowspan = count($cells)+1;
-        $row->cells[] = $cell;
-        $table->data[] = $row;
+  $enrolledusers = get_enrolled_users ($context, 'mod/gradeimporter:view');
 
-        foreach ($cells as $cell) {
-          $row = new html_table_row();
-          foreach ($cell as $value) {
-            $row->cells[] = new html_table_cell($value);
-          }
-          $table->data[] = $row;
-        }
-      }
-    }
-  }
+  get_teacher_view($cm->id, $gradeimporter->id, $enrolledusers);
+  
 } else {
+  $data = get_comments($cm->id, $id);
+
   //loads student view
   $table = new html_table();
   $table->attributes['class'] = 'generaltable mod_index';
-  $table->head  = array ("Tipo", "Nome", "Nota", "Comentários", "Arquivos");
+  $table->head  = array (get_string('type', 'gradeimporter'), get_string('submission', 'gradeimporter'), get_string('grade', 'gradeimporter'), get_string('comment', 'gradeimporter'), get_string('file', 'gradeimporter'));
   $table->align = array ('center', 'center', 'center', 'center', 'center');
 
   if (count($data)) {
@@ -186,8 +150,9 @@ if (has_capability('mod/gradeimporter:edit', $context)){
       }
     }
   }
+  echo html_writer::table($table);
 }
 
-echo html_writer::table($table);
+
 /// Finish the page
 echo $output->footer();