Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-23805

User rating system with unlogged users cause some problems

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0
    • Fix Version/s: 2.0
    • Component/s: Ratings
    • Labels:
      None
    • Affected Branches:
      MOODLE_20_STABLE
    • Fixed Branches:
      MOODLE_20_STABLE

      Description

      I had some problems to see ratings when I use rating system for hub course. I use ratings like that:

      //load ratings
      if (!empty($courses)) ...
      require_once($CFG->dirroot . '/rating/lib.php');
      $ratingoptions = new stdclass();
      $ratingoptions->context = get_system_context();
      $ratingoptions->items = $courses;
      $ratingoptions->aggregate = RATING_AGGREGATE_AVERAGE;
      $ratingoptions->scaleid = 10;
      $ratingoptions->userid = $USER->id; //can be empty
      $ratingoptions->returnurl = "$CFG->wwwroot/local/hub/index.php";

      $rm = new rating_manager();
      $courses = $rm->get_ratings($ratingoptions);

      foreach ($courses as $course) ...
      $course->rating->settings->permissions->viewany = 1;
      ...
      ...

      • the summary popup is broken when unlogged users access it from the front page. To fix it I added $PAGE->set_context($context); after $PAGE->set_url($url) in rating/index.php.
      • I changed the renderer to check when useritemid is empty (otherwise the ratings weren't displayed for unlogged user)

        if ( ($rating->itemuserid==$USER->id
                      && $rating->settings->permissions->view && $rating->settings->pluginpermissions->view)
                  || ($rating->itemuserid!=$USER->id
                      && $rating->settings->permissions->viewany && $rating->settings->pluginpermissions->viewany) ) {

      =>

       if ( ($rating->itemuserid==$USER->id
                      && $rating->settings->permissions->view && $rating->settings->pluginpermissions->view)
                  || ((empty($rating->itemuserid) or $rating->itemuserid!=$USER->id)
                      && $rating->settings->permissions->viewany && $rating->settings->pluginpermissions->viewany) ) {

      Note: or we could remove the $rating->itemuserid!=$USER->id test? if any people can view, so the item creator can. Or maybe I'm missing something...

        Attachments

          Activity

            People

            • Assignee:
              andyjdavis Andrew Davis
              Reporter:
              jerome Jérôme Mouneyrac
              Tester:
              Nobody
              Participants:
              Component watchers:
              Adrian Greeve, Mihail Geshoski, Peter Dias
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                24/Nov/10