mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-9549 some more grading and rating improvements, cleanup and fixes
This commit is contained in:
parent
3e6303b7be
commit
dd232d0100
3 changed files with 67 additions and 73 deletions
|
@ -72,7 +72,6 @@ function glossary_add_instance($glossary) {
|
||||||
|
|
||||||
$glossary->timecreated = time();
|
$glossary->timecreated = time();
|
||||||
$glossary->timemodified = $glossary->timecreated;
|
$glossary->timemodified = $glossary->timecreated;
|
||||||
$glossary->courseid = $glossary->course;
|
|
||||||
|
|
||||||
//Check displayformat is a valid one
|
//Check displayformat is a valid one
|
||||||
$formats = get_list_of_plugins('mod/glossary/formats','TEMPLATE');
|
$formats = get_list_of_plugins('mod/glossary/formats','TEMPLATE');
|
||||||
|
@ -107,7 +106,6 @@ function glossary_update_instance($glossary) {
|
||||||
|
|
||||||
$glossary->timemodified = time();
|
$glossary->timemodified = time();
|
||||||
$glossary->id = $glossary->instance;
|
$glossary->id = $glossary->instance;
|
||||||
$glossary->courseid = $glossary->course;
|
|
||||||
|
|
||||||
if (empty($glossary->userating)) {
|
if (empty($glossary->userating)) {
|
||||||
$glossary->assessed = 0;
|
$glossary->assessed = 0;
|
||||||
|
@ -145,8 +143,6 @@ function glossary_delete_instance($id) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$glossary->courseid = $glossary->course;
|
|
||||||
|
|
||||||
$result = true;
|
$result = true;
|
||||||
|
|
||||||
# Delete any dependent records here #
|
# Delete any dependent records here #
|
||||||
|
@ -365,7 +361,7 @@ function glossary_update_grades($grade_item=null, $userid=0, $deleteifnone=true)
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$sql = "SELECT g.*, cm.idnumber as cmidnumber, g.course as courseid
|
$sql = "SELECT g.*, cm.idnumber as cmidnumber
|
||||||
FROM {$CFG->prefix}glossary g, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
|
FROM {$CFG->prefix}glossary g, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
|
||||||
WHERE m.name='glossary' AND m.id=cm.module AND cm.instance=g.id";
|
WHERE m.name='glossary' AND m.id=cm.module AND cm.instance=g.id";
|
||||||
if ($rs = get_recordset_sql($sql)) {
|
if ($rs = get_recordset_sql($sql)) {
|
||||||
|
@ -386,35 +382,43 @@ function glossary_update_grades($grade_item=null, $userid=0, $deleteifnone=true)
|
||||||
/**
|
/**
|
||||||
* Return (create if needed) grade item for given glossary
|
* Return (create if needed) grade item for given glossary
|
||||||
*
|
*
|
||||||
* @param object $glossary object with extra cmidnumber and courseid property
|
* @param object $glossary object with optional cmidnumber
|
||||||
* @return object grade_item
|
* @return object grade_item
|
||||||
*/
|
*/
|
||||||
function glossary_grade_item_get($glossary) {
|
function glossary_grade_item_get($glossary) {
|
||||||
if ($items = grade_get_items($glossary->courseid, 'mod', 'glossary', $glossary->id)) {
|
if ($items = grade_get_items($glossary->course, 'mod', 'glossary', $glossary->id)) {
|
||||||
if (count($items) > 1) {
|
if (count($items) > 1) {
|
||||||
debugging('Multiple grade items present!');
|
debugging('Multiple grade items present!');
|
||||||
}
|
}
|
||||||
$grade_item = reset($items);
|
$grade_item = reset($items);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
if (!isset($glossary->cmidnumber)) {
|
||||||
|
if (!$cm = get_coursemodule_from_instance('glossary', $glossary->id)) {
|
||||||
|
error("Course Module ID was incorrect");
|
||||||
|
}
|
||||||
|
$glossary->cmidnumber = $cm->idnumber;
|
||||||
|
}
|
||||||
if (!$itemid = glossary_grade_item_create($glossary)) {
|
if (!$itemid = glossary_grade_item_create($glossary)) {
|
||||||
error('Can not create grade item!');
|
error('Can not create grade item!');
|
||||||
}
|
}
|
||||||
$grade_item = grade_item::fetch('id', $itemid);
|
$grade_item = grade_item::fetch('id', $itemid);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $grade_item;
|
return $grade_item;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update grade item for given glossary
|
* Update grade item for given glossary
|
||||||
*
|
*
|
||||||
* @param object $glossary object with extra cmidnumber and courseid property
|
* @param object $glossary object with extra cmidnumber
|
||||||
* @return object grade_item
|
* @return object grade_item
|
||||||
*/
|
*/
|
||||||
function glossary_grade_item_update($glossary) {
|
function glossary_grade_item_update($glossary) {
|
||||||
$grade_item = glossary_grade_item_get($glossary);
|
$grade_item = glossary_grade_item_get($glossary);
|
||||||
|
|
||||||
$grade_item->name = $glossary->name;
|
$grade_item->name = $glossary->name;
|
||||||
$grade_item->cmidnumber = $glossary->cmidnumber;
|
$grade_item->idnumber = $glossary->cmidnumber;
|
||||||
|
|
||||||
if (!$glossary->assessed) {
|
if (!$glossary->assessed) {
|
||||||
//how to indicate no grading?
|
//how to indicate no grading?
|
||||||
|
@ -436,11 +440,11 @@ function glossary_grade_item_update($glossary) {
|
||||||
/**
|
/**
|
||||||
* Create grade item for given glossary
|
* Create grade item for given glossary
|
||||||
*
|
*
|
||||||
* @param object $glossary object with extra cmidnumber and courseid property
|
* @param object $glossary object with extra cmidnumber
|
||||||
* @return object grade_item
|
* @return object grade_item
|
||||||
*/
|
*/
|
||||||
function glossary_grade_item_create($glossary) {
|
function glossary_grade_item_create($glossary) {
|
||||||
$params = array('courseid' =>$glossary->courseid,
|
$params = array('courseid' =>$glossary->course,
|
||||||
'itemtype' =>'mod',
|
'itemtype' =>'mod',
|
||||||
'itemmodule' =>'glossary',
|
'itemmodule' =>'glossary',
|
||||||
'iteminstance'=>$glossary->id,
|
'iteminstance'=>$glossary->id,
|
||||||
|
@ -468,11 +472,11 @@ function glossary_grade_item_create($glossary) {
|
||||||
/**
|
/**
|
||||||
* Delete grade item for given glossary
|
* Delete grade item for given glossary
|
||||||
*
|
*
|
||||||
* @param object $glossary object with extra cmidnumber and courseid property
|
* @param object $glossary object
|
||||||
* @return object grade_item
|
* @return object grade_item
|
||||||
*/
|
*/
|
||||||
function glossary_grade_item_delete($glossary) {
|
function glossary_grade_item_delete($glossary) {
|
||||||
if ($grade_items = grade_get_items($glossary->courseid, 'mod', 'glossary', $glossary->id)) {
|
if ($grade_items = grade_get_items($glossary->course, 'mod', 'glossary', $glossary->id)) {
|
||||||
foreach($grade_items as $grade_item) {
|
foreach($grade_items as $grade_item) {
|
||||||
$grade_item->delete();
|
$grade_item->delete();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,26 +3,48 @@
|
||||||
// Collect ratings, store them, then return to where we came from
|
// Collect ratings, store them, then return to where we came from
|
||||||
|
|
||||||
|
|
||||||
require_once("../../config.php");
|
require_once('../../config.php');
|
||||||
require_once("lib.php");
|
require_once('lib.php');
|
||||||
|
|
||||||
|
$glossaryid = required_param('glossaryid', PARAM_INT); // The forum the rated posts are from
|
||||||
|
|
||||||
$id = required_param('id', PARAM_INT); // The course these ratings are part of
|
if (!$glossary = get_record('glossary', 'id', $glossaryid)) {
|
||||||
|
error("Incorrect glossary id");
|
||||||
|
}
|
||||||
|
|
||||||
if (! $course = get_record("course", "id", $id)) {
|
if (!$course = get_record('course', 'id', $glossary->course)) {
|
||||||
error("Course ID was incorrect");
|
error("Course ID was incorrect");
|
||||||
}
|
}
|
||||||
|
|
||||||
require_login($course);
|
if (!$cm = get_coursemodule_from_instance('glossary', $glossary->id)) {
|
||||||
|
error("Course Module ID was incorrect");
|
||||||
|
}
|
||||||
|
|
||||||
|
require_login($course, false, $cm);
|
||||||
|
|
||||||
if (isguestuser()) {
|
if (isguestuser()) {
|
||||||
error("Guests are not allowed to rate entries.");
|
error("Guests are not allowed to rate entries.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$returnurl = isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : null;
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||||
|
|
||||||
$glossary = false;
|
if (!$glossary->assessed) {
|
||||||
if ($data = data_submitted("$CFG->wwwroot/mod/glossary/view.php")) { // form submitted
|
error("Rating of items not allowed!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($glossary->assessed == 2) {
|
||||||
|
require_capability('mod/glossary:rate', $context);
|
||||||
|
}
|
||||||
|
|
||||||
|
$grade_item = glossary_grade_item_get($glossary);
|
||||||
|
|
||||||
|
if (!empty($_SERVER['HTTP_REFERER'])) {
|
||||||
|
$returnurl = $_SERVER['HTTP_REFERER'];
|
||||||
|
} else {
|
||||||
|
$returnurl = $CFG->wwwroot.'/mod/glossary/view.php?id='.$cm->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($data = data_submitted()) { // form submitted
|
||||||
foreach ((array)$data as $entryid => $rating) {
|
foreach ((array)$data as $entryid => $rating) {
|
||||||
if (!is_numeric($entryid)) {
|
if (!is_numeric($entryid)) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -30,42 +52,14 @@
|
||||||
if (!$entry = get_record('glossary_entries', 'id', $entryid)) {
|
if (!$entry = get_record('glossary_entries', 'id', $entryid)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!$glossary) {
|
|
||||||
if (!$glossary = get_record('glossary', 'id', $entry->glossaryid)) {
|
|
||||||
error('Incorrect glossary id');
|
|
||||||
}
|
|
||||||
if (!$cm = get_coursemodule_from_instance('glossary', $glossary->id)) {
|
|
||||||
error("Course Module ID was incorrect");
|
|
||||||
}
|
|
||||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
|
||||||
|
|
||||||
require_login($course, false, $cm);
|
|
||||||
|
|
||||||
if (!$glossary->assessed) {
|
|
||||||
error('Rating of items not allowed!');
|
|
||||||
}
|
|
||||||
if ($glossary->assessed == 2 and !has_capability('mod/glossary:rate', $context)) {
|
|
||||||
error('You can not rate items!');
|
|
||||||
}
|
|
||||||
|
|
||||||
// add extra info into glossary object
|
|
||||||
$glossary->courseid = $course->id;
|
|
||||||
$glossary->cmidnumber = $cm->idnumber;
|
|
||||||
|
|
||||||
$grade_item = glossary_grade_item_get($glossary);
|
|
||||||
|
|
||||||
if (empty($returnurl)) {
|
|
||||||
$returnurl = $CFG->wwwroot.'/mod/glossary/view.php?id='.$cm->id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($entry->glossaryid != $glossary->id) {
|
if ($entry->glossaryid != $glossary->id) {
|
||||||
error('This is not valid entry!!');
|
error("This is not valid entry!");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($glossary->assesstimestart and $glossary->assesstimefinish) {
|
if ($glossary->assesstimestart and $glossary->assesstimefinish) {
|
||||||
if ($entry->timecreated < $glossary->assesstimestart or $entry->timecreated > $glossary->assesstimefinish) {
|
if ($entry->timecreated < $glossary->assesstimestart or $entry->timecreated > $glossary->assesstimefinish) {
|
||||||
// we can not grade this, ignore it - this should not happen anyway unless teachr changes setting
|
// we can not rate this, ignore it - this should not happen anyway unless teacher changes setting
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,6 +83,7 @@
|
||||||
}
|
}
|
||||||
glossary_update_grades($grade_item, $entry->userid);
|
glossary_update_grades($grade_item, $entry->userid);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if ($rating >= 0) {
|
} else if ($rating >= 0) {
|
||||||
$newrating = new object();
|
$newrating = new object();
|
||||||
$newrating->userid = $USER->id;
|
$newrating->userid = $USER->id;
|
||||||
|
@ -103,11 +98,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$glossary) {
|
|
||||||
// something wrong happended - no rating changed/added
|
|
||||||
error('Incorrect ratings submitted');
|
|
||||||
}
|
|
||||||
|
|
||||||
redirect($returnurl, get_string("ratingssaved", "glossary"));
|
redirect($returnurl, get_string("ratingssaved", "glossary"));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -411,7 +411,7 @@
|
||||||
|
|
||||||
echo "<form method=\"post\" action=\"rate.php\">";
|
echo "<form method=\"post\" action=\"rate.php\">";
|
||||||
echo "<div>";
|
echo "<div>";
|
||||||
echo "<input type=\"hidden\" name=\"id\" value=\"$course->id\" />";
|
echo "<input type=\"hidden\" name=\"glossaryid\" value=\"$glossary->id\" />";
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($allentries as $entry) {
|
foreach ($allentries as $entry) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue