Procházet zdrojové kódy

Gradebook update
- Submission grades are now inserted into database if teacher chooses so in submissionform
- Update several files to enable this changes
-- install.xml: Quality of life changes, removing deprecated fields and adding new fields like maxgrade at submission table
-- New functions for grade insertion at lib.php
-- Removal of deprecated code at many files
-- Added maxgrade text field at submission_form.php

Bernardo před 2 roky
rodič
revize
f65f0a81a5

+ 1 - 1
db/install.xml

@@ -32,7 +32,7 @@
         <FIELD NAME="position" TYPE="int" LENGTH="3" NOTNULL="true" SEQUENCE="false" COMMENT="Position relative to other submissions" />
         <FIELD NAME="visibility" TYPE="int" LENGTH="1" NOTNULL="true" SEQUENCE="false" COMMENT="Registers if students can see this submission." />
         <FIELD NAME="gradebook" TYPE="int" LENGTH="1" NOTNULL="true" SEQUENCE="false" COMMENT="Register if the submission is going to the gradebook" />
-        <FIELD NAME="maxgrade" TYPE="int"  LENGTH="10" NOTNULL=false SEQUENCE="false" COMMENT="Max grade if going to gradebook" />
+        <FIELD NAME="maxgrade" TYPE="int"  LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="Max grade if going to gradebook" />
         <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" />
         <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" />
         <FIELD NAME="usermodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" />

+ 2 - 2
forms/submission/submission.php

