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

Reference to deprecated course modinfo field still exists

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 3.7
    • Fix Version/s: None
    • Component/s: Forum
    • Labels:
      None
    • Affected Branches:
      MOODLE_37_STABLE

      Description

      In mod/forum/lib.php function forum_get_readable_forums($userid, $courseid=0) is almost inevitably called with $courseid set, and therefore the else in the following test is not called.

       

      if ($courseid)
      {      $courses = $DB->get_records('course', array('id' => $courseid)); }
      else
      {    // If no course is specified, then the user can see SITE + his courses.
           $courses1 = $DB->get_records('course', array('id' => SITEID));
           $courses2 = enrol_get_users_courses($userid, true, array('modinfo')); 
           $courses = array_merge($courses1, $courses2);
      }
      

       

      If the test were to be called with $courseid==0 this would result in an error because modinfo no longer exists in mdl_course.

      The fault can simply be remove with 

           $courses2 = enrol_get_users_courses($userid, true); 

      because the true modinfo is collected after this test.

      However may I suggest that the test itself not be removed because it is in fact very useful! I hit the field error when intentionally calling the above function with:

          $forums = forum_get_readable_forums($USER->id, 0);

      from, function forum_search_posts(...).

      With array('modinfo') removed, this call returns ALL the forums in ALL the courses to which the current user has access. In the case of a very small site with limited numbers of courses, or perhaps with single-activity courses, this behaviour can be very useful. In fact in such a forum-only course, the title "Search forums" on the quick search is a misnomer currently.

      Naturally an admin setting that allows this global search behaviour to be turned on if desired would be the obvious solution.

       To complete the picture this would also imply the need to see ALL forums in the dropdown within advanced search, using a function

      function forum_big_menu_list($course)  {
       global $USER; // We now need current user
          $menu = array();
          $forums = forum_get_readable_forums($USER->id, 0);
          foreach ($forums as $forum) { 
             $cm = $forum->cm;
              if (!$cm->uservisible) {
              continue;
              }
              $context = context_module::instance($cm->id);
              if (!has_capability('mod/forum:viewdiscussion', $context)) {
                  continue;
              }
              $menu[$cm->instance] = format_string($cm->name);
          }
          return $menu;
      }

      If others found this functionality useful, then again it could be controlled by the same admin setting.

       

      Many thanks, John White

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              jwhite10 John White
              Participants:
              Component watchers:
              Andrew Nicols, Mathew May, Michael Hawkins, Shamim Rezaie, Simey Lameze
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: