123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- <?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/>.
- // Adds gradeimporter to add new activity page
- function tool_devcourse_extend_navigation_course($navigation, $course, $coursecontext) {
- $url = new moodle_url('/admin/tool/devcourse/index.php');
- $devcoursenode = navigation_node::create('Development course', $url, navigation_node::TYPE_CUSTOM, 'Dev course', 'devcourse');
- $navigation->add_node($devcoursenode);
- }
- function gradeimporter_supports($feature) {
- switch ($feature) {
- 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;
- case FEATURE_GRADE_HAS_GRADE:
- return true;
- case FEATURE_GRADE_OUTCOMES:
- return true;
- default:
- return null;
- }
- }
- function gradeimporter_add_instance($data, $mform) {
- /*
- *Given an object containing all the necessary data,
- *(defined by the form in mod_form.php) this function
- *creates a new instance and returns the id of this new
- *instance.
- *
- *@param $data: an object from the form in mod_form.php
- *@return int: the id of the newly inserted gradeimport record
- */
- global $DB;
- $data->timemodified = time();
- $data->id = $DB->insert_record("gradeimporter", $data);
- return $data->id;
- }
- function gradeimporter_update_instance($data) {
- /*
- *given an object containing all the necessary data,
- *(defined by the form in mod_form.php) this function
- *updates an existing instance with the new data.
- *
- *@param $data: an object from the form mod_form.php
- *@return boolean: if the record update was a success of fail
- */
- global $DB;
- $data->timemodified = time();
- $data->id = $data->instance;
- return $DB->update_record('gradeimporter', $data);
- }
- function gradeimporter_delete_instance($data) {
- /*
- *Given an id of a gradeimporter instance,
- * this function permanently deletes the instance
- * and any data that depends on it.
- *
- *@param int $id: Id of the gradeimporter instance
- *@return boolean, if the deletion was a success or
- * a failure.
- */
- global $DB;
- if (!$data = $DB->get_record('gradeimporter', array('id' => $id))) {
- 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, 'submissionfiles');
- // 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));
- $DB->delete_records('gradeimporter_submissiontype', array('gradeimporterid' => $gradeimporter->id));
- // Delete the instance itself
- $DB->delete_records('gradeimporter', array('id' => $id));
- return true;
- }
- /**
- * Implementation of pluginfile function to get file from a pluginfile url
- */
- function mod_gradeimporter_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) {
- // Check the contextlevel is as expected - if your plugin is a block, this becomes CONTEXT_BLOCK, etc.
- if ($context->contextlevel != CONTEXT_MODULE) {
- return false;
- }
- // Make sure the filearea is one of those used by the plugin.
- if ($filearea !== 'submissionfiles') {
- return false;
- }
- // Make sure the user is logged in and has access to the module
- // (plugins that are not course modules should leave out the 'cm' part).
- require_login($course, true, $cm);
- // Check the relevant capabilities - these may vary depending on the filearea being accessed.
- if (!has_capability('mod/gradeimporter:view', $context)) {
- return false;
- }
- // Leave this line out if you set the itemid to null in make_pluginfile_url (set $itemid to 0 instead).
- $itemid = array_shift($args); // The first item in the $args array.
- // Use the itemid to retrieve any relevant data records and perform any security checks to see if the
- // user really does have access to the file in question.
- // Extract the filename / filepath from the $args array.
- $filename = array_pop($args); // The last item in the $args array.
- if (!$args) {
- $filepath = '/'; // If $args is empty => the path is '/'
- } else {
- $filepath = '/'.implode('/', $args).'/'; // If $args contains elements of the filepath
- }
- // Retrieve the file from the Files API.
- $fs = get_file_storage();
- $file = $fs->get_file($context->id, 'mod_gradeimporter', $filearea, $itemid, $filepath, $filename);
- if (!$file) {
- echo "didnt find the file";
- return false; // The file does not exist.
- }
- // We can now send the file back to the browser - in this case with a cache lifetime of 1 day and no filtering.
- send_stored_file($file, 86400, 0, $forcedownload, $options);
- }
- function gradeimporter_grade_item_update ($submission, $grades = null) {
- global $CFG, $COURSE;
- require_once("{$CFG->libdir}/gradelib.php");
- $params = array('itemname' => $submission->name, 'idnumber' => $submission->cmid);
- if ($submission->gradebook == 0) {
- $params['gradetype'] = GRADE_TYPE_NONE;
- } else {
- $params['gradetype'] = GRADE_TYPE_VALUE;
- $params['grademax'] = 10;
- $params['grademin'] = 0;
- }
- if ($grades == 'reset') {
- $params['reset'] == true;
- $grades = null;
- }
- return grade_update('mod/gradeimporter', $COURSE->id, 'mod', 'gradeimporter', $submission->gradeimporterid, 0, $grades, $params);
- }
- function gradeimporter_update_grades ($submission, $userid = 0, $nullifnone = true) {
- global $CFG, $DB, $COURSE;
- require_once("{$CFG->libdir}/gradelib.php");
- if ($submission->gradebook == 0) {
- gradeimporter_grade_item_update($submission);
- return;
- }
- // If submission is gradeable (gradebook==1) then tries to submit the grades
- if ($grades = gradeimporter_get_user_grades($submission, $userid)) {
- // Gets student grade from gradeimporter_feedback table
- gradeimporter_grade_item_update($submission, $grades);
- } else 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);
- }
- }
- function gradeimporter_reset_gradebook ($courseid, $type = '') {
- global $CFG, $DB;
- // Select all grades on gradebook and reset them
- }
- function gradeimporter_get_user_grades($submission, $userid) {
- global $DB;
- $grade = new stdClass();
- $grade->userid = $userid;
- $feedback = $DB->get_record('gradeimporter_feedback',
- ['submissionid' => $submission->id, 'studendit' => $userid],
- ['grade']
- );
- if ($feedback) {
- $grade->rawgrade = $feedback->grade;
- return $grade;
- }
- return null;
- }
|