original_string: public static function get_courses($search, $downloadable, $enrollable, $options) {
          static $availableoptions = ['ids', 'sitecourseids', 'coverage', 'licenceshortname', 'subject', 'audience',
              'educationallevel', 'language', 'orderby', 'givememore', 'allsitecourses'];
  
          if (empty($options)) {
              $options = [];
          } else if (is_object($options)) {
              $options = (array)$options;
          } else if (!is_array($options)) {
              throw new \coding_exception('Parameter $options is invalid');
          }
  
          if ($unknownkeys = array_diff(array_keys($options), $availableoptions)) {
              throw new \coding_exception('Unknown option(s): ' . join(', ', $unknownkeys));
          }
  
          $params = [
              'search' => $search,
              'downloadable' => (int)(bool)$downloadable,
              'enrollable' => (int)(bool)$enrollable,
              'options' => $options
          ];
          $result = self::call('hub_get_courses', $params, true);
          $courses = $result['courses'];
          $coursetotal = $result['coursetotal'];
  
          foreach ($courses as $idx => $course) {
              $courses[$idx]['screenshotbaseurl'] = null;
              if (!empty($course['screenshots'])) {
                  $courses[$idx]['screenshotbaseurl'] = new moodle_url(HUB_MOODLEORGHUBURL . '/local/hub/webservice/download.php',
                      array('courseid' => $course['id'],
                          'filetype' => self::HUB_SCREENSHOT_FILE_TYPE));
              }
              $courses[$idx]['commenturl'] = new moodle_url(HUB_MOODLEORGHUBURL,
                  array('courseid' => $course['id'], 'mustbelogged' => true));
          }
  
          return [$courses, $coursetotal];
      }
code: public static function get_courses($search, $downloadable, $enrollable, $options) {
          static $availableoptions = ['ids', 'sitecourseids', 'coverage', 'licenceshortname', 'subject', 'audience',
              'educationallevel', 'language', 'orderby', 'givememore', 'allsitecourses'];
  
          if (empty($options)) {
              $options = [];
          } else if (is_object($options)) {
              $options = (array)$options;
          } else if (!is_array($options)) {
              throw new \coding_exception('Parameter $options is invalid');
          }
  
          if ($unknownkeys = array_diff(array_keys($options), $availableoptions)) {
              throw new \coding_exception('Unknown option(s): ' . join(', ', $unknownkeys));
          }
  
          $params = [
              'search' => $search,
              'downloadable' => (int)(bool)$downloadable,
              'enrollable' => (int)(bool)$enrollable,
              'options' => $options
          ];
          $result = self::call('hub_get_courses', $params, true);
          $courses = $result['courses'];
          $coursetotal = $result['coursetotal'];
  
          foreach ($courses as $idx => $course) {
              $courses[$idx]['screenshotbaseurl'] = null;
              if (!empty($course['screenshots'])) {
                  $courses[$idx]['screenshotbaseurl'] = new moodle_url(HUB_MOODLEORGHUBURL . '/local/hub/webservice/download.php',
                      array('courseid' => $course['id'],
                          'filetype' => self::HUB_SCREENSHOT_FILE_TYPE));
              }
              $courses[$idx]['commenturl'] = new moodle_url(HUB_MOODLEORGHUBURL,
                  array('courseid' => $course['id'], 'mustbelogged' => true));
          }
  
          return [$courses, $coursetotal];
      }
code_tokens: public static function get_courses ( $ search , $ downloadable , $ enrollable , $ options ) { static $ availableoptions = [ 'ids' , 'sitecourseids' , 'coverage' , 'licenceshortname' , 'subject' , 'audience' , 'educationallevel' , 'language' , 'orderby' , 'givememore' , 'allsitecourses' ] ; if ( empty ( $ options ) ) { $ options = [ ] ; } else if ( is_object ( $ options ) ) { $ options = ( array ) $ options ; } else if ( ! is_array ( $ options ) ) { throw new \ coding_exception ( 'Parameter $options is invalid' ) ; } if ( $ unknownkeys = array_diff ( array_keys ( $ options ) , $ availableoptions ) ) { throw new \ coding_exception ( 'Unknown option(s): ' . join ( ', ' , $ unknownkeys ) ) ; } $ params = [ 'search' => $ search , 'downloadable' => ( int ) ( bool ) $ downloadable , 'enrollable' => ( int ) ( bool ) $ enrollable , 'options' => $ options ] ; $ result = self :: call ( 'hub_get_courses' , $ params , true ) ; $ courses = $ result [ 'courses' ] ; $ coursetotal = $ result [ 'coursetotal' ] ; foreach ( $ courses as $ idx => $ course ) { $ courses [ $ idx ] [ 'screenshotbaseurl' ] = null ; if ( ! empty ( $ course [ 'screenshots' ] ) ) { $ courses [ $ idx ] [ 'screenshotbaseurl' ] = new moodle_url ( HUB_MOODLEORGHUBURL . '/local/hub/webservice/download.php' , array ( 'courseid' => $ course [ 'id' ] , 'filetype' => self :: HUB_SCREENSHOT_FILE_TYPE ) ) ; } $ courses [ $ idx ] [ 'commenturl' ] = new moodle_url ( HUB_MOODLEORGHUBURL , array ( 'courseid' => $ course [ 'id' ] , 'mustbelogged' => true ) ) ; } return [ $ courses , $ coursetotal ] ; }
docstring: Calls WS function hub_get_courses
  
  Parameter $options may have any of these fields:
  [
  'ids' => new external_multiple_structure(new external_value(PARAM_INTEGER, 'id of a course in the hub course
  directory'), 'ids of course', VALUE_OPTIONAL),
  'sitecourseids' => new external_multiple_structure(new external_value(PARAM_INTEGER, 'id of a course in the
  site'), 'ids of course in the site', VALUE_OPTIONAL),
  'coverage' => new external_value(PARAM_TEXT, 'coverage', VALUE_OPTIONAL),
  'licenceshortname' => new external_value(PARAM_ALPHANUMEXT, 'licence short name', VALUE_OPTIONAL),
  'subject' => new external_value(PARAM_ALPHANUM, 'subject', VALUE_OPTIONAL),
  'audience' => new external_value(PARAM_ALPHA, 'audience', VALUE_OPTIONAL),
  'educationallevel' => new external_value(PARAM_ALPHA, 'educational level', VALUE_OPTIONAL),
  'language' => new external_value(PARAM_ALPHANUMEXT, 'language', VALUE_OPTIONAL),
  'orderby' => new external_value(PARAM_ALPHA, 'orderby method: newest, eldest, publisher, fullname,
  ratingaverage', VALUE_OPTIONAL),
  'givememore' => new external_value(PARAM_INT, 'next range of result - range size being set by the hub
  server ', VALUE_OPTIONAL),
  'allsitecourses' => new external_value(PARAM_INTEGER,
  'if 1 return all not visible and visible courses whose siteid is the site
  matching token. Only courses of this site are returned.
  givememore parameter is ignored if this param = 1.
  In case of public token access, this param option is ignored', VALUE_DEFAULT, 0),
  ]
  
  Each course in the returned array of courses will have fields:
  [
  'id' => new external_value(PARAM_INTEGER, 'id'),
  'fullname' => new external_value(PARAM_TEXT, 'course name'),
  'shortname' => new external_value(PARAM_TEXT, 'course short name'),
  'description' => new external_value(PARAM_TEXT, 'course description'),
  'language' => new external_value(PARAM_ALPHANUMEXT, 'course language'),
  'publishername' => new external_value(PARAM_TEXT, 'publisher name'),
  'publisheremail' => new external_value(PARAM_EMAIL, 'publisher email', VALUE_OPTIONAL),
  'privacy' => new external_value(PARAM_INT, 'privacy: published or not', VALUE_OPTIONAL),
  'sitecourseid' => new external_value(PARAM_INT, 'course id on the site', VALUE_OPTIONAL),
  'contributornames' => new external_value(PARAM_TEXT, 'contributor names', VALUE_OPTIONAL),
  'coverage' => new external_value(PARAM_TEXT, 'coverage', VALUE_OPTIONAL),
  'creatorname' => new external_value(PARAM_TEXT, 'creator name'),
  'licenceshortname' => new external_value(PARAM_ALPHANUMEXT, 'licence short name'),
  'subject' => new external_value(PARAM_ALPHANUM, 'subject'),
  'audience' => new external_value(PARAM_ALPHA, 'audience'),
  'educationallevel' => new external_value(PARAM_ALPHA, 'educational level'),
  'creatornotes' => new external_value(PARAM_RAW, 'creator notes'),
  'creatornotesformat' => new external_value(PARAM_INTEGER, 'notes format'),
  'demourl' => new external_value(PARAM_URL, 'demo URL', VALUE_OPTIONAL),
  'courseurl' => new external_value(PARAM_URL, 'course URL', VALUE_OPTIONAL),
  'backupsize' => new external_value(PARAM_INT, 'course backup size in bytes', VALUE_OPTIONAL),
  'enrollable' => new external_value(PARAM_BOOL, 'is the course enrollable'),
  'screenshots' => new external_value(PARAM_INT, 'total number of screenshots'),
  'timemodified' => new external_value(PARAM_INT, 'time of last modification - timestamp'),
  'contents' => new external_multiple_structure(new external_single_structure(
  array(
  'moduletype' => new external_value(PARAM_ALPHA, 'the type of module (activity/block)'),
  'modulename' => new external_value(PARAM_TEXT, 'the name of the module (forum, resource etc)'),
  'contentcount' => new external_value(PARAM_INT, 'how many time the module is used in the course'),
  )), 'contents', VALUE_OPTIONAL),
  'rating' => new external_single_structure (
  array(
  'aggregate' =>  new external_value(PARAM_FLOAT, 'Rating average', VALUE_OPTIONAL),
  'scaleid' => new external_value(PARAM_INT, 'Rating scale'),
  'count' => new external_value(PARAM_INT, 'Rating count'),
  ), 'rating', VALUE_OPTIONAL),
  'comments' => new external_multiple_structure(new external_single_structure (
  array(
  'comment' => new external_value(PARAM_TEXT, 'the comment'),
  'commentator' => new external_value(PARAM_TEXT, 'the name of commentator'),
  'date' => new external_value(PARAM_INT, 'date of the comment'),
  )), 'contents', VALUE_OPTIONAL),
  'outcomes' => new external_multiple_structure(new external_single_structure(
  array(
  'fullname' => new external_value(PARAM_TEXT, 'the outcome fullname')
  )), 'outcomes', VALUE_OPTIONAL)
  ]
  
  Additional fields for each course:
  'screenshotbaseurl' (moodle_url) URL of the first screenshot, only set if $course['screenshots']>0
  'commenturl' (moodle_url) URL for comments
  
  @param string $search search string
  @param bool $downloadable return downloadable courses
  @param bool $enrollable return enrollable courses
  @param array|\stdClass $options other options from the list of allowed options:
  'ids', 'sitecourseids', 'coverage', 'licenceshortname', 'subject', 'audience',
  'educationallevel', 'language', 'orderby', 'givememore', 'allsitecourses'
  @return array of two elements: [$courses, $coursetotal]
  @throws \coding_exception
  @throws moodle_exception
docstring_tokens: Calls WS function hub_get_courses