MDL-9632; MDL-9545 basic assignment grading support - event triggers implemented + some minor cleanup
This commit is contained in:
+49
-15
@@ -283,7 +283,7 @@ function standardise_score($gradevalue, $source_min, $source_max, $target_min, $
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
/**
|
||||
* Handles all grade_added and grade_updated events
|
||||
*
|
||||
* @param object $eventdata contains all the data for the event
|
||||
@@ -291,33 +291,67 @@ function standardise_score($gradevalue, $source_min, $source_max, $target_min, $
|
||||
*
|
||||
*/
|
||||
function grade_handler($eventdata) {
|
||||
$eventdata = (array)$eventdata;
|
||||
|
||||
/// each grade must belong to some user
|
||||
if (empty($eventdata['userid'])) {
|
||||
debugging('Missing user id in event data!');
|
||||
return true;
|
||||
}
|
||||
|
||||
/// First let's make sure a grade_item exists for this grade
|
||||
$gradeitem = new grade_item($eventdata);
|
||||
|
||||
if (empty($gradeitem->id)) { // Doesn't exist yet
|
||||
if (!$gradeitem->id = $gradeitem->insert()) { // Try to create a new item...
|
||||
debugging('Could not create a grade_item!');
|
||||
return false;
|
||||
if (!empty($eventdata['itemid'])) { // if itemid specified, do not use searching
|
||||
$gradeitem = new grade_item(array('id'=>$eventdata['itemid']));
|
||||
|
||||
if (empty($gradeitem->id)) { // Item with itemid doesn't exist yet
|
||||
debugging('grade_item does not exist! id:'.$eventdata['itemid']);
|
||||
// this $eventadata can not be fixed, do not block the queue
|
||||
// we should log the error somewhere on production servers
|
||||
return true;
|
||||
}
|
||||
|
||||
} else {
|
||||
$gradeitem = new grade_item($eventdata);
|
||||
if (empty($gradeitem->id)) { // Doesn't exist yet
|
||||
if (!$gradeitem->id = $gradeitem->insert()) { // Try to create a new item...
|
||||
debugging('Could not create a new grade_item!');
|
||||
// do we need false here? - it would stop all other grades indefinitelly!
|
||||
// we shouuld not IMO block other events, one silly bug in 3rd party module would disable all grading
|
||||
// if we return false we must to notify admin and add some gui to fix the trouble
|
||||
// skodak
|
||||
return true; //for now
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$eventdata->itemid = $gradeitem->id;
|
||||
$rawgrade = new grade_grades_raw(array('itemid'=>$gradeitem->id, 'userid'=>$eventdata['userid']));
|
||||
$rawgrade->grade_item = &$gradeitem; // we already have it, so let's use it
|
||||
|
||||
/// Grade_item exists, now we can insert the new raw grade
|
||||
// store these to keep track of original grade item settings
|
||||
$rawgrade->grademax = $gradeitem->grademax;
|
||||
$rawgrade->grademin = $gradeitem->grademin;
|
||||
$rawgrade->scaleid = $gradeitem->scaleid;
|
||||
|
||||
$rawgrade = new grade_grades_raw($eventdata);
|
||||
if (isset($eventdata['feedback'])) {
|
||||
$rawgrade->feedback = $eventdata['feedback'];
|
||||
if (isset($eventdata['feedbackformat'])) {
|
||||
$rawgrade->feedbackformat = $eventdata['feedbackformat'];
|
||||
} else {
|
||||
$rawgrade->feedbackformat = FORMAT_PLAIN;
|
||||
}
|
||||
|
||||
}
|
||||
if (!isset($eventdata['gradevalue'])) {
|
||||
$eventdata['gradevalue'] = null; // means no grade yet
|
||||
}
|
||||
if ($rawgrade->id) {
|
||||
$rawgrade->update($eventdata->gradevalue, 'event');
|
||||
$rawgrade->update($eventdata['gradevalue'], 'event');
|
||||
} else {
|
||||
$rawgrade->gradevalue = $eventdata['gradevalue'];
|
||||
$rawgrade->insert();
|
||||
}
|
||||
|
||||
// Check how it went
|
||||
|
||||
/// Are there other checks to do?
|
||||
|
||||
// everything ok :-)
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
@@ -23,14 +23,38 @@ function xmldb_assignment_upgrade($oldversion=0) {
|
||||
|
||||
$result = true;
|
||||
|
||||
/// And upgrade begins here. For each one, you'll need one
|
||||
/// block of code similar to the next one. Please, delete
|
||||
/// this comment lines once this file start handling proper
|
||||
/// upgrade code.
|
||||
|
||||
/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
|
||||
/// $result = result of "/lib/ddllib.php" function calls
|
||||
/// }
|
||||
if ($result && $oldversion < 2007052700) {
|
||||
require_once $CFG->dirroot.'/mod/assignment/lib.php';
|
||||
// we do not want grade items for orphaned activities
|
||||
$sql = "SELECT a.*, cm.idnumber as cmidnumber, a.course as courseid FROM {$CFG->prefix}assignment a, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
|
||||
WHERE m.name='assignment' AND m.id=cm.module AND cm.instance=a.id";
|
||||
if ($rs = get_recordset_sql($sql)) {
|
||||
$db->debug = false;
|
||||
if ($rs->RecordCount() > 0) {
|
||||
while ($assignment = rs_fetch_next_record($rs)) {
|
||||
$item = grade_get_items($assignment->course, 'grade', 'mod', 'assignment', $assignment->id);
|
||||
if (!empty($item)) {
|
||||
//already converted, it should not happen - probably interrupted upgrade?
|
||||
continue;
|
||||
}
|
||||
$itemid = assignment_base::create_grade_item($assignment);
|
||||
if ($rs2 = get_recordset('assignment_submissions', 'assignment', $assignment->id)) {
|
||||
while ($sub = rs_fetch_next_record($rs2)) {
|
||||
if ($sub->grade != -1 or !empty($sub->submissioncomment)) {
|
||||
if ($sub->grade <0 ) {
|
||||
$sub->grade = null;
|
||||
}
|
||||
events_trigger('grade_added', array('itemid'=>$itemid, 'gradevalue'=>$sub->grade, 'userid'=>$sub->userid, 'feedback'=>$sub->submissioncomment, 'feedbackformat'=>$sub->format));
|
||||
}
|
||||
}
|
||||
rs_close($rs2);
|
||||
}
|
||||
}
|
||||
}
|
||||
$db->debug = true;
|
||||
rs_close($rs);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
<?php // $Id$
|
||||
// This script prints the setup screen for any assignment
|
||||
// It does this by calling the setup method in the appropriate class
|
||||
|
||||
require_once("../../config.php");
|
||||
require_once("lib.php");
|
||||
|
||||
if (!$form = data_submitted($CFG->wwwroot.'/course/mod.php')) {
|
||||
error("This script was called wrongly");
|
||||
}
|
||||
|
||||
if (!$course = get_record('course', 'id', $form->course)) {
|
||||
error("Non-existent course!");
|
||||
}
|
||||
|
||||
require_login($course->id);
|
||||
|
||||
if (!has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $form->course))) {
|
||||
redirect($CFG->wwwroot.'/course/view.php?id='.$course->id);
|
||||
}
|
||||
|
||||
$form->assignmenttype = clean_param($form->assignmenttype, PARAM_SAFEDIR);
|
||||
|
||||
require_once("$CFG->dirroot/mod/assignment/type/$form->assignmenttype/assignment.class.php");
|
||||
|
||||
$assignmentclass = "assignment_$form->assignmenttype";
|
||||
|
||||
$assignmentinstance = new $assignmentclass();
|
||||
|
||||
echo $assignmentinstance->setup($form); /// The actual form is all printed here
|
||||
|
||||
|
||||
?>
|
||||
+211
-204
@@ -5,6 +5,8 @@
|
||||
* This class provides all the functionality for an assignment
|
||||
*/
|
||||
|
||||
require_once($CFG->libdir.'/gradelib.php');
|
||||
|
||||
DEFINE ('ASSIGNMENT_COUNT_WORDS', 1);
|
||||
DEFINE ('ASSIGNMENT_COUNT_LETTERS', 2);
|
||||
|
||||
@@ -47,54 +49,60 @@ class assignment_base {
|
||||
* @param cm object, usually null, but if we have it we pass it to save db access
|
||||
* @param course object, usually null, but if we have it we pass it to save db access
|
||||
*/
|
||||
function assignment_base($cmid=0, $assignment=NULL, $cm=NULL, $course=NULL) {
|
||||
function assignment_base($cmid='staticonly', $assignment=NULL, $cm=NULL, $course=NULL) {
|
||||
if ($cmid == 'staticonly') {
|
||||
//use static functions only!
|
||||
return;
|
||||
}
|
||||
|
||||
global $CFG;
|
||||
|
||||
if ($cmid) {
|
||||
if ($cm) {
|
||||
$this->cm = $cm;
|
||||
} else if (! $this->cm = get_coursemodule_from_id('assignment', $cmid)) {
|
||||
error('Course Module ID was incorrect');
|
||||
}
|
||||
|
||||
$this->context = get_context_instance(CONTEXT_MODULE,$this->cm->id);
|
||||
|
||||
if ($course) {
|
||||
$this->course = $course;
|
||||
} else if (! $this->course = get_record('course', 'id', $this->cm->course)) {
|
||||
error('Course is misconfigured');
|
||||
}
|
||||
|
||||
if ($assignment) {
|
||||
$this->assignment = $assignment;
|
||||
} else if (! $this->assignment = get_record('assignment', 'id', $this->cm->instance)) {
|
||||
error('assignment ID was incorrect');
|
||||
}
|
||||
|
||||
$this->strassignment = get_string('modulename', 'assignment');
|
||||
$this->strassignments = get_string('modulenameplural', 'assignment');
|
||||
$this->strsubmissions = get_string('submissions', 'assignment');
|
||||
$this->strlastmodified = get_string('lastmodified');
|
||||
|
||||
$this->navigation[] = array('name' => $this->strassignments, 'link' => "index.php?id={$this->course->id}", 'type' => 'activity');
|
||||
|
||||
$this->pagetitle = strip_tags($this->course->shortname.': '.$this->strassignment.': '.format_string($this->assignment->name,true));
|
||||
|
||||
// visibility
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cmid);
|
||||
if (!$this->cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)) {
|
||||
$pagetitle = strip_tags($this->course->shortname.': '.$this->strassignment);
|
||||
$this->navigation[] = array('name' => $this->strassignment, 'link' => '', 'type' => 'activityinstance');
|
||||
$navigation = build_navigation($this->navigation);
|
||||
|
||||
print_header($pagetitle, $this->course->fullname, "$this->navigation $this->strassignment",
|
||||
"", "", true, '', navmenu($this->course, $this->cm));
|
||||
notice(get_string("activityiscurrentlyhidden"), "$CFG->wwwroot/course/view.php?id={$this->course->id}");
|
||||
}
|
||||
$this->currentgroup = get_current_group($this->course->id);
|
||||
if ($cm) {
|
||||
$this->cm = $cm;
|
||||
} else if (! $this->cm = get_coursemodule_from_id('assignment', $cmid)) {
|
||||
debugging('grr');
|
||||
error('Course Module ID was incorrect');
|
||||
}
|
||||
|
||||
$this->context = get_context_instance(CONTEXT_MODULE,$this->cm->id);
|
||||
|
||||
if ($course) {
|
||||
$this->course = $course;
|
||||
} else if (! $this->course = get_record('course', 'id', $this->cm->course)) {
|
||||
error('Course is misconfigured');
|
||||
}
|
||||
|
||||
if ($assignment) {
|
||||
$this->assignment = $assignment;
|
||||
} else if (! $this->assignment = get_record('assignment', 'id', $this->cm->instance)) {
|
||||
error('assignment ID was incorrect');
|
||||
}
|
||||
|
||||
$this->assignment->cmidnumber = $cm->id; // compatibility with modedit assignment obj
|
||||
$this->assignment->courseid = $course->id; // compatibility with modedit assignment obj
|
||||
|
||||
$this->strassignment = get_string('modulename', 'assignment');
|
||||
$this->strassignments = get_string('modulenameplural', 'assignment');
|
||||
$this->strsubmissions = get_string('submissions', 'assignment');
|
||||
$this->strlastmodified = get_string('lastmodified');
|
||||
|
||||
$this->navigation[] = array('name' => $this->strassignments, 'link' => "index.php?id={$this->course->id}", 'type' => 'activity');
|
||||
|
||||
$this->pagetitle = strip_tags($this->course->shortname.': '.$this->strassignment.': '.format_string($this->assignment->name,true));
|
||||
|
||||
// visibility
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cmid);
|
||||
if (!$this->cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)) {
|
||||
$pagetitle = strip_tags($this->course->shortname.': '.$this->strassignment);
|
||||
$this->navigation[] = array('name' => $this->strassignment, 'link' => '', 'type' => 'activityinstance');
|
||||
$navigation = build_navigation($this->navigation);
|
||||
|
||||
print_header($pagetitle, $this->course->fullname, "$this->navigation $this->strassignment",
|
||||
"", "", true, '', navmenu($this->course, $this->cm));
|
||||
notice(get_string("activityiscurrentlyhidden"), "$CFG->wwwroot/course/view.php?id={$this->course->id}");
|
||||
}
|
||||
$this->currentgroup = get_and_set_current_group($this->course, groupmode($this->course, $this->cm));
|
||||
|
||||
/// Set up things for a HTML editor if it's needed
|
||||
if ($this->usehtmleditor = can_use_html_editor()) {
|
||||
$this->defaultformat = FORMAT_HTML;
|
||||
@@ -155,7 +163,11 @@ class assignment_base {
|
||||
true, update_module_button($this->cm->id, $this->course->id, $this->strassignment),
|
||||
navmenu($this->course, $this->cm));
|
||||
|
||||
$groupmode = groupmode($this->course, $this->cm);
|
||||
$currentgroup = setup_and_print_groups($this->course, $groupmode, 'view.php?id=' . $this->cm->id);
|
||||
|
||||
echo '<div class="reportlink">'.$this->submittedlink().'</div>';
|
||||
echo '<div class="clearer"></div>';
|
||||
}
|
||||
|
||||
|
||||
@@ -316,82 +328,6 @@ class assignment_base {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the setup form for the current assignment type
|
||||
*
|
||||
* Includes common.html and the assignment type's mod.html
|
||||
* This will be suitable for all assignment types
|
||||
*
|
||||
* @param $form object The object used to fill the form
|
||||
* @param $action url Default destination for this form
|
||||
*/
|
||||
function setup(&$form, $action='') {
|
||||
global $CFG, $THEME;
|
||||
|
||||
if (empty($this->course)) {
|
||||
if (! $this->course = get_record("course", "id", $form->course)) {
|
||||
error("Course is misconfigured");
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($action)) { // Default destination for this form
|
||||
$action = $CFG->wwwroot.'/course/mod.php';
|
||||
}
|
||||
|
||||
if (empty($form->assignmenttype)) {
|
||||
$form->assignmenttype = '';
|
||||
} else {
|
||||
$form->assignmenttype = clean_param($form->assignmenttype, PARAM_SAFEDIR);
|
||||
}
|
||||
|
||||
if (empty($form->name)) {
|
||||
$form->name = '';
|
||||
} else {
|
||||
$form->name = stripslashes($form->name);
|
||||
}
|
||||
|
||||
if (empty($form->description)) {
|
||||
$form->description = '';
|
||||
} else {
|
||||
$form->description = stripslashes($form->description);
|
||||
}
|
||||
|
||||
$strname = get_string('name');
|
||||
$strassignments = get_string('modulenameplural', 'assignment');
|
||||
$strheading = empty($form->name) ? get_string("type$form->assignmenttype",'assignment') : s(format_string(stripslashes($form->name),true));
|
||||
|
||||
print_header($this->course->shortname.': '.$strheading, $this->course->fullname,
|
||||
"<a href=\"$CFG->wwwroot/course/view.php?id={$this->course->id}\">{$this->course->shortname} </a> -> ".
|
||||
"<a href=\"$CFG->wwwroot/mod/assignment/index.php?id={$this->course->id}\">$strassignments</a> -> $strheading");
|
||||
|
||||
print_simple_box_start('center', '70%');
|
||||
print_heading(get_string('type'.$form->assignmenttype,'assignment'));
|
||||
print_simple_box(get_string('help'.$form->assignmenttype, 'assignment'), 'center');
|
||||
include("$CFG->dirroot/mod/assignment/type/common.html");
|
||||
|
||||
include("$CFG->dirroot/mod/assignment/type/".$form->assignmenttype."/mod.html");
|
||||
$this->setup_end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the end of the setup form for the current assignment type
|
||||
*
|
||||
* Includes common_end.html
|
||||
*/
|
||||
function setup_end() {
|
||||
global $CFG;
|
||||
|
||||
include($CFG->dirroot.'/mod/assignment/type/common_end.html');
|
||||
|
||||
print_simple_box_end();
|
||||
|
||||
if ($this->usehtmleditor) {
|
||||
use_html_editor();
|
||||
}
|
||||
|
||||
print_footer($this->course);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new assignment activity
|
||||
*
|
||||
@@ -406,13 +342,16 @@ class assignment_base {
|
||||
* @return int The id of the assignment
|
||||
*/
|
||||
function add_instance($assignment) {
|
||||
global $COURSE;
|
||||
|
||||
$assignment->timemodified = time();
|
||||
$assignment->courseid = $assignment->course;
|
||||
|
||||
if ($returnid = insert_record("assignment", $assignment)) {
|
||||
$assignment->id = $returnid;
|
||||
|
||||
if ($assignment->timedue) {
|
||||
$event = NULL;
|
||||
$event = new object();
|
||||
$event->name = $assignment->name;
|
||||
$event->description = $assignment->description;
|
||||
$event->courseid = $assignment->course;
|
||||
@@ -426,8 +365,13 @@ class assignment_base {
|
||||
|
||||
add_event($event);
|
||||
}
|
||||
|
||||
$assignment = stripslashes_recursive($assignment);
|
||||
assignment_base::create_grade_item($assignment);
|
||||
|
||||
}
|
||||
|
||||
|
||||
return $returnid;
|
||||
}
|
||||
|
||||
@@ -485,44 +429,134 @@ class assignment_base {
|
||||
* @return int The assignment id
|
||||
*/
|
||||
function update_instance($assignment) {
|
||||
global $COURSE;
|
||||
|
||||
$assignment->timemodified = time();
|
||||
|
||||
$assignment->id = $assignment->instance;
|
||||
$assignment->courseid = $assignment->course;
|
||||
|
||||
if ($returnid = update_record('assignment', $assignment)) {
|
||||
|
||||
if ($assignment->timedue) {
|
||||
$event = NULL;
|
||||
|
||||
if ($event->id = get_field('event', 'id', 'modulename', 'assignment', 'instance', $assignment->id)) {
|
||||
|
||||
$event->name = $assignment->name;
|
||||
$event->description = $assignment->description;
|
||||
$event->timestart = $assignment->timedue;
|
||||
|
||||
update_event($event);
|
||||
} else {
|
||||
$event = NULL;
|
||||
$event->name = $assignment->name;
|
||||
$event->description = $assignment->description;
|
||||
$event->courseid = $assignment->course;
|
||||
$event->groupid = 0;
|
||||
$event->userid = 0;
|
||||
$event->modulename = 'assignment';
|
||||
$event->instance = $assignment->id;
|
||||
$event->eventtype = 'due';
|
||||
$event->timestart = $assignment->timedue;
|
||||
$event->timeduration = 0;
|
||||
|
||||
add_event($event);
|
||||
}
|
||||
} else {
|
||||
delete_records('event', 'modulename', 'assignment', 'instance', $assignment->id);
|
||||
}
|
||||
if (!update_record('assignment', $assignment)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $returnid;
|
||||
if ($assignment->timedue) {
|
||||
$event = new object();
|
||||
|
||||
if ($event->id = get_field('event', 'id', 'modulename', 'assignment', 'instance', $assignment->id)) {
|
||||
|
||||
$event->name = $assignment->name;
|
||||
$event->description = $assignment->description;
|
||||
$event->timestart = $assignment->timedue;
|
||||
|
||||
update_event($event);
|
||||
} else {
|
||||
$event = new object();
|
||||
$event->name = $assignment->name;
|
||||
$event->description = $assignment->description;
|
||||
$event->courseid = $assignment->course;
|
||||
$event->groupid = 0;
|
||||
$event->userid = 0;
|
||||
$event->modulename = 'assignment';
|
||||
$event->instance = $assignment->id;
|
||||
$event->eventtype = 'due';
|
||||
$event->timestart = $assignment->timedue;
|
||||
$event->timeduration = 0;
|
||||
|
||||
add_event($event);
|
||||
}
|
||||
} else {
|
||||
delete_records('event', 'modulename', 'assignment', 'instance', $assignment->id);
|
||||
}
|
||||
|
||||
// get existing grade item
|
||||
$assignment = stripslashes_recursive($assignment);
|
||||
$grade_item = assignment_base::get_grade_item($assignment);
|
||||
$grade_item->idnumber = $assignment->cmidnumber;
|
||||
|
||||
if ($assignment->grade > 0) {
|
||||
$grade_item->gradetype = GRADE_TYPE_VALUE;
|
||||
$grade_item->grademax = $assignment->grade;
|
||||
$grade_item->grademin = 0;
|
||||
$grade_item->scaleid = 0;
|
||||
$grade_item->update();
|
||||
|
||||
} else if ($assignment->grade < 0) {
|
||||
$grade_item->gradetype = GRADE_TYPE_SCALE;
|
||||
$grade_item->scaleid = -$assignment->grade;
|
||||
$grade_item->update();
|
||||
|
||||
} else {
|
||||
//how to indicate no grading?
|
||||
$grade_item->gradetype = GRADE_TYPE_TEXT;
|
||||
$grade_item->grademax = 0;
|
||||
$grade_item->grademin = 0;
|
||||
$grade_item->scaleid = 0;
|
||||
$grade_item->update();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates grade item for assignment.
|
||||
* Static method - do not override!
|
||||
*/
|
||||
function create_grade_item($assignment) {
|
||||
$params = array('courseid'=>$assignment->courseid,
|
||||
'itemname'=>'assignment',
|
||||
'itemtype'=>'mod',
|
||||
'itemmodule'=>'assignment',
|
||||
'iteminstance'=>$assignment->id,
|
||||
'idnumber'=>$assignment->cmidnumber);
|
||||
|
||||
if ($assignment->grade > 0) {
|
||||
$params['gradetype'] = GRADE_TYPE_VALUE;
|
||||
$params['grademax'] = $assignment->grade;
|
||||
|
||||
} else if ($assignment->grade < 0) {
|
||||
$params['gradetype'] = GRADE_TYPE_SCALE;
|
||||
$params['scaleid'] = -$assignment->grade;
|
||||
|
||||
} else {
|
||||
//how to indicate no grading?
|
||||
$params['gradetype'] = GRADE_TYPE_TEXT;
|
||||
$params['grademax'] = $assignment->grade;
|
||||
$params['grademax'] = 0;
|
||||
$params['grademin'] = 0;
|
||||
}
|
||||
|
||||
$itemid = grade_create_item($params);
|
||||
return $itemid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns grade item for assignment.
|
||||
* Final static method - do not override!
|
||||
*/
|
||||
function get_grade_item($assignment) {
|
||||
if ($items = grade_get_items($assignment->courseid, NULL, 'mod', 'assignment', $assignment->id)) {
|
||||
$grade_item = reset($items);
|
||||
return $grade_item;
|
||||
}
|
||||
// create new one
|
||||
if (!$itemid = assignment_base::create_grade_item($assignment)) {
|
||||
error('Can not create grade item!');
|
||||
}
|
||||
return grade_item::fetch('id', $itemid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update grade item for assignment.
|
||||
* Final static method - do not override!
|
||||
*/
|
||||
function update_grade($sid) {
|
||||
$grade_item = assignment_base::get_grade_item($this->assignment);
|
||||
$sub = get_record('assignment_submissions', 'id', $sid);
|
||||
if ($sub->grade <0 ) {
|
||||
$sub->grade = null;
|
||||
}
|
||||
events_trigger('grade_added', array('itemid'=>$grade_item->id, 'gradevalue'=>$sub->grade, 'userid'=>$sub->userid, 'feedback'=>$sub->submissioncomment, 'feedbackformat'=>$sub->format));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -620,14 +654,19 @@ class assignment_base {
|
||||
|
||||
if ($updatedb){
|
||||
if ($newsubmission) {
|
||||
if (!insert_record('assignment_submissions', $submission)) {
|
||||
if (!$sid = insert_record('assignment_submissions', $submission)) {
|
||||
return false;
|
||||
}
|
||||
$submission->id = $sid;
|
||||
} else {
|
||||
if (!update_record('assignment_submissions', $submission)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// triger grade event
|
||||
$this->update_grade($submission->id);
|
||||
|
||||
//add to log only if updating
|
||||
add_to_log($this->course->id, 'assignment', 'update grades',
|
||||
'submissions.php?id='.$this->assignment->id.'&user='.$submission->userid,
|
||||
@@ -795,16 +834,11 @@ class assignment_base {
|
||||
$cm = $this->cm;
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
|
||||
/// Get all teachers and students
|
||||
/// Get all ppl that can submit assignments
|
||||
|
||||
$currentgroup = get_current_group($course->id);
|
||||
$currentgroup = get_and_set_current_group($course, groupmode($course, $cm));
|
||||
|
||||
if ($currentgroup) {
|
||||
$users = get_group_users($currentgroup);
|
||||
} else {
|
||||
$users = get_users_by_capability($context, 'mod/assignment:submit', 'u.id, u.id', '',
|
||||
'', '', '', '', false);
|
||||
}
|
||||
$users = get_users_by_capability($context, 'mod/assignment:submit', 'u.id, u.id', '', '', '', $currentgroup, '', false);
|
||||
|
||||
$select = 'SELECT u.id, u.firstname, u.lastname, u.picture,
|
||||
s.id AS submissionid, s.grade, s.submissioncomment,
|
||||
@@ -1001,45 +1035,15 @@ class assignment_base {
|
||||
$navigation = build_navigation($crumbs);
|
||||
|
||||
print_header_simple(format_string($this->assignment->name,true), "", $navigation, '', '', true, update_module_button($cm->id, $course->id, $this->strassignment), navmenu($course, $cm));
|
||||
|
||||
///Position swapped
|
||||
/*
|
||||
if ($groupmode = groupmode($course, $cm)) { // Groups are being used
|
||||
$currentgroup = setup_and_print_groups($course, $groupmode, 'submissions.php?id='.$this->cm->id);
|
||||
} else {
|
||||
$currentgroup = false;
|
||||
}
|
||||
*/
|
||||
|
||||
/// copied code from assignment module, if this is not the way to do this please change it
|
||||
/// the above code does not work
|
||||
/// set_and_print_groups() is not fully implemented as function groups_instance_print_grouping_selector()
|
||||
/// and function groups_instance_print_group_selector() are missing.
|
||||
|
||||
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
$changegroup = optional_param('group', -1, PARAM_INT); // choose the current group
|
||||
|
||||
/// find out current groups mode
|
||||
$groupmode = groupmode($course, $cm);
|
||||
$currentgroup = get_and_set_current_group($course, $groupmode, $changegroup);
|
||||
|
||||
/// Now we need a menu for separategroups as well!
|
||||
if ($groupmode == VISIBLEGROUPS || ($groupmode
|
||||
&& has_capability('moodle/site:accessallgroups', $context))) {
|
||||
|
||||
//the following query really needs to change
|
||||
if ($groups = groups_get_groups_names($course->id)) { //TODO:
|
||||
print_box_start('groupmenu');
|
||||
print_group_menu($groups, $groupmode, $currentgroup, 'submissions.php?id='.$this->cm->id);
|
||||
print_box_end(); // groupmenu
|
||||
}
|
||||
}
|
||||
|
||||
/// Get all teachers and students
|
||||
if ($currentgroup) {
|
||||
$users = get_group_users($currentgroup);
|
||||
} else {
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
$users = get_users_by_capability($context, 'mod/assignment:submit'); // everyone with this capability set to non-prohibit
|
||||
}
|
||||
$currentgroup = setup_and_print_groups($course, $groupmode, 'submissions.php?id=' . $this->cm->id);
|
||||
|
||||
/// Get all ppl that are allowed to submit assignments
|
||||
$users = get_users_by_capability($context, 'mod/assignment:submit', '', '', '', '', $currentgroup, '', false);
|
||||
|
||||
$tablecolumns = array('picture', 'fullname', 'grade', 'submissioncomment', 'timemodified', 'timemarked', 'status');
|
||||
$tableheaders = array('', get_string('fullname'), get_string('grade'), get_string('comment', 'assignment'), get_string('lastmodified').' ('.$course->student.')', get_string('lastmodified').' ('.$course->teacher.')', get_string('status'));
|
||||
@@ -1301,6 +1305,9 @@ class assignment_base {
|
||||
return false;
|
||||
}
|
||||
|
||||
// triger grade event
|
||||
$this->update_grade($submission->id);
|
||||
|
||||
add_to_log($this->course->id, 'assignment', 'update grades',
|
||||
'submissions.php?id='.$this->assignment->id.'&user='.$feedback->userid, $feedback->userid, $this->cm->id);
|
||||
|
||||
@@ -1426,8 +1433,8 @@ class assignment_base {
|
||||
*/
|
||||
function get_graders($user) {
|
||||
//potential graders
|
||||
$potgraders = get_users_by_capability($this->context, 'mod/assignment:grade', $fields='', $sort='', $limitfrom='',
|
||||
$limitnum='', $groups='', $exceptions='', $doanything=false, $view=false);
|
||||
$potgraders = get_users_by_capability($this->context, 'mod/assignment:grade', '', '', '', '', '', '', false, false);
|
||||
|
||||
$graders = array();
|
||||
if (groupmode($this->course, $this->cm) == SEPARATEGROUPS) { // Separate groups are being used
|
||||
if ($groups = user_group($this->course->id, $user->id)) { // Try to find all groups
|
||||
@@ -2253,7 +2260,7 @@ function assignment_count_real_submissions($assignment, $groupid=0) {
|
||||
global $CFG;
|
||||
|
||||
if ($groupid) { /// How many in a particular group?
|
||||
return count_records_sql("SELECT COUNT(DISTINCT g.userid, g.groupid)
|
||||
return count_records_sql("SELECT COUNT(DISTINCT gm.userid, gm.groupid)
|
||||
FROM {$CFG->prefix}assignment_submissions a,
|
||||
".groups_members_from_sql()."
|
||||
WHERE a.assignment = $assignment->id
|
||||
@@ -2264,7 +2271,7 @@ function assignment_count_real_submissions($assignment, $groupid=0) {
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
|
||||
// this is all the users with this capability set, in this context or higher
|
||||
if ($users = get_users_by_capability($context, 'mod/assignment:submit')) {
|
||||
if ($users = get_users_by_capability($context, 'mod/assignment:submit', '', '', '', '', 0, '', false)) {
|
||||
foreach ($users as $user) {
|
||||
$array[] = $user->id;
|
||||
}
|
||||
@@ -2483,8 +2490,8 @@ function assignment_print_overview($courses, &$htmlarray) {
|
||||
|
||||
// count how many people can submit
|
||||
$submissions = 0; // init
|
||||
if ($students = get_users_by_capability($context, 'mod/assignment:submit')) {
|
||||
foreach ($students as $student) {
|
||||
if ($students = get_users_by_capability($context, 'mod/assignment:submit', '', '', '', '', 0, '', false)) {
|
||||
foreach ($students as $student) {
|
||||
if (get_records_sql("SELECT id,id FROM {$CFG->prefix}assignment_submissions
|
||||
WHERE assignment = $assignment->id AND
|
||||
userid = $student->id AND
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
<form id="form" method="post" action="<?php p($action) ?>">
|
||||
<fieldset class="invisiblefieldset">
|
||||
<?php
|
||||
$form->sesskey = sesskey();
|
||||
|
||||
// Pass variables through
|
||||
foreach ($form as $assname => $assvalue) {
|
||||
echo '<input type="hidden" name="'.$assname.'" value="'.s($assvalue).'" />'."\n";
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,2 +0,0 @@
|
||||
</fieldset>
|
||||
</form>
|
||||
@@ -6,8 +6,8 @@
|
||||
*/
|
||||
class assignment_offline extends assignment_base {
|
||||
|
||||
function assignment_offline($cmid=0) {
|
||||
parent::assignment_base($cmid);
|
||||
function assignment_offline($cmid='staticonly', $assignment=NULL, $cm=NULL, $course=NULL) {
|
||||
parent::assignment_base($cmid, $assignment, $cm, $course);
|
||||
}
|
||||
|
||||
function display_lateness($timesubmitted) {
|
||||
@@ -75,6 +75,9 @@ class assignment_offline extends assignment_base {
|
||||
return false;
|
||||
}
|
||||
|
||||
// triger grade event
|
||||
$this->update_grade($submission->id);
|
||||
|
||||
add_to_log($this->course->id, 'assignment', 'update grades',
|
||||
'submissions.php?id='.$this->assignment->id.'&user='.$feedback->userid, $feedback->userid, $this->cm->id);
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ require_once($CFG->libdir.'/formslib.php');
|
||||
*/
|
||||
class assignment_online extends assignment_base {
|
||||
|
||||
function assignment_online($cmid=0) {
|
||||
parent::assignment_base($cmid);
|
||||
function assignment_online($cmid='staticonly', $assignment=NULL, $cm=NULL, $course=NULL) {
|
||||
parent::assignment_base($cmid, $assignment, $cm, $course);
|
||||
}
|
||||
|
||||
function view() {
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
<input type="hidden" name=grade value="<?php p($form->grade) ?>" />
|
||||
<input type="hidden" name=course value="<?php p($form->course) ?>" />
|
||||
<input type="hidden" name=coursemodule value="<?php p($form->coursemodule) ?>" />
|
||||
<input type="hidden" name=section value="<?php p($form->section) ?>" />
|
||||
<input type="hidden" name=module value="<?php p($form->module) ?>" />
|
||||
<input type="hidden" name=modulename value="<?php p($form->modulename) ?>" />
|
||||
<input type="hidden" name=instance value="<?php p($form->instance) ?>" />
|
||||
<input type="hidden" name=mode value="<?php p($form->mode) ?>" />
|
||||
|
||||
<input type="hidden" name=name value="<?php p($form->name) ?>" />
|
||||
<input type="hidden" name=description value="<?php p($form->description) ?>" />
|
||||
<input type="hidden" name=format value="<?php p($form->format) ?>" />
|
||||
<input type="hidden" name=type value="<?php p($form->type) ?>" />
|
||||
<input type="hidden" name=closestate value="<?php p($form->closestate) ?>" />
|
||||
<input type="hidden" name=availableday value="<?php p($form->availableday) ?>" />
|
||||
<input type="hidden" name=availablemonth value="<?php p($form->availablemonth) ?>" />
|
||||
<input type="hidden" name=availableyear value="<?php p($form->availableyear) ?>" />
|
||||
<input type="hidden" name=availablehour value="<?php p($form->availablehour) ?>" />
|
||||
<input type="hidden" name=availableminute value="<?php p($form->availableminute) ?>" />
|
||||
<input type="hidden" name=dueday value="<?php p($form->dueday) ?>" />
|
||||
<input type="hidden" name=duemonth value="<?php p($form->duemonth) ?>" />
|
||||
<input type="hidden" name=dueyear value="<?php p($form->dueyear) ?>" />
|
||||
<input type="hidden" name=duehour value="<?php p($form->duehour) ?>" />
|
||||
<input type="hidden" name=dueminute value="<?php p($form->dueminute) ?>" />
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ define('ASSIGNMENT_STATUS_SUBMITTED', 'submitted');
|
||||
*/
|
||||
class assignment_upload extends assignment_base {
|
||||
|
||||
function assignment_upload($cmid=0) {
|
||||
parent::assignment_base($cmid);
|
||||
function assignment_upload($cmid='staticonly', $assignment=NULL, $cm=NULL, $course=NULL) {
|
||||
parent::assignment_base($cmid, $assignment, $cm, $course);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -39,8 +39,8 @@ class assignment_uploadsingle extends assignment_base {
|
||||
return $output;
|
||||
}
|
||||
|
||||
function assignment_uploadsingle($cmid=0) {
|
||||
parent::assignment_base($cmid);
|
||||
function assignment_uploadsingle($cmid='staticonly', $assignment=NULL, $cm=NULL, $course=NULL) {
|
||||
parent::assignment_base($cmid, $assignment, $cm, $course);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
// This fragment is called by /admin/index.php
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
$module->version = 2007020200;
|
||||
$module->requires = 2007020200; // Requires this Moodle version
|
||||
$module->version = 2007052700;
|
||||
$module->requires = 2007052700; // Requires this Moodle version
|
||||
$module->cron = 60;
|
||||
|
||||
?>
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
// This is compared against the values stored in the database to determine
|
||||
// whether upgrades should be performed (see lib/db/*.php)
|
||||
|
||||
$version = 2007052200; // YYYYMMDD = date
|
||||
$version = 2007052700; // YYYYMMDD = date
|
||||
// XY = increments within a single day
|
||||
|
||||
$release = '1.9 dev'; // Human-friendly version name
|
||||
|
||||
Reference in New Issue
Block a user