Explorar o código

submission form partially done

bernardo %!s(int64=5) %!d(string=hai) anos
pai
achega
d28990f480
Modificáronse 8 ficheiros con 256 adicións e 16 borrados
  1. 4 2
      db/install.xml
  2. 1 0
      lang/en/gradeimporter.php
  3. 10 4
      lib.php
  4. 58 0
      locallib.php
  5. 19 0
      renderer.php
  6. 139 9
      submission.php
  7. 1 1
      version.php
  8. 24 0
      view.php

+ 4 - 2
db/install.xml

@@ -26,7 +26,7 @@
     <TABLE NAME="gradeimporter_submission" COMMENT="submission table, relates the submission to the gradeimporter, feedback files and student." PREVIOUS="gradeimporter" NEXT="gradeimporter_submissiontype" >
       <FIELDS>
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" NEXT="gradeimporter"/>
-        <FIELD NAME="gradeimporter" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" 
+        <FIELD NAME="gradeimporterid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" 
               COMMENT="Which gradeimporter instance this submission is related to" PREVIOUS="id" NEXT="type"/>
         <FIELD NAME="type" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Type of the submission (exam, exercise list,"
                 PREVIOUS="gradeimporter" NEXT="gradebook"/>
@@ -40,8 +40,10 @@
                 PREVIOUS="timemodified" NEXT="name"/>
         <FIELD NAME="name" TYPE="char" LENGTH="20" NOTNULL="true" SEQUENCE="false" COMMENT="submission name"
                 PREVIOUS="usermodified" NEXT="info"/>
-        <FIELD NAME="info" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Description of the submission type ex: exam 1 given on day YYYY/MM/DD"
+        <FIELD NAME="description" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Description of the submission type ex: exam 1 given on day YYYY/MM/DD"
               PREVIOUS="name" NEXT="position"/>
+        <FIELD NAME="descriptionformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
+
         <!--<FIELD NAME="descriptionformat" TYPE="char" LENGTH="10" NOTNULL="false" DEFAULT="plaintext" SEQUENCE="false" COMMENT="Description text format (html, plaintext, etc)"/>-->
         <FIELD NAME="position" TYPE="int" LENGTH="3" NOTNULL="true" SEQUENCE="false" COMMENT="Position relative to other submissions"
                 PREVIOUS="info" NEXT="visibility"/>

+ 1 - 0
lang/en/gradeimporter.php

@@ -12,6 +12,7 @@ $string['displayingview'] = 'Posted Grades';
 //submission.oho
 $string['invalidgradeimporterid'] = 'Invalid Grade Importer ID';
 $string['submissionadded'] = "Submission added to DB";
+$string['newsubmission'] = "Add new submission";
 
 //formStrings
 

+ 10 - 4
lib.php

@@ -9,10 +9,16 @@ function tool_devcourse_extend_navigation_course($navigation, $course, $courseco
 
 function gradeimporter_supports($feature) {
     switch($feature) {
-       case FEATURE_MOD_INTRO:         return true;
-       case FEATURE_SHOW_DESCRIPTION:  return true;
-  
-       default:                        return null;
+        case FEATURE_MOD_ARCHETYPE:                 return MOD_ARCHETYPE_RESOURCE;
+        case FEATURE_GROUPS:                        return false;
+        case FEATURE_GROUPINGS:                     return false;
+        case FEATURE_MOD_INTRO:                     return true;
+        case FEATURE_COMPLETION_TRACKS_VIEWS:       return true;
+        case FEATURE_GRADE_HAS_GRADE:               return false;
+        case FEATURE_GRADE_OUTCOMES:                return false;
+        case FEATURE_BACKUP_MOODLE2:                return true;
+        
+       default:                                     return null;
       }
     }
 

+ 58 - 0
locallib.php

@@ -38,6 +38,64 @@ class feedback {
     }
 }
 
+function gradeimporter_check_for_zips ($context, $cm, $submission){
+  $fs = get_file_storage();
+  $files = $fs->get_area_files($context->id, 'mod_gradeimporter', 'submission', $submission->id, "itemid, filepath, filename", false);
+
+  foreach ($files as $storedfile) {
+    if ($storedfile->get_mimetype() == 'application/zip') {
+      //unpack zip
+      $packer = get_file_packer('application/zip');
+      $fs->delete_area_files($context->id, 'mod_gradeimporter', 'unpacktemp', 0);
+      $storedfiles = $fs->get_area_files($context->id, 'mod_gradeimporter', 'unpacktemp', 0, "itemid, filepath, filename", false);
+      if (count($tempfiles > 0)) {
+        $storedfile->delete(); // delete the zip
+        
+        foreach (glob('*.csv') as $filename){
+          $csv = array_map('str_getcsv', file($filename));
+          array_walk($csv, function(&$a) use ($csv) { //adds first row as keys
+            $a = array_combine($csv[0], $a);
+          });
+          array_shift($csv); # remove column header
+
+          for ($i = 1; i< sizeof($csv); $i++){
+            $fileinfo = array(
+              'contextid'   =>  $context->id,
+              'component'   =>  'mod_gradeimporter',
+              'filearea'    =>  'submission',
+              'itemid'      =>  $submission->id,
+              'filepath'    =>  '/',
+              'filename'    =>  $csv[i]['filename'],
+              'studentid'   => $csv[i]['id']
+            );
+
+            foreach ($tempfiles as $storedfile) {
+              if ($storedfile->get_filename() == $csv[i]['filename']){
+                $storedfile = $fs->create_file_from_storedfile($fileinfo, $storedfile);
+                $bdentry = array(
+                          'submissionid'  => $submission->id,
+                          'studentid'     => $csv[i]['id'],
+                          'grade'         => $csv[i]['grade'],
+                          'comment'       => $csv[i]['comment'],
+                          'fileid'        => $csv[i][$storedfile],
+                          'usermodified'  => $USER->id,
+                          'timecreated'   => time(),
+                          'timemodified'  => time()
+                        ); 
+                $bdentry->id = $DB->insert_record("feedback", $dbentry);
+                break;
+              }
+            }
+            
+          }
+        }
+
+
+        }
+      $fs->delete_area_files($context->id, 'mod_gradeimporter', 'unpacktemp', 0);
+    }
+  }
+}
 //
 // INSERT INTO `mdl_gradeimporter_feedback` (`id`, `submissionid`, `studentid`, `grade`, `comment`, `fileid`, `usermodified`, `timecreated`, `timemodified`)
 // VALUES

+ 19 - 0
renderer.php

@@ -0,0 +1,19 @@
+<?php
+
+defined('MOODLE_INTERNAL') || die();
+
+class mod_wavefront_renderer extends plugin_renderer_base{
+    /**
+     * Returns html to display the gradeimporter feedbacks
+     * @param object $gradeimporter feedback with which is associated to the user
+     */
+    public function display_feedback($gradeimporter, $editing = false) {
+        global $DB;
+
+        $output = '';
+
+        if ($gradeimporter->intro && !editing) {
+            $output .= $this->output->box(format_module_intro('gradeimporter', $gradeimporter, $this->page->cm->id), 'generalbox', 'intro');
+        }
+    }
+}

+ 139 - 9
submission.php

@@ -1,14 +1,144 @@
 <?php
 
-require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
-require_once(dirname(__FILE__).'/locallib.php');
-require_once(dirname(__FILE__).'/comment_form.php');
+require_once('../../config.php');
+require_once('locallib.php');
+require_once('lib.php');
+require_once('submission_form.php');
 
-$id      = required_param('id', PARAM_INT);
-$delete  = optional_param('delete', 0, PARAM_INT);
-$confirm = optional_param('confirm', 0, PARAM_INT);
+echo "pagina submission";
 
-if (!$gradeimporter = $DB->get_record('gradeimporter', array('id' => $id))) {
+
+$cmid = required_param('cmid', PARAM_INT);            // Course Module ID
+$id      = required_param('id', PARAM_INT);           //Gradeimporter id
+//$delete  = optional_param('delete', 0, PARAM_INT);
+//$confirm = optional_param('confirm', 0, PARAM_INT);
+
+if (!$cm = get_coursemodule_from_id('gradeimporter', $cmid)){
+    print_error('invalidcoursemodule');
+}
+
+if (!$course = $DB->get_record('course', array('id'=>$cm->course))){
+    print_error('coursemisconf');
+}
+
+$context = context_module::instance($cm->id);
+
+require_capability('mod/gradeimporter:edit', $context);
+
+if (!$gradeimporter = $DB->get_record('gradeimporter', array('id'=>$cm->instance))){
+    print_error('invalidid', 'gradeimporter');
+}
+
+$url = new moodle_url('/mod/gradeimporter/submission.php', array('cmid'=>$cm->id));
+if(!empty($id)){
+    $url->param('id', $id);
+}
+$PAGE->set_url($url);
+
+require_login($course, false, $cm);
+
+//attempt to get the correct submission
+$model = $DB->get_record('gradeimporter_submission', array('gradeimporterid'=>$gradeimporter->$id));
+
+if($submission){
+    if (isguestuser()){
+        print_error('guestnoedit', 'gradeimporter', "$CFG->wwwroot/mod/gradeimporter/view.php?id=$cmid");
+    }
+} else{
+    $submission = new stdClass();
+    $model->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', 'submission', $submission->id));
+$submissionoptions = array('subdirs'=>false, 'maxfiles'=>$maxfiles, 'maxbytes'=>$maxbytes);
+
+$submission = file_prepare_standard_editor($submission, 'description', $descriptionoptions, $context, 'mod_gradeimporter', 'description', $submission->id);
+$submission = file_prepare_standard_filemanager($submission, 'submission', $submissionoptions, $context, 'mod_gradeimporter', 'submission', $submission->id);
+
+$submission->cmid = $cm->id;
+
+$mform = new mod_gradeimporter_submission_form(null, array('submission'=>$submission, 'cm'=>$cm, 'descriptionoptions'=>$descriptionoptions, 'submissionoptions'=>$submissionoptions));
+
+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 ($submission = $mform->get_data()){
+    $timenow = time();
+
+    if (empty($submission->id)) {
+        $submission->gradeimporterid    = $gradeimporter->id;
+        $submission->userid             = $USER->id;
+        $submission->timecreated        = $timenow;
+
+        $isnewentry                     = true;
+    } else {
+        $isnewentry                     = false;
+    }
+
+    $submission->description        = '';           //updated later
+    $submission->descriptionformat  = FORMAT_HTML;  //updated later
+    //$submission->definitiontrust  = 0             //n sei oq faz
+    $submission->timemodified       = $timenow;     
+
+    if ($isnewentry) {
+        //add new entry
+        $submission->id = $DB->insert_record('gradeimporter_submission', $submission);
+    } else {
+        //update existing entry
+        $DB->update_record('gradeimporter', $submission);
+    }
+
+    $submission = file_postupdate_standard_editor($model, 'description', $descriptionoptions, $context, 'mod_gradeimporter', 'description', $submission->id);
+    $submission = file_postupdate_standard_filemanager($submission, 'submission', $submissionoptions, $context, 'mod_gradeimporter', 'submission', $submission->id);
+
+    gradeimporter_check_for_zips($context, $cm, $submission);
+
+    //store updated values
+    $DB->update_record('gradeimporter_submission', $submission);
+
+    //refetch complete entry
+    $submission = $DB->get_record('gradeimporter_submission', array('id'=>$submission->id));
+
+    //trigger event and update completion (if entry was created)
+    $eventparams = array(
+        'context'=>context,
+        'objectid'=>$submission->id,
+        );
+    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("view.php?id=$cm->id&edition=1");
+}
+
+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();
+
+//codigo antigo
+/*if (!$gradeimporter = $DB->get_record('gradeimporter', array('id' => $id))) {
     print_error('invalidgradeimproterdid', 'gradeimporter');
 }
 
@@ -67,7 +197,7 @@ if ($mform-is_cancelled()) {
     $newsubmission->visibility = $formdata->visibility;
     
     if ($DB->insert_record('gradeimporter_submission', $newsubmission)) {
-        $params = array(
+        $params = array($cmid = required_param('cmid', PARAM_INT);            // Course Module ID
             'context' => $context,
             'other' => array(
                 'gradeimporterid' => $gradeimporter->id
@@ -85,4 +215,4 @@ echo $OUTPUT->header();
 
 $mform->display();
 
-echo $OUTPUT->footer();
+echo $OUTPUT->footer();*/

+ 1 - 1
version.php

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

+ 24 - 0
view.php

@@ -42,17 +42,41 @@
 
 
     /// Print the page header
+    $PAGE->set_cm($cm);
     $PAGE->set_url('/mod/gradeimporter/view.php', array('id' => $cm->id));
     $PAGE->set_title(format_string($gradeimporter->name));
     $PAGE->set_heading(format_string($course->fullname));
     $PAGE->set_context($context);
+    /*$button = '';
+    if (has_capability('mod/gradeimporter:edit', $context)) {
+      $urlparams = array('id'=>$id, 'page'=>$page, 'editing'=>$editing ? '0' : '1');
+      $url = new moodle_url('/mod/gradeimporter/view.php', $urlparams);
+      $strediting = get_string('turnediting'.($editing ? 'off' : 'on'));
+      $button = $OUTPUT->single_button($url, $strediting, 'get'). ' ';
+    }
+    $PAGE->set_button($button);*/
 /// Print the main part of the page
 
 $output = $PAGE->get_renderer('mod_folder');
 echo $output->header();
+
 $heading = get_string('displayingview', 'gradeimporter', $gradeimporter->name);
+
 echo $output->heading($heading);
 
+
+//button to add new submission
+if (has_capability('mod/gradeimporter:edit', $context)) {
+  $url = new moodle_url('/mod/gradeimporter/submission.php');
+  $newSubmission = '<form action="'. $url . '">'.
+          '<input type="hidden" name="id" value="'. $gradeimporter->id .'" />'.
+          '<input type="hidden" name="cmid" value="'.$cm->id.'" />'.
+          '<input type="hidden" name="page" value="0" />'.
+          '<input type="submit" Value="'.get_string('newsubmission', 'gradeimporter').'" />'.
+          '</form>';
+  echo $newSubmission;
+}
+
 //tabela com as notas vem aqui
 echo 'parte principal do importador de notas Z';