original_string: protected static function filter_collapsed_categories($courseid, $collapsed) {
          global $DB;
          if (empty($collapsed)) {
              $collapsed = array('aggregatesonly' => array(), 'gradesonly' => array());
          }
          if (empty($collapsed['aggregatesonly']) && empty($collapsed['gradesonly'])) {
              return $collapsed;
          }
          $cats = $DB->get_fieldset_select('grade_categories', 'id', 'courseid = ?', array($courseid));
          $collapsed['aggregatesonly'] = array_values(array_intersect($collapsed['aggregatesonly'], $cats));
          $collapsed['gradesonly'] = array_values(array_intersect($collapsed['gradesonly'], $cats));
          return $collapsed;
      }
code: protected static function filter_collapsed_categories($courseid, $collapsed) {
          global $DB;
          if (empty($collapsed)) {
              $collapsed = array('aggregatesonly' => array(), 'gradesonly' => array());
          }
          if (empty($collapsed['aggregatesonly']) && empty($collapsed['gradesonly'])) {
              return $collapsed;
          }
          $cats = $DB->get_fieldset_select('grade_categories', 'id', 'courseid = ?', array($courseid));
          $collapsed['aggregatesonly'] = array_values(array_intersect($collapsed['aggregatesonly'], $cats));
          $collapsed['gradesonly'] = array_values(array_intersect($collapsed['gradesonly'], $cats));
          return $collapsed;
      }
code_tokens: protected static function filter_collapsed_categories ( $ courseid , $ collapsed ) { global $ DB ; if ( empty ( $ collapsed ) ) { $ collapsed = array ( 'aggregatesonly' => array ( ) , 'gradesonly' => array ( ) ) ; } if ( empty ( $ collapsed [ 'aggregatesonly' ] ) && empty ( $ collapsed [ 'gradesonly' ] ) ) { return $ collapsed ; } $ cats = $ DB -> get_fieldset_select ( 'grade_categories' , 'id' , 'courseid = ?' , array ( $ courseid ) ) ; $ collapsed [ 'aggregatesonly' ] = array_values ( array_intersect ( $ collapsed [ 'aggregatesonly' ] , $ cats ) ) ; $ collapsed [ 'gradesonly' ] = array_values ( array_intersect ( $ collapsed [ 'gradesonly' ] , $ cats ) ) ; return $ collapsed ; }
docstring: From the list of categories that this user prefers to collapse choose ones that belong to the current course.
  
  This function serves two purposes.
  Mainly it helps migrating from user preference style when all courses were stored in one preference.
  Also it helps to remove the settings for categories that were removed if the array for one course grows too big.
  
  @param int $courseid
  @param array $collapsed
  @return array
docstring_tokens: From the list of categories that this user prefers to collapse choose ones that belong to the current course .