Skip to content

Commit

Permalink
MDL-17365 forum rate - validate rating against scale values. Backport…
Browse files Browse the repository at this point in the history
…ed from HEAD
  • Loading branch information
stronk7 committed Jan 27, 2009
1 parent 96ff525 commit 461ca1b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions lang/en_utf8/forum.php
Expand Up @@ -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';
Expand Down
12 changes: 12 additions & 0 deletions mod/forum/rate.php
Expand Up @@ -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);

Expand All @@ -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;
Expand All @@ -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);

Expand Down

0 comments on commit 461ca1b

Please sign in to comment.