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

get_user_preferences() returns the supplied default if the preference in the database is 0

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 2.0
    • Fix Version/s: 2.0
    • Component/s: General
    • Labels:
      None
    • Affected Branches:
      MOODLE_20_STABLE
    • Fixed Branches:
      MOODLE_20_STABLE

      Description

      If a user preference has the value of 0 get_user_preferences() interprets this as meaning that their preference is unset so returns the default. I believe its due to this:

      else if ($value = $DB->get_field('user_preferences', 'value', array('userid'=>$otheruserid, 'name'=>$name))) {

      The value of 0 is being interpreted as false. If you change this to something like the below it works:

      $value = $DB->get_field('user_preferences', 'value', array('userid'=>$otheruserid, 'name'=>$name));
      if ($value!==null) {
      return $value;
      } else {
      return $default;
      }

        Attachments

          Activity

            People

            Assignee:
            skodak Petr Skoda
            Reporter:
            andyjdavis Andrew Davis
            Tester:
            Nobody
            Participants:
            Component watchers:
            Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

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