Prechádzať zdrojové kódy

created submission creation view

bernardo 5 rokov pred
rodič
commit
2cd521a188

+ 67 - 0
classes/event/gradeimporter_submission_created.php

@@ -0,0 +1,67 @@
+<?php
+
+namespace mod_gradeimporter\event;
+
+defined('MOODLE_INTERNAL') || die();
+
+class gradeimporter_submission_created extends \core\event\base {
+    
+    protected function init() {
+        $this->data['crud'] = 'c';
+        $this->data['edulevel'] = self::LEVEL_PARTICIPATING;
+    }
+
+    /**
+    *Returns the description of what happened
+    *
+    *@return string
+    */ 
+    public function get_description(){
+        return "The user with id '$this->userid' has created a submission " . 
+                "on the grade importer with the course module id '$this->contextinstanceid'."  
+    }
+
+    /**
+     * Returns localised event name
+     * 
+     * @return string
+     */
+    public static function get_name(){
+        return get_string('eventmodelsubmissioncreated', 'mod_gradeimporter');
+    }
+
+    /**
+     * Get URL related to the action
+     * 
+     * @return \moodle_url
+     */
+    public function get_url(){
+        $url = new \moodle_url('/mod/gradeimporter/view.php', array('id' => $this->contextinstanceid));
+        return $url;
+    }
+
+    /**
+     * Return the legacy event log data.
+     * 
+     * @return array|null
+     */
+    protected function get_legacy_logdata(){
+        //the legacy log table expects a relative path to /mod/model/
+        $logurl = new \moodle_url('/mod/gradeimporter/view.php', array('id' => $this->contextinstanceid));
+        return array($this->courseid, 'gradeimporter', 'editgradeimporter', $logurl, 
+                        $this->other['gradeimporterid'], $this->gradeimporterid);
+    }
+
+    /**
+     * Custom validation
+     * 
+     * @throws \coding_exception
+     * @return void
+     */
+    protected function validate_data(){
+        parent::validate_data();
+        if ($this->contextlevel != CONTEXT_MODULE) {
+            throw new \coding_exception('Context level must be CONTEXT_MODULE');
+        }
+    }
+}

+ 16 - 1
db/access.php

@@ -19,6 +19,21 @@
                 'teacher' => CAP_ALLOW,
                 'editingteacher' => CAP_ALLOW,
                 'manager' => CAP_ALLOW
-            )
+                )
+            ),
+        'mod/gradeimporter:addsubmission' => array(
+                'captype' => 'write',
+                'contextlevel' => CONTEXT_MODULE,
+                'archetypes' => array(
+                    'editingteacher' => CAP_ALLOW
+                )
+            ),
+        'mod/gradeimporter:edit' => array(
+                    'captype' => 'write',
+                    'contextlevel' => CONTEXT_MODULE,
+                    'archetypes' => array(
+                        'editingteacher' => CAP_ALLOW,
+                        'manager' => CAP_ALLOW
+                    )
         )
 );

+ 10 - 2
lang/en/gradeimporter.php

@@ -9,6 +9,10 @@ $string['gradeimportername'] = 'Grade Importer Name';
 $string['pluginadministration'] ='plugin administration string';
 $string['displayingview'] = 'Posted Grades';
 
+//submission.oho
+$string['invalidgradeimporterid'] = 'Invalid Grade Importer ID';
+$string['submissionadded'] = "Submission added to DB";
+
 //formStrings
 
     //Generic 
@@ -38,7 +42,11 @@ $string['displayingview'] = 'Posted Grades';
 
 
     //submission form help buttons
-    $string['helpsubmissionfiles'] = 'Must be only one file, either a .zip or a .csv'
+    $string['helpsubmissionfiles'] = 'Must be only one file, either a .zip or a .csv';
     $string['helpcsvdelimiter'] = 'CSV delimiter of the config.csv file';
 
-    //submission form errors
+    //submission form errors
+
+
+//events string
+    $string['eventmodelsubmissioncreated'] = 'Submission created';

+ 12 - 0
lib.php

@@ -68,6 +68,18 @@ function gradeimporter_delete_instance($data){
         return false;
     }
 
+    $cm = get_coursemodule_from_instance('gradeimporter', $gradeimporter->id);
+
+    $context = context_module::instance($cm->id);
+    // Files
+    $fs = get_file_storage();
+    $fs->delete_area_files($context->id, 'mod_gradeimporter');
+    
+    //delete all files and submissions associated with this instance
+    $DB->delete_records('gradeimporter_submission', array('gradeimporterid' => $gradeimporter->id));
+    $DB->delete_records('gradeimporter_feedback', array('gradeimporterid' => $gradeimporter->id));
+
+    //delete the instance itself
     $DB->delete_records('gradeimporter', array('id'=>$id) );
     return true;
 }

+ 18 - 2
mod_form.php

@@ -9,7 +9,7 @@
     class mod_gradeimporter_mod_form extends moodleform_mod {
 
         function definition() {
-            global $CFG, $DB;
+            global $CFG, $COURSE, $USER, $DB, $OUTPUT;
 
             $mform =& $this->_form;
             $course_modules_id = optional_param('update', 0, PARAM_INT);
@@ -30,8 +30,22 @@
             $features = array('groups' => false, 'groupings' => false, 'groupmembersonly' => false,  'outcomes' => false,'gradecat' => false, 'idnumber' => false);
             $this->standard_coursemodule_elements($features);
             
+            //hidden fields
+            $mform->addElement('hidden', 'action');
+            $mform->setType('action', PARAM_TEXT);
+            $mform->addElement('hidden', 'id');
+            $mform->setType('id', PARAM_TEXT);
+            $mform->addElement('hidden', 'iassign_id');
+            $mform->setType('iassign_id', PARAM_TEXT);
+            $mform->addElement('hidden', 'author_name');
+            $mform->setType('author_name', PARAM_TEXT);
+            $mform->addElement('hidden', 'author_modified_name');
+            $mform->setType('author_modified_name', PARAM_TEXT);
+            $mform->addElement('hidden', 'timecreated');
+            $mform->setType('timecreated', PARAM_TEXT);
+            $mform->addElement('hidden', 'position');
+            $mform->setType('position', PARAM_TEXT);
 
-            
             $this->add_action_buttons();
             }
 
@@ -83,4 +97,6 @@
                 }
                 }
             }*/
+
+            
     }

+ 88 - 0
submission.php

@@ -0,0 +1,88 @@
+<?php
+
+require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
+require_once(dirname(__FILE__).'/locallib.php');
+require_once(dirname(__FILE__).'/comment_form.php');
+
+$id      = required_param('id', PARAM_INT);
+$delete  = optional_param('delete', 0, PARAM_INT);
+$confirm = optional_param('confirm', 0, PARAM_INT);
+
+if (!$gradeimporter = $DB->get_record('gradeimporter', array('id' => $id))) {
+    print_error('invalidgradeimproterdid', 'gradeimporter');
+}
+
+list($course, $cm) = get_course_and_cm_from_instance($gradeimporter, 'gradeimporter');
+
+if ($delete && ! $submission = $DB->get_record('gradeimporter_sumbmission', array('gradeimporterid' => $gradeimporter->id, 'id' => $delete))) {
+    print_error('Invalid comment ID');
+}
+
+require_login($course, true, $cm);
+
+$PAGE->set_cm($cm);
+$PAGE->set_url('/mod/gradeimporter/view.php', array('id' => $id));
+$PAGE->set_title($gradeimporter->name);
+$page->set_heading($course->shortname);
+
+$context = context_module::instance($cm->id);
+
+$gradeimporterurl = $CFG->wwwroot.'mod/gradeimporter/view.php?id='.$cm->id;
+
+if ($delete && has_capability('mod/wavefront:edit', $context)) {
+    if($confirm && confirm_sesskey()) {
+        $DB->delete_records('gradeimporter_submission', array('id' => $comment->id));
+        redirect($gradeimporterurl);
+    } else {
+        echo $OUTPUT->header();
+        $paramyes = array('id' => $gradeimporter->id, 'delete' => $gradeimporter->id, 'sesskey' => sesskey(), 'confirm' => 1);
+        $paramsno = array('id' => $cm->id);
+        echo $OUTPUT->confirm(get_string('submissiondelete', 'gradeimporter'),
+                                new moodle_url('/mod/gradeimporter/submission.php', $paramsyes),
+                                new moodle_url('/mod/gradeimporter/view.php', $paramsno));
+        echo $OUTPUT->footer();
+        die();
+    }
+}
+
+require_capability('mod/gradeimporter/addsubmission', $context);
+
+if(!$gradeimporter->submission) {
+    print_error('Submissions disabled', $gradeimporterurl);
+}
+
+$mform = new mod_gradeimporter_submission_form(null, $gradeimporter);
+
+if ($mform-is_cancelled()) {
+    redirect($gradeimporterurl);
+} else if ($formdata = $mform->get_data()) {
+    $newsubmission = new stdClass;
+    $newsubmission->gradeimporter = $gradeimporter->id;
+    $newsubmission->type = $formdata->type;
+    $newsubmission->timemodified = time();
+    $newsubmission->usermodified = $USER->id;
+    //$newsubmission->name = $formdata->name;
+    //$newsubmission->info = $formdata->info;
+    $newsubmission->position = $formdata->position;
+    $newsubmission->visibility = $formdata->visibility;
+    
+    if ($DB->insert_record('gradeimporter_submission', $newsubmission)) {
+        $params = array(
+            'context' => $context,
+            'other' => array(
+                'gradeimporterid' => $gradeimporter->id
+            )
+        );
+        $event = \mod_gradeimporter\event\gradeimporter_submission_created::create($params);
+        $event->trigger();
+        redirect($gradeimporterurl, get_string('submission added', 'gradeimporter'));
+    } else {
+        print_error('gradeimporter creation failed');
+    }
+}
+
+echo $OUTPUT->header();
+
+$mform->display();
+
+echo $OUTPUT->footer();

+ 6 - 4
submission_form.php

@@ -12,6 +12,7 @@
             global $CFG, $DB, $OUTPUT;
 
             $mform =& $this->_form;
+            $gradeimporter = $this->_customdata;
 
             $mform->addElement('text', 'name', get_string('name', 'gradeimporter'), array('size'=>'64'));
             $mform->setType('name', PARAM_TEXT);
@@ -24,18 +25,19 @@
                                 'accepted_types' => array('*'),  'return_types' => FILE_INTERNAL | FILE_EXTERNAL)); 
                                                                 //restrict accepted types to compacted?
             $mform->addHelpButton('submissionFiles', 'helpsubmissionfiles', 'gradeimporter');
+            
             //csv delimiter
 
-           /* $csv_delimiter = array();
+            $csv_delimiter = array();
             $csv_delimiter[1] = ',';
-            $csv_delimiter[2] = ';';
+            /*$csv_delimiter[2] = ';';
             $csv_delimiter[3] = ':';
             $csv_delimiter[4] = '\t';
-        
+*/        
             $mform->addElement('select', 'csv_delimiter', get_string('choose_type_activity', 'iassign'), $csv_delimiter, array('onChange' => 'config_type(this.value);'));
             $mform->setDefault('csv_delimiter', 1); // default csv_delimiter = 3
             $mform->addHelpButton('csv_delimiter', 'helpcsvdelimiter', 'gradeimporter');
-*/
+
             //submissionType