original_string: protected static function get_course_records($whereclause, $params, $options, $checkvisibility = false) {
          global $DB;
          $ctxselect = context_helper::get_preload_record_columns_sql('ctx');
          $fields = array('c.id', 'c.category', 'c.sortorder',
                          'c.shortname', 'c.fullname', 'c.idnumber',
                          'c.startdate', 'c.enddate', 'c.visible', 'c.cacherev');
          if (!empty($options['summary'])) {
              $fields[] = 'c.summary';
              $fields[] = 'c.summaryformat';
          } else {
              $fields[] = $DB->sql_substr('c.summary', 1, 1). ' as hassummary';
          }
          $sql = "SELECT ". join(',', $fields). ", $ctxselect
                  FROM {course} c
                  JOIN {context} ctx ON c.id = ctx.instanceid AND ctx.contextlevel = :contextcourse
                  WHERE ". $whereclause." ORDER BY c.sortorder";
          $list = $DB->get_records_sql($sql,
                  array('contextcourse' => CONTEXT_COURSE) + $params);
  
          if ($checkvisibility) {
              $mycourses = enrol_get_my_courses();
              // Loop through all records and make sure we only return the courses accessible by user.
              foreach ($list as $course) {
                  if (isset($list[$course->id]->hassummary)) {
                      $list[$course->id]->hassummary = strlen($list[$course->id]->hassummary) > 0;
                  }
                  context_helper::preload_from_record($course);
                  $context = context_course::instance($course->id);
                  // Check that course is accessible by user.
                  if (!array_key_exists($course->id, $mycourses) && !self::can_view_course_info($course)) {
                      unset($list[$course->id]);
                  }
              }
          }
  
          return $list;
      }
code: protected static function get_course_records($whereclause, $params, $options, $checkvisibility = false) {
          global $DB;
          $ctxselect = context_helper::get_preload_record_columns_sql('ctx');
          $fields = array('c.id', 'c.category', 'c.sortorder',
                          'c.shortname', 'c.fullname', 'c.idnumber',
                          'c.startdate', 'c.enddate', 'c.visible', 'c.cacherev');
          if (!empty($options['summary'])) {
              $fields[] = 'c.summary';
              $fields[] = 'c.summaryformat';
          } else {
              $fields[] = $DB->sql_substr('c.summary', 1, 1). ' as hassummary';
          }
          $sql = "SELECT ". join(',', $fields). ", $ctxselect
                  FROM {course} c
                  JOIN {context} ctx ON c.id = ctx.instanceid AND ctx.contextlevel = :contextcourse
                  WHERE ". $whereclause." ORDER BY c.sortorder";
          $list = $DB->get_records_sql($sql,
                  array('contextcourse' => CONTEXT_COURSE) + $params);
  
          if ($checkvisibility) {
              $mycourses = enrol_get_my_courses();
              // Loop through all records and make sure we only return the courses accessible by user.
              foreach ($list as $course) {
                  if (isset($list[$course->id]->hassummary)) {
                      $list[$course->id]->hassummary = strlen($list[$course->id]->hassummary) > 0;
                  }
                  context_helper::preload_from_record($course);
                  $context = context_course::instance($course->id);
                  // Check that course is accessible by user.
                  if (!array_key_exists($course->id, $mycourses) && !self::can_view_course_info($course)) {
                      unset($list[$course->id]);
                  }
              }
          }
  
          return $list;
      }
code_tokens: protected static function get_course_records ( $ whereclause , $ params , $ options , $ checkvisibility = false ) { global $ DB ; $ ctxselect = context_helper :: get_preload_record_columns_sql ( 'ctx' ) ; $ fields = array ( 'c.id' , 'c.category' , 'c.sortorder' , 'c.shortname' , 'c.fullname' , 'c.idnumber' , 'c.startdate' , 'c.enddate' , 'c.visible' , 'c.cacherev' ) ; if ( ! empty ( $ options [ 'summary' ] ) ) { $ fields [ ] = 'c.summary' ; $ fields [ ] = 'c.summaryformat' ; } else { $ fields [ ] = $ DB -> sql_substr ( 'c.summary' , 1 , 1 ) . ' as hassummary' ; } $ sql = "SELECT " . join ( ',' , $ fields ) . ", $ctxselect
                  FROM {course} c
                  JOIN {context} ctx ON c.id = ctx.instanceid AND ctx.contextlevel = :contextcourse
                  WHERE " . $ whereclause . " ORDER BY c.sortorder" ; $ list = $ DB -> get_records_sql ( $ sql , array ( 'contextcourse' => CONTEXT_COURSE ) + $ params ) ; if ( $ checkvisibility ) { $ mycourses = enrol_get_my_courses ( ) ; // Loop through all records and make sure we only return the courses accessible by user. foreach ( $ list as $ course ) { if ( isset ( $ list [ $ course -> id ] -> hassummary ) ) { $ list [ $ course -> id ] -> hassummary = strlen ( $ list [ $ course -> id ] -> hassummary ) > 0 ; } context_helper :: preload_from_record ( $ course ) ; $ context = context_course :: instance ( $ course -> id ) ; // Check that course is accessible by user. if ( ! array_key_exists ( $ course -> id , $ mycourses ) && ! self :: can_view_course_info ( $ course ) ) { unset ( $ list [ $ course -> id ] ) ; } } } return $ list ; }
docstring: Retrieves number of records from course table
  
  Not all fields are retrieved. Records are ready for preloading context
  
  @param string $whereclause
  @param array $params
  @param array $options may indicate that summary needs to be retrieved
  @param bool $checkvisibility if true, capability 'moodle/course:viewhiddencourses' will be checked
  on not visible courses and 'moodle/category:viewcourselist' on all courses
  @return array array of stdClass objects
docstring_tokens: Retrieves number of records from course table