Moodle
  1. Moodle
  2. MDL-27905

Incoherence between course list by category and the same list in the navigation bloc

    Details

    • Database:
      MySQL
    • Testing Instructions:
      Hide
      • Log yourself as Administrator
      • Go to the Course categories list (http://mymoodle/course/) and turn editing on
      • Click on a category that has more than 20 courses (course limit in navigation must be 20).
      • Make visible 2 courses : One that is between 1 and 20 (sortorder) and the other higher than 20.
      • As an anonymous user, go to the Course categories list (http://mymoodle/course/)
      • Click on the category you just edited as an administrator.
      • You should see only one course in the navigation block
      Show
      Log yourself as Administrator Go to the Course categories list ( http://mymoodle/course/ ) and turn editing on Click on a category that has more than 20 courses (course limit in navigation must be 20). Make visible 2 courses : One that is between 1 and 20 (sortorder) and the other higher than 20. As an anonymous user, go to the Course categories list ( http://mymoodle/course/ ) Click on the category you just edited as an administrator. You should see only one course in the navigation block
    • Affected Branches:
      MOODLE_20_STABLE, MOODLE_21_STABLE, MOODLE_22_STABLE, MOODLE_24_STABLE
    • Rank:
      17554

      Description

      There's an Incoherence between course list by category (http://mymoodle/course/category.php?id=111) and the same list in the navigation bloc.
      This occurs when a user don't have permissions to see hidden courses (See image attachment).

      To solve the problem, the function load_all_courses of the file /lib/navigationlib.php must be fixed :

              $limit = 20;
              if (!empty($CFG->navcourselimit)) {
                  $limit = $CFG->navcourselimit;
              }
              $courses = $DB->get_records_sql($sql, $params, 0, $limit);
      
              $coursenodes = array();
              foreach ($courses as $course) {
                  context_instance_preload($course);
                  $coursenodes[$course->id] = $this->add_course($course);
              }
      

      Here's a simple solution (but not the most efficient for performances)

              $limit = 20;
              if (!empty($CFG->navcourselimit)) {
                  $limit = $CFG->navcourselimit;
              }
      
              $courses = $DB->get_records_sql($sql, $params);
      
      	$coursenodes = array();
      
      	$i = 0;
      	foreach ($courses as $course) {
      	    if($i >= $limit) {
      		break;
      	    }
      
                  context_instance_preload($course);
                  if($coursenodes[$course->id] = $this->add_course($course)) {
      		$i++;
      	    }
              }
      
      

      NOTE : It seems like there's other functions in /lib/navigationlib.php that may need to be fixed because this code is replicated elsewhere

        Issue Links

          Activity

          Hide
          Michael de Raadt added a comment -

          Thanks for reporting this.

          I've put it on our backlog and we'll try to get to it as soon as we can.

          Show
          Michael de Raadt added a comment - Thanks for reporting this. I've put it on our backlog and we'll try to get to it as soon as we can.
          Hide
          Gilles-Philippe Leblanc added a comment -

          The code has been changed in version 2.3.2 of Moodle but the problem is still relevant

          Show
          Gilles-Philippe Leblanc added a comment - The code has been changed in version 2.3.2 of Moodle but the problem is still relevant

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: