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