@@ -105,8 +105,8 @@ if ($mform->is_cancelled()) {
     // If its updating an existing submission
     // Get data from db and insert into form
     $subdata = $DB->get_record('gradeimporter_submission', array('id' => $subid));
-    $subdata->description = array('text' => $subdata->description,
-                    'format' => $subdata->descriptionformat
+    $subdata->intro = array('text' => $subdata->intro,
+                    'format' => $subdata->introformat
                   );
     $mform->set_data($subdata);
   }

+ 7 - 2
forms/submission/submission_form.php

@@ -43,8 +43,9 @@ class mod_gradeimporter_submission_form extends moodleform {
     $mform->setType('name', PARAM_TEXT);
     $mform->addRule('name', null, 'required', null, 'client');
 
-    $mform->addElement('editor', 'description', get_string('description'));
-    $mform->setType('description', PARAM_TEXT);
+    // Description
+    $mform->addElement('editor', 'intro', get_string('submissionintro', 'gradeimporter'));
+    $mform->setType('intro', PARAM_RAW);
 
     $mform->addElement('filemanager', 'submissionfiles_filemanager', get_string('submissionfiles', 'gradeimporter'),
               null, $filemanageroptions);
@@ -81,6 +82,10 @@ class mod_gradeimporter_submission_form extends moodleform {
     $mform->setDefault('gradebook', array('value' => 0));
     $mform->addHelpButton('gradebook', 'gradebook', 'gradeimporter');
 
+    $mform->addElement('text', 'maxgrade', get_string('maxgrade', 'gradeimporter'), array('type' => 'number', 'value' => 100));
+    $mform->setType('maxgrade', PARAM_INT);
+    $mform->hideIf('maxgrade', 'gradebook', 'eq', 0);
+
     // -----------------------------
     // Hidden fields
     $mform->addElement('hidden', 'id');

+ 6 - 6
forms/submission/submission_form_functions.php

@@ -28,8 +28,8 @@ function create_submission ($data, $gradeimporterid, $userid) {
     $isnewentry = false;
   }
 
-  $data->descriptionformat = $data->description["format"];
-  $data->description = $data->description["text"];
+  $data->introformat = $data->intro["format"];
+  $data->intro = $data->intro["text"];
   $data->timemodified = $timenow;
   $data->position = -1; // Do later
 
@@ -82,7 +82,7 @@ function read_csv ($content, $context, $data, $zipfiles = null) {
   foreach ($csv as $line => $feedback) {
     $feedback = fix_feedback($feedback, $line); // Check if data is correct
     $feedbackid = store_feedback($feedback, $context->id, $data->id);
-    gradeimporter_update_grades($data, $feedback->id);
+    gradeimporter_update_grades($data, $feedback['id']);
     if ($feedback['file'] != "") {
       // If feedback has associated file, insert it into pluginfile
       foreach ($zipfiles as $file) {
@@ -141,7 +141,7 @@ function store_feedback ($feedback, $contextid, $submissionid) {
   $entry->timemodified = time();
   $entry->grade = $feedback['grade'];
   $entry->comment = $feedback['comment'];
-  $entry->name = $feedback['file'];
+  $entry->filename = $feedback['file'];
   $entry->usermodified = $USER->id;
 
   // If is not a new feedback update previous record and return id
@@ -162,7 +162,7 @@ function store_feedback_file ($feedback, $context, $submission, $filetostore, $f
     'timecreated' => time(), 'timemodified' => time()
   );
 
-  // store files in correct area
+  // Store files in correct area
   return $fs->create_file_from_storedfile($fileinfo, $filetostore);
 }
 
@@ -229,7 +229,7 @@ function feedback_exists($feedback, $submissionid) {
  */
 function delete_feedback_files($feedback) {
   $fs = get_file_storage();
-  $file = $fs->get_file($feedback->contextid, 'mod_gradeimporter', 'submissionfiles', $feedback->id, '/', $feedback->name);
+  $file = $fs->get_file($feedback->contextid, 'mod_gradeimporter', 'submissionfiles', $feedback->id, '/', $feedback->filename);
   if ($file) {
     $file->delete();
   }

+ 4 - 4
forms/submissiontype/submissiontype.php

@@ -68,8 +68,8 @@ if ($mform->is_cancelled()) {
     $isnewentry = false;
   }
 
-  $entry->description    = $entry->description_editor["text"];
-  $entry->descriptionformat  = FORMAT_HTML;
+  $entry->introformat = $entry->intro['format'];
+  $entry->intro = $entry->intro['text'];
 
   if ($isnewentry) {
     $entry->id = $DB->insert_record('gradeimporter_submissiontype', $entry);
@@ -93,8 +93,8 @@ if ($typeid != -1) {
   // Get data from DB and insert into form
   $PAGE->navbar->add(get_string('edit'));
   $data = $DB->get_record('gradeimporter_submissiontype', array('id' => $typeid));
-  $data->description_editor = array('text' => $data->description,
-                    'format' => $data->descriptionformat
+  $data->intro = array('text' => $data->intro,
+                    'format' => $data->introformat
                   );
   $mform->set_data($data);
 }

+ 2 - 2
forms/submissiontype/submissiontype_form.php

@@ -35,8 +35,8 @@ class mod_gradeimporter_submissiontype_form extends moodleform {
     $mform->addRule('name', get_string('error_nameField', 'gradeimporter'), 'required', null, 'client');
 
     // Description
-    $mform->addElement('editor', 'description_editor', get_string('submissionDescription', 'gradeimporter'));
-    $mform->setType('description_editor', PARAM_TEXT);
+    $mform->addElement('editor', 'intro', get_string('typeintro', 'gradeimporter'));
+    $mform->setType('intro', PARAM_TEXT);
 
     // Hidden fields
     $mform->addElement('hidden', 'id');

+ 26 - 0
grade.php

@@ -0,0 +1,26 @@
+<?php
+// This file is part of
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+// Page redirected to when user clicks on modname at gradebook page
+
+defined('MOODLE_INTERNAL') || die();
+
+$id = required_param('id', PARAM_INT);          // Course module ID
+$itemnumber = optional_param('itemnumber', 0, PARAM_INT);
+      // Item number, may be != 0 for activities that allow more than one grade per user
+$userid = optional_param('userid', 0, PARAM_INT); // Graded user ID (optional)
+
+redirect('view.php');

+ 6 - 0
lang/en/forms_lang.php

@@ -18,10 +18,12 @@
 // Submission form
 $string['newsubmission'] = 'New Submission';
 $string['submissionname'] = 'Submission name';
+$string['submissionintro'] = 'Submission description';
 $string['visibility_help'] = 'Not working at the moment, still being built';
 $string['submissiontype'] = 'Submission type';
 $string['gradebook'] = 'Gradebook';
 $string['gradebook_help'] = 'Submission goes to gradebook?';
+$string['maxgrade'] = "Max Grade allowed";
 $string['submissionfiles'] = 'Submission files';
 $string['submissionfiles_help'] = 'Submit 1 file with all submissions inside it, either a .csv or a .zip with a csv and a folder with the submissions inside it';
 
@@ -29,3 +31,7 @@ $string['newtypebutton'] = 'New type';
   // Exceptions
   $string['invalidtype'] = "Submission type is invalid, must first create a type";
   $string['studentidmissing'] = 'Student id missing in .csv at line {$a}';
+
+
+// Submission type
+$string['typeintro'] = "Submission type Description";

+ 89 - 13
lib.php

@@ -177,7 +177,7 @@ function gradeimporter_grade_item_update ($submission, $grades = null) {
     $params['gradetype'] = GRADE_TYPE_NONE;
   } else {
     $params['gradetype'] = GRADE_TYPE_VALUE;
-    $params['grademax'] = 10;
+    $params['grademax'] = $submission->maxgrade;
     $params['grademin'] = 0;
   }
 
@@ -203,16 +203,19 @@ function gradeimporter_update_grades ($submission, $userid = 0, $nullifnone = tr
   if ($grades = gradeimporter_get_user_grades($submission, $userid)) {
     // Gets student grade from gradeimporter_feedback table
     gradeimporter_grade_item_update($submission, $grades);
+    return;
+  }
 
-  } else if ($userid and $nullifnone) {
+  if ($userid and $nullifnone) {
     $grade = new stdClass();
     $grade->userid = $userid;
     $grade->rawgrade = null;
     gradeimporter_grade_item_update($submission, $grade);
-
-  } else {
-    gradeimporter_grade_item_update($submission);
+    return;
   }
+
+  gradeimporter_grade_item_update($submission);
+
 }
 
 function gradeimporter_reset_gradebook ($courseid, $type = '') {
@@ -221,19 +224,92 @@ function gradeimporter_reset_gradebook ($courseid, $type = '') {
 }
 
 function gradeimporter_get_user_grades($submission, $userid) {
-  global $DB;
+  global $DB, $CFG;
   $grade = new stdClass();
   $grade->userid = $userid;
 
-  $feedback = $DB->get_record('gradeimporter_feedback',
-                                    ['submissionid' => $submission->id, 'studendit' => $userid],
-                                    ['grade']
-                                  );
-
-  if ($feedback) {
-    $grade->rawgrade = $feedback->grade;
+  $tp = $CFG->prefix;
+  $sql = "SELECT gf.id, gf.grade as grade
+          FROM {$tp}gradeimporter_feedback as gf
+          JOIN {$tp}gradeimporter_submission as gs
+            ON gs.id = gf.submissionid
+          JOIN {$tp}gradeimporter as gi
+            ON gi.id = gs.gradeimporterid
+          WHERE gf.studentid = $userid
+              AND gi.id = $submission->gradeimporterid
+              AND gs.gradebook = 1
+              AND gs.visibility = 1";
+  $feedbacks = $DB->get_records_sql($sql);
+
+  if ($feedbacks) {
+    $grade->rawgrade = sum_property($feedbacks, 'grade');
     return $grade;
   }
 
   return null;
 }
+
+function sum_property ($array, $property) {
+  $sum = 0;
+  foreach ($array as $object) {
+    $sum += $object->$property;
+  }
+  return $sum;
+}
+
+function create_grade_item($submission) {
+  global $CFG, $COURSE;
+
+  require_once("{$CFG->libdir}/gradelib.php");
+
+  $gradeitem = new grade_item(array('id' => 0, 'courseid' => $COURSE->id));
+  $data = new stdClass();
+  $data->itemname = $submission->name;
+  $data->iteminfo = $submission->intro;
+  // Blank [idnumer] for now
+  $data->outcomeid = $submission->gradeimporterid;
+  $data->cmid = $submission->gradeimporterid;
+  $data->id = 0;
+  $data->courseid = $COURSE->id;
+  $data->aggregationcoef = 0;
+  $data->itemtype = 'gradeimporter';
+
+  grade_item::set_properties($gradeitem, $data);
+
+  $gradeitem->itemnumber = $submission->id;
+
+  $outcome = grade_outcome::fetch(array('id' => $submission->gradeimporterid));
+  $gradeitem->gradetype = GRADE_TYPE_SCALE;
+  $gradeitem->scaleid = $outcome->scaleid;
+
+  $gradeitem->insert();
+
+  if ($item = grade_item::fetch(array('itemtype' => 'gradeimporter', 'itemmodule' => $gradeitem->itemmodule,
+                                    'iteminstance' => $gradeitem->iteminstance, 'itemnumber' => 0, 'courseid' => $COURSE->id))) {
+      $gradeitem->set_parent($item->categoryid);
+      $gradeitem->move_after_sortorder($item->sortorder);
+  }
+}
+
+function insert_grade_outcome($submission, $userid) {
+  global $CFG, $DB, $COURSE;
+  echo "abdesg";
+  if (empty($CFG->enableoutcomes)) {
+    return;
+  }
+  echo "abc";
+  require_once("$CFG->libdir/gradelib.php");
+
+  $data = array();
+  $gradinginfo = grade_get_grades($COURSE->id, 'mod', 'gradeimporter', $submission->gradeimporterid, $userid);
+
+  if (!empty($gradinginfo->outcomes)) {
+    foreach ($gradinginfo->outcomes as $n => $old) {
+      $data[$n] = 2;
+    }
+  }
+
+  if (count($data) > 0) {
+    grade_update_outcomes('mod/gradeimporter', $COURSE->id, 'mod', 'gradeimporter', $submission->gradeimporterid, $userid, $data);
+  }
+}

+ 2 - 2
libs/student_viewlib.php

@@ -30,14 +30,14 @@ function query_feedbacks ($gradeimporterid) {
         gf.id as id,
         gst.name as typename,
         gst.id as typeid,
-        gst.description as typedescription,
+        gst.intro as typeintro,
         gs.name as submissionname,
         gs.id as submissionid,
         gf.grade as grade,
         gf.comment as comment,
         gf.name as filename,
         gf.contextid as contextid,
-        gs.description as submissiondescription,
+        gs.intro as submissionintro,
         gs.position as position
         FROM {$tp}gradeimporter_feedback as gf
         JOIN {$tp}gradeimporter_submission as gs

+ 4 - 4
libs/teacher_viewlib.php

@@ -173,7 +173,7 @@ class Teacherview {
     $tp = $CFG->prefix;
 
     // Build Query
-    $sql = "SELECT id, name, type, description
+    $sql = "SELECT id, name, type, intro
         FROM {$tp}gradeimporter_submission
         WHERE gradeimporterid ={$this->get_gradeimporterid()}
         ORDER BY type, id";
@@ -203,10 +203,10 @@ class Teacherview {
                       'submissionfiles',
                       $feedback->id,
                       "/",
-                      $feedback->name,
+                      $feedback->filename,
                       true
                     );
-    return "<a href='{$url}'>$feedback->name</a>";
+    return "<a href='{$url}'>$feedback->filename</a>";
   }
 
   /**
@@ -229,7 +229,7 @@ class Teacherview {
                                                                                       'subid' => $submission->id)
                                                                                     );
     $editlinktitle = get_string('editSub', 'gradeimporter', $submission->name);
-    return "<a title=\"$submission->description\">
+    return "<a title='$submission->intro'>
               $submission->name
             </a>
             <a href=\"$url\" target=\"_blank\">

+ 2 - 2
version.php

@@ -16,8 +16,8 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$plugin->version = 20200220;
+$plugin->version = 20220405;
 $plugin->requires = 2014021100;
-$plugin->release = 'v1.0';
+$plugin->release = 'v0.9';
 $plugin->component = 'mod_gradeimporter';
 $plugin->maturity = MATURITY_STABLE;