]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-20058 workshop pushed grades into gradebook
authorDavid Mudrak <david.mudrak@gmail.com>
Mon, 4 Jan 2010 18:23:52 +0000 (18:23 +0000)
committerDavid Mudrak <david.mudrak@gmail.com>
Mon, 4 Jan 2010 18:23:52 +0000 (18:23 +0000)
mod/workshop/lang/en_utf8/workshop.php
mod/workshop/lib.php
mod/workshop/locallib.php
mod/workshop/view.php

index aec261240f6f3e2fe32107562792bc579dbec57e..698f208d05e85e259479c365d069930ab3b160d5 100644 (file)
@@ -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'] = ' &gt; ';
+$string['gradeitemassessment'] = '$a->workshopname (assessment)';
+$string['gradeitemsubmission'] = '$a->workshopname (submission)';
 $string['gradeover'] = 'Override grade for submission';
 $string['gradereceivedfrom'] = ' &lt; ';
 $string['gradinggradecalculated'] = 'Calculated grade for assessment';
index a07946461e3057531dfaa96cf6cc502157c28071..4f8da4f193990fcb79c65993cadb0e439566a0b4 100644 (file)
 // 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
- * 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 <david.mudrak@gmail.com>
 
 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                                                                   //
 ////////////////////////////////////////////////////////////////////////////////
index e5fff4b2ac32b3d31e38050190465b21ee8187b9..f7dca6a6ba3317f92ebc0e27e55aff535e2ad57d 100644 (file)
@@ -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,
index 2152000d58403378a7fdbf2ff22014c0f56392f5..e2f1d44f3eedd4b2e82b68c625b5ebf08d264323 100644 (file)
@@ -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:
 }