original_string: public static function get_cohort_members($cohortids) {
          global $DB;
          $params = self::validate_parameters(self::get_cohort_members_parameters(), array('cohortids' => $cohortids));
  
          $members = array();
  
          foreach ($params['cohortids'] as $cohortid) {
              // Validate params.
              $cohort = $DB->get_record('cohort', array('id' => $cohortid), '*', MUST_EXIST);
              // Now security checks.
              $context = context::instance_by_id($cohort->contextid, MUST_EXIST);
              if ($context->contextlevel != CONTEXT_COURSECAT and $context->contextlevel != CONTEXT_SYSTEM) {
                  throw new invalid_parameter_exception('Invalid context');
              }
              self::validate_context($context);
              if (!has_any_capability(array('moodle/cohort:manage', 'moodle/cohort:view'), $context)) {
                  throw new required_capability_exception($context, 'moodle/cohort:view', 'nopermissions', '');
              }
  
              $cohortmembers = $DB->get_records_sql("SELECT u.id FROM {user} u, {cohort_members} cm
                  WHERE u.id = cm.userid AND cm.cohortid = ?
                  ORDER BY lastname ASC, firstname ASC", array($cohort->id));
              $members[] = array('cohortid' => $cohortid, 'userids' => array_keys($cohortmembers));
          }
          return $members;
      }
code: public static function get_cohort_members($cohortids) {
          global $DB;
          $params = self::validate_parameters(self::get_cohort_members_parameters(), array('cohortids' => $cohortids));
  
          $members = array();
  
          foreach ($params['cohortids'] as $cohortid) {
              // Validate params.
              $cohort = $DB->get_record('cohort', array('id' => $cohortid), '*', MUST_EXIST);
              // Now security checks.
              $context = context::instance_by_id($cohort->contextid, MUST_EXIST);
              if ($context->contextlevel != CONTEXT_COURSECAT and $context->contextlevel != CONTEXT_SYSTEM) {
                  throw new invalid_parameter_exception('Invalid context');
              }
              self::validate_context($context);
              if (!has_any_capability(array('moodle/cohort:manage', 'moodle/cohort:view'), $context)) {
                  throw new required_capability_exception($context, 'moodle/cohort:view', 'nopermissions', '');
              }
  
              $cohortmembers = $DB->get_records_sql("SELECT u.id FROM {user} u, {cohort_members} cm
                  WHERE u.id = cm.userid AND cm.cohortid = ?
                  ORDER BY lastname ASC, firstname ASC", array($cohort->id));
              $members[] = array('cohortid' => $cohortid, 'userids' => array_keys($cohortmembers));
          }
          return $members;
      }
code_tokens: public static function get_cohort_members ( $ cohortids ) { global $ DB ; $ params = self :: validate_parameters ( self :: get_cohort_members_parameters ( ) , array ( 'cohortids' => $ cohortids ) ) ; $ members = array ( ) ; foreach ( $ params [ 'cohortids' ] as $ cohortid ) { // Validate params. $ cohort = $ DB -> get_record ( 'cohort' , array ( 'id' => $ cohortid ) , '*' , MUST_EXIST ) ; // Now security checks. $ context = context :: instance_by_id ( $ cohort -> contextid , MUST_EXIST ) ; if ( $ context -> contextlevel != CONTEXT_COURSECAT and $ context -> contextlevel != CONTEXT_SYSTEM ) { throw new invalid_parameter_exception ( 'Invalid context' ) ; } self :: validate_context ( $ context ) ; if ( ! has_any_capability ( array ( 'moodle/cohort:manage' , 'moodle/cohort:view' ) , $ context ) ) { throw new required_capability_exception ( $ context , 'moodle/cohort:view' , 'nopermissions' , '' ) ; } $ cohortmembers = $ DB -> get_records_sql ( "SELECT u.id FROM {user} u, {cohort_members} cm
                  WHERE u.id = cm.userid AND cm.cohortid = ?
                  ORDER BY lastname ASC, firstname ASC" , array ( $ cohort -> id ) ) ; $ members [ ] = array ( 'cohortid' => $ cohortid , 'userids' => array_keys ( $ cohortmembers ) ) ; } return $ members ; }
docstring: Return all members for a cohort
  
  @param array $cohortids array of cohort ids
  @return array with cohort id keys containing arrays of user ids
  @since Moodle 2.5
docstring_tokens: Return all members for a cohort