original_string: public function get_format_options($section = null) {
          global $DB;
          if ($section === null) {
              $options = $this->course_format_options();
          } else {
              $options = $this->section_format_options();
          }
          if (empty($options)) {
              // there are no option for course/sections anyway, no need to go further
              return array();
          }
          if ($section === null) {
              // course format options will be returned
              $sectionid = 0;
          } else if ($this->courseid && isset($section->id)) {
              // course section format options will be returned
              $sectionid = $section->id;
          } else if ($this->courseid && is_int($section) &&
                  ($sectionobj = $DB->get_record('course_sections',
                          array('section' => $section, 'course' => $this->courseid), 'id'))) {
              // course section format options will be returned
              $sectionid = $sectionobj->id;
          } else {
              // non-existing (yet) section was passed as an argument
              // default format options for course section will be returned
              $sectionid = -1;
          }
          if (!array_key_exists($sectionid, $this->formatoptions)) {
              $this->formatoptions[$sectionid] = array();
              // first fill with default values
              foreach ($options as $optionname => $optionparams) {
                  $this->formatoptions[$sectionid][$optionname] = null;
                  if (array_key_exists('default', $optionparams)) {
                      $this->formatoptions[$sectionid][$optionname] = $optionparams['default'];
                  }
              }
              if ($this->courseid && $sectionid !== -1) {
                  // overwrite the default options values with those stored in course_format_options table
                  // nothing can be stored if we are interested in generic course ($this->courseid == 0)
                  // or generic section ($sectionid === 0)
                  $records = $DB->get_records('course_format_options',
                          array('courseid' => $this->courseid,
                                'format' => $this->format,
                                'sectionid' => $sectionid
                              ), '', 'id,name,value');
                  foreach ($records as $record) {
                      if (array_key_exists($record->name, $this->formatoptions[$sectionid])) {
                          $value = $record->value;
                          if ($value !== null && isset($options[$record->name]['type'])) {
                              // this will convert string value to number if needed
                              $value = clean_param($value, $options[$record->name]['type']);
                          }
                          $this->formatoptions[$sectionid][$record->name] = $value;
                      }
                  }
              }
          }
          return $this->formatoptions[$sectionid];
      }
code: public function get_format_options($section = null) {
          global $DB;
          if ($section === null) {
              $options = $this->course_format_options();
          } else {
              $options = $this->section_format_options();
          }
          if (empty($options)) {
              // there are no option for course/sections anyway, no need to go further
              return array();
          }
          if ($section === null) {
              // course format options will be returned
              $sectionid = 0;
          } else if ($this->courseid && isset($section->id)) {
              // course section format options will be returned
              $sectionid = $section->id;
          } else if ($this->courseid && is_int($section) &&
                  ($sectionobj = $DB->get_record('course_sections',
                          array('section' => $section, 'course' => $this->courseid), 'id'))) {
              // course section format options will be returned
              $sectionid = $sectionobj->id;
          } else {
              // non-existing (yet) section was passed as an argument
              // default format options for course section will be returned
              $sectionid = -1;
          }
          if (!array_key_exists($sectionid, $this->formatoptions)) {
              $this->formatoptions[$sectionid] = array();
              // first fill with default values
              foreach ($options as $optionname => $optionparams) {
                  $this->formatoptions[$sectionid][$optionname] = null;
                  if (array_key_exists('default', $optionparams)) {
                      $this->formatoptions[$sectionid][$optionname] = $optionparams['default'];
                  }
              }
              if ($this->courseid && $sectionid !== -1) {
                  // overwrite the default options values with those stored in course_format_options table
                  // nothing can be stored if we are interested in generic course ($this->courseid == 0)
                  // or generic section ($sectionid === 0)
                  $records = $DB->get_records('course_format_options',
                          array('courseid' => $this->courseid,
                                'format' => $this->format,
                                'sectionid' => $sectionid
                              ), '', 'id,name,value');
                  foreach ($records as $record) {
                      if (array_key_exists($record->name, $this->formatoptions[$sectionid])) {
                          $value = $record->value;
                          if ($value !== null && isset($options[$record->name]['type'])) {
                              // this will convert string value to number if needed
                              $value = clean_param($value, $options[$record->name]['type']);
                          }
                          $this->formatoptions[$sectionid][$record->name] = $value;
                      }
                  }
              }
          }
          return $this->formatoptions[$sectionid];
      }
code_tokens: public function get_format_options ( $ section = null ) { global $ DB ; if ( $ section === null ) { $ options = $ this -> course_format_options ( ) ; } else { $ options = $ this -> section_format_options ( ) ; } if ( empty ( $ options ) ) { // there are no option for course/sections anyway, no need to go further return array ( ) ; } if ( $ section === null ) { // course format options will be returned $ sectionid = 0 ; } else if ( $ this -> courseid && isset ( $ section -> id ) ) { // course section format options will be returned $ sectionid = $ section -> id ; } else if ( $ this -> courseid && is_int ( $ section ) && ( $ sectionobj = $ DB -> get_record ( 'course_sections' , array ( 'section' => $ section , 'course' => $ this -> courseid ) , 'id' ) ) ) { // course section format options will be returned $ sectionid = $ sectionobj -> id ; } else { // non-existing (yet) section was passed as an argument // default format options for course section will be returned $ sectionid = - 1 ; } if ( ! array_key_exists ( $ sectionid , $ this -> formatoptions ) ) { $ this -> formatoptions [ $ sectionid ] = array ( ) ; // first fill with default values foreach ( $ options as $ optionname => $ optionparams ) { $ this -> formatoptions [ $ sectionid ] [ $ optionname ] = null ; if ( array_key_exists ( 'default' , $ optionparams ) ) { $ this -> formatoptions [ $ sectionid ] [ $ optionname ] = $ optionparams [ 'default' ] ; } } if ( $ this -> courseid && $ sectionid !== - 1 ) { // overwrite the default options values with those stored in course_format_options table // nothing can be stored if we are interested in generic course ($this->courseid == 0) // or generic section ($sectionid === 0) $ records = $ DB -> get_records ( 'course_format_options' , array ( 'courseid' => $ this -> courseid , 'format' => $ this -> format , 'sectionid' => $ sectionid ) , '' , 'id,name,value' ) ; foreach ( $ records as $ record ) { if ( array_key_exists ( $ record -> name , $ this -> formatoptions [ $ sectionid ] ) ) { $ value = $ record -> value ; if ( $ value !== null && isset ( $ options [ $ record -> name ] [ 'type' ] ) ) { // this will convert string value to number if needed $ value = clean_param ( $ value , $ options [ $ record -> name ] [ 'type' ] ) ; } $ this -> formatoptions [ $ sectionid ] [ $ record -> name ] = $ value ; } } } } return $ this -> formatoptions [ $ sectionid ] ; }
docstring: Returns the format options stored for this course or course section
  
  When overriding please note that this function is called from rebuild_course_cache()
  and section_info object, therefore using of get_fast_modinfo() and/or any function that
  accesses it may lead to recursion.
  
  @param null|int|stdClass|section_info $section if null the course format options will be returned
  otherwise options for specified section will be returned. This can be either
  section object or relative section number (field course_sections.section)
  @return array
docstring_tokens: Returns the format options stored for this course or course section