original_string: protected function validate_and_get_users($versionids, $userids, $action) {
          global $DB;
  
          $usernames = [];
          list($sql, $params) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);
          $params['usercontextlevel'] = CONTEXT_USER;
          $users = $DB->get_records_sql("SELECT u.id, " . get_all_user_name_fields(true, 'u') . ", " .
                  \context_helper::get_preload_record_columns_sql('ctx') .
              " FROM {user} u JOIN {context} ctx ON ctx.contextlevel=:usercontextlevel AND ctx.instanceid = u.id
              WHERE u.id " . $sql, $params);
  
          foreach ($userids as $userid) {
              if (!isset($users[$userid])) {
                  throw new \dml_missing_record_exception('user', 'id=?', [$userid]);
              }
              $user = $users[$userid];
              if (isguestuser($user)) {
                  throw new \moodle_exception('noguest');
              }
              \context_helper::preload_from_record($user);
              if ($action === 'revoke') {
                  api::can_revoke_policies($versionids, $userid, true);
              } else if ($action === 'accept') {
                  api::can_accept_policies($versionids, $userid, true);
              } else if ($action === 'decline') {
                  api::can_decline_policies($versionids, $userid, true);
              }
              $usernames[$userid] = fullname($user);
          }
          return $usernames;
      }
code: protected function validate_and_get_users($versionids, $userids, $action) {
          global $DB;
  
          $usernames = [];
          list($sql, $params) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);
          $params['usercontextlevel'] = CONTEXT_USER;
          $users = $DB->get_records_sql("SELECT u.id, " . get_all_user_name_fields(true, 'u') . ", " .
                  \context_helper::get_preload_record_columns_sql('ctx') .
              " FROM {user} u JOIN {context} ctx ON ctx.contextlevel=:usercontextlevel AND ctx.instanceid = u.id
              WHERE u.id " . $sql, $params);
  
          foreach ($userids as $userid) {
              if (!isset($users[$userid])) {
                  throw new \dml_missing_record_exception('user', 'id=?', [$userid]);
              }
              $user = $users[$userid];
              if (isguestuser($user)) {
                  throw new \moodle_exception('noguest');
              }
              \context_helper::preload_from_record($user);
              if ($action === 'revoke') {
                  api::can_revoke_policies($versionids, $userid, true);
              } else if ($action === 'accept') {
                  api::can_accept_policies($versionids, $userid, true);
              } else if ($action === 'decline') {
                  api::can_decline_policies($versionids, $userid, true);
              }
              $usernames[$userid] = fullname($user);
          }
          return $usernames;
      }
code_tokens: protected function validate_and_get_users ( $ versionids , $ userids , $ action ) { global $ DB ; $ usernames = [ ] ; list ( $ sql , $ params ) = $ DB -> get_in_or_equal ( $ userids , SQL_PARAMS_NAMED ) ; $ params [ 'usercontextlevel' ] = CONTEXT_USER ; $ users = $ DB -> get_records_sql ( "SELECT u.id, " . get_all_user_name_fields ( true , 'u' ) . ", " . \ context_helper :: get_preload_record_columns_sql ( 'ctx' ) . " FROM {user} u JOIN {context} ctx ON ctx.contextlevel=:usercontextlevel AND ctx.instanceid = u.id
              WHERE u.id " . $ sql , $ params ) ; foreach ( $ userids as $ userid ) { if ( ! isset ( $ users [ $ userid ] ) ) { throw new \ dml_missing_record_exception ( 'user' , 'id=?' , [ $ userid ] ) ; } $ user = $ users [ $ userid ] ; if ( isguestuser ( $ user ) ) { throw new \ moodle_exception ( 'noguest' ) ; } \ context_helper :: preload_from_record ( $ user ) ; if ( $ action === 'revoke' ) { api :: can_revoke_policies ( $ versionids , $ userid , true ) ; } else if ( $ action === 'accept' ) { api :: can_accept_policies ( $ versionids , $ userid , true ) ; } else if ( $ action === 'decline' ) { api :: can_decline_policies ( $ versionids , $ userid , true ) ; } $ usernames [ $ userid ] = fullname ( $ user ) ; } return $ usernames ; }
docstring: Validate userids and return usernames
  
  @param array $versionids int[] List of policy version ids to process.
  @param array $userids
  @param string $action accept|decline|revoke
  @return array (userid=>username)
docstring_tokens: Validate userids and return usernames