original_string: protected function get_course_options($instance, $coursecontext) {
          global $DB;
  
          if ($instance->id) {
              $where = 'WHERE c.id = :courseid';
              $params = array('courseid' => $instance->customint1);
              $existing = array();
          } else {
              $where = '';
              $params = array();
              $instanceparams = array('enrol' => 'meta', 'courseid' => $instance->courseid);
              $existing = $DB->get_records('enrol', $instanceparams, '', 'customint1, id');
          }
  
          // TODO: this has to be done via ajax or else it will fail very badly on large sites!
          $courses = array();
          $select = ', ' . context_helper::get_preload_record_columns_sql('ctx');
          $join = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
  
          $sortorder = 'c.' . $this->get_config('coursesort', 'sortorder') . ' ASC';
  
          $sql = "SELECT c.id, c.fullname, c.shortname, c.visible $select FROM {course} c $join $where ORDER BY $sortorder";
          $rs = $DB->get_recordset_sql($sql, array('contextlevel' => CONTEXT_COURSE) + $params);
          foreach ($rs as $c) {
              if ($c->id == SITEID or $c->id == $instance->courseid or isset($existing[$c->id])) {
                  continue;
              }
              context_helper::preload_from_record($c);
              $coursecontext = context_course::instance($c->id);
              if (!$c->visible and !has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
                  continue;
              }
              if (!has_capability('enrol/meta:selectaslinked', $coursecontext)) {
                  continue;
              }
              $courses[$c->id] = $coursecontext->get_context_name(false);
          }
          $rs->close();
          return $courses;
      }
code: protected function get_course_options($instance, $coursecontext) {
          global $DB;
  
          if ($instance->id) {
              $where = 'WHERE c.id = :courseid';
              $params = array('courseid' => $instance->customint1);
              $existing = array();
          } else {
              $where = '';
              $params = array();
              $instanceparams = array('enrol' => 'meta', 'courseid' => $instance->courseid);
              $existing = $DB->get_records('enrol', $instanceparams, '', 'customint1, id');
          }
  
          // TODO: this has to be done via ajax or else it will fail very badly on large sites!
          $courses = array();
          $select = ', ' . context_helper::get_preload_record_columns_sql('ctx');
          $join = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
  
          $sortorder = 'c.' . $this->get_config('coursesort', 'sortorder') . ' ASC';
  
          $sql = "SELECT c.id, c.fullname, c.shortname, c.visible $select FROM {course} c $join $where ORDER BY $sortorder";
          $rs = $DB->get_recordset_sql($sql, array('contextlevel' => CONTEXT_COURSE) + $params);
          foreach ($rs as $c) {
              if ($c->id == SITEID or $c->id == $instance->courseid or isset($existing[$c->id])) {
                  continue;
              }
              context_helper::preload_from_record($c);
              $coursecontext = context_course::instance($c->id);
              if (!$c->visible and !has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
                  continue;
              }
              if (!has_capability('enrol/meta:selectaslinked', $coursecontext)) {
                  continue;
              }
              $courses[$c->id] = $coursecontext->get_context_name(false);
          }
          $rs->close();
          return $courses;
      }
code_tokens: protected function get_course_options ( $ instance , $ coursecontext ) { global $ DB ; if ( $ instance -> id ) { $ where = 'WHERE c.id = :courseid' ; $ params = array ( 'courseid' => $ instance -> customint1 ) ; $ existing = array ( ) ; } else { $ where = '' ; $ params = array ( ) ; $ instanceparams = array ( 'enrol' => 'meta' , 'courseid' => $ instance -> courseid ) ; $ existing = $ DB -> get_records ( 'enrol' , $ instanceparams , '' , 'customint1, id' ) ; } // TODO: this has to be done via ajax or else it will fail very badly on large sites! $ courses = array ( ) ; $ select = ', ' . context_helper :: get_preload_record_columns_sql ( 'ctx' ) ; $ join = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)" ; $ sortorder = 'c.' . $ this -> get_config ( 'coursesort' , 'sortorder' ) . ' ASC' ; $ sql = "SELECT c.id, c.fullname, c.shortname, c.visible $select FROM {course} c $join $where ORDER BY $sortorder" ; $ rs = $ DB -> get_recordset_sql ( $ sql , array ( 'contextlevel' => CONTEXT_COURSE ) + $ params ) ; foreach ( $ rs as $ c ) { if ( $ c -> id == SITEID or $ c -> id == $ instance -> courseid or isset ( $ existing [ $ c -> id ] ) ) { continue ; } context_helper :: preload_from_record ( $ c ) ; $ coursecontext = context_course :: instance ( $ c -> id ) ; if ( ! $ c -> visible and ! has_capability ( 'moodle/course:viewhiddencourses' , $ coursecontext ) ) { continue ; } if ( ! has_capability ( 'enrol/meta:selectaslinked' , $ coursecontext ) ) { continue ; } $ courses [ $ c -> id ] = $ coursecontext -> get_context_name ( false ) ; } $ rs -> close ( ) ; return $ courses ; }
docstring: Return an array of valid options for the courses.
  
  @param stdClass $instance
  @param context $coursecontext
  @return array
docstring_tokens: Return an array of valid options for the courses .