original_string: public function enrol_cohort(stdClass $instance, $cohortid, $roleid = null, $timestart = 0, $timeend = 0, $status = null, $recovergrades = null) {
          global $DB;
          $context = context_course::instance($instance->courseid);
          list($esql, $params) = get_enrolled_sql($context);
          $sql = "SELECT cm.userid FROM {cohort_members} cm LEFT JOIN ($esql) u ON u.id = cm.userid ".
              "WHERE cm.cohortid = :cohortid AND u.id IS NULL";
          $params['cohortid'] = $cohortid;
          $members = $DB->get_fieldset_sql($sql, $params);
          foreach ($members as $userid) {
              $this->enrol_user($instance, $userid, $roleid, $timestart, $timeend, $status, $recovergrades);
          }
      }
code: public function enrol_cohort(stdClass $instance, $cohortid, $roleid = null, $timestart = 0, $timeend = 0, $status = null, $recovergrades = null) {
          global $DB;
          $context = context_course::instance($instance->courseid);
          list($esql, $params) = get_enrolled_sql($context);
          $sql = "SELECT cm.userid FROM {cohort_members} cm LEFT JOIN ($esql) u ON u.id = cm.userid ".
              "WHERE cm.cohortid = :cohortid AND u.id IS NULL";
          $params['cohortid'] = $cohortid;
          $members = $DB->get_fieldset_sql($sql, $params);
          foreach ($members as $userid) {
              $this->enrol_user($instance, $userid, $roleid, $timestart, $timeend, $status, $recovergrades);
          }
      }
code_tokens: public function enrol_cohort ( stdClass $ instance , $ cohortid , $ roleid = null , $ timestart = 0 , $ timeend = 0 , $ status = null , $ recovergrades = null ) { global $ DB ; $ context = context_course :: instance ( $ instance -> courseid ) ; list ( $ esql , $ params ) = get_enrolled_sql ( $ context ) ; $ sql = "SELECT cm.userid FROM {cohort_members} cm LEFT JOIN ($esql) u ON u.id = cm.userid " . "WHERE cm.cohortid = :cohortid AND u.id IS NULL" ; $ params [ 'cohortid' ] = $ cohortid ; $ members = $ DB -> get_fieldset_sql ( $ sql , $ params ) ; foreach ( $ members as $ userid ) { $ this -> enrol_user ( $ instance , $ userid , $ roleid , $ timestart , $ timeend , $ status , $ recovergrades ) ; } }
docstring: Enrol all not enrolled cohort members into course via enrol instance.
  
  @param stdClass $instance
  @param int $cohortid
  @param int $roleid optional role id
  @param int $timestart 0 means unknown
  @param int $timeend 0 means forever
  @param int $status default to ENROL_USER_ACTIVE for new enrolments, no change by default in updates
  @param bool $recovergrades restore grade history
docstring_tokens: Enrol all not enrolled cohort members into course via enrol instance .