Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-25241 forum: reimplemented the display of ratings on the forum se…

…arch page
  • Loading branch information...
commit 4b5c0b461c26380323e2cf2759943cbcc1d708c8 1 parent 136fa79
Andrew Davis andyjdavis authored

Showing 1 changed file with 28 additions and 0 deletions. Show diff stats Hide diff stats

  1. +28 0 mod/forum/search.php
28 mod/forum/search.php
@@ -158,6 +158,17 @@
158 158 exit;
159 159 }
160 160
  161 +//including this here to prevent it being included if there are no search results
  162 +require_once($CFG->dirroot.'/rating/lib.php');
  163 +
  164 +//set up the ratings information that will be the same for all posts
  165 +$ratingoptions = new stdClass();
  166 +$ratingoptions->component = 'mod_forum';
  167 +$ratingoptions->ratingarea = 'post';
  168 +$ratingoptions->userid = $USER->id;
  169 +$ratingoptions->returnurl = $PAGE->url->out(false);
  170 +$rm = new rating_manager();
  171 +
161 172 $PAGE->set_title($strsearchresults);
162 173 $PAGE->set_heading($course->fullname);
163 174 $PAGE->set_button($searchform);
@@ -227,6 +238,23 @@
227 238 $post->subject = $fullsubject;
228 239 $post->subjectnoformat = true;
229 240
  241 + //add the ratings information to the post
  242 + //Unfortunately seem to have do this individually as posts may be from different forums
  243 + if ($forum->assessed != RATING_AGGREGATE_NONE) {
  244 + $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
  245 + $ratingoptions->context = $modcontext;
  246 + $ratingoptions->items = array($post);
  247 + $ratingoptions->aggregate = $forum->assessed;//the aggregation method
  248 + $ratingoptions->scaleid = $forum->scale;
  249 + $ratingoptions->assesstimestart = $forum->assesstimestart;
  250 + $ratingoptions->assesstimefinish = $forum->assesstimefinish;
  251 + $postswithratings = $rm->get_ratings($ratingoptions);
  252 +
  253 + if ($postswithratings && count($postswithratings)==1) {
  254 + $post = $postswithratings[0];
  255 + }
  256 + }
  257 +
230 258 // Identify search terms only found in HTML markup, and add a warning about them to
231 259 // the start of the message text. However, do not do the highlighting here. forum_print_post
232 260 // will do it for us later.

0 comments on commit 4b5c0b4

Please sign in to comment.
Something went wrong with that request. Please try again.