From 365c2cc22a841f6cbfd62ed288c9c6b4548f4540 Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Mon, 4 Jan 2010 18:23:52 +0000 Subject: [PATCH] MDL-20058 workshop pushed grades into gradebook --- mod/workshop/lang/en_utf8/workshop.php | 3 +- mod/workshop/lib.php | 159 +++++++++++++++++++------ mod/workshop/locallib.php | 4 +- mod/workshop/view.php | 23 ---- 4 files changed, 127 insertions(+), 62 deletions(-) diff --git a/mod/workshop/lang/en_utf8/workshop.php b/mod/workshop/lang/en_utf8/workshop.php index aec261240f..698f208d05 100644 --- a/mod/workshop/lang/en_utf8/workshop.php +++ b/mod/workshop/lang/en_utf8/workshop.php @@ -33,7 +33,6 @@ $string[''] = ''; $string[''] = ''; $string[''] = ''; $string[''] = ''; -$string[''] = ''; $string['accesscontrol'] = 'Access control'; $string['aggregategrades'] = 'Re-calculate grades'; $string['aggregation'] = 'Grades aggregation'; @@ -93,6 +92,8 @@ $string['givengradestatus'] = 'Status: $a'; $string['gradecalculated'] = 'Calculated grade for submission'; $string['gradedecimals'] = 'Decimal places in grades'; $string['gradegivento'] = ' > '; +$string['gradeitemassessment'] = '$a->workshopname (assessment)'; +$string['gradeitemsubmission'] = '$a->workshopname (submission)'; $string['gradeover'] = 'Override grade for submission'; $string['gradereceivedfrom'] = ' < '; $string['gradinggradecalculated'] = 'Calculated grade for assessment'; diff --git a/mod/workshop/lib.php b/mod/workshop/lib.php index a07946461e..4f8da4f193 100644 --- a/mod/workshop/lib.php +++ b/mod/workshop/lib.php @@ -16,10 +16,10 @@ // along with Moodle. If not, see . /** - * 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 - * integrated in Moodle should be placed here. + * All the functions neeeded by Moodle core, gradebook, file subsystem etc + * are placed here. * * @package mod-workshop * @copyright 2009 David Mudrak @@ -28,6 +28,10 @@ defined('MOODLE_INTERNAL') || die(); +//////////////////////////////////////////////////////////////////////////////// +// Moodle core API // +//////////////////////////////////////////////////////////////////////////////// + /** * 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 * 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 */ -function workshop_add_instance($data) { +function workshop_add_instance(stdClass $workshop) { global $CFG, $DB; require_once(dirname(__FILE__) . '/locallib.php'); - $data->phase = workshop::PHASE_SETUP; - $data->timecreated = time(); - $data->timemodified = $data->timecreated; + $workshop->phase = workshop::PHASE_SETUP; + $workshop->timecreated = time(); + $workshop->timemodified = $workshop->timecreated; // 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 - $cmid = $data->coursemodule; - $DB->set_field('course_modules', 'instance', $data->id, array('id' => $cmid)); + $cmid = $workshop->coursemodule; + $DB->set_field('course_modules', 'instance', $workshop->id, array('id' => $cmid)); $context = get_context_instance(CONTEXT_MODULE, $cmid); // process the custom wysiwyg editors - if ($draftitemid = $data->instructauthorseditor['itemid']) { - $data->instructauthors = file_save_draft_area_files($draftitemid, $context->id, 'workshop_instructauthors', - 0, workshop::instruction_editors_options($context), $data->instructauthorseditor['text']); - $data->instructauthorsformat = $data->instructauthorseditor['format']; + if ($draftitemid = $workshop->instructauthorseditor['itemid']) { + $workshop->instructauthors = file_save_draft_area_files($draftitemid, $context->id, 'workshop_instructauthors', + 0, workshop::instruction_editors_options($context), $workshop->instructauthorseditor['text']); + $workshop->instructauthorsformat = $workshop->instructauthorseditor['format']; } - if ($draftitemid = $data->instructreviewerseditor['itemid']) { - $data->instructreviewers = file_save_draft_area_files($draftitemid, $context->id, 'workshop_instructreviewers', - 0, workshop::instruction_editors_options($context), $data->instructreviewerseditor['text']); - $data->instructreviewersformat = $data->instructreviewerseditor['format']; + if ($draftitemid = $workshop->instructreviewerseditor['itemid']) { + $workshop->instructreviewers = file_save_draft_area_files($draftitemid, $context->id, 'workshop_instructreviewers', + 0, workshop::instruction_editors_options($context), $workshop->instructreviewerseditor['text']); + $workshop->instructreviewersformat = $workshop->instructreviewerseditor['format']; } // re-save the record with the replaced URLs in editor fields - $DB->update_record('workshop', $data); + $DB->update_record('workshop', $workshop); + + // update gradebook item + workshop_grade_item_update($workshop); - return $data->id; + return $workshop->id; } /** @@ -102,37 +109,42 @@ function workshop_add_instance($data) { * (defined by the form in mod_form.php) this function * 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 */ -function workshop_update_instance($data) { +function workshop_update_instance(stdClass $workshop) { global $CFG, $DB; require_once(dirname(__FILE__) . '/locallib.php'); - $data->timemodified = time(); - $data->id = $data->instance; + $workshop->timemodified = time(); + $workshop->id = $workshop->instance; // 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 - $DB->update_record('workshop', $data); - $context = get_context_instance(CONTEXT_MODULE, $data->coursemodule); + $DB->update_record('workshop', $workshop); + $context = get_context_instance(CONTEXT_MODULE, $workshop->coursemodule); // process the custom wysiwyg editors - if ($draftitemid = $data->instructauthorseditor['itemid']) { - $data->instructauthors = file_save_draft_area_files($draftitemid, $context->id, 'workshop_instructauthors', - 0, workshop::instruction_editors_options($context), $data->instructauthorseditor['text']); - $data->instructauthorsformat = $data->instructauthorseditor['format']; + if ($draftitemid = $workshop->instructauthorseditor['itemid']) { + $workshop->instructauthors = file_save_draft_area_files($draftitemid, $context->id, 'workshop_instructauthors', + 0, workshop::instruction_editors_options($context), $workshop->instructauthorseditor['text']); + $workshop->instructauthorsformat = $workshop->instructauthorseditor['format']; } - if ($draftitemid = $data->instructreviewerseditor['itemid']) { - $data->instructreviewers = file_save_draft_area_files($draftitemid, $context->id, 'workshop_instructreviewers', - 0, workshop::instruction_editors_options($context), $data->instructreviewerseditor['text']); - $data->instructreviewersformat = $data->instructreviewerseditor['format']; + if ($draftitemid = $workshop->instructreviewerseditor['itemid']) { + $workshop->instructreviewers = file_save_draft_area_files($draftitemid, $context->id, 'workshop_instructreviewers', + 0, workshop::instruction_editors_options($context), $workshop->instructreviewerseditor['text']); + $workshop->instructreviewersformat = $workshop->instructreviewerseditor['format']; } // 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 $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; } @@ -289,6 +305,77 @@ function workshop_get_extra_capabilities() { 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 // //////////////////////////////////////////////////////////////////////////////// diff --git a/mod/workshop/locallib.php b/mod/workshop/locallib.php index e5fff4b2ac..f7dca6a6ba 100644 --- a/mod/workshop/locallib.php +++ b/mod/workshop/locallib.php @@ -992,7 +992,7 @@ class workshop { public function switch_phase($newphase) { global $DB; - $known = $this->available_phases(); + $known = $this->available_phases_list(); if (!isset($known[$newphase])) { return false; } @@ -1696,7 +1696,7 @@ class workshop { /** * @return array of available workshop phases */ - protected function available_phases() { + protected function available_phases_list() { return array( self::PHASE_SETUP => true, self::PHASE_SUBMISSION => true, diff --git a/mod/workshop/view.php b/mod/workshop/view.php index 2152000d58..e2f1d44f3e 100644 --- a/mod/workshop/view.php +++ b/mod/workshop/view.php @@ -241,29 +241,6 @@ case workshop::PHASE_EVALUATION: } break; 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; default: } -- 2.39.5