Skip to content

Commit

Permalink
MDL-25241 forum: reimplemented the display of ratings on the forum se…
Browse files Browse the repository at this point in the history
…arch page
  • Loading branch information
andyjdavis committed Sep 22, 2011
1 parent 51e1e3d commit 1239f5a
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions mod/forum/search.php
Expand Up @@ -158,6 +158,17 @@
exit; exit;
} }


//including this here to prevent it being included if there are no search results
require_once($CFG->dirroot.'/rating/lib.php');

//set up the ratings information that will be the same for all posts
$ratingoptions = new stdClass();
$ratingoptions->component = 'mod_forum';
$ratingoptions->ratingarea = 'post';
$ratingoptions->userid = $USER->id;
$ratingoptions->returnurl = $PAGE->url->out(false);
$rm = new rating_manager();

$PAGE->set_title($strsearchresults); $PAGE->set_title($strsearchresults);
$PAGE->set_heading($course->fullname); $PAGE->set_heading($course->fullname);
$PAGE->set_button($searchform); $PAGE->set_button($searchform);
Expand Down Expand Up @@ -227,6 +238,23 @@
$post->subject = $fullsubject; $post->subject = $fullsubject;
$post->subjectnoformat = true; $post->subjectnoformat = true;


//add the ratings information to the post
//Unfortunately seem to have do this individually as posts may be from different forums
if ($forum->assessed != RATING_AGGREGATE_NONE) {
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
$ratingoptions->context = $modcontext;
$ratingoptions->items = array($post);
$ratingoptions->aggregate = $forum->assessed;//the aggregation method
$ratingoptions->scaleid = $forum->scale;
$ratingoptions->assesstimestart = $forum->assesstimestart;
$ratingoptions->assesstimefinish = $forum->assesstimefinish;
$postswithratings = $rm->get_ratings($ratingoptions);

if ($postswithratings && count($postswithratings)==1) {
$post = $postswithratings[0];
}
}

// Identify search terms only found in HTML markup, and add a warning about them to // Identify search terms only found in HTML markup, and add a warning about them to
// the start of the message text. However, do not do the highlighting here. forum_print_post // the start of the message text. However, do not do the highlighting here. forum_print_post
// will do it for us later. // will do it for us later.
Expand Down

0 comments on commit 1239f5a

Please sign in to comment.