original_string: protected static function get_collapsed_preferences($courseid) {
          if ($collapsed = get_user_preferences('grade_report_grader_collapsed_categories'.$courseid)) {
              return json_decode($collapsed, true);
          }
  
          // Try looking for old location of user setting that used to store all courses in one serialized user preference.
          if (($oldcollapsedpref = get_user_preferences('grade_report_grader_collapsed_categories')) !== null) {
              if ($collapsedall = unserialize_array($oldcollapsedpref)) {
                  // We found the old-style preference, filter out only categories that belong to this course and update the prefs.
                  $collapsed = static::filter_collapsed_categories($courseid, $collapsedall);
                  if (!empty($collapsed['aggregatesonly']) || !empty($collapsed['gradesonly'])) {
                      static::set_collapsed_preferences($courseid, $collapsed);
                      $collapsedall['aggregatesonly'] = array_diff($collapsedall['aggregatesonly'], $collapsed['aggregatesonly']);
                      $collapsedall['gradesonly'] = array_diff($collapsedall['gradesonly'], $collapsed['gradesonly']);
                      if (!empty($collapsedall['aggregatesonly']) || !empty($collapsedall['gradesonly'])) {
                          set_user_preference('grade_report_grader_collapsed_categories', serialize($collapsedall));
                      } else {
                          unset_user_preference('grade_report_grader_collapsed_categories');
                      }
                  }
              } else {
                  // We found the old-style preference, but it is unreadable, discard it.
                  unset_user_preference('grade_report_grader_collapsed_categories');
              }
          } else {
              $collapsed = array('aggregatesonly' => array(), 'gradesonly' => array());
          }
          return $collapsed;
      }
code: protected static function get_collapsed_preferences($courseid) {
          if ($collapsed = get_user_preferences('grade_report_grader_collapsed_categories'.$courseid)) {
              return json_decode($collapsed, true);
          }
  
          // Try looking for old location of user setting that used to store all courses in one serialized user preference.
          if (($oldcollapsedpref = get_user_preferences('grade_report_grader_collapsed_categories')) !== null) {
              if ($collapsedall = unserialize_array($oldcollapsedpref)) {
                  // We found the old-style preference, filter out only categories that belong to this course and update the prefs.
                  $collapsed = static::filter_collapsed_categories($courseid, $collapsedall);
                  if (!empty($collapsed['aggregatesonly']) || !empty($collapsed['gradesonly'])) {
                      static::set_collapsed_preferences($courseid, $collapsed);
                      $collapsedall['aggregatesonly'] = array_diff($collapsedall['aggregatesonly'], $collapsed['aggregatesonly']);
                      $collapsedall['gradesonly'] = array_diff($collapsedall['gradesonly'], $collapsed['gradesonly']);
                      if (!empty($collapsedall['aggregatesonly']) || !empty($collapsedall['gradesonly'])) {
                          set_user_preference('grade_report_grader_collapsed_categories', serialize($collapsedall));
                      } else {
                          unset_user_preference('grade_report_grader_collapsed_categories');
                      }
                  }
              } else {
                  // We found the old-style preference, but it is unreadable, discard it.
                  unset_user_preference('grade_report_grader_collapsed_categories');
              }
          } else {
              $collapsed = array('aggregatesonly' => array(), 'gradesonly' => array());
          }
          return $collapsed;
      }
code_tokens: protected static function get_collapsed_preferences ( $ courseid ) { if ( $ collapsed = get_user_preferences ( 'grade_report_grader_collapsed_categories' . $ courseid ) ) { return json_decode ( $ collapsed , true ) ; } // Try looking for old location of user setting that used to store all courses in one serialized user preference. if ( ( $ oldcollapsedpref = get_user_preferences ( 'grade_report_grader_collapsed_categories' ) ) !== null ) { if ( $ collapsedall = unserialize_array ( $ oldcollapsedpref ) ) { // We found the old-style preference, filter out only categories that belong to this course and update the prefs. $ collapsed = static :: filter_collapsed_categories ( $ courseid , $ collapsedall ) ; if ( ! empty ( $ collapsed [ 'aggregatesonly' ] ) || ! empty ( $ collapsed [ 'gradesonly' ] ) ) { static :: set_collapsed_preferences ( $ courseid , $ collapsed ) ; $ collapsedall [ 'aggregatesonly' ] = array_diff ( $ collapsedall [ 'aggregatesonly' ] , $ collapsed [ 'aggregatesonly' ] ) ; $ collapsedall [ 'gradesonly' ] = array_diff ( $ collapsedall [ 'gradesonly' ] , $ collapsed [ 'gradesonly' ] ) ; if ( ! empty ( $ collapsedall [ 'aggregatesonly' ] ) || ! empty ( $ collapsedall [ 'gradesonly' ] ) ) { set_user_preference ( 'grade_report_grader_collapsed_categories' , serialize ( $ collapsedall ) ) ; } else { unset_user_preference ( 'grade_report_grader_collapsed_categories' ) ; } } } else { // We found the old-style preference, but it is unreadable, discard it. unset_user_preference ( 'grade_report_grader_collapsed_categories' ) ; } } else { $ collapsed = array ( 'aggregatesonly' => array ( ) , 'gradesonly' => array ( ) ) ; } return $ collapsed ; }
docstring: Returns the list of categories that this user wants to collapse or display aggregatesonly
  
  This method also migrates on request from the old format of storing user preferences when they were stored
  in one preference for all courses causing DB error when trying to insert very big value.
  
  @param int $courseid
  @return array
docstring_tokens: Returns the list of categories that this user wants to collapse or display aggregatesonly