diff options
Diffstat (limited to 'http')
-rw-r--r-- | http/api-inc.php | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/http/api-inc.php b/http/api-inc.php index c75ed2e..e70957e 100644 --- a/http/api-inc.php +++ b/http/api-inc.php @@ -85,27 +85,35 @@ class ApiPkl { } function check_parameters() { - $this->ensure_parameters(array('type', 'contestants', 'title_sum')); + $this->ensure_parameters(array('type', 'contestants')); $this->check_values($this->parameters, array( - 'type' => function($r) { return ctype_digit($r) && intval($r) > 0; }, - 'contestants' => function($r) { return ctype_digit($r) && intval($r) > 0; }, - 'title_sum' => function($r) { return floatval($r) >= 0; } + 'type' => function($r) { return $this->is_integer($r) && intval($r) > 0; }, + 'contestants' => function($r) { return $this->is_integer($r) && intval($r) > 0; } )); if (isset($this->parameters['players'])) { $this->check_values($this->parameters, array( - 'players' => function($r) { return ctype_digit($r) && intval($r) > 0; } + 'players' => function($r) { return $this->is_integer($r) && intval($r) > 0; } )); } - if (!isset($this->parameters['manual']) || !isset($this->parameters['manual']['min_points']) || !isset($this->parameters['manual']['tournament_weight'])) { - $this->ensure_parameters(array('tournament_rank', 'over39_boards')); + if (!isset($this->parameters['manual']) || !isset($this->parameters['manual']['min_points'])) { + $this->ensure_parameters(array('title_sum')); $this->check_values($this->parameters, array( - 'tournament_rank' => function($r) { return ctype_digit($r) && ((intval($r) >= 0 && intval($r) <= 7) || in_array(intval($r), array(ApiPkl::RANK_KMP, ApiPkl::RANK_BNET))); }, - 'over39_boards' => function($r) { return ctype_digit($r) && intval($r) >= 0 && intval($r) <= 1; } + 'title_sum' => function($r) { return floatval($r) >= 0; } )); + if (!isset($this->parameters['manual']) || !isset($this->parameters['manual']['tournament_weight'])) { + $this->ensure_parameters(array('tournament_rank', 'over39_boards')); + $this->check_values($this->parameters, array( + 'tournament_rank' => function($r) { return $this->is_integer($r) && ((intval($r) >= 0 && intval($r) <= 7) || in_array(intval($r), array(ApiPkl::RANK_KMP, ApiPkl::RANK_BNET))); }, + 'over39_boards' => function($r) { return $this->is_integer($r) && intval($r) >= 0 && intval($r) <= 1; } + )); + } else { + $this->check_values($this->parameters['manual'], array( + 'tournament_weight' => function($r) { return $this->is_integer($r) && intval($r) > 0; } + )); + } } else { $this->check_values($this->parameters['manual'], array( - 'min_points' => function($r) { return ctype_digit($r) && intval($r) >= 0; }, - 'tournament_weight' => function($r) { return ctype_digit($r) && intval($r) > 0; } + 'min_points' => function($r) { return $this->is_integer($r) && intval($r) >= 0; } )); } if (isset($this->parameters['manual']) && isset($this->parameters['manual']['players_coefficient'])) { @@ -129,12 +137,19 @@ class ApiPkl { } $return['contestants'] = intval($this->parameters['contestants']); $return['players'] = isset($this->parameters['players']) ? intval($this->parameters['players']) : intval($this->parameters['contestants']) * $return['type']; - $return['title_sum'] = floatval($this->parameters['title_sum']); + $return['title_sum'] = isset($this->parameters['title_sum']) ? floatval($this->parameters['title_sum']) : 0.0; $weights = array( array(1, 2, 4, 5, 7, 10, 15, 25, ApiPkl::RANK_KMP => 0, ApiPkl::RANK_BNET => 1), array(2, 3, 5, 7, 10, 15, 25, 40, ApiPkl::RANK_KMP => 0, ApiPkl::RANK_BNET => 1) // not 2, according to MarcinW ); - $return['tournament_weight'] = (isset($this->parameters['manual']) && isset($this->parameters['manual']['tournament_weight'])) ? intval($this->parameters['manual']['tournament_weight']) : $weights[intval($this->parameters['over39_boards'])][intval($this->parameters['tournament_rank'])]; + $return['tournament_weight'] = 0; + if (isset($this->parameters['manual']) && isset($this->parameters['manual']['tournament_weight'])) { + $return['tournament_weight'] = intval($this->parameters['manual']['tournament_weight']); + } else { + if (isset($this->parameters['over39_boards']) && isset($this->parameters['tournament_rank'])) { + $return['tournament_weight'] = $weights[intval($this->parameters['over39_boards'])][intval($this->parameters['tournament_rank'])]; + } + } $min_points = array( array(0, 0, 0, 0, 50, 75, 150, 200, ApiPkl::RANK_KMP => 0, ApiPkl::RANK_BNET => 0), array(0, 0, 0, 0, 70, 100, 200, 300, ApiPkl::RANK_KMP => 0, ApiPkl::RANK_BNET => 0) |