Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
75.00% |
285 / 380 |
|
66.67% |
4 / 6 |
CRAP | |
0.00% |
0 / 1 |
| Play | |
74.32% |
275 / 370 |
|
66.67% |
4 / 6 |
296.19 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getTsumegoStatus | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
3 | |||
| play | |
69.21% |
209 / 302 |
|
0.00% |
0 / 1 |
308.04 | |||
| getActivityValue | |
100.00% |
29 / 29 |
|
100.00% |
1 / 1 |
6 | |||
| getActivityValueSingle | |
88.24% |
15 / 17 |
|
0.00% |
0 / 1 |
3.01 | |||
| renderTitle | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | App::uses('SetNavigationButtonsInput', 'Utility'); |
| 4 | App::uses('TsumegoButton', 'Utility'); |
| 5 | App::uses('TsumegoButtons', 'Utility'); |
| 6 | App::uses('HeroPowers', 'Utility'); |
| 7 | App::uses('TsumegoXPAndRating', 'Utility'); |
| 8 | App::uses('Level', 'Utility'); |
| 9 | App::uses('AdminActivityLogger', 'Utility'); |
| 10 | App::uses('AdminActivityType', 'Model'); |
| 11 | App::uses('TagConnectionsEdit', 'Utility'); |
| 12 | App::uses('NotFoundException', 'Routing/Error'); |
| 13 | |
| 14 | class Play |
| 15 | { |
| 16 | public function __construct($setFunction) |
| 17 | { |
| 18 | $this->setFunction = $setFunction; |
| 19 | } |
| 20 | |
| 21 | public function getTsumegoStatus(array $tsumego): string |
| 22 | { |
| 23 | if (Auth::isLoggedIn()) |
| 24 | { |
| 25 | $status = ClassRegistry::init('TsumegoStatus')->find('first', ['conditions' => [ |
| 26 | 'user_id' => Auth::getUserID(), |
| 27 | 'tsumego_id' => $tsumego['Tsumego']['id']]]); |
| 28 | if (!$status) |
| 29 | return 'V'; |
| 30 | return $status['TsumegoStatus']['status']; |
| 31 | } |
| 32 | return 'V'; |
| 33 | } |
| 34 | |
| 35 | public function play(int $setConnectionID, $params, $data): mixed |
| 36 | { |
| 37 | ($this->setFunction)('page', 'play'); |
| 38 | |
| 39 | $highestTsumegoOrder = 0; |
| 40 | $doublexp = null; |
| 41 | $suspiciousBehavior = false; |
| 42 | $half = ''; |
| 43 | $isSandbox = false; |
| 44 | $goldenTsumego = false; |
| 45 | $potion = 0; |
| 46 | $potionSuccess = false; |
| 47 | $reviewCheat = false; |
| 48 | $commentCoordinates = []; |
| 49 | $trs = []; |
| 50 | $potionAlert = false; |
| 51 | $eloScore = 0; |
| 52 | $eloScore2 = 0; |
| 53 | $requestProblem = ''; |
| 54 | $achievementUpdate = []; |
| 55 | $tRank = '15k'; |
| 56 | $nothingInRange = false; |
| 57 | $queryTitle = ''; |
| 58 | |
| 59 | $currentSetConnection = ClassRegistry::init('SetConnection')->findById($setConnectionID); |
| 60 | if (!$currentSetConnection) |
| 61 | throw new NotFoundException("Set connection " . $setConnectionID . " wasn't found in the database."); |
| 62 | $id = $currentSetConnection['SetConnection']['tsumego_id']; |
| 63 | |
| 64 | $setConnections = TsumegoUtil::getSetConnectionsWithTitles($id); |
| 65 | $set = ClassRegistry::init('Set')->findById($currentSetConnection['SetConnection']['set_id']); |
| 66 | |
| 67 | $tsumegoVariant = ClassRegistry::init('TsumegoVariant')->find('first', ['conditions' => ['tsumego_id' => $id]]); |
| 68 | |
| 69 | if (isset($params['url']['potionAlert'])) |
| 70 | $potionAlert = true; |
| 71 | |
| 72 | if (isset($params['url']['search'])) |
| 73 | if ($params['url']['search'] == 'topics') |
| 74 | { |
| 75 | $query = $params['url']['search']; |
| 76 | $_COOKIE['query'] = $params['url']['search']; |
| 77 | } |
| 78 | |
| 79 | $tsumegoFilters = new TsumegoFilters(); |
| 80 | |
| 81 | $t = ClassRegistry::init('Tsumego')->findById($id); //the tsumego |
| 82 | |
| 83 | if ($t == null) |
| 84 | $t = ClassRegistry::init('Tsumego')->findById($_COOKIE['lastVisit'] ?? Constants::$DEFAULT_TSUMEGO_ID); |
| 85 | |
| 86 | if (Auth::isLoggedIn()) |
| 87 | $activityValue = $this->getActivityValue(Auth::getUserID(), $t['Tsumego']['id']); |
| 88 | |
| 89 | if ($t['Tsumego']['rating']) |
| 90 | $tRank = Rating::getReadableRankFromRating($t['Tsumego']['rating']); |
| 91 | |
| 92 | Util::setCookie('lastVisit', $id); |
| 93 | |
| 94 | if (Auth::isLoggedIn()) |
| 95 | if (!empty($data)) |
| 96 | { |
| 97 | if (isset($data['Study'])) |
| 98 | { |
| 99 | $tsumegoVariant['TsumegoVariant']['answer1'] = $data['Study']['study1']; |
| 100 | $tsumegoVariant['TsumegoVariant']['answer2'] = $data['Study']['study2']; |
| 101 | $tsumegoVariant['TsumegoVariant']['answer3'] = $data['Study']['study3']; |
| 102 | $tsumegoVariant['TsumegoVariant']['answer4'] = $data['Study']['study4']; |
| 103 | $tsumegoVariant['TsumegoVariant']['explanation'] = $data['Study']['explanation']; |
| 104 | $tsumegoVariant['TsumegoVariant']['numAnswer'] = $data['Study']['studyCorrect']; |
| 105 | ClassRegistry::init('TsumegoVariant')->save($tsumegoVariant); |
| 106 | } |
| 107 | elseif (isset($data['Study2'])) |
| 108 | { |
| 109 | $tsumegoVariant['TsumegoVariant']['winner'] = $data['Study2']['winner']; |
| 110 | $tsumegoVariant['TsumegoVariant']['answer1'] = $data['Study2']['answer1']; |
| 111 | $tsumegoVariant['TsumegoVariant']['answer2'] = $data['Study2']['answer2']; |
| 112 | $tsumegoVariant['TsumegoVariant']['answer3'] = $data['Study2']['answer3']; |
| 113 | ClassRegistry::init('TsumegoVariant')->save($tsumegoVariant); |
| 114 | } |
| 115 | elseif (isset($data['Settings'])) |
| 116 | { |
| 117 | if ($data['Settings']['r39'] == 'on' && $t['Tsumego']['alternative_response'] != 1) |
| 118 | AdminActivityLogger::log(AdminActivityType::ALTERNATIVE_RESPONSE, $t['Tsumego']['id'], null, null, '1'); |
| 119 | if ($data['Settings']['r39'] == 'off' && $t['Tsumego']['alternative_response'] != 0) |
| 120 | AdminActivityLogger::log(AdminActivityType::ALTERNATIVE_RESPONSE, $t['Tsumego']['id'], null, null, '0'); |
| 121 | if ($data['Settings']['r43'] == 'no' && $t['Tsumego']['pass'] != 0) |
| 122 | AdminActivityLogger::log(AdminActivityType::PASS_MODE, $t['Tsumego']['id'], null, null, '0'); |
| 123 | if ($data['Settings']['r43'] == 'yes' && $t['Tsumego']['pass'] != 1) |
| 124 | AdminActivityLogger::log(AdminActivityType::PASS_MODE, $t['Tsumego']['id'], null, null, '1'); |
| 125 | if ($data['Settings']['r41'] == 'yes' && $tsumegoVariant == null) |
| 126 | { |
| 127 | AdminActivityLogger::log(AdminActivityType::MULTIPLE_CHOICE, $t['Tsumego']['id'], null, null, '1'); |
| 128 | $tv1 = []; |
| 129 | $tv1['TsumegoVariant']['tsumego_id'] = $id; |
| 130 | $tv1['TsumegoVariant']['type'] = 'multiple_choice'; |
| 131 | $tv1['TsumegoVariant']['answer1'] = 'Black is dead'; |
| 132 | $tv1['TsumegoVariant']['answer2'] = 'White is dead'; |
| 133 | $tv1['TsumegoVariant']['answer3'] = 'Ko'; |
| 134 | $tv1['TsumegoVariant']['answer4'] = 'Seki'; |
| 135 | $tv1['TsumegoVariant']['numAnswer'] = '1'; |
| 136 | ClassRegistry::init('TsumegoVariant')->create(); |
| 137 | ClassRegistry::init('TsumegoVariant')->save($tv1); |
| 138 | } |
| 139 | if ($data['Settings']['r41'] == 'no' && $tsumegoVariant != null) |
| 140 | { |
| 141 | AdminActivityLogger::log(AdminActivityType::MULTIPLE_CHOICE, $t['Tsumego']['id'], null, null, '0'); |
| 142 | ClassRegistry::init('TsumegoVariant')->delete($tsumegoVariant['TsumegoVariant']['id']); |
| 143 | $tsumegoVariant = null; |
| 144 | } |
| 145 | if ($data['Settings']['r42'] == 'yes' && $tsumegoVariant == null) |
| 146 | { |
| 147 | AdminActivityLogger::log(AdminActivityType::SCORE_ESTIMATING, $t['Tsumego']['id'], null, null, '1'); |
| 148 | $tv1 = []; |
| 149 | $tv1['TsumegoVariant']['tsumego_id'] = $id; |
| 150 | $tv1['TsumegoVariant']['type'] = 'score_estimating'; |
| 151 | $tv1['TsumegoVariant']['numAnswer'] = '0'; |
| 152 | ClassRegistry::init('TsumegoVariant')->create(); |
| 153 | ClassRegistry::init('TsumegoVariant')->save($tv1); |
| 154 | } |
| 155 | if ($data['Settings']['r42'] == 'no' && $tsumegoVariant != null) |
| 156 | { |
| 157 | AdminActivityLogger::log(AdminActivityType::SCORE_ESTIMATING, $t['Tsumego']['id'], null, null, '0'); |
| 158 | ClassRegistry::init('TsumegoVariant')->delete($tsumegoVariant['TsumegoVariant']['id']); |
| 159 | $tsumegoVariant = null; |
| 160 | } |
| 161 | if ($data['Settings']['r39'] == 'on') |
| 162 | $t['Tsumego']['alternative_response'] = 1; |
| 163 | else |
| 164 | $t['Tsumego']['alternative_response'] = 0; |
| 165 | if ($data['Settings']['r43'] == 'yes') |
| 166 | $t['Tsumego']['pass'] = 1; |
| 167 | else |
| 168 | $t['Tsumego']['pass'] = 0; |
| 169 | if ($t['Tsumego']['rating'] > 100) |
| 170 | ClassRegistry::init('Tsumego')->save($t, true); |
| 171 | } |
| 172 | ($this->setFunction)('formRedirect', true); |
| 173 | } |
| 174 | if (Auth::isAdmin()) |
| 175 | { |
| 176 | $aad = ClassRegistry::init('AdminActivity')->find('first', ['order' => 'id DESC']); |
| 177 | if ($aad && $aad['AdminActivity']['type'] === AdminActivityType::PROBLEM_DELETE)($this->setFunction)('deleteProblem2', true); |
| 178 | } |
| 179 | |
| 180 | if (isset($_COOKIE['skip']) && $_COOKIE['skip'] != '0' && Auth::getUser()) |
| 181 | { |
| 182 | Auth::getUser()['readingTrial']--; |
| 183 | unset($_COOKIE['skip']); |
| 184 | } |
| 185 | $sandboxSets = ClassRegistry::init('Set')->find('all', ['conditions' => ['public' => 0]]) ?: []; |
| 186 | foreach ($sandboxSets as $sandboxSet) |
| 187 | if ($set['Set']['id'] == $sandboxSet['Set']['id']) |
| 188 | $isSandbox = true; |
| 189 | |
| 190 | $tsumegoStatus = Play::getTsumegoStatus($t); |
| 191 | |
| 192 | if ($tsumegoStatus == 'G') |
| 193 | $goldenTsumego = true; |
| 194 | |
| 195 | if (Auth::isLoggedIn() && Auth::getUser()['potion'] >= 15) |
| 196 | AppController::setPotionCondition(); |
| 197 | |
| 198 | Util::setCookie('previousTsumegoID', $id); |
| 199 | |
| 200 | $amountOfOtherCollection = count(TsumegoUtil::collectTsumegosFromSet($set['Set']['id'])); |
| 201 | |
| 202 | $sgf = []; |
| 203 | $sgfdb = ClassRegistry::init('Sgf')->find('first', [ |
| 204 | 'order' => 'id DESC', |
| 205 | 'conditions' => [ |
| 206 | 'tsumego_id' => $id, |
| 207 | 'accepted' => true]]); |
| 208 | if (!$sgfdb) |
| 209 | { |
| 210 | $sgf['Sgf']['sgf'] = Constants::$SGF_PLACEHOLDER; |
| 211 | $sgf['Sgf']['tsumego_id'] = $id; |
| 212 | } |
| 213 | else |
| 214 | $sgf = $sgfdb; |
| 215 | if (!is_null($t['Tsumego']['semeaiType']) && $t['Tsumego']['semeaiType'] != 0) |
| 216 | { |
| 217 | $tr = strpos($sgf['Sgf']['sgf'], 'TR'); |
| 218 | $sq = strpos($sgf['Sgf']['sgf'], 'SQ'); |
| 219 | $sequencesSign = strpos($sgf['Sgf']['sgf'], ';B'); |
| 220 | $p4 = substr($sgf['Sgf']['sgf'], $tr, $sq - $tr); |
| 221 | $trX = str_split(substr($p4, 2), 4); |
| 222 | $p5 = substr($sgf['Sgf']['sgf'], $sq, $sequencesSign - $sq); |
| 223 | $sqX = str_split(substr($p5, 2), 4); |
| 224 | $sqXCount = count($sqX); |
| 225 | |
| 226 | for ($i = 0; $i < $sqXCount; $i++) |
| 227 | if (strlen($sqX[$i]) < 4) |
| 228 | unset($sqX[$i]); |
| 229 | ($this->setFunction)('multipleChoiceTriangles', count($trX)); |
| 230 | ($this->setFunction)('multipleChoiceSquares', count($sqX)); |
| 231 | } |
| 232 | if ($tsumegoFilters->query == 'topics')($this->setFunction)('_title', $set['Set']['title'] . ' ' . $currentSetConnection['SetConnection']['num'] . '/' . $highestTsumegoOrder . ' on Tsumego Hero'); |
| 233 | else |
| 234 | ($this->setFunction)('_title', ($_COOKIE['lastSet'] ?? 'Tsumego') . ' ' . $currentSetConnection['SetConnection']['num'] . '/' . $highestTsumegoOrder . ' on Tsumego Hero'); |
| 235 | |
| 236 | if (Auth::isInLevelMode()) |
| 237 | { |
| 238 | $tsumegoButtons = new TsumegoButtons($tsumegoFilters, $currentSetConnection['SetConnection']['id'], null, $set['Set']['id']); |
| 239 | new SetNavigationButtonsInput($this->setFunction)->execute($tsumegoButtons, $currentSetConnection); |
| 240 | $queryTitle = $tsumegoFilters->getSetTitle($set) . $tsumegoButtons->getPartitionTitleSuffix() . ' ' . $tsumegoButtons->currentOrder . '/' . $tsumegoButtons->highestTsumegoOrder; |
| 241 | } |
| 242 | |
| 243 | $t['Tsumego']['status'] = $tsumegoStatus; |
| 244 | |
| 245 | if (!isset($t['Tsumego']['file']) || $t['Tsumego']['file'] == '') |
| 246 | $t['Tsumego']['file'] = $currentSetConnection['SetConnection']['num']; |
| 247 | $orientation = null; |
| 248 | $colorOrientation = null; |
| 249 | if (isset($params['url']['orientation'])) |
| 250 | $orientation = $params['url']['orientation']; |
| 251 | if (isset($params['url']['playercolor'])) |
| 252 | $colorOrientation = $params['url']['playercolor']; |
| 253 | |
| 254 | $checkBSize = 19; |
| 255 | for ($i = 2; $i <= 19; $i++) |
| 256 | if (strpos(';' . $set['Set']['title'], $i . 'x' . $i)) |
| 257 | $checkBSize = $i; |
| 258 | |
| 259 | if (Util::getHealthBasedOnLevel(Auth::getWithDefault('level', 0)) >= 8) |
| 260 | { |
| 261 | $fullHeart = 'heart1small'; |
| 262 | $emptyHeart = 'heart2small'; |
| 263 | } |
| 264 | else |
| 265 | { |
| 266 | $fullHeart = 'heart1'; |
| 267 | $emptyHeart = 'heart2'; |
| 268 | } |
| 269 | if (Auth::isLoggedIn()) |
| 270 | if (Auth::getUser()['reuse5'] == 1) |
| 271 | $suspiciousBehavior = true; |
| 272 | $hash = AppController::encrypt($currentSetConnection['SetConnection']['num'] . 'number' . $set['Set']['id']); |
| 273 | |
| 274 | $activate = true; |
| 275 | if (Auth::isInRatingMode() || Auth::isInTimeMode())($this->setFunction)('_title', 'Tsumego Hero'); |
| 276 | if ($isSandbox) |
| 277 | $t['Tsumego']['userWin'] = 0; |
| 278 | |
| 279 | $crs = 0; |
| 280 | |
| 281 | if (Auth::isInLevelMode())($this->setFunction)('page', 'level mode'); |
| 282 | elseif (Auth::isInRatingMode())($this->setFunction)('page', 'rating mode'); |
| 283 | elseif (Auth::isInTimeMode())($this->setFunction)('page', 'time mode'); |
| 284 | |
| 285 | $ui = 2; |
| 286 | $file = 'placeholder2.sgf'; |
| 287 | $startingPlayer = TsumegosController::getStartingPlayer($sgf['Sgf']['sgf']); |
| 288 | |
| 289 | $eloScoreRounded = round($eloScore); |
| 290 | $eloScore2Rounded = round($eloScore2); |
| 291 | |
| 292 | $existingSignatures = ClassRegistry::init('Signature')->find('all', ['conditions' => ['tsumego_id' => $id]]); |
| 293 | if ($existingSignatures == null || $existingSignatures[0]['Signature']['created'] < date('Y-m-d', strtotime('-1 week'))) |
| 294 | $requestSignature = 'true'; |
| 295 | else |
| 296 | $requestSignature = 'false'; |
| 297 | if (isset($_COOKIE['signatures']) && $set['Set']['public'] == 1) |
| 298 | { |
| 299 | $signature = explode('/', $_COOKIE['signatures']); |
| 300 | $oldSignatures = ClassRegistry::init('Signature')->find('all', ['conditions' => ['tsumego_id' => $signature[count($signature) - 1]]]); |
| 301 | if (!$oldSignatures) |
| 302 | $oldSignatures = []; |
| 303 | |
| 304 | $oldSignaturesCount = count($oldSignatures); |
| 305 | |
| 306 | for ($i = 0; $i < $oldSignaturesCount; $i++) |
| 307 | ClassRegistry::init('Signature')->delete($oldSignatures[$i]['Signature']['id']); |
| 308 | |
| 309 | $signatureCountMinus1 = count($signature) - 1; |
| 310 | for ($i = 0; $i < $signatureCountMinus1; $i++) |
| 311 | { |
| 312 | ClassRegistry::init('Signature')->create(); |
| 313 | $newSignature = []; |
| 314 | $newSignature['Signature']['tsumego_id'] = $signature[count($signature) - 1]; |
| 315 | $newSignature['Signature']['signature'] = $signature[$i]; |
| 316 | ClassRegistry::init('Signature')->save($newSignature); |
| 317 | } |
| 318 | unset($_COOKIE['signatures']); |
| 319 | } |
| 320 | $idForSignature = -1; |
| 321 | $idForSignature2 = -1; |
| 322 | if (isset($params['url']['idForTheThing'])) |
| 323 | { |
| 324 | $idForSignature2 = $params['url']['idForTheThing'] + 1; |
| 325 | $idForSignature = TsumegosController::getTheIdForTheThing($idForSignature2); |
| 326 | } |
| 327 | |
| 328 | $tagConnectionsEdit = new TagConnectionsEdit($id, TsumegoUtil::hasStateAllowingInspection($t)); |
| 329 | |
| 330 | $isAllowedToContribute = false; |
| 331 | $isAllowedToContribute2 = false; |
| 332 | if (Auth::isLoggedIn()) |
| 333 | { |
| 334 | if (Auth::getUser()['level'] >= 40) |
| 335 | $isAllowedToContribute = true; |
| 336 | elseif (Auth::getUser()['rating'] >= Constants::$MINIMUM_RATING_TO_CONTRIBUTE) |
| 337 | $isAllowedToContribute = true; |
| 338 | |
| 339 | if (Auth::isAdmin()) |
| 340 | { |
| 341 | $isAllowedToContribute = true; |
| 342 | $isAllowedToContribute2 = true; |
| 343 | } |
| 344 | else |
| 345 | { |
| 346 | $tagsToCheck = ClassRegistry::init('TagConnection')->find('all', ['limit' => 20, 'order' => 'created DESC', 'conditions' => ['user_id' => Auth::getUserID()]]) ?: []; |
| 347 | $datex = date('Y-m-d', strtotime('today')); |
| 348 | $tagsToCheckCount = count($tagsToCheck); |
| 349 | |
| 350 | for ($i = 0; $i < $tagsToCheckCount; $i++) |
| 351 | { |
| 352 | $datexx = new DateTime($tagsToCheck[$i]['TagConnection']['created']); |
| 353 | $datexx = $datexx->format('Y-m-d'); |
| 354 | if ($datex !== $datexx) |
| 355 | $isAllowedToContribute2 = true; |
| 356 | } |
| 357 | if (count($tagsToCheck) < 20) |
| 358 | $isAllowedToContribute2 = true; |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | $checkNotInSearch = false; |
| 363 | |
| 364 | $isTSUMEGOinFAVORITE = ClassRegistry::init('Favorite')->find('first', ['conditions' => ['user_id' => Auth::getUserID(), 'tsumego_id' => $id]]); |
| 365 | |
| 366 | if (Auth::isInLevelMode()) |
| 367 | $tsumegoButtons->exportCurrentAndPreviousLink($this->setFunction, $tsumegoFilters, $setConnectionID, $set); |
| 368 | |
| 369 | ($this->setFunction)('isAllowedToContribute', $isAllowedToContribute); |
| 370 | ($this->setFunction)('isAllowedToContribute2', $isAllowedToContribute2); |
| 371 | |
| 372 | $sgfProposal = ClassRegistry::init('Sgf')->find('first', ['conditions' => ['tsumego_id' => $id, 'user_id' => Auth::getUserID(), 'accepted' => false]]); |
| 373 | ($this->setFunction)('hasSgfProposal', $sgfProposal != null); |
| 374 | |
| 375 | ($this->setFunction)('tagConnectionsEdit', $tagConnectionsEdit); |
| 376 | ($this->setFunction)('requestSignature', $requestSignature); |
| 377 | ($this->setFunction)('idForSignature', $idForSignature); |
| 378 | ($this->setFunction)('idForSignature2', $idForSignature2); |
| 379 | if (isset($activityValue))($this->setFunction)('activityValue', $activityValue); |
| 380 | ($this->setFunction)('nothingInRange', $nothingInRange); |
| 381 | ($this->setFunction)('tRank', $tRank); |
| 382 | ($this->setFunction)('sgf', $sgf); |
| 383 | ($this->setFunction)('crs', $crs); |
| 384 | ($this->setFunction)('orientation', $orientation); |
| 385 | ($this->setFunction)('colorOrientation', $colorOrientation); |
| 386 | ($this->setFunction)('isTSUMEGOinFAVORITE', $isTSUMEGOinFAVORITE != null); |
| 387 | ($this->setFunction)('suspiciousBehavior', $suspiciousBehavior); |
| 388 | ($this->setFunction)('isSandbox', $isSandbox); |
| 389 | ($this->setFunction)('goldenTsumego', $goldenTsumego); |
| 390 | $boardsBitmask = BoardSelector::filterValidBits(Auth::isLoggedIn() ? Auth::getUser()['boards_bitmask'] : BoardSelector::$DEFAULT_BOARDS_BITMASK); |
| 391 | ($this->setFunction)('boardSelection', BoardSelector::selectBoard($boardsBitmask, $goldenTsumego, $set['Set']['board_theme_index'])); |
| 392 | ($this->setFunction)('fullHeart', $fullHeart); |
| 393 | ($this->setFunction)('emptyHeart', $emptyHeart); |
| 394 | ($this->setFunction)('maxHealth', Util::getHealthBasedOnLevel(Auth::getWithDefault('level', 0))); |
| 395 | ($this->setFunction)('libertyCount', $t['Tsumego']['libertyCount']); |
| 396 | ($this->setFunction)('semeaiType', $t['Tsumego']['semeaiType']); |
| 397 | ($this->setFunction)('insideLiberties', $t['Tsumego']['insideLiberties']); |
| 398 | ($this->setFunction)('doublexp', $doublexp); |
| 399 | ($this->setFunction)('half', $half); |
| 400 | ($this->setFunction)('set', $set); |
| 401 | if (Auth::isLoggedIn())($this->setFunction)('barPercent', Util::getPercent(Auth::getUser()['xp'], Level::getXPForNext(Auth::getUser()['level']))); |
| 402 | else |
| 403 | ($this->setFunction)('barPercent', 0); |
| 404 | ($this->setFunction)('t', $t); |
| 405 | ($this->setFunction)('solvedCheck', AppController::encrypt($t['Tsumego']['id'] . '-' . time())); |
| 406 | ($this->setFunction)('hash', $hash); |
| 407 | ($this->setFunction)('rating', Auth::getWithDefault('rating', 0)); |
| 408 | ($this->setFunction)('eloScore', $eloScore); |
| 409 | ($this->setFunction)('eloScore2', $eloScore2); |
| 410 | ($this->setFunction)('eloScoreRounded', $eloScoreRounded); |
| 411 | ($this->setFunction)('eloScore2Rounded', $eloScore2Rounded); |
| 412 | ($this->setFunction)('activate', $activate); |
| 413 | ($this->setFunction)('tsumegoElo', $t['Tsumego']['rating']); |
| 414 | ($this->setFunction)('trs', $trs); |
| 415 | ($this->setFunction)('potion', $potion); |
| 416 | ($this->setFunction)('potionSuccess', $potionSuccess); |
| 417 | ($this->setFunction)('reviewCheat', $reviewCheat); |
| 418 | ($this->setFunction)('part', $t['Tsumego']['part']); |
| 419 | ($this->setFunction)('checkBSize', $checkBSize); |
| 420 | ($this->setFunction)('potionAlert', $potionAlert); |
| 421 | ($this->setFunction)('file', $file); |
| 422 | ($this->setFunction)('ui', $ui); |
| 423 | ($this->setFunction)('requestProblem', $requestProblem); |
| 424 | ($this->setFunction)('alternative_response', $t['Tsumego']['alternative_response']); |
| 425 | ($this->setFunction)('passEnabled', $t['Tsumego']['pass']); |
| 426 | ($this->setFunction)('achievementUpdate', $achievementUpdate); |
| 427 | ($this->setFunction)('setConnection', $currentSetConnection); |
| 428 | ($this->setFunction)('setConnections', $setConnections); |
| 429 | if (isset($params['url']['requestSolution']))($this->setFunction)('requestSolution', AdminActivityLogger::log(AdminActivityType::SOLUTION_REQUEST, $id)); |
| 430 | ($this->setFunction)('startingPlayer', $startingPlayer); |
| 431 | ($this->setFunction)('tv', $tsumegoVariant); |
| 432 | ($this->setFunction)('tsumegoFilters', $tsumegoFilters); |
| 433 | ($this->setFunction)('queryTitle', $queryTitle); |
| 434 | ($this->setFunction)('amountOfOtherCollection', $amountOfOtherCollection); |
| 435 | ($this->setFunction)('checkNotInSearch', $checkNotInSearch); |
| 436 | ($this->setFunction)('tsumegoXPAndRating', new TsumegoXPAndRating($t['Tsumego'], $tsumegoStatus)); |
| 437 | |
| 438 | return null; |
| 439 | } |
| 440 | |
| 441 | protected function getActivityValue($uid, $tid) |
| 442 | { |
| 443 | $return = []; |
| 444 | $tsumegoNum = 90; |
| 445 | $ra = ClassRegistry::init('TsumegoAttempt')->find('all', ['limit' => $tsumegoNum, 'order' => 'created DESC', 'conditions' => ['user_id' => $uid]]); |
| 446 | if (!$ra) |
| 447 | $ra = []; |
| 448 | if (count($ra) < $tsumegoNum) |
| 449 | { |
| 450 | $missing = $tsumegoNum - count($ra); |
| 451 | $raSize = count($ra); |
| 452 | $datex = new DateTime('-1 month'); |
| 453 | while ($missing != 0) |
| 454 | { |
| 455 | $ra[$raSize]['TsumegoAttempt']['created'] = $datex->format('Y-m-d H:i:s'); |
| 456 | $ra[$raSize]['TsumegoAttempt']['tsumego_id'] = 1; |
| 457 | $raSize++; |
| 458 | $missing--; |
| 459 | } |
| 460 | } |
| 461 | $date = date('Y-m-d H:i:s'); |
| 462 | $x = []; |
| 463 | $avg = 0; |
| 464 | $foundTsumego = 0; |
| 465 | $raCount = count($ra); |
| 466 | for ($i = 0; $i < $raCount; $i++) |
| 467 | { |
| 468 | if ($ra[$i]['TsumegoAttempt']['tsumego_id'] == $tid) |
| 469 | $foundTsumego = 1; |
| 470 | $d = $this->getActivityValueSingle($ra[$i]['TsumegoAttempt']['created']); |
| 471 | $avg += $d; |
| 472 | array_push($x, $d); |
| 473 | } |
| 474 | $avg /= count($x); |
| 475 | $return[0] = round($avg); |
| 476 | $return[1] = $foundTsumego; |
| 477 | |
| 478 | return $return; |
| 479 | } |
| 480 | |
| 481 | private function getActivityValueSingle($date2) |
| 482 | { |
| 483 | $date1 = new DateTime('now'); |
| 484 | $date2 = new DateTime($date2); |
| 485 | $interval = $date1->diff($date2); |
| 486 | $m = $interval->m; |
| 487 | $d = $interval->d; |
| 488 | $h = $interval->h; |
| 489 | $i = $interval->i; |
| 490 | $months = 0; |
| 491 | while ($m > 0) |
| 492 | { |
| 493 | $months += 672; |
| 494 | $m--; |
| 495 | } |
| 496 | $hours = $h; |
| 497 | while ($d > 0) |
| 498 | { |
| 499 | $hours += 24; |
| 500 | $d--; |
| 501 | } |
| 502 | $hours += $months; |
| 503 | |
| 504 | return $hours; |
| 505 | } |
| 506 | |
| 507 | public static function renderTitle($setConnection, $set, $tsumegoFilters, $tsumegoButtons, $amountOfOtherCollection, $difficulty, $timeMode, $queryTitle, $t) |
| 508 | { |
| 509 | if (Auth::isInTimeMode()) |
| 510 | return '<font size="5px">' . $timeMode->currentOrder . ' of ' . $timeMode->overallCount . '</font>'; |
| 511 | |
| 512 | if (Auth::isInRatingMode()) |
| 513 | return '<div class="slidecontainer"> |
| 514 | <input type="range" min="1" max="7" value="' . $difficulty . '" class="slider" id="rangeInput" name="rangeInput"> |
| 515 | <div id="sliderText">regular</div> |
| 516 | </div> |
| 517 | <a id="playTitleA" href=""></a>'; |
| 518 | |
| 519 | $order = $setConnection['SetConnection']['num']; |
| 520 | if ($tsumegoFilters->query == 'difficulty' || $tsumegoFilters->query == 'tags' || $tsumegoFilters->query == 'favorites') |
| 521 | return '<a id="playTitleA" href="/sets/view/' . $tsumegoFilters->getSetID($set['Set']['id']) . $tsumegoButtons->getPartitionLinkSuffix() . '">' . $queryTitle . '</a><br> |
| 522 | <font style="font-weight:400;" color="grey"> |
| 523 | <a style="color:grey;" id="playTitleA" href="/sets/view/' . $set['Set']['id'] . '"> |
| 524 | (' . $set['Set']['title'] . ' ' . $order . '/' . $amountOfOtherCollection . ') |
| 525 | </a> |
| 526 | </font>'; |
| 527 | return '<a id="playTitleA" href="/sets/view/' . $set['Set']['id'] . $tsumegoButtons->getPartitionLinkSuffix() . '">' . $set['Set']['title'] . ' ' . $tsumegoButtons->getPartitionTitleSuffix() . ' ' . $order . '/' . $tsumegoButtons->highestTsumegoOrder . '</a>'; |
| 528 | } |
| 529 | |
| 530 | private $setFunction; |
| 531 | } |