summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2025-02-13 23:12:34 +0100
committeremkael <emkael@tlen.pl>2025-02-13 23:12:34 +0100
commitc171b61f3f775e28ac0de926c787dd5c1c9735f4 (patch)
tree67e08757cd25bc276c56e6f08fc251fc4fdf45d7
parent48210e8f28a5afdee40d041352f37676564bf717 (diff)
Validation checks stay in check_parameters, parameter parsing moved to parse_parameters.
-rw-r--r--http/api-inc.php48
1 files changed, 23 insertions, 25 deletions
diff --git a/http/api-inc.php b/http/api-inc.php
index ddc526f..36b2cd5 100644
--- a/http/api-inc.php
+++ b/http/api-inc.php
@@ -537,7 +537,7 @@ class ApiPklV3 extends ApiPklV2 {
const BNET_POINTS_FACTOR_QUOTIENT = 27.0;
const BNET_POINTS_FACTOR_CAP = 1.0;
- protected function _bridgenet_parameters($parameters) {
+ protected function _check_bridgenet_parameters($parameters) {
$this->ensure_parameters($parameters, array('boards', 'type'));
if ($parameters['type'] == ApiPkl::TYPE_TEAMS) {
throw new ParametersException(
@@ -547,39 +547,42 @@ class ApiPklV3 extends ApiPklV2 {
}
}
- protected function _set_board_count($parameters) {
+ function check_parameters($parameters) {
+ // Checks for BridgeNET parameters if type == BridgeNET
+ if (isset($parameters['tournament_rank'])
+ && $parameters['tournament_rank'] == ApiPkl::RANK_BNET) {
+ $this->_check_bridgenet_parameters($parameters);
+ }
+ // Validate newly introduced 'boards' parameter, if provided
if (isset($parameters['boards'])) {
$this->check_values($parameters, array(
'boards' => function($r) {
return is_integer_like($r);
}
));
+ // It overrides 'over39_boards',
+ // so we can force-set it and treat it as non-mandatory.
+ // But we need to do this *before* parent::check_parameters,
+ // as it checks for it occurence.
$parameters['over39_boards'] = strval(
intval($parameters['boards'] > 39)
);
}
- return $parameters;
- }
-
- function check_parameters($parameters) {
- // Checks for BridgeNET parameters if type == BridgeNET
- if (isset($parameters['tournament_rank'])
- && $parameters['tournament_rank'] == ApiPkl::RANK_BNET) {
- $this->_bridgenet_parameters($parameters);
- if (isset($parameters['manual'])) {
- unset($parameters['manual']);
- }
- }
- // Newly introduced 'boards' parameter overrides 'over39_boards'
- $parameters = $this->_set_board_count($parameters);
return parent::check_parameters($parameters);
}
function parse_parameters($parameters) {
$return = parent::parse_parameters($parameters);
- // 'boards' parameter needs to be maintained in $this->parameters
- // as it's used in BridgeNET calculations
+ // BridgeNET type tournaments disregard all 'manual' parameters
+ if (isset($return['tournament_rank'])
+ && $return['tournament_rank'] == ApiPkl::RANK_BNET) {
+ if (isset($return['manual'])) {
+ unset($return['manual']);
+ }
+ }
if (isset($parameters['boards'])) {
+ // 'boards' param needs to be parsed and maintained,
+ // as it's used in BridgeNET calculcations
$return['boards'] = intval($parameters['boards']);
}
return $return;
@@ -600,16 +603,11 @@ class ApiPklV3_1 extends ApiPklV3 {
const BNET_MINIMUM_BOARD_COUNT = 20;
- protected function _bridgenet_parameters($parameters) {
+ protected function _check_bridgenet_parameters($parameters) {
// 'boards' are mandatory for BridgeNET
$this->ensure_parameters($parameters, array('boards'));
- $this->check_values($parameters, array(
- 'boards' => function($r) {
- return is_integer_like($r);
- }
- ));
- // There's no longer a check against type == TEAMS
+ // There's no longer a check against type == TEAMS
// But there's one for minimum board count
if (intval($parameters['boards']) < static::BNET_MINIMUM_BOARD_COUNT) {
throw new ParametersException(