Permalink
Browse files

MDL-17365 forum rate - validate rating against scale values. Backport…

…ed from HEAD
  • Loading branch information...
1 parent 96ff525 commit 461ca1b47ec2426ff1c0b0b9502296d7ca458534 stronk7 committed Jan 27, 2009
Showing with 13 additions and 0 deletions.
  1. +1 −0 lang/en_utf8/forum.php
  2. +12 −0 mod/forum/rate.php
View
@@ -111,6 +111,7 @@
$string['intronews'] = 'General news and announcements';
$string['introsocial'] = 'An open forum for chatting about anything you want to';
$string['introteacher'] = 'A forum for teacher-only notes and discussion';
+$string['invalidrate'] = 'Invalid rate ($a)';
$string['lastpost'] = 'Last post';
$string['learningforums'] = 'Learning forums';
$string['mailnow'] = 'Mail now';
View
@@ -13,6 +13,10 @@
if (! $cm = get_coursemodule_from_instance('forum', $forumid, $id)) {
error('Course Module ID was incorrect');
}
+
+ if (!$forum = get_record('forum', 'id', $forumid)) {
+ error("Course ID was incorrect");
+ }
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
@@ -39,6 +43,9 @@
$lastpostid = 0;
+ /// Calculate scale values
+ $scale_values = make_grades_menu($forum->scale);
+
foreach ((array)$data as $postid => $rating) {
if ($postid == "id") {
continue;
@@ -47,6 +54,11 @@
$postid = (int)$postid;
$lastpostid = $postid;
+ /// Check rate is valid for for that forum scale values
+ if (!array_key_exists($rating, $scale_values) && $rating != FORUM_UNSET_POST_RATING) {
+ print_error('invalidrate', 'forum', '', $rating);
+ }
+
if ($rating == FORUM_UNSET_POST_RATING) {
delete_records('forum_ratings', 'post', $postid, 'userid', $USER->id);

0 comments on commit 461ca1b

Please sign in to comment.