mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +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 {
|
||||||
|
|
|
@ -230,21 +230,21 @@
|
||||||
/// If we are in approval mode, prit special header
|
/// If we are in approval mode, prit special header
|
||||||
if ($tab == GLOSSARY_APPROVAL_VIEW) {
|
if ($tab == GLOSSARY_APPROVAL_VIEW) {
|
||||||
require_capability('mod/glossary:approve', $context);
|
require_capability('mod/glossary:approve', $context);
|
||||||
|
|
||||||
$crumbs[] = array('name' => $strwaitingapproval, 'link' => '', 'type' => 'title');
|
$crumbs[] = array('name' => $strwaitingapproval, 'link' => '', 'type' => 'title');
|
||||||
$navigation = build_navigation($crumbs);
|
$navigation = build_navigation($crumbs);
|
||||||
|
|
||||||
print_header_simple(format_string($glossary->name), "", $navigation, "", "", true,
|
print_header_simple(format_string($glossary->name), "", $navigation, "", "", true,
|
||||||
update_module_button($cm->id, $course->id, $strglossary), navmenu($course, $cm));
|
update_module_button($cm->id, $course->id, $strglossary), navmenu($course, $cm));
|
||||||
|
|
||||||
print_heading($strwaitingapproval);
|
print_heading($strwaitingapproval);
|
||||||
} else { /// Print standard header
|
} else { /// Print standard header
|
||||||
$navigation = build_navigation($crumbs);
|
$navigation = build_navigation($crumbs);
|
||||||
print_header_simple(format_string($glossary->name), "", $navigation, "", "", true,
|
print_header_simple(format_string($glossary->name), "", $navigation, "", "", true,
|
||||||
update_module_button($cm->id, $course->id, $strglossary), navmenu($course, $cm));
|
update_module_button($cm->id, $course->id, $strglossary), navmenu($course, $cm));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// All this depends if whe have $showcommonelements
|
/// All this depends if whe have $showcommonelements
|
||||||
if ($showcommonelements) {
|
if ($showcommonelements) {
|
||||||
/// To calculate available options
|
/// To calculate available options
|
||||||
$availableoptions = '';
|
$availableoptions = '';
|
||||||
|
@ -263,7 +263,7 @@
|
||||||
$availableoptions .= ' / ';
|
$availableoptions .= ' / ';
|
||||||
}
|
}
|
||||||
$availableoptions .='<span class="helplink">' .
|
$availableoptions .='<span class="helplink">' .
|
||||||
'<a href="' . $CFG->wwwroot . '/mod/glossary/export.php?id=' . $cm->id .
|
'<a href="' . $CFG->wwwroot . '/mod/glossary/export.php?id=' . $cm->id .
|
||||||
'&mode='.$mode . '&hook=' . urlencode($hook) . '"' .
|
'&mode='.$mode . '&hook=' . urlencode($hook) . '"' .
|
||||||
' title="' . s(get_string('exportentries', 'glossary')) . '">' .
|
' title="' . s(get_string('exportentries', 'glossary')) . '">' .
|
||||||
get_string('exportentries', 'glossary') . '</a>' .
|
get_string('exportentries', 'glossary') . '</a>' .
|
||||||
|
@ -278,7 +278,7 @@
|
||||||
$availableoptions .= '<br />';
|
$availableoptions .= '<br />';
|
||||||
}
|
}
|
||||||
$availableoptions .='<span class="helplink">' .
|
$availableoptions .='<span class="helplink">' .
|
||||||
'<a href="' . $CFG->wwwroot . '/mod/glossary/view.php?id=' . $cm->id .
|
'<a href="' . $CFG->wwwroot . '/mod/glossary/view.php?id=' . $cm->id .
|
||||||
'&mode=approval' . '"' .
|
'&mode=approval' . '"' .
|
||||||
' title="' . s(get_string('waitingapproval', 'glossary')) . '">' .
|
' title="' . s(get_string('waitingapproval', 'glossary')) . '">' .
|
||||||
get_string('waitingapproval', 'glossary') . ' ('.$hiddenentries.')</a>' .
|
get_string('waitingapproval', 'glossary') . ' ('.$hiddenentries.')</a>' .
|
||||||
|
@ -293,7 +293,7 @@
|
||||||
/// If rss are activated at site and glossary level and this glossary has rss defined, show link
|
/// If rss are activated at site and glossary level and this glossary has rss defined, show link
|
||||||
if (isset($CFG->enablerssfeeds) && isset($CFG->glossary_enablerssfeeds) &&
|
if (isset($CFG->enablerssfeeds) && isset($CFG->glossary_enablerssfeeds) &&
|
||||||
$CFG->enablerssfeeds && $CFG->glossary_enablerssfeeds && $glossary->rsstype && $glossary->rssarticles) {
|
$CFG->enablerssfeeds && $CFG->glossary_enablerssfeeds && $glossary->rsstype && $glossary->rssarticles) {
|
||||||
|
|
||||||
$tooltiptext = get_string("rsssubscriberss","glossary",format_string($glossary->name,true));
|
$tooltiptext = get_string("rsssubscriberss","glossary",format_string($glossary->name,true));
|
||||||
if (empty($USER->id)) {
|
if (empty($USER->id)) {
|
||||||
$userid = 0;
|
$userid = 0;
|
||||||
|
@ -302,7 +302,7 @@
|
||||||
}
|
}
|
||||||
print_box_start('rsslink');
|
print_box_start('rsslink');
|
||||||
rss_print_link($course->id, $userid, "glossary", $glossary->id, $tooltiptext);
|
rss_print_link($course->id, $userid, "glossary", $glossary->id, $tooltiptext);
|
||||||
print_box_end();
|
print_box_end();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The print icon
|
/// The print icon
|
||||||
|
@ -310,7 +310,7 @@
|
||||||
if (has_capability('mod/glossary:manageentries', $context) or $glossary->allowprintview) {
|
if (has_capability('mod/glossary:manageentries', $context) or $glossary->allowprintview) {
|
||||||
print_box_start('printicon');
|
print_box_start('printicon');
|
||||||
echo " <a title =\"". get_string("printerfriendly","glossary") ."\" href=\"print.php?id=$cm->id&mode=$mode&hook=".urlencode($hook)."&sortkey=$sortkey&sortorder=$sortorder&offset=$offset\"><img class=\"icon\" src=\"print.gif\" alt=\"". get_string("printerfriendly","glossary") . "\" /></a>";
|
echo " <a title =\"". get_string("printerfriendly","glossary") ."\" href=\"print.php?id=$cm->id&mode=$mode&hook=".urlencode($hook)."&sortkey=$sortkey&sortorder=$sortorder&offset=$offset\"><img class=\"icon\" src=\"print.gif\" alt=\"". get_string("printerfriendly","glossary") . "\" /></a>";
|
||||||
print_box_end();
|
print_box_end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// End glossary controls
|
/// End glossary controls
|
||||||
|
@ -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) {
|
||||||
|
@ -422,8 +422,8 @@
|
||||||
// Reduce pivot to 1cc if necessary
|
// Reduce pivot to 1cc if necessary
|
||||||
if ( !$fullpivot ) {
|
if ( !$fullpivot ) {
|
||||||
$upperpivot = $textlib->substr($upperpivot, 0, 1);
|
$upperpivot = $textlib->substr($upperpivot, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if there's a group break
|
// if there's a group break
|
||||||
if ( $currentpivot != $upperpivot ) {
|
if ( $currentpivot != $upperpivot ) {
|
||||||
|
|
||||||
|
@ -498,15 +498,15 @@
|
||||||
print_scale_menu_helpbutton($course->id, $scale );
|
print_scale_menu_helpbutton($course->id, $scale );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo "</div>";
|
echo "</div>";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($formsent)) {
|
if (!empty($formsent)) {
|
||||||
// close the form properly if used
|
// close the form properly if used
|
||||||
echo "</div>";
|
echo "</div>";
|
||||||
echo "</form>";
|
echo "</form>";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $paging ) {
|
if ( $paging ) {
|
||||||
echo '<hr />';
|
echo '<hr />';
|
||||||
echo '<div class="paging">';
|
echo '<div class="paging">';
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue