rating MDL-21657 removed old per module rating implementations
This commit is contained in:
@@ -1,104 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once('../../config.php');
|
||||
require_once('lib.php');
|
||||
|
||||
$dataid = required_param('dataid', PARAM_INT); // The forum the rated posts are from
|
||||
|
||||
$PAGE->set_url('/mod/data/rate.php', array('dataid'=>$dataid));
|
||||
|
||||
if (!$data = $DB->get_record('data', array('id'=>$dataid))) {
|
||||
print_error('invalidid', 'data');
|
||||
}
|
||||
|
||||
if (!$course = $DB->get_record('course', array('id'=>$data->course))) {
|
||||
print_error('invalidcourseid');
|
||||
}
|
||||
|
||||
if (!$cm = get_coursemodule_from_instance('data', $data->id)) {
|
||||
print_error('invalidcoursemodule');
|
||||
} else {
|
||||
$data->cmidnumber = $cm->id; //MDL-12961
|
||||
}
|
||||
|
||||
require_login($course, false, $cm);
|
||||
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
require_capability('mod/data:rate', $context);
|
||||
|
||||
if (!$data->assessed) {
|
||||
print_error('cannotrate', 'data');
|
||||
}
|
||||
|
||||
if (!$frmdata = data_submitted() or !confirm_sesskey()) {
|
||||
print_error('invalidaccess', 'data');
|
||||
}
|
||||
|
||||
/// Calculate scale values
|
||||
$scale_values = make_grades_menu($data->scale);
|
||||
|
||||
$count = 0;
|
||||
|
||||
foreach ((array)$frmdata as $recordid => $rating) {
|
||||
if (!is_numeric($recordid)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$record = $DB->get_record('data_records', array('id'=>$recordid))) {
|
||||
print_error('invalidid', 'data');
|
||||
}
|
||||
|
||||
if ($data->id != $record->dataid) {
|
||||
print_error('invalidrecord', 'data');
|
||||
}
|
||||
|
||||
if ($record->userid == $USER->id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/// Check rate is valid for that database scale values
|
||||
if (!array_key_exists($rating, $scale_values) && $rating != -999) {
|
||||
print_error('invalidrate', 'data', '', $rating);
|
||||
}
|
||||
|
||||
// input validation ok
|
||||
|
||||
$count++;
|
||||
|
||||
if ($oldrating = $DB->get_record('data_ratings', array('userid'=>$USER->id, 'recordid'=>$record->id))) {
|
||||
if ($rating == -999) {
|
||||
$DB->delete_records('data_ratings', array('userid'=>$oldrating->userid, 'recordid'=>$oldrating->recordid));
|
||||
data_update_grades($data, $record->userid);
|
||||
|
||||
} else if ($rating != $oldrating->rating) {
|
||||
$oldrating->rating = $rating;
|
||||
$DB->update_record('data_ratings', $oldrating);
|
||||
data_update_grades($data, $record->userid);
|
||||
|
||||
}
|
||||
|
||||
} else if ($rating) {
|
||||
$newrating = new object();
|
||||
$newrating->userid = $USER->id;
|
||||
$newrating->recordid = $record->id;
|
||||
$newrating->rating = $rating;
|
||||
$DB->insert_record('data_ratings', $newrating);
|
||||
data_update_grades($data, $record->userid);
|
||||
}
|
||||
}
|
||||
|
||||
if ($count == 0) {
|
||||
print_error('invalidratedata', 'data');
|
||||
}
|
||||
|
||||
if (!empty($_SERVER['HTTP_REFERER'])) {
|
||||
redirect($_SERVER['HTTP_REFERER'], get_string('ratingssaved', 'data'));
|
||||
} else {
|
||||
// try to guess where to return
|
||||
if ($count == 1) {
|
||||
redirect('view.php?mode=single&rid='.$record->id, get_string('ratingssaved', 'data'));
|
||||
} else {
|
||||
redirect('view.php?d='.$data->id, get_string('ratingssaved', 'data'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
<?php
|
||||
|
||||
// For a given post, shows a report of all the ratings it has
|
||||
|
||||
require_once("../../config.php");
|
||||
require_once("lib.php");
|
||||
|
||||
$id = required_param('id', PARAM_INT);
|
||||
$sort = optional_param('sort', '', PARAM_ALPHA);
|
||||
|
||||
$url = new moodle_url('/mod/data/report.php', array('id'=>$id));
|
||||
if ($sort !== 0) {
|
||||
$url->param('sort', $sort);
|
||||
}
|
||||
$PAGE->set_url($url);
|
||||
|
||||
if (!$record = $DB->get_record('data_records', array('id'=>$id))) {
|
||||
print_error('invalidrecord', 'data');
|
||||
}
|
||||
|
||||
if (!$data = $DB->get_record('data', array('id'=>$record->dataid))) {
|
||||
print_error('invalidid', 'data');
|
||||
}
|
||||
|
||||
if (!$course = $DB->get_record('course', array('id'=>$data->course))) {
|
||||
print_error('coursemisconf');
|
||||
}
|
||||
|
||||
if (!$cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
|
||||
print_error('invalidcoursemodule');
|
||||
}
|
||||
|
||||
require_login($course->id, false, $cm);
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
|
||||
if (!$data->assessed) {
|
||||
print_error('norating', 'data');
|
||||
}
|
||||
|
||||
if (!data_isowner($record->id) and !has_capability('mod/data:viewrating', $context) and !has_capability('mod/data:rate', $context)) {
|
||||
print_error('cannotviewrate', 'data');
|
||||
}
|
||||
|
||||
switch ($sort) {
|
||||
case 'firstname': $sqlsort = "u.firstname ASC"; break;
|
||||
case 'rating': $sqlsort = "r.rating ASC"; break;
|
||||
default: $sqlsort = "r.id ASC";
|
||||
}
|
||||
|
||||
$scalemenu = make_grades_menu($data->scale);
|
||||
|
||||
$strratings = get_string('ratings', 'data');
|
||||
$strrating = get_string('rating', 'data');
|
||||
$strname = get_string('name');
|
||||
|
||||
$PAGE->set_title($strratings);
|
||||
echo $OUTPUT->header();
|
||||
|
||||
if (!$ratings = data_get_ratings($record->id, $sqlsort)) {
|
||||
print_error('noratingforrecord', 'data');
|
||||
|
||||
} else {
|
||||
echo "<table border=\"0\" cellpadding=\"3\" cellspacing=\"3\" class=\"generalbox\" style=\"width:100%\">";
|
||||
echo "<tr>";
|
||||
echo "<th class=\"header\" scope=\"col\"> </th>";
|
||||
echo "<th class=\"header\" scope=\"col\"><a href=\"report.php?id=$record->id&sort=firstname\">$strname</a></th>";
|
||||
echo "<th class=\"header\" scope=\"col\" style=\"width:100%\"><a href=\"report.php?id=$id&sort=rating\">$strrating</a></th>";
|
||||
echo "</tr>";
|
||||
foreach ($ratings as $rating) {
|
||||
if (has_capability('mod/data:manageentries', $context)) {
|
||||
echo '<tr class="forumpostheadertopic">';
|
||||
} else {
|
||||
echo '<tr class="forumpostheader">';
|
||||
}
|
||||
echo '<td class="picture">';
|
||||
echo $OUTPUT->user_picture($rating, array('courseid'=>$data->course));
|
||||
echo '</td>';
|
||||
echo '<td class="author">' . html_writer::link($CFG->wwwroot.'/user/view.php?id='.$rating->id.'&course='.$data->course, fullname($rating)) . '</td>';
|
||||
echo '<td style="white-space:nowrap" align="center" class="rating">'.$scalemenu[$rating->rating].'</td>';
|
||||
echo "</tr>\n";
|
||||
}
|
||||
echo "</table>";
|
||||
echo "<br />";
|
||||
}
|
||||
|
||||
echo $OUTPUT->close_window_button();
|
||||
echo $OUTPUT->footer();
|
||||
Reference in New Issue
Block a user