Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
80.95% |
34 / 42 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| RatingModeController | |
80.95% |
34 / 42 |
|
0.00% |
0 / 2 |
14.17 | |
0.00% |
0 / 1 |
| ratingAdjustment | |
66.67% |
10 / 15 |
|
0.00% |
0 / 1 |
10.37 | |||
| index | |
88.89% |
24 / 27 |
|
0.00% |
0 / 1 |
5.03 | |||
| 1 | <?php |
| 2 | |
| 3 | class RatingModeController extends AppController |
| 4 | { |
| 5 | public static function ratingAdjustment($difficultySetting) |
| 6 | { |
| 7 | if ($difficultySetting == 1) |
| 8 | return -Constants::$RATING_MODE_DIFFERENCE_SETTING_3; |
| 9 | if ($difficultySetting == 2) |
| 10 | return -Constants::$RATING_MODE_DIFFERENCE_SETTING_2; |
| 11 | if ($difficultySetting == 3) |
| 12 | return -Constants::$RATING_MODE_DIFFERENCE_SETTING_1; |
| 13 | if ($difficultySetting == 4) |
| 14 | return 0; |
| 15 | if ($difficultySetting == 5) |
| 16 | return Constants::$RATING_MODE_DIFFERENCE_SETTING_1; |
| 17 | if ($difficultySetting == 6) |
| 18 | return Constants::$RATING_MODE_DIFFERENCE_SETTING_2; |
| 19 | if ($difficultySetting == 7) |
| 20 | return Constants::$RATING_MODE_DIFFERENCE_SETTING_3; |
| 21 | return 0; |
| 22 | } |
| 23 | |
| 24 | public function index(): mixed |
| 25 | { |
| 26 | if (!Auth::isLoggedIn()) |
| 27 | return $this->redirect('/users/login'); |
| 28 | |
| 29 | if (!Auth::isInRatingMode()) |
| 30 | Auth::getUser()['mode'] = Constants::$RATING_MODE; |
| 31 | if ($difficultyChange = Util::clearCookie('difficulty')) |
| 32 | Auth::getUser()['t_glicko'] = $difficultyChange; |
| 33 | Auth::saveUser(); |
| 34 | |
| 35 | $adjustedRating = Auth::getUser()['rating'] + self::ratingAdjustment(Auth::getUser()['t_glicko']); |
| 36 | $ratingBounds = new RatingBounds( |
| 37 | $adjustedRating - Constants::$RATING_MODE_SELECTION_INTERVAL / 2, |
| 38 | $adjustedRating + Constants::$RATING_MODE_SELECTION_INTERVAL / 2); |
| 39 | |
| 40 | $queryCondition = ""; |
| 41 | Util::addSqlCondition($queryCondition, "`set`.public = true"); |
| 42 | $ratingBounds->addSqlConditions($queryCondition); |
| 43 | $query = " |
| 44 | SELECT |
| 45 | set_connection.id as id |
| 46 | FROM |
| 47 | tsumego |
| 48 | JOIN set_connection ON set_connection.tsumego_id = tsumego.id |
| 49 | JOIN `set` ON set_connection.set_id = set.id |
| 50 | WHERE " . $queryCondition; |
| 51 | $relatedTsumegos = Util::query($query); |
| 52 | |
| 53 | if (empty($relatedTsumegos)) |
| 54 | { |
| 55 | CookieFlash::set("No problems found for your rating selection", 'failure'); |
| 56 | return $this->redirect('/sets'); |
| 57 | } |
| 58 | shuffle($relatedTsumegos); |
| 59 | |
| 60 | $this->set('nextLink', '/ratingMode'); |
| 61 | $this->set('difficulty', Auth::getUser()['t_glicko']); |
| 62 | |
| 63 | $play = new Play(function ($name, $value) { $this->set($name, $value); }); |
| 64 | $play->play($relatedTsumegos[0]['id'], $this->params, $this->data); |
| 65 | $this->render('/Tsumegos/play'); |
| 66 | return null; |
| 67 | } |
| 68 | } |