MDL-20058 workshop pushed grades into gradebook

This commit is contained in:
David Mudrak 2010-01-04 18:23:52 +00:00
parent f82567aff7
commit 365c2cc22a
4 changed files with 127 additions and 62 deletions

View file

@ -33,7 +33,6 @@ $string[''] = '';
$string[''] = ''; $string[''] = '';
$string[''] = ''; $string[''] = '';
$string[''] = ''; $string[''] = '';
$string[''] = '';
$string['accesscontrol'] = 'Access control'; $string['accesscontrol'] = 'Access control';
$string['aggregategrades'] = 'Re-calculate grades'; $string['aggregategrades'] = 'Re-calculate grades';
$string['aggregation'] = 'Grades aggregation'; $string['aggregation'] = 'Grades aggregation';
@ -93,6 +92,8 @@ $string['givengradestatus'] = 'Status: $a';
$string['gradecalculated'] = 'Calculated grade for submission'; $string['gradecalculated'] = 'Calculated grade for submission';
$string['gradedecimals'] = 'Decimal places in grades'; $string['gradedecimals'] = 'Decimal places in grades';
$string['gradegivento'] = ' > '; $string['gradegivento'] = ' > ';
$string['gradeitemassessment'] = '$a->workshopname (assessment)';
$string['gradeitemsubmission'] = '$a->workshopname (submission)';
$string['gradeover'] = 'Override grade for submission'; $string['gradeover'] = 'Override grade for submission';
$string['gradereceivedfrom'] = ' < '; $string['gradereceivedfrom'] = ' < ';
$string['gradinggradecalculated'] = 'Calculated grade for assessment'; $string['gradinggradecalculated'] = 'Calculated grade for assessment';

View file

@ -16,10 +16,10 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** /**
* Library of interface functions and constants for module workshop * Library of functions needed by Moodle core and other subsystems
* *
* All the core Moodle functions, neeeded to allow the module to work * All the functions neeeded by Moodle core, gradebook, file subsystem etc
* integrated in Moodle should be placed here. * are placed here.
* *
* @package mod-workshop * @package mod-workshop
* @copyright 2009 David Mudrak <david.mudrak@gmail.com> * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
@ -28,6 +28,10 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
////////////////////////////////////////////////////////////////////////////////
// Moodle core API //
////////////////////////////////////////////////////////////////////////////////
/** /**
* Returns the information if the module supports a feature * Returns the information if the module supports a feature
* *
@ -59,42 +63,45 @@ function workshop_supports($feature) {
* will save a new instance and return the id number * will save a new instance and return the id number
* of the new instance. * of the new instance.
* *
* @param stdClass $data An object from the form in mod_form.php * @param stdClass $workshop An object from the form in mod_form.php
* @return int The id of the newly inserted workshop record * @return int The id of the newly inserted workshop record
*/ */
function workshop_add_instance($data) { function workshop_add_instance(stdClass $workshop) {
global $CFG, $DB; global $CFG, $DB;
require_once(dirname(__FILE__) . '/locallib.php'); require_once(dirname(__FILE__) . '/locallib.php');
$data->phase = workshop::PHASE_SETUP; $workshop->phase = workshop::PHASE_SETUP;
$data->timecreated = time(); $workshop->timecreated = time();
$data->timemodified = $data->timecreated; $workshop->timemodified = $workshop->timecreated;
// insert the new record so we get the id // insert the new record so we get the id
$data->id = $DB->insert_record('workshop', $data); $workshop->id = $DB->insert_record('workshop', $workshop);
// we need to use context now, so we need to make sure all needed info is already in db // we need to use context now, so we need to make sure all needed info is already in db
$cmid = $data->coursemodule; $cmid = $workshop->coursemodule;
$DB->set_field('course_modules', 'instance', $data->id, array('id' => $cmid)); $DB->set_field('course_modules', 'instance', $workshop->id, array('id' => $cmid));
$context = get_context_instance(CONTEXT_MODULE, $cmid); $context = get_context_instance(CONTEXT_MODULE, $cmid);
// process the custom wysiwyg editors // process the custom wysiwyg editors
if ($draftitemid = $data->instructauthorseditor['itemid']) { if ($draftitemid = $workshop->instructauthorseditor['itemid']) {
$data->instructauthors = file_save_draft_area_files($draftitemid, $context->id, 'workshop_instructauthors', $workshop->instructauthors = file_save_draft_area_files($draftitemid, $context->id, 'workshop_instructauthors',
0, workshop::instruction_editors_options($context), $data->instructauthorseditor['text']); 0, workshop::instruction_editors_options($context), $workshop->instructauthorseditor['text']);
$data->instructauthorsformat = $data->instructauthorseditor['format']; $workshop->instructauthorsformat = $workshop->instructauthorseditor['format'];
} }
if ($draftitemid = $data->instructreviewerseditor['itemid']) { if ($draftitemid = $workshop->instructreviewerseditor['itemid']) {
$data->instructreviewers = file_save_draft_area_files($draftitemid, $context->id, 'workshop_instructreviewers', $workshop->instructreviewers = file_save_draft_area_files($draftitemid, $context->id, 'workshop_instructreviewers',
0, workshop::instruction_editors_options($context), $data->instructreviewerseditor['text']); 0, workshop::instruction_editors_options($context), $workshop->instructreviewerseditor['text']);
$data->instructreviewersformat = $data->instructreviewerseditor['format']; $workshop->instructreviewersformat = $workshop->instructreviewerseditor['format'];
} }
// re-save the record with the replaced URLs in editor fields // re-save the record with the replaced URLs in editor fields
$DB->update_record('workshop', $data); $DB->update_record('workshop', $workshop);
return $data->id; // update gradebook item
workshop_grade_item_update($workshop);
return $workshop->id;
} }
/** /**
@ -102,37 +109,42 @@ function workshop_add_instance($data) {
* (defined by the form in mod_form.php) this function * (defined by the form in mod_form.php) this function
* will update an existing instance with new data. * will update an existing instance with new data.
* *
* @param stdClass $data An object from the form in mod_form.php * @param stdClass $workshop An object from the form in mod_form.php
* @return bool success * @return bool success
*/ */
function workshop_update_instance($data) { function workshop_update_instance(stdClass $workshop) {
global $CFG, $DB; global $CFG, $DB;
require_once(dirname(__FILE__) . '/locallib.php'); require_once(dirname(__FILE__) . '/locallib.php');
$data->timemodified = time(); $workshop->timemodified = time();
$data->id = $data->instance; $workshop->id = $workshop->instance;
// todo - if the grading strategy is being changed, we must replace all aggregated peer grades with nulls // 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 // todo - if maximum grades are being changed, we should probably recalculate or invalidate them
$DB->update_record('workshop', $data); $DB->update_record('workshop', $workshop);
$context = get_context_instance(CONTEXT_MODULE, $data->coursemodule); $context = get_context_instance(CONTEXT_MODULE, $workshop->coursemodule);
// process the custom wysiwyg editors // process the custom wysiwyg editors
if ($draftitemid = $data->instructauthorseditor['itemid']) { if ($draftitemid = $workshop->instructauthorseditor['itemid']) {
$data->instructauthors = file_save_draft_area_files($draftitemid, $context->id, 'workshop_instructauthors', $workshop->instructauthors = file_save_draft_area_files($draftitemid, $context->id, 'workshop_instructauthors',
0, workshop::instruction_editors_options($context), $data->instructauthorseditor['text']); 0, workshop::instruction_editors_options($context), $workshop->instructauthorseditor['text']);
$data->instructauthorsformat = $data->instructauthorseditor['format']; $workshop->instructauthorsformat = $workshop->instructauthorseditor['format'];
} }
if ($draftitemid = $data->instructreviewerseditor['itemid']) { if ($draftitemid = $workshop->instructreviewerseditor['itemid']) {
$data->instructreviewers = file_save_draft_area_files($draftitemid, $context->id, 'workshop_instructreviewers', $workshop->instructreviewers = file_save_draft_area_files($draftitemid, $context->id, 'workshop_instructreviewers',
0, workshop::instruction_editors_options($context), $data->instructreviewerseditor['text']); 0, workshop::instruction_editors_options($context), $workshop->instructreviewerseditor['text']);
$data->instructreviewersformat = $data->instructreviewerseditor['format']; $workshop->instructreviewersformat = $workshop->instructreviewerseditor['format'];
} }
// re-save the record with the replaced URLs in editor fields // re-save the record with the replaced URLs in editor fields
return $DB->update_record('workshop', $data); $DB->update_record('workshop', $workshop);
// update gradebook item
workshop_grade_item_update($workshop);
return true;
} }
/** /**
@ -164,6 +176,10 @@ function workshop_delete_instance($id) {
// finally remove the workshop record itself // finally remove the workshop record itself
$DB->delete_records('workshop', array('id' => $workshop->id)); $DB->delete_records('workshop', array('id' => $workshop->id));
// 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));
return true; return true;
} }
@ -289,6 +305,77 @@ function workshop_get_extra_capabilities() {
return array('moodle/site:accessallgroups'); return array('moodle/site:accessallgroups');
} }
////////////////////////////////////////////////////////////////////////////////
// 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()}.
*
* @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
* @return void
*/
function workshop_grade_item_update(stdClass $workshop, $submissiongrades=null, $assessmentgrades=null) {
global $CFG;
require_once($CFG->libdir.'/gradelib.php');
$a = new stdClass();
$a->workshopname = clean_param($workshop->name, PARAM_NOTAGS);
$item = array();
$item['itemname'] = get_string('gradeitemsubmission', 'workshop', $a);
$item['idnumber'] = $workshop->cmidnumber;
$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['idnumber'] = $workshop->cmidnumber;
$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
*
* @param stdClass $workshop instance object with extra cmidnumber and modname property
* @param int $userid update grade of specific user only, 0 means all participants
* @return void
*/
function workshop_update_grades(stdClass $workshop, $userid=0) {
global $CFG, $DB;
require_once($CFG->libdir.'/gradelib.php');
$whereuser = $userid ? ' AND authorid = :userid' : '';
$params = array('workshopid' => $workshop->id, 'maxgrade' => $workshop->grade, 'userid' => $userid);
$sql = 'SELECT authorid, authorid AS userid, grade * :maxgrade / 100 AS rawgrade,
feedbackauthor AS feedback, feedbackauthorformat AS feedbackformat,
timemodified AS datesubmitted
FROM {workshop_submissions}
WHERE workshopid = :workshopid AND example=0' . $whereuser;
$submissiongrades = $DB->get_records_sql($sql, $params);
$whereuser = $userid ? ' AND userid = :userid' : '';
$params = array('workshopid' => $workshop->id, 'maxgrade' => $workshop->gradinggrade, 'userid' => $userid);
$sql = 'SELECT userid, gradinggrade * :maxgrade / 100 AS rawgrade
FROM {workshop_aggregations}
WHERE workshopid = :workshopid' . $whereuser;
$assessmentgrades = $DB->get_records_sql($sql, $params);
workshop_grade_item_update($workshop, $submissiongrades, $assessmentgrades);
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// File API // // File API //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View file

@ -992,7 +992,7 @@ class workshop {
public function switch_phase($newphase) { public function switch_phase($newphase) {
global $DB; global $DB;
$known = $this->available_phases(); $known = $this->available_phases_list();
if (!isset($known[$newphase])) { if (!isset($known[$newphase])) {
return false; return false;
} }
@ -1696,7 +1696,7 @@ class workshop {
/** /**
* @return array of available workshop phases * @return array of available workshop phases
*/ */
protected function available_phases() { protected function available_phases_list() {
return array( return array(
self::PHASE_SETUP => true, self::PHASE_SETUP => true,
self::PHASE_SUBMISSION => true, self::PHASE_SUBMISSION => true,

View file

@ -241,29 +241,6 @@ case workshop::PHASE_EVALUATION:
} }
break; break;
case workshop::PHASE_CLOSED: case workshop::PHASE_CLOSED:
$page = optional_param('page', 0, PARAM_INT);
$sortby = optional_param('sortby', 'totalgrade', PARAM_ALPHA);
$sorthow = optional_param('sorthow', 'DESC', PARAM_ALPHA);
$perpage = 10; // todo let the user modify this
$groups = ''; // todo let the user choose the group
$PAGE->set_url(new moodle_url($PAGE->url, compact('sortby', 'sorthow', 'page')));
$data = $workshop->prepare_grading_report($USER->id, $groups, $page, $perpage, $sortby, $sorthow);
if ($data) {
$showauthornames = has_capability('mod/workshop:viewauthornames', $workshop->context);
$showreviewernames = has_capability('mod/workshop:viewreviewernames', $workshop->context);
// prepare paging bar
$pagingbar = new moodle_paging_bar();
$pagingbar->totalcount = $data->totalcount;
$pagingbar->page = $page;
$pagingbar->perpage = $perpage;
$pagingbar->baseurl = $PAGE->url;
$pagingbar->pagevar = 'page';
echo $OUTPUT->paging_bar($pagingbar);
echo $wsoutput->grading_report($data, $showauthornames, $showreviewernames, $sortby, $sorthow);
echo $OUTPUT->paging_bar($pagingbar);
}
break; break;
default: default:
} }