Browse Source

Submission form fully working:
- Correctly calls submissiontype form and reflects the changes in gradeimporter_submissiontype table in DB.
- UI can be improved

Teacher view under reconstruction:
- Updating teacherview to be a class;
- Improving maintainability and readability;
- Views (student and teacher) are inside libs/
- To be finished on next commit

Bernardo 2 years ago
parent
commit
8c8d2d2ea5

+ 11 - 9
submission.php

@@ -14,15 +14,15 @@
 // You should have received a copy of the GNU General Public License
 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
-require_once('../../config.php');
-require_once('locallib.php');
-require_once('lib.php');
+require_once('../../../../config.php');
+require_once('../../locallib.php');
+require_once('../../lib.php');
 
 // Test libs
-require_once('libs/testlib.php'); // Remove when going to production
+require_once('../../libs/testlib.php'); // Remove when going to production
 
-require_once('forms/submission_form.php'); // Requires Form class File
-require_once('forms/submission_form_functions.php'); // Require functions file for submission form
+require_once('submission_form.php'); // Requires Form class File
+require_once('submission_form_functions.php'); // Require functions file for submission form
 
 $cmid = required_param('cmid', PARAM_INT);            // Course Module ID.
 $id = optional_param('id', 0, PARAM_INT);           // Gradeimporter id.
@@ -40,7 +40,7 @@ $gradeimporter = $DB->get_record('gradeimporter', array('id' => $cm->instance),
 $context = context_module::instance($cm->id);
 
 // Sets URL
-$url = new moodle_url('/mod/gradeimporter/submission.php', array('cmid' => $cm->id));
+$url = new moodle_url('/mod/gradeimporter/forms/submission/submission.php', array('cmid' => $cm->id));
 if (!empty($id)) {
     $url->param('id', $id);
 }
@@ -75,13 +75,15 @@ $entry = file_prepare_standard_filemanager($entry, 'submissionfiles', $filemanag
 
 // Create new mform to show to the user
 $mform = new mod_gradeimporter_submission_form(null, array('submission' => $entry,
-                                                            'filemanageroptions' => $filemanageroptions
+                                                            'filemanageroptions' => $filemanageroptions,
+                                                            'gradeimporterid' => $gradeimporter->id,
+                                                            'cmid' => $cm->id
                                                         )
                                                 );
 
 if ($mform->is_cancelled()) {
     // Handle form cancel operation, if cancel button is present on form
-    echo("form is cancelled");
+    redirect("view.php?id=$cm->id&edit=1");
 } else if ($formdata = $mform->get_data()) {
 
     reset_submissions($context->id); // Remove when going to production

+ 27 - 3
forms/submission_form.php

@@ -16,8 +16,9 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-require_once($CFG->dirroot.'/course/moodleform_mod.php');
+require_once("$CFG->dirroot/course/moodleform_mod.php");
 require_once("$CFG->libdir/formslib.php");
+require_once("submission_form_functions.php");
 
 class mod_gradeimporter_submission_form extends moodleform {
 
@@ -29,6 +30,8 @@ class mod_gradeimporter_submission_form extends moodleform {
         // Custom data
         $submission = $this->_customdata['submission']; // Load fields data
         $filemanageroptions = $this->_customdata['filemanageroptions'];
+        $gradeimporterid = $this->_customdata['gradeimporterid'];
+        $cmid = $this->_customdata['cmid'];
         // ----------------------------------------------------------------
         // General information
 
@@ -47,8 +50,29 @@ class mod_gradeimporter_submission_form extends moodleform {
                             null, $filemanageroptions);
         $mform->addHelpButton('submissionfiles_filemanager', 'submissionfiles', 'gradeimporter');
 
-        $selectvalues = array('red', 'green', 'blue');
-        $select = $mform->addElement('select', 'type', get_string('submissiontype', 'gradeimporter'), $selectvalues);
+        // Add button to open new subtypeform
+        $subtypeformurl = new moodle_url("/mod/gradeimporter/forms/submissiontype/submissiontype.php",
+                                            array('cmid' => $cmid, 'id' => $gradeimporterid)
+                                        );
+        $newsubtypebutton = "<div class=\"col-md-9 form-inline align-items-start felement\">
+                                <button class=\"btn btn-primary\" onclick=\"window.open('$subtypeformurl','_self')\">
+                                    New type
+                                </button>
+                            </div>";
+        $mform->addElement('html', $newsubtypebutton);
+
+        // To edit
+        $subtypes = get_types_array($gradeimporterid);
+        var_dump ($subtypes);
+        if ($subtypes) {
+            $selectvalues = array();
+            foreach ($subtypes as $id => $type) {
+                $selectvalues[$id] = $type->name;
+            }
+        } else {
+            $selectvalues = array('create new type first');
+        }
+        $mform->addElement('select', 'type', get_string('submissiontype', 'gradeimporter'), $selectvalues);
 
         $mform->addElement('selectyesno', 'visibility',  get_string('visibility', 'gradeimporter'));
         $mform->setDefault('visibility', array('value' => 1));

+ 8 - 0
forms/submission_form_functions.php

@@ -187,3 +187,11 @@ function read_zip ($file, $context, $fs) {
     // Returns an array of files object
     return $tempfiles;
 }
+
+function get_types_array($gradeimporterid) {
+    global $DB, $CFG;
+    // Gets moodle table prefix, usually mdl_
+    $tp = $CFG->prefix;
+    $query = "select id, name from {$tp}gradeimporter_submissiontype where gradeimporterid = $gradeimporterid";
+    return $DB->get_records_sql($query);
+}

+ 0 - 139
forms/submissiontype.php

@@ -1,139 +0,0 @@
-<?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/>.
-
-require_once('../../config.php');
-require_once('locallib.php');
-require_once('lib.php');
-require_once('submissiontype_form.php');
-
-
-$cmid = required_param('cmid', PARAM_INT);            // Course Module ID
-$id   = required_param('id' , PARAM_INT);           // Gradeimporter id
-
-if (!$cm = get_coursemodule_from_id('gradeimporter', $cmid)) {
-    throw new moodle_exception('invalidcoursemodule');
-}
-
-if (!$course = $DB->get_record('course', array('id' => $cm->course))) {
-    throw new moodle_exception('coursemisconf');
-}
-
-$context = context_module::instance($cm->id);
-
-require_capability('mod/gradeimporter:edit', $context);
-
-if (!$gradeimporter = $DB->get_record('gradeimporter', array('id' => $cm->instance))) {
-    throw new moodle_exception(get_string('invalidid', 'gradeimporter'));
-}
-
-$url = new moodle_url('/mod/gradeimporter/submissiontype.php', array('cmid' => $cm->id));
-if (!empty($id)) {
-    $url->param('id', $id);
-}
-$PAGE->set_url($url);
-
-require_login($course, false, $cm);
-
-
-if ($submissiontype) {
-    if (isguestuser()) {
-        throw new moodle_exception('guestnoedit', 'gradeimporter', "$CFG->wwwroot/mod/gradeimporter/view.php?id=$cmid");
-    }
-} else {
-
-    $submissiontype = new stdClass();
-    $submissiontype->id = null;
-}
-
-$maxfiles = 50;
-$maxbytes = $course->maxbytes;
-
-$descriptionoptions = array('trusttext' => true, 'maxfiles' => $maxfiles,
-                    'maxbytes' => $maxbytes, 'context' => $context,
-                    'subdirs' => file_area_contains_subdirs($context, 'mod_gradeimporter',
-                                                        'submissiontype', $submissiontype->id));
-
-$submissiontypeoptions = array('subdirs' => false, 'maxfiles' => $maxfiles, 'maxbytes' => $maxbytes);
-
-$submissiontype = file_prepare_standard_editor($submissiontype, 'description', $descriptionoptions,
-                                            $context, 'mod_gradeimporter', 'description', $submissiontype->id);
-
-$submissiontype->cmid = $cm->id;
-
-$mform = new mod_gradeimporter_submissiontype_form(null, array('submissiontype' => $submissiontype,
-                                                                'cm' => $cm,
-                                                                'descriptionoptions' => $descriptionoptions,
-                                                                'submissiontypeoptions' => $submissiontypeoptions
-                                                            )
-                                                    );
-
-if ($mform->is_cancelled()) {
-    if ($id) {
-        redirect("view.php?id=$cm->id&mode=entry&hook=$id");
-    } else {
-        redirect("view.php?id=$cm->id");
-    }
-} else if ($submissiontype = $mform->get_data()) {
-    if (empty($submissiontype->id)) {
-        $submissiontype->gradeimporterid    = $gradeimporter->id;
-
-        $isnewentry                         = true;
-    } else {
-        $isnewentry                         = false;
-    }
-
-    $submissiontype->description        = '';
-    $submissiontype->descriptionformat  = FORMAT_HTML;
-    $submissiontype->definitiontrust    = 0;
-
-    if ($isnewentry) {
-        $submissiontype->id = $DB->insert_record('gradeimporter_submissiontype', $submissiontype);
-    } else {
-        $DB->update_record('gradeimporter', $submissiontype);
-    }
-
-    $submissiontype = file_postupdate_standard_editor($submissiontype, 'description',
-                                                    $descriptionoptions, $context, 'mod_gradeimporter',
-                                                    'submissiontype', $submissiontype->id);
-
-    $DB->update_record('gradeimporter_submissiontype', $submissiontype);
-
-    if ($isnewentry) {
-        // Update completion state
-        $completion = new completion_info($course);
-        if ($completion->is_enabled($cm) == COMPLETION_TRACKING_AUTOMATIC && $gradeimporter->completionentries) {
-            $completion->update_state($cm, COMPLETION_COMPLETE);
-        }
-    }
-
-    redirect("submission.php?id=$id&cmid=$cm->id&page=0");
-}
-
-if (!empty($id)) {
-    $PAGE->navbar->add(get_string('edit'));
-}
-
-$PAGE->set_title($gradeimporter->name);
-$PAGE->set_heading($course->fullname);
-echo $OUTPUT->header();
-echo $OUTPUT->heading(format_string($gradeimporter->name), 2);
-if ($gradeimporter->intro) {
-    echo $OUTPUT->box(format_module_intro('gradeimporter', $gradeimporter, $cm->id), 'generalbox', 'intro');
-}
-
-$mform->display();
-
-echo $OUTPUT->footer();

+ 112 - 0
forms/submissiontype/submissiontype.php

@@ -0,0 +1,112 @@
+<?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/>.
+
+require_once("../../../../config.php");
+require_once("$CFG->dirroot/mod/gradeimporter/lib.php");
+
+require_once('submissiontype_form.php');
+$cmid = required_param('cmid', PARAM_INT); // Course Module ID
+$id   = required_param('id', PARAM_INT);  // Gradeimporter id
+$typeid = optional_param('tid', -1, PARAM_INT); // Type id, used if editing already existing type
+
+// Check if its inside a course and this gradeimporter exists
+$cm = get_coursemodule_from_id('gradeimporter', $cmid, 0, false, MUST_EXIST);
+$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
+$gradeimporter = $DB->get_record('gradeimporter', array('id' => $cm->instance), '*', MUST_EXIST);
+
+// Get context
+$context = context_module::instance($cm->id);
+
+// Sets url
+$url = new moodle_url('/mod/gradeimporter/submissiontype.php', array('cmid' => $cm->id));
+if (!empty($id)) {
+    $url->param('id', $id);
+}
+$PAGE->set_url($url);
+
+// Requires user to be logged in and have edit capability
+require_login($course, false, $cm);
+require_capability('mod/gradeimporter:edit', $context);
+
+if (!isSet($entry)) {
+    $entry = new stdClass();
+    $entry->id = null;
+}
+
+$entry->cmid = $cm->id;
+$entry->gradeimporterid = $gradeimporter->id;
+
+$mform = new mod_gradeimporter_submissiontype_form(null, array('submissiontype' => $entry));
+
+if ($mform->is_cancelled()) {
+    if ($id) {
+        redirect("view.php?id=$cm->id&mode=entry&hook=$id");
+    } else {
+        redirect("view.php?id=$cm->id");
+    }
+} else if ($entry = $mform->get_data()) {
+    // If data is valid
+    // Submit $entry into DB
+    if (empty($entry->id)) {
+        // If entry doesn't have id its a new entry
+        $entry->gradeimporterid = $gradeimporter->id;
+        $isnewentry = true;
+    } else {
+        $isnewentry = false;
+    }
+
+    $entry->description        = $entry->description_editor["text"];
+    $entry->descriptionformat  = FORMAT_HTML;
+
+    if ($isnewentry) {
+        $entry->id = $DB->insert_record('gradeimporter_submissiontype', $entry);
+    } else {
+        $DB->update_record('gradeimporter', $submissiontype);
+    }
+
+    if ($isnewentry) {
+        // Update completion state
+        $completion = new completion_info($course);
+        if ($completion->is_enabled($cm) == COMPLETION_TRACKING_AUTOMATIC && $gradeimporter->completionentries) {
+            $completion->update_state($cm, COMPLETION_COMPLETE);
+        }
+    }
+
+    redirect("../submission/submission.php?id=$id&cmid=$cm->id&page=0");
+}
+
+if ($typeid != -1) {
+    // If typeid is not empty then its editing an already existing submissiontype
+    // 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
+                                    );
+    $mform->set_data($data);
+}
+
+$PAGE->set_title($gradeimporter->name);
+$PAGE->set_heading($course->fullname);
+echo $OUTPUT->header();
+echo $OUTPUT->heading(format_string($gradeimporter->name), 2);
+if ($gradeimporter->intro) {
+    echo $OUTPUT->box(format_module_intro('gradeimporter', $gradeimporter, $cm->id), 'generalbox', 'intro');
+}
+
+$mform->display();
+
+echo $OUTPUT->footer();

+ 5 - 10
forms/submissiontype_form.php

@@ -22,15 +22,8 @@ class mod_gradeimporter_submissiontype_form extends moodleform {
     public function definition() {
         global $CFG, $DB;
 
-        $mform =& $this->_form;
-
+        $mform = $this->_form;
         $submissiontype = $this->_customdata['submissiontype'];
-        $cm             = $this->_customdata['cm'];
-        $descriptionoptions = $this->_customdata['descriptionoptions'];
-        $submissiontypeoptions  = $this->_customdata['submissiontypeoptions'];
-
-        $context    = context_module::instance($cm->id);
-        $fmtoptions = array('context' => $context);
 
         // --------------------
         // Form starts here
@@ -42,14 +35,16 @@ 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'), null, $descriptionoptions);
-        $mform->setType('description_editor', PARAM_RAW);
+        $mform->addElement('editor', 'description_editor', get_string('submissionDescription', 'gradeimporter'));
+        $mform->setType('description_editor', PARAM_TEXT);
 
         // Hidden fields
         $mform->addElement('hidden', 'id');
         $mform->setType('id', PARAM_INT);
         $mform->addElement('hidden', 'cmid');
         $mform->setType('cmid', PARAM_INT);
+        $mform->addElement('hidden', 'gradeimporterid');
+        $mform->setType('gradeimporterid', PARAM_INT);
 
         // Buttons
         $this->add_action_buttons();

+ 2 - 0
lang/en/forms_lang.php

@@ -24,3 +24,5 @@ $string['gradebook'] = 'Gradebook';
 $string['gradebook_help'] = 'Submission goes to gradebook?';
 $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';
+
+$string['newtypebutton'] = 'New type';

+ 5 - 4
libs/student_viewlib.php

@@ -21,9 +21,9 @@ function query_feedbacks($cmid, $gradeimporterid) {
 
     // Build database query to fetch feedbacks for the student
     $query = " SELECT
-                /* gst.name as typename,
+                gst.name as typename,
                 gst.id as typeid,
-                gst.description as typedescription, */
+                gst.description as typedescription,
                 gf.id as id,
                 gs.name as submissionname,
                 gs.id as submissionid,
@@ -35,8 +35,8 @@ function query_feedbacks($cmid, $gradeimporterid) {
                 FROM {$tp}gradeimporter_feedback as gf
                 JOIN {$tp}gradeimporter_submission as gs
                     ON gf.submissionid = gs.id
-                /* JOIN {$tp}gradeimporter_submissiontype as gst
-                    ON gs.type = gst.id */
+                JOIN {$tp}gradeimporter_submissiontype as gst
+                    ON gs.type = gst.id
                 WHERE gs.gradeimporterid = {$gradeimporterid}
                     AND gf.studentid = {$USER->id}
                     AND gs.visibility = 1
@@ -57,6 +57,7 @@ function make_feedback_table ($feedbacks, $cmid) {
                     get_string('file', 'gradeimporter')
                 );
     $table->aling = array('center', 'center', 'center', 'center', 'center');
+    $table->attributes = array('class' => 'generaltable mod_index');
 
     if (count($feedbacks)) {
         // If feedbacks is not an empty list

+ 104 - 0
libs/teacher_viewlib.php

@@ -0,0 +1,104 @@
+<?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/>.
+class Teacherview {
+    private $cmid;
+    private $gradeimporterid;
+    private $context;
+    private $table;
+    private $cellstyle = "border:1px solid black";
+
+    public function __construct(int $cmid, int $gradeimporterid) {
+        $this->$cmid = $cmid;
+        $this->$gradeimporterid = $gradeimporterid;
+        $this->context = context_module::instance($this->get_cmid);
+        $this->$table = make_table($cmid, $gradeimporterid);
+    }
+
+    private function get_cmid() {
+        return $this->cmid;
+    }
+    private function get_gradeimporterid() {
+        return $this->gradeimporterid;
+    }
+    private function get_context() {
+        return $this->context;
+    }
+    private function get_cellstyle() {
+        return $this->cellstyle;
+    }
+    public function get_table() {
+        return $this->table;
+    }
+
+
+    private function make_table() {
+        global $DB, $CFG;
+
+        // Prepare variables
+        $studentlist = get_studentlist();
+
+        // Create table
+        $table = new html_table();
+        $table->align = array('center');
+        $table->attributes = array('class' => 'generaltable mod_index');
+        $table->head = get_table_head();
+
+        return $table;
+    }
+
+    private function get_studentlist() {
+        // Get students list with userid as key and fullname as value
+        $enrolledusers = get_enrolled_users($this->get_context(), 'mod/gradeimporter:view',
+                                        0, 'u.id, u.firstname, u.lastname',
+                                        'u.firstname, u.lastname'
+                                    );
+        $studentlist = array();
+        foreach ($enrolledusers as $user) {
+            $userslist[$user->id] = array('name' => $user->firstname." ".$user->lastname);
+        }
+        return $studentlist;
+    }
+
+    private function get_table_head() {
+        global $CFG;
+        $tp = $CFG->prefix;
+        // Creates teacher view table head
+        $head = new html_table_row();
+
+        // Creates name column header
+        $cell = new html_table_cell(get_string('nameCol', 'gradeimporter'));
+        $cell->style = $this->get_cellstyle();
+        $cell->colspan = 1;
+
+        // Add name header to header row
+        $header->cells[] = $cell;
+
+        // Get Submissions names and ids
+        $sql = "SELECT id, name, type
+                FROM {$tp}gradeimporter_submission
+                WHERE gradeimporterid = {$this->get_gradeimporterid()}
+                ORDER BY type, id";
+        $submissions = $DB->get_records($sql);
+        foreach ($submissions as $submission) {
+            // $subname = editSub($submission->name, $gradeimporterid, $cmid, $submission->id);
+            $cell = new html_table_cell($submission->name);
+            $cell->colspan = 2;
+            $cell->style = $this->get_cellstyle();
+            $header->cells[] = $cell;
+        }
+        return $header;
+    }
+}

+ 0 - 99
locallib.php

@@ -57,105 +57,6 @@ function get_comments($cmid, $id) {
     return $data;
 }
 
-
-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->align = array('center');
-    $table->attributes = array('class' => 'generaltable mod_index');
-
-    // Creates table head
-    $subrow = new html_table_row();
-
-    $cell = new html_table_cell(get_string('nameCol', 'gradeimporter'));
-    $cell->style = "border:1px solid black";
-
-    $cell->colspan = 1;
-    $subrow->cells[] = $cell;
-    $submissionssql = "SELECT id, name
-                      FROM ".$tp."gradeimporter_submission
-                      WHERE gradeimporterid = $gradeimporterid
-                      ORDER BY id";
-    $submissions = $DB->get_records_sql($submissionssql);
-    foreach ($submissions as $submission) {
-        $subname = editSub($submission->name, $gradeimporterid, $cmid, $submission->id);
-        $cell = new html_table_cell($subname);
-        $cell->colspan = 2;
-        $cell->style = "border:1px solid black";
-        $subrow->cells[] = $cell;
-
-        // Adds 2 align, one for grade and another to the file
-        $table->align[] = 'center';
-        $table->align[] = 'center';
-    }
-    $table->data[] = $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);
-    }
-
-    foreach ($records as $record) {
-        $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']);
-        $cell->style = "border:1px solid black";
-        $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);
-            $cell->style = "border:1px solid black; border-right:0";
-            $row->cells[] = $cell;
-
-            $cell = new html_table_cell($url);
-            $cell->style = "border:1px solid black; border-left:0";
-            $row->cells[] = $cell;
-        }
-        $table->data[] = $row;
-    }
-    echo html_writer::table($table);
-}
-
-
 require_once($CFG->libdir . '/filelib.php');
 require_once("$CFG->libdir/csvlib.class.php");
 

+ 4 - 7
view.php

@@ -19,6 +19,7 @@ require_once(dirname(__FILE__).'/lib.php');
 require_once($CFG->libdir.'/filelib.php');
 require_once('locallib.php');
 require_once('libs/student_viewlib.php');
+require_once('libs/teacher_viewlib.php');
 
   global $DB;
 
@@ -92,7 +93,7 @@ echo $output->heading($heading);
 
 // Button to add new submission.
 if (has_capability('mod/gradeimporter:edit', $context)) {
-    $url = new moodle_url('/mod/gradeimporter/submission.php');
+    $url = new moodle_url('/mod/gradeimporter/forms/submission/submission.php');
     $newbutton = '<form action="'. $url . '">'.
           '<input type="hidden" name="id" value="'. $gradeimporter->id .'" />'.
           '<input type="hidden" name="cmid" value="'.$cm->id.'" />'.
@@ -115,14 +116,10 @@ if (has_capability('mod/gradeimporter:edit', $context)) {
 require_once($CFG->libdir . '/tablelib.php');
 require_once(dirname(__FILE__).'/locallib.php');
 
-
-
 if (has_capability('mod/gradeimporter:edit', $context)) {
     // Loads teacher view.
-
-    $enrolledusers = get_enrolled_users($context, 'mod/gradeimporter:view', 0, 'u.id, u.firstname, u.lastname', 'u.firstname, u.lastname');
-
-    get_teacher_view($cm->id, $gradeimporter->id, $enrolledusers);
+    get_teacher_view($cm->id, $gradeimporter->id);
+    // get_teacher_view($cm->id, $gradeimporter->id, $enrolledusers);
 } else {
     // Load student view