2010-01-04 17:34:08 +00:00
|
|
|
<?php
|
2010-01-04 17:47:09 +00:00
|
|
|
|
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
2010-01-04 17:34:08 +00:00
|
|
|
// 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.
|
2010-01-04 17:47:09 +00:00
|
|
|
//
|
2010-01-04 17:34:08 +00:00
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
2010-01-04 17:47:09 +00:00
|
|
|
|
2010-01-04 17:34:08 +00:00
|
|
|
/**
|
2010-01-04 18:23:52 +00:00
|
|
|
* Library of functions needed by Moodle core and other subsystems
|
2010-01-04 17:34:08 +00:00
|
|
|
*
|
2010-01-04 18:23:52 +00:00
|
|
|
* All the functions neeeded by Moodle core, gradebook, file subsystem etc
|
|
|
|
* are placed here.
|
2010-01-04 17:34:08 +00:00
|
|
|
*
|
|
|
|
* @package mod-workshop
|
|
|
|
* @copyright 2009 David Mudrak <david.mudrak@gmail.com>
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
2010-01-04 17:42:27 +00:00
|
|
|
defined('MOODLE_INTERNAL') || die();
|
2010-01-04 17:34:08 +00:00
|
|
|
|
2010-01-04 18:23:52 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Moodle core API //
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-01-04 18:00:54 +00:00
|
|
|
/**
|
|
|
|
* Returns the information if the module supports a feature
|
|
|
|
*
|
|
|
|
* @see plugin_supports() in lib/moodlelib.php
|
|
|
|
* @param string $feature FEATURE_xx constant for requested feature
|
|
|
|
* @return mixed true if the feature is supported, null if unknown
|
|
|
|
*/
|
|
|
|
function workshop_supports($feature) {
|
|
|
|
switch($feature) {
|
|
|
|
case FEATURE_GRADE_HAS_GRADE: return true;
|
|
|
|
case FEATURE_GROUPS: return true;
|
|
|
|
case FEATURE_GROUPINGS: return true;
|
|
|
|
case FEATURE_GROUPMEMBERSONLY: return true;
|
|
|
|
case FEATURE_MOD_INTRO: return true;
|
|
|
|
default: return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-04 17:46:05 +00:00
|
|
|
/**
|
2010-01-04 17:49:01 +00:00
|
|
|
* Saves a new instance of the workshop into the database
|
2010-01-04 17:46:05 +00:00
|
|
|
*
|
2010-01-04 17:34:08 +00:00
|
|
|
* Given an object containing all the necessary data,
|
|
|
|
* (defined by the form in mod_form.php) this function
|
2010-01-04 17:49:01 +00:00
|
|
|
* will save a new instance and return the id number
|
2010-01-04 17:34:08 +00:00
|
|
|
* of the new instance.
|
|
|
|
*
|
2010-01-04 18:30:57 +00:00
|
|
|
* @param stdclass $workshop An object from the form in mod_form.php
|
2010-01-04 17:34:08 +00:00
|
|
|
* @return int The id of the newly inserted workshop record
|
|
|
|
*/
|
2010-01-04 18:30:57 +00:00
|
|
|
function workshop_add_instance(stdclass $workshop) {
|
2010-01-04 18:01:29 +00:00
|
|
|
global $CFG, $DB;
|
|
|
|
require_once(dirname(__FILE__) . '/locallib.php');
|
2010-01-04 17:34:08 +00:00
|
|
|
|
2010-01-04 18:27:07 +00:00
|
|
|
$workshop->phase = workshop::PHASE_SETUP;
|
|
|
|
$workshop->timecreated = time();
|
|
|
|
$workshop->timemodified = $workshop->timecreated;
|
|
|
|
$workshop->useexamples = (int)!empty($workshop->useexamples); // unticked checkbox hack
|
|
|
|
$workshop->usepeerassessment = (int)!empty($workshop->usepeerassessment); // unticked checkbox hack
|
|
|
|
$workshop->useselfassessment = (int)!empty($workshop->useselfassessment); // unticked checkbox hack
|
|
|
|
$workshop->latesubmissions = (int)!empty($workshop->latesubmissions); // unticked checkbox hack
|
2010-07-07 21:46:05 +00:00
|
|
|
$workshop->evaluation = 'best';
|
2010-01-04 17:49:01 +00:00
|
|
|
|
2010-01-04 18:02:27 +00:00
|
|
|
// insert the new record so we get the id
|
2010-01-04 18:23:52 +00:00
|
|
|
$workshop->id = $DB->insert_record('workshop', $workshop);
|
2010-01-04 18:02:27 +00:00
|
|
|
|
|
|
|
// we need to use context now, so we need to make sure all needed info is already in db
|
2010-01-04 18:23:52 +00:00
|
|
|
$cmid = $workshop->coursemodule;
|
|
|
|
$DB->set_field('course_modules', 'instance', $workshop->id, array('id' => $cmid));
|
2010-01-04 18:02:27 +00:00
|
|
|
$context = get_context_instance(CONTEXT_MODULE, $cmid);
|
|
|
|
|
|
|
|
// process the custom wysiwyg editors
|
2010-01-04 18:23:52 +00:00
|
|
|
if ($draftitemid = $workshop->instructauthorseditor['itemid']) {
|
2010-07-03 13:37:13 +00:00
|
|
|
$workshop->instructauthors = file_save_draft_area_files($draftitemid, $context->id, 'mod_workshop', 'instructauthors',
|
2010-01-04 18:23:52 +00:00
|
|
|
0, workshop::instruction_editors_options($context), $workshop->instructauthorseditor['text']);
|
|
|
|
$workshop->instructauthorsformat = $workshop->instructauthorseditor['format'];
|
2010-01-04 18:02:27 +00:00
|
|
|
}
|
|
|
|
|
2010-01-04 18:23:52 +00:00
|
|
|
if ($draftitemid = $workshop->instructreviewerseditor['itemid']) {
|
2010-07-03 13:37:13 +00:00
|
|
|
$workshop->instructreviewers = file_save_draft_area_files($draftitemid, $context->id, 'mod_workshop', 'instructreviewers',
|
2010-01-04 18:23:52 +00:00
|
|
|
0, workshop::instruction_editors_options($context), $workshop->instructreviewerseditor['text']);
|
|
|
|
$workshop->instructreviewersformat = $workshop->instructreviewerseditor['format'];
|
2010-01-04 18:07:17 +00:00
|
|
|
}
|
|
|
|
|
2010-01-04 18:02:27 +00:00
|
|
|
// re-save the record with the replaced URLs in editor fields
|
2010-01-04 18:23:52 +00:00
|
|
|
$DB->update_record('workshop', $workshop);
|
2010-01-04 18:02:27 +00:00
|
|
|
|
2010-01-04 18:23:52 +00:00
|
|
|
// update gradebook item
|
|
|
|
workshop_grade_item_update($workshop);
|
|
|
|
|
|
|
|
return $workshop->id;
|
2010-01-04 17:49:01 +00:00
|
|
|
}
|
2010-01-04 17:47:43 +00:00
|
|
|
|
2010-01-04 17:34:08 +00:00
|
|
|
/**
|
|
|
|
* Given an object containing all the necessary data,
|
|
|
|
* (defined by the form in mod_form.php) this function
|
|
|
|
* will update an existing instance with new data.
|
|
|
|
*
|
2010-01-04 18:30:57 +00:00
|
|
|
* @param stdclass $workshop An object from the form in mod_form.php
|
2010-01-04 18:02:27 +00:00
|
|
|
* @return bool success
|
2010-01-04 17:34:08 +00:00
|
|
|
*/
|
2010-01-04 18:30:57 +00:00
|
|
|
function workshop_update_instance(stdclass $workshop) {
|
2010-01-04 18:02:27 +00:00
|
|
|
global $CFG, $DB;
|
|
|
|
require_once(dirname(__FILE__) . '/locallib.php');
|
|
|
|
|
2010-01-04 18:27:07 +00:00
|
|
|
$workshop->timemodified = time();
|
|
|
|
$workshop->id = $workshop->instance;
|
|
|
|
$workshop->useexamples = (int)!empty($workshop->useexamples); // unticked checkbox hack
|
|
|
|
$workshop->usepeerassessment = (int)!empty($workshop->usepeerassessment); // unticked checkbox hack
|
|
|
|
$workshop->useselfassessment = (int)!empty($workshop->useselfassessment); // unticked checkbox hack
|
|
|
|
$workshop->latesubmissions = (int)!empty($workshop->latesubmissions); // unticked checkbox hack
|
2010-07-07 21:46:05 +00:00
|
|
|
$workshop->evaluation = 'best';
|
2010-01-04 17:34:08 +00:00
|
|
|
|
2010-01-04 18:05:48 +00:00
|
|
|
// todo - if the grading strategy is being changed, we must replace all aggregated peer grades with nulls
|
|
|
|
// todo - if maximum grades are being changed, we should probably recalculate or invalidate them
|
|
|
|
|
2010-01-04 18:23:52 +00:00
|
|
|
$DB->update_record('workshop', $workshop);
|
|
|
|
$context = get_context_instance(CONTEXT_MODULE, $workshop->coursemodule);
|
2010-01-04 17:34:08 +00:00
|
|
|
|
2010-01-04 18:02:27 +00:00
|
|
|
// process the custom wysiwyg editors
|
2010-01-04 18:23:52 +00:00
|
|
|
if ($draftitemid = $workshop->instructauthorseditor['itemid']) {
|
2010-07-03 13:37:13 +00:00
|
|
|
$workshop->instructauthors = file_save_draft_area_files($draftitemid, $context->id, 'mod_workshop', 'instructauthors',
|
2010-01-04 18:23:52 +00:00
|
|
|
0, workshop::instruction_editors_options($context), $workshop->instructauthorseditor['text']);
|
|
|
|
$workshop->instructauthorsformat = $workshop->instructauthorseditor['format'];
|
2010-01-04 18:02:27 +00:00
|
|
|
}
|
|
|
|
|
2010-01-04 18:23:52 +00:00
|
|
|
if ($draftitemid = $workshop->instructreviewerseditor['itemid']) {
|
2010-07-03 13:37:13 +00:00
|
|
|
$workshop->instructreviewers = file_save_draft_area_files($draftitemid, $context->id, 'mod_workshop', 'instructreviewers',
|
2010-01-04 18:23:52 +00:00
|
|
|
0, workshop::instruction_editors_options($context), $workshop->instructreviewerseditor['text']);
|
|
|
|
$workshop->instructreviewersformat = $workshop->instructreviewerseditor['format'];
|
2010-01-04 18:07:17 +00:00
|
|
|
}
|
|
|
|
|
2010-01-04 18:02:27 +00:00
|
|
|
// re-save the record with the replaced URLs in editor fields
|
2010-01-04 18:23:52 +00:00
|
|
|
$DB->update_record('workshop', $workshop);
|
|
|
|
|
|
|
|
// update gradebook item
|
|
|
|
workshop_grade_item_update($workshop);
|
|
|
|
|
|
|
|
return true;
|
2010-01-04 17:34:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given an ID of an instance of this module,
|
|
|
|
* this function will permanently delete the instance
|
|
|
|
* and any data that depends on it.
|
|
|
|
*
|
|
|
|
* @param int $id Id of the module instance
|
|
|
|
* @return boolean Success/Failure
|
|
|
|
*/
|
|
|
|
function workshop_delete_instance($id) {
|
2010-01-04 18:25:03 +00:00
|
|
|
global $CFG, $DB;
|
|
|
|
require_once($CFG->libdir.'/gradelib.php');
|
|
|
|
|
2010-01-04 17:34:08 +00:00
|
|
|
|
|
|
|
if (! $workshop = $DB->get_record('workshop', array('id' => $id))) {
|
|
|
|
return false;
|
|
|
|
}
|
2010-01-04 18:12:12 +00:00
|
|
|
// delete all associated aggregations
|
|
|
|
$DB->delete_records('workshop_aggregations', array('workshopid' => $workshop->id));
|
|
|
|
// get the list of ids of all submissions
|
|
|
|
$submissions = $DB->get_records('workshop_submissions', array('workshopid' => $workshop->id), '', 'id');
|
|
|
|
// get the list of all allocated assessments
|
|
|
|
$assessments = $DB->get_records_list('workshop_assessments', 'submissionid', array_keys($submissions), '', 'id');
|
|
|
|
// delete the associated records from the workshop core tables
|
|
|
|
$DB->delete_records_list('workshop_grades', 'assessmentid', array_keys($assessments));
|
|
|
|
$DB->delete_records_list('workshop_assessments', 'id', array_keys($assessments));
|
|
|
|
$DB->delete_records_list('workshop_submissions', 'id', array_keys($submissions));
|
|
|
|
// todo call the static clean-up methods of all available subplugins
|
|
|
|
// ...
|
|
|
|
// finally remove the workshop record itself
|
|
|
|
$DB->delete_records('workshop', array('id' => $workshop->id));
|
2010-01-04 17:34:08 +00:00
|
|
|
|
2010-01-04 18:23:52 +00:00
|
|
|
// gradebook cleanup
|
|
|
|
grade_update('mod/workshop', $workshop->course, 'mod', 'workshop', $workshop->id, 0, null, array('deleted' => true));
|
|
|
|
grade_update('mod/workshop', $workshop->course, 'mod', 'workshop', $workshop->id, 1, null, array('deleted' => true));
|
|
|
|
|
2010-01-04 18:12:12 +00:00
|
|
|
return true;
|
2010-01-04 17:34:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a small object with summary information about what a
|
|
|
|
* user has done with a given particular instance of this module
|
|
|
|
* Used for user activity reports.
|
|
|
|
* $return->time = the time they did it
|
|
|
|
* $return->info = a short text description
|
|
|
|
*
|
|
|
|
* @return null
|
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
|
|
|
function workshop_user_outline($course, $user, $mod, $workshop) {
|
2010-01-04 18:30:57 +00:00
|
|
|
$return = new stdclass();
|
2010-01-04 17:34:08 +00:00
|
|
|
$return->time = 0;
|
|
|
|
$return->info = '';
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Print a detailed representation of what a user has done with
|
|
|
|
* a given particular instance of this module, for user activity reports.
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
|
|
|
function workshop_user_complete($course, $user, $mod, $workshop) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a course and a time, this module should find recent activity
|
|
|
|
* that has occurred in workshop activities and print it out.
|
|
|
|
* Return true if there was output, or false is there was none.
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
* @todo Finish documenting this function
|
|
|
|
*/
|
|
|
|
function workshop_print_recent_activity($course, $isteacher, $timestart) {
|
|
|
|
return false; // True if anything was printed, otherwise false
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to be run periodically according to the moodle cron
|
|
|
|
* This function searches for things that need to be done, such
|
|
|
|
* as sending out mail, toggling flags etc ...
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
* @todo Finish documenting this function
|
|
|
|
**/
|
|
|
|
function workshop_cron () {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Must return an array of user records (all data) who are participants
|
|
|
|
* for a given instance of workshop. Must include every user involved
|
|
|
|
* in the instance, independient of his role (student, teacher, admin...)
|
|
|
|
* See other modules as example.
|
|
|
|
*
|
|
|
|
* @param int $workshopid ID of an instance of this module
|
|
|
|
* @return mixed boolean/array of students
|
|
|
|
*/
|
|
|
|
function workshop_get_participants($workshopid) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-06-01 14:55:33 +00:00
|
|
|
* Is a given scale used by the instance of workshop?
|
2010-01-04 17:34:08 +00:00
|
|
|
*
|
2010-06-01 14:55:33 +00:00
|
|
|
* The function asks all installed grading strategy subplugins. The workshop
|
|
|
|
* core itself does not use scales. Both grade for submission and grade for
|
|
|
|
* assessments do not use scales.
|
|
|
|
*
|
|
|
|
* @param int $workshopid id of workshop instance
|
|
|
|
* @param int $scaleid id of the scale to check
|
|
|
|
* @return bool
|
2010-01-04 17:34:08 +00:00
|
|
|
*/
|
|
|
|
function workshop_scale_used($workshopid, $scaleid) {
|
2010-06-01 14:55:33 +00:00
|
|
|
global $CFG; // other files included from here
|
|
|
|
|
|
|
|
$strategies = get_plugin_list('workshopform');
|
|
|
|
foreach ($strategies as $strategy => $strategypath) {
|
|
|
|
$strategylib = $strategypath . '/lib.php';
|
|
|
|
if (is_readable($strategylib)) {
|
|
|
|
require_once($strategylib);
|
|
|
|
} else {
|
|
|
|
throw new coding_exception('the grading forms subplugin must contain library ' . $strategylib);
|
|
|
|
}
|
|
|
|
$classname = 'workshop_' . $strategy . '_strategy';
|
|
|
|
if (method_exists($classname, 'scale_used')) {
|
|
|
|
if (call_user_func_array(array($classname, 'scale_used'), array($scaleid, $workshopid))) {
|
|
|
|
// no need to include any other files - scale is used
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-01-04 17:34:08 +00:00
|
|
|
|
2010-06-01 14:55:33 +00:00
|
|
|
return false;
|
2010-01-04 17:34:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-06-01 14:55:33 +00:00
|
|
|
* Is a given scale used by any instance of workshop?
|
|
|
|
*
|
|
|
|
* The function asks all installed grading strategy subplugins. The workshop
|
|
|
|
* core itself does not use scales. Both grade for submission and grade for
|
|
|
|
* assessments do not use scales.
|
2010-01-04 17:34:08 +00:00
|
|
|
*
|
2010-06-01 14:55:33 +00:00
|
|
|
* @param int $scaleid id of the scale to check
|
|
|
|
* @return bool
|
2010-01-04 17:34:08 +00:00
|
|
|
*/
|
|
|
|
function workshop_scale_used_anywhere($scaleid) {
|
2010-06-01 14:55:33 +00:00
|
|
|
global $CFG; // other files included from here
|
|
|
|
|
|
|
|
$strategies = get_plugin_list('workshopform');
|
|
|
|
foreach ($strategies as $strategy => $strategypath) {
|
|
|
|
$strategylib = $strategypath . '/lib.php';
|
|
|
|
if (is_readable($strategylib)) {
|
|
|
|
require_once($strategylib);
|
|
|
|
} else {
|
|
|
|
throw new coding_exception('the grading forms subplugin must contain library ' . $strategylib);
|
|
|
|
}
|
|
|
|
$classname = 'workshop_' . $strategy . '_strategy';
|
|
|
|
if (method_exists($classname, 'scale_used')) {
|
|
|
|
if (call_user_func(array($classname, 'scale_used'), $scaleid)) {
|
|
|
|
// no need to include any other files - scale is used
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2010-01-04 17:34:08 +00:00
|
|
|
}
|
2010-06-01 14:55:33 +00:00
|
|
|
|
|
|
|
return false;
|
2010-01-04 17:34:08 +00:00
|
|
|
}
|
|
|
|
|
2010-01-04 17:48:20 +00:00
|
|
|
/**
|
|
|
|
* Returns all other caps used in the module
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
function workshop_get_extra_capabilities() {
|
|
|
|
return array('moodle/site:accessallgroups');
|
|
|
|
}
|
|
|
|
|
2010-01-04 18:23:52 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Gradebook API //
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates or updates grade items for the give workshop instance
|
|
|
|
*
|
|
|
|
* Needed by grade_update_mod_grades() in lib/gradelib.php. Also used by
|
|
|
|
* {@link workshop_update_grades()}.
|
|
|
|
*
|
2010-01-04 18:30:57 +00:00
|
|
|
* @param stdclass $workshop instance object with extra cmidnumber and modname property
|
|
|
|
* @param stdclass $submissiongrades data for the first grade item
|
|
|
|
* @param stdclass $assessmentgrades data for the second grade item
|
2010-01-04 18:23:52 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-01-04 18:30:57 +00:00
|
|
|
function workshop_grade_item_update(stdclass $workshop, $submissiongrades=null, $assessmentgrades=null) {
|
2010-01-04 18:23:52 +00:00
|
|
|
global $CFG;
|
|
|
|
require_once($CFG->libdir.'/gradelib.php');
|
|
|
|
|
2010-01-04 18:30:57 +00:00
|
|
|
$a = new stdclass();
|
2010-01-04 18:23:52 +00:00
|
|
|
$a->workshopname = clean_param($workshop->name, PARAM_NOTAGS);
|
|
|
|
|
|
|
|
$item = array();
|
|
|
|
$item['itemname'] = get_string('gradeitemsubmission', 'workshop', $a);
|
|
|
|
$item['gradetype'] = GRADE_TYPE_VALUE;
|
|
|
|
$item['grademax'] = $workshop->grade;
|
|
|
|
$item['grademin'] = 0;
|
|
|
|
grade_update('mod/workshop', $workshop->course, 'mod', 'workshop', $workshop->id, 0, $submissiongrades , $item);
|
|
|
|
|
|
|
|
$item = array();
|
|
|
|
$item['itemname'] = get_string('gradeitemassessment', 'workshop', $a);
|
|
|
|
$item['gradetype'] = GRADE_TYPE_VALUE;
|
|
|
|
$item['grademax'] = $workshop->gradinggrade;
|
|
|
|
$item['grademin'] = 0;
|
|
|
|
grade_update('mod/workshop', $workshop->course, 'mod', 'workshop', $workshop->id, 1, $assessmentgrades, $item);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update workshop grades in the gradebook
|
|
|
|
*
|
|
|
|
* Needed by grade_update_mod_grades() in lib/gradelib.php
|
|
|
|
*
|
2010-01-04 18:30:57 +00:00
|
|
|
* @param stdclass $workshop instance object with extra cmidnumber and modname property
|
2010-01-04 18:23:52 +00:00
|
|
|
* @param int $userid update grade of specific user only, 0 means all participants
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-01-04 18:30:57 +00:00
|
|
|
function workshop_update_grades(stdclass $workshop, $userid=0) {
|
2010-01-04 18:23:52 +00:00
|
|
|
global $CFG, $DB;
|
|
|
|
require_once($CFG->libdir.'/gradelib.php');
|
|
|
|
|
|
|
|
$whereuser = $userid ? ' AND authorid = :userid' : '';
|
2010-01-04 18:24:17 +00:00
|
|
|
$params = array('workshopid' => $workshop->id, 'userid' => $userid);
|
|
|
|
$sql = 'SELECT authorid, grade, gradeover, gradeoverby, feedbackauthor, feedbackauthorformat, timemodified, timegraded
|
2010-01-04 18:23:52 +00:00
|
|
|
FROM {workshop_submissions}
|
|
|
|
WHERE workshopid = :workshopid AND example=0' . $whereuser;
|
2010-01-04 18:24:17 +00:00
|
|
|
$records = $DB->get_records_sql($sql, $params);
|
|
|
|
$submissiongrades = array();
|
|
|
|
foreach ($records as $record) {
|
2010-01-04 18:30:57 +00:00
|
|
|
$grade = new stdclass();
|
2010-01-04 18:24:17 +00:00
|
|
|
$grade->userid = $record->authorid;
|
|
|
|
if (!is_null($record->gradeover)) {
|
|
|
|
$grade->rawgrade = grade_floatval($workshop->grade * $record->gradeover / 100);
|
|
|
|
$grade->usermodified = $record->gradeoverby;
|
|
|
|
} else {
|
|
|
|
$grade->rawgrade = grade_floatval($workshop->grade * $record->grade / 100);
|
|
|
|
}
|
|
|
|
$grade->feedback = $record->feedbackauthor;
|
|
|
|
$grade->feedbackformat = $record->feedbackauthorformat;
|
|
|
|
$grade->datesubmitted = $record->timemodified;
|
|
|
|
$grade->dategraded = $record->timegraded;
|
|
|
|
$submissiongrades[$record->authorid] = $grade;
|
|
|
|
}
|
2010-01-04 18:23:52 +00:00
|
|
|
|
|
|
|
$whereuser = $userid ? ' AND userid = :userid' : '';
|
2010-01-04 18:24:17 +00:00
|
|
|
$params = array('workshopid' => $workshop->id, 'userid' => $userid);
|
|
|
|
$sql = 'SELECT userid, gradinggrade, timegraded
|
2010-01-04 18:23:52 +00:00
|
|
|
FROM {workshop_aggregations}
|
|
|
|
WHERE workshopid = :workshopid' . $whereuser;
|
2010-01-04 18:24:17 +00:00
|
|
|
$records = $DB->get_records_sql($sql, $params);
|
|
|
|
$assessmentgrades = array();
|
|
|
|
foreach ($records as $record) {
|
2010-01-04 18:30:57 +00:00
|
|
|
$grade = new stdclass();
|
2010-01-04 18:24:17 +00:00
|
|
|
$grade->userid = $record->userid;
|
|
|
|
$grade->rawgrade = grade_floatval($workshop->gradinggrade * $record->gradinggrade / 100);
|
|
|
|
$grade->dategraded = $record->timegraded;
|
|
|
|
$assessmentgrades[$record->userid] = $grade;
|
|
|
|
}
|
2010-01-04 18:23:52 +00:00
|
|
|
|
|
|
|
workshop_grade_item_update($workshop, $submissiongrades, $assessmentgrades);
|
|
|
|
}
|
|
|
|
|
2010-01-04 17:48:33 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// File API //
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2010-01-04 17:48:20 +00:00
|
|
|
|
2010-01-04 17:49:01 +00:00
|
|
|
/**
|
|
|
|
* Returns the lists of all browsable file areas within the given module context
|
|
|
|
*
|
|
|
|
* The file area workshop_intro for the activity introduction field is added automatically
|
2010-07-03 13:37:13 +00:00
|
|
|
* by {@link file_browser::get_file_info_context_module()}
|
2010-01-04 17:49:01 +00:00
|
|
|
*
|
2010-01-04 18:30:57 +00:00
|
|
|
* @param stdclass $course
|
|
|
|
* @param stdclass $cm
|
|
|
|
* @param stdclass $context
|
2010-01-04 17:49:01 +00:00
|
|
|
* @return array of [(string)filearea] => (string)description
|
|
|
|
*/
|
|
|
|
function workshop_get_file_areas($course, $cm, $context) {
|
|
|
|
$areas = array();
|
2010-07-03 13:37:13 +00:00
|
|
|
$areas['instructauthors'] = get_string('areainstructauthors', 'workshop');
|
|
|
|
$areas['instructreviewers'] = get_string('areainstructreviewers', 'workshop');
|
|
|
|
$areas['submission_content'] = get_string('areasubmissioncontent', 'workshop');
|
|
|
|
$areas['submission_attachment'] = get_string('areasubmissionattachment', 'workshop');
|
|
|
|
|
2010-01-04 17:49:01 +00:00
|
|
|
return $areas;
|
|
|
|
}
|
|
|
|
|
2010-01-04 17:48:20 +00:00
|
|
|
/**
|
2010-01-04 17:48:33 +00:00
|
|
|
* Serves the files from the workshop file areas
|
2010-01-04 17:48:20 +00:00
|
|
|
*
|
2010-01-04 17:48:33 +00:00
|
|
|
* Apart from module intro (handled by pluginfile.php automatically), workshop files may be
|
|
|
|
* media inserted into submission content (like images) and submission attachments. For these two,
|
|
|
|
* the fileareas workshop_submission_content and workshop_submission_attachment are used.
|
|
|
|
* The access rights to the files are checked here. The user must be either a peer-reviewer
|
|
|
|
* of the submission or have capability ... (todo) to access the submission files.
|
2010-07-03 13:37:13 +00:00
|
|
|
* Besides that, areas workshop_instructauthors and mod_workshop instructreviewers contain the media
|
2010-01-04 18:02:27 +00:00
|
|
|
* embedded using the mod_form.php.
|
2010-01-04 17:48:20 +00:00
|
|
|
*
|
2010-01-04 18:30:57 +00:00
|
|
|
* @param stdclass $course
|
2010-07-03 13:37:13 +00:00
|
|
|
* @param stdclass $cm
|
2010-01-04 18:30:57 +00:00
|
|
|
* @param stdclass $context
|
2010-01-04 17:48:20 +00:00
|
|
|
* @param string $filearea
|
|
|
|
* @param array $args
|
|
|
|
* @param bool $forcedownload
|
2010-01-04 18:02:27 +00:00
|
|
|
* @return void this should never return to the caller
|
2010-01-04 17:48:20 +00:00
|
|
|
*/
|
2010-07-03 13:37:13 +00:00
|
|
|
function workshop_pluginfile($course, $cm, $context, $filearea, array $args, $forcedownload) {
|
2010-01-04 17:48:20 +00:00
|
|
|
global $DB;
|
|
|
|
|
2010-07-03 13:37:13 +00:00
|
|
|
if ($context->contextlevel != CONTEXT_MODULE) {
|
|
|
|
return false;
|
2010-01-04 18:02:27 +00:00
|
|
|
}
|
2010-07-03 13:37:13 +00:00
|
|
|
|
2010-01-04 18:02:27 +00:00
|
|
|
require_login($course, true, $cm);
|
|
|
|
|
2010-07-03 13:37:13 +00:00
|
|
|
if ($filearea === 'instructauthors') {
|
2010-01-04 18:02:27 +00:00
|
|
|
// submission instructions may contain sensitive data
|
|
|
|
if (!has_any_capability(array('moodle/course:manageactivities', 'mod/workshop:submit'), $context)) {
|
|
|
|
send_file_not_found();
|
|
|
|
}
|
|
|
|
|
|
|
|
array_shift($args); // we do not use itemids here
|
2010-07-03 13:37:13 +00:00
|
|
|
$relativepath = implode('/', $args);
|
|
|
|
$fullpath = "/$context->id/mod_workshop/$filearea/0/$relativepath"; // beware, slashes are not used here!
|
2010-01-04 18:02:27 +00:00
|
|
|
|
|
|
|
$fs = get_file_storage();
|
|
|
|
if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
|
2010-01-04 18:07:17 +00:00
|
|
|
send_file_not_found();
|
|
|
|
}
|
|
|
|
|
|
|
|
$lifetime = isset($CFG->filelifetime) ? $CFG->filelifetime : 86400;
|
|
|
|
|
|
|
|
// finally send the file
|
|
|
|
send_stored_file($file, $lifetime, 0);
|
|
|
|
}
|
|
|
|
|
2010-07-03 13:37:13 +00:00
|
|
|
if ($filearea === 'instructreviewers') {
|
2010-01-04 18:07:17 +00:00
|
|
|
// submission instructions may contain sensitive data
|
|
|
|
if (!has_any_capability(array('moodle/course:manageactivities', 'mod/workshop:peerassess'), $context)) {
|
|
|
|
send_file_not_found();
|
|
|
|
}
|
|
|
|
|
|
|
|
array_shift($args); // we do not use itemids here
|
2010-07-03 13:37:13 +00:00
|
|
|
$relativepath = implode('/', $args);
|
|
|
|
$fullpath = "/$context->id/mod_workshop/$filearea/0/$relativepath"; // beware, slashes are not used here!
|
2010-01-04 18:07:17 +00:00
|
|
|
|
|
|
|
$fs = get_file_storage();
|
|
|
|
if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
|
2010-01-04 18:02:27 +00:00
|
|
|
send_file_not_found();
|
|
|
|
}
|
|
|
|
|
|
|
|
$lifetime = isset($CFG->filelifetime) ? $CFG->filelifetime : 86400;
|
|
|
|
|
|
|
|
// finally send the file
|
|
|
|
send_stored_file($file, $lifetime, 0);
|
2010-01-04 17:48:20 +00:00
|
|
|
|
2010-07-03 13:37:13 +00:00
|
|
|
} else if ($filearea === 'submission_content' or $filearea === 'submission_attachment') {
|
2010-01-04 17:50:48 +00:00
|
|
|
$itemid = (int)array_shift($args);
|
2010-07-03 13:37:13 +00:00
|
|
|
if (!$workshop = $DB->get_record('workshop', array('id' => $cm->instance))) {
|
2010-01-04 17:50:48 +00:00
|
|
|
return false;
|
|
|
|
}
|
2010-07-03 13:37:13 +00:00
|
|
|
if (!$submission = $DB->get_record('workshop_submissions', array('id' => $itemid, 'workshopid' => $workshop->id))) {
|
2010-01-04 17:50:48 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// TODO now make sure the user is allowed to see the file
|
|
|
|
$fs = get_file_storage();
|
2010-07-03 13:37:13 +00:00
|
|
|
$relativepath = implode('/', $args);
|
|
|
|
$fullpath = "/$context->id/mod_workshop/$filearea/$itemid/$relativepath";
|
2010-01-04 17:50:48 +00:00
|
|
|
if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// finally send the file
|
|
|
|
// these files are uploaded by students - forcing download for security reasons
|
2010-01-04 17:49:01 +00:00
|
|
|
send_stored_file($file, 0, 0, true);
|
2010-01-04 17:48:20 +00:00
|
|
|
}
|
2010-01-04 17:50:48 +00:00
|
|
|
|
|
|
|
return false;
|
2010-01-04 17:48:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* File browsing support for workshop file areas
|
|
|
|
*
|
2010-01-04 18:30:57 +00:00
|
|
|
* @param stdclass $browser
|
|
|
|
* @param stdclass $areas
|
|
|
|
* @param stdclass $course
|
|
|
|
* @param stdclass $cm
|
|
|
|
* @param stdclass $context
|
2010-01-04 17:48:20 +00:00
|
|
|
* @param string $filearea
|
|
|
|
* @param int $itemid
|
|
|
|
* @param string $filepath
|
|
|
|
* @param string $filename
|
2010-01-04 18:30:57 +00:00
|
|
|
* @return stdclass file_info instance or null if not found
|
2010-01-04 17:48:20 +00:00
|
|
|
*/
|
|
|
|
function workshop_get_file_info($browser, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename) {
|
|
|
|
global $CFG, $DB;
|
|
|
|
|
2010-01-04 17:49:01 +00:00
|
|
|
if (!has_capability('moodle/course:managefiles', $context)) {
|
2010-01-04 17:48:20 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$fs = get_file_storage();
|
2010-01-04 17:49:01 +00:00
|
|
|
|
2010-07-03 13:37:13 +00:00
|
|
|
if ($filearea === 'content' or $filearea === 'attachment') {
|
2010-01-04 17:49:01 +00:00
|
|
|
|
|
|
|
if (is_null($itemid)) {
|
|
|
|
require_once($CFG->dirroot . '/mod/workshop/fileinfolib.php');
|
|
|
|
return new workshop_file_info_submissions_container($browser, $course, $cm, $context, $areas, $filearea);
|
|
|
|
}
|
|
|
|
|
|
|
|
// we are inside the submission container
|
|
|
|
|
|
|
|
$filepath = is_null($filepath) ? '/' : $filepath;
|
|
|
|
$filename = is_null($filename) ? '.' : $filename;
|
|
|
|
|
2010-07-03 13:37:13 +00:00
|
|
|
if (!$storedfile = $fs->get_file($context->id, 'mod_workshop', $filearea, $itemid, $filepath, $filename)) {
|
2010-01-04 17:49:01 +00:00
|
|
|
if ($filepath === '/' and $filename === '.') {
|
2010-07-03 13:37:13 +00:00
|
|
|
$storedfile = new virtual_root_file($context->id, 'mod_workshop', $filearea, $itemid);
|
2010-01-04 17:49:01 +00:00
|
|
|
} else {
|
|
|
|
// not found
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// let us display the author's name instead of itemid (submission id)
|
2010-01-04 17:51:54 +00:00
|
|
|
// todo some sort of caching should happen here
|
|
|
|
|
2010-01-04 17:56:34 +00:00
|
|
|
$sql = 'SELECT s.id, u.lastname, u.firstname
|
2010-01-04 17:51:54 +00:00
|
|
|
FROM {workshop_submissions} s
|
2010-01-04 18:08:13 +00:00
|
|
|
INNER JOIN {user} u ON (s.authorid = u.id)
|
2010-01-04 17:56:34 +00:00
|
|
|
WHERE s.workshopid = ?';
|
2010-01-04 17:51:54 +00:00
|
|
|
$params = array($cm->instance);
|
|
|
|
$authors = $DB->get_records_sql($sql, $params);
|
2010-01-04 17:49:01 +00:00
|
|
|
$urlbase = $CFG->wwwroot . '/pluginfile.php';
|
|
|
|
$topvisiblename = fullname($authors[$itemid]);
|
|
|
|
// do not allow manual modification of any files!
|
|
|
|
return new file_info_stored($browser, $context, $storedfile, $urlbase, $topvisiblename, true, true, false, false);
|
2010-01-04 17:48:20 +00:00
|
|
|
}
|
|
|
|
|
2010-07-03 13:37:13 +00:00
|
|
|
if ($filearea == 'instructauthors' or $filearea == 'instructreviewers') {
|
2010-01-04 17:49:01 +00:00
|
|
|
// always only itemid 0
|
|
|
|
|
|
|
|
$filepath = is_null($filepath) ? '/' : $filepath;
|
|
|
|
$filename = is_null($filename) ? '.' : $filename;
|
|
|
|
|
|
|
|
$urlbase = $CFG->wwwroot.'/pluginfile.php';
|
2010-07-03 13:37:13 +00:00
|
|
|
if (!$storedfile = $fs->get_file($context->id, 'mod_workshop', $filearea, 0, $filepath, $filename)) {
|
2010-01-04 17:49:01 +00:00
|
|
|
if ($filepath === '/' and $filename === '.') {
|
2010-07-03 13:37:13 +00:00
|
|
|
$storedfile = new virtual_root_file($context->id, 'mod_workshop', $filearea, 0);
|
2010-01-04 17:49:01 +00:00
|
|
|
} else {
|
|
|
|
// not found
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new file_info_stored($browser, $context, $storedfile, $urlbase, $areas[$filearea], false, true, true, false);
|
2010-01-04 17:48:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-04 18:02:27 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Navigation API //
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-01-04 18:00:12 +00:00
|
|
|
/**
|
|
|
|
* Extends the global navigation tree by adding workshop nodes if there is a relevant content
|
|
|
|
*
|
2010-01-04 18:00:54 +00:00
|
|
|
* This can be called by an AJAX request so do not rely on $PAGE as it might not be set up properly.
|
|
|
|
*
|
2010-01-04 18:00:12 +00:00
|
|
|
* @param navigation_node $navref An object representing the navigation tree node of the workshop module instance
|
2010-01-04 18:30:57 +00:00
|
|
|
* @param stdclass $course
|
|
|
|
* @param stdclass $module
|
|
|
|
* @param stdclass $cm
|
2010-01-04 18:00:12 +00:00
|
|
|
*/
|
2010-01-04 18:30:57 +00:00
|
|
|
function workshop_extend_navigation(navigation_node $navref, stdclass $course, stdclass $module, stdclass $cm) {
|
2010-01-04 18:00:12 +00:00
|
|
|
global $CFG;
|
|
|
|
|
2010-03-31 07:41:31 +00:00
|
|
|
if (has_capability('mod/workshop:submit', get_context_instance(CONTEXT_MODULE, $cm->id))) {
|
2010-01-16 15:39:56 +00:00
|
|
|
$url = new moodle_url('/mod/workshop/submission.php', array('cmid' => $cm->id));
|
2010-04-19 06:30:30 +00:00
|
|
|
$mysubmission = $navref->add(get_string('mysubmission', 'workshop'), $url);
|
|
|
|
$mysubmission->mainnavonly = true;
|
2010-01-04 18:00:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extends the settings navigation with the Workshop settings
|
|
|
|
|
2010-01-04 18:00:54 +00:00
|
|
|
* This function is called when the context for the page is a workshop module. This is not called by AJAX
|
|
|
|
* so it is safe to rely on the $PAGE.
|
2010-01-04 18:00:12 +00:00
|
|
|
*
|
|
|
|
* @param settings_navigation $settingsnav {@link settings_navigation}
|
2010-03-22 03:04:00 +00:00
|
|
|
* @param navigation_node $workshopnode {@link navigation_node}
|
2010-01-04 18:00:12 +00:00
|
|
|
*/
|
2010-03-22 03:04:00 +00:00
|
|
|
function workshop_extend_settings_navigation(settings_navigation $settingsnav, navigation_node $workshopnode=null) {
|
|
|
|
global $PAGE;
|
2010-01-04 18:00:12 +00:00
|
|
|
|
|
|
|
//$workshopobject = $DB->get_record("workshop", array("id" => $PAGE->cm->instance));
|
|
|
|
|
2010-01-04 18:00:54 +00:00
|
|
|
if (has_capability('mod/workshop:editdimensions', $PAGE->cm->context)) {
|
2010-01-16 15:39:56 +00:00
|
|
|
$url = new moodle_url('/mod/workshop/editform.php', array('cmid' => $PAGE->cm->id));
|
2010-01-04 18:00:54 +00:00
|
|
|
$workshopnode->add(get_string('editassessmentform', 'workshop'), $url, settings_navigation::TYPE_SETTING);
|
2010-01-04 18:00:12 +00:00
|
|
|
}
|
2010-01-04 18:30:09 +00:00
|
|
|
if (has_capability('mod/workshop:allocate', $PAGE->cm->context)) {
|
2010-01-16 15:39:56 +00:00
|
|
|
$url = new moodle_url('/mod/workshop/allocation.php', array('cmid' => $PAGE->cm->id));
|
2010-01-04 18:00:54 +00:00
|
|
|
$workshopnode->add(get_string('allocate', 'workshop'), $url, settings_navigation::TYPE_SETTING);
|
2010-01-04 18:00:12 +00:00
|
|
|
}
|
|
|
|
}
|