Compare commits
2 Commits
7a1674fdd0
...
45ddb7f56a
Author | SHA1 | Date | |
---|---|---|---|
45ddb7f56a | |||
7792f1c3ff |
@ -1,7 +1,7 @@
|
|||||||
CREATE TABLE `challenges` (
|
CREATE TABLE `challenges` (
|
||||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||||
`token` int(10) unsigned NOT NULL,
|
`token` int(10) unsigned NOT NULL,
|
||||||
`timer_sec` int(10) unsigned,
|
`time_limit` int(10) unsigned,
|
||||||
`no_move` tinyint(1) NOT NULL DEFAULT 0,
|
`no_move` tinyint(1) NOT NULL DEFAULT 0,
|
||||||
`no_pan` tinyint(1) NOT NULL DEFAULT 0,
|
`no_pan` tinyint(1) NOT NULL DEFAULT 0,
|
||||||
`no_zoom` tinyint(1) NOT NULL DEFAULT 0,
|
`no_zoom` tinyint(1) NOT NULL DEFAULT 0,
|
||||||
@ -13,7 +13,7 @@ CREATE TABLE `user_in_challenge` (
|
|||||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||||
`user_id` int(10) unsigned NOT NULL,
|
`user_id` int(10) unsigned NOT NULL,
|
||||||
`challenge_id` int(10) unsigned NOT NULL,
|
`challenge_id` int(10) unsigned NOT NULL,
|
||||||
`round` smallint(5) signed NOT NULL DEFAULT 0,
|
`current_round` smallint(5) signed NOT NULL DEFAULT 0,
|
||||||
`time_left` int(10) unsigned,
|
`time_left` int(10) unsigned,
|
||||||
`is_owner` tinyint(1) NOT NULL DEFAULT 0,
|
`is_owner` tinyint(1) NOT NULL DEFAULT 0,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
@ -27,13 +27,13 @@ CREATE TABLE `place_in_challenge` (
|
|||||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||||
`place_id` int(10) unsigned NOT NULL,
|
`place_id` int(10) unsigned NOT NULL,
|
||||||
`challenge_id` int(10) unsigned NOT NULL,
|
`challenge_id` int(10) unsigned NOT NULL,
|
||||||
`order` smallint(5) unsigned NOT NULL,
|
`round` smallint(5) unsigned NOT NULL,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `place_id` (`place_id`),
|
KEY `place_id` (`place_id`),
|
||||||
KEY `challenge_id` (`challenge_id`),
|
KEY `challenge_id` (`challenge_id`),
|
||||||
CONSTRAINT `place_in_challenge_place_id` FOREIGN KEY (`place_id`) REFERENCES `places` (`id`),
|
CONSTRAINT `place_in_challenge_place_id` FOREIGN KEY (`place_id`) REFERENCES `places` (`id`),
|
||||||
CONSTRAINT `place_in_challenge_challenge_id` FOREIGN KEY (`challenge_id`) REFERENCES `challenges` (`id`),
|
CONSTRAINT `place_in_challenge_challenge_id` FOREIGN KEY (`challenge_id`) REFERENCES `challenges` (`id`),
|
||||||
CONSTRAINT `unique_order_in_challenge` UNIQUE (`order`, `challenge_id`)
|
CONSTRAINT `unique_order_in_challenge` UNIQUE (`round`, `challenge_id`)
|
||||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
|
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
|
||||||
|
|
||||||
CREATE TABLE `guesses` (
|
CREATE TABLE `guesses` (
|
||||||
|
@ -297,19 +297,28 @@ const GameType = Object.freeze({'SINGLE': 0, 'MULTI': 1, 'CHALLENGE': 2});
|
|||||||
|
|
||||||
Game.history = this.response.history;
|
Game.history = this.response.history;
|
||||||
|
|
||||||
for (var i = 0; i < this.response.history.length; ++i) {
|
if (this.response.history !== undefined) {
|
||||||
var round = this.response.history[i];
|
for (var i = 0; i < this.response.history.length; ++i) {
|
||||||
Game.rounds.push({ position: round.position, guessPosition: round.result.guessPosition, realMarker: null, guessMarkers: [] });
|
var round = this.response.history[i];
|
||||||
Game.addPositionToResultMap(true);
|
|
||||||
if (round.result.guessPosition) {
|
if (round.result) {
|
||||||
Game.addGuessPositionToResultMap(round.result.guessPosition, null, true);
|
Game.rounds.push({ position: round.position, guessPosition: round.result.guessPosition, realMarker: null, guessMarkers: [] });
|
||||||
}
|
Game.addPositionToResultMap(true);
|
||||||
Game.scoreSum += round.result.score;
|
if (round.result.guessPosition) {
|
||||||
|
Game.addGuessPositionToResultMap(round.result.guessPosition, null, true);
|
||||||
|
}
|
||||||
|
Game.scoreSum += round.result.score;
|
||||||
|
|
||||||
|
|
||||||
|
if (round.allResults !== undefined) {
|
||||||
|
for (var j = 0; j < round.allResults.length; ++j) {
|
||||||
|
var result = round.allResults[j];
|
||||||
|
if (result.guessPosition) {
|
||||||
|
Game.addGuessPositionToResultMap(result.guessPosition, result, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (var j = 0; j < round.allResults.length; ++j) {
|
|
||||||
var result = round.allResults[j];
|
|
||||||
if (result.guessPosition) {
|
|
||||||
Game.addGuessPositionToResultMap(result.guessPosition, result, true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -800,10 +809,12 @@ const GameType = Object.freeze({'SINGLE': 0, 'MULTI': 1, 'CHALLENGE': 2});
|
|||||||
}
|
}
|
||||||
Game.scoreSum += round.result.score;
|
Game.scoreSum += round.result.score;
|
||||||
|
|
||||||
for (var j = 0; j < round.allResults.length; ++j) {
|
if(round.allResults !== undefined) {
|
||||||
var result = round.allResults[j];
|
for (var j = 0; j < round.allResults.length; ++j) {
|
||||||
if (result.guessPosition) {
|
var result = round.allResults[j];
|
||||||
Game.addGuessPositionToResultMap(result.guessPosition, result, true);
|
if (result.guessPosition) {
|
||||||
|
Game.addGuessPositionToResultMap(result.guessPosition, result, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ class GameController
|
|||||||
$challenge->setCreatedDate(new DateTime());
|
$challenge->setCreatedDate(new DateTime());
|
||||||
|
|
||||||
if($this->request->post('timerEnabled') !== null && $this->request->post('timeLimit') !== null) {
|
if($this->request->post('timerEnabled') !== null && $this->request->post('timeLimit') !== null) {
|
||||||
$challenge->setTimerSec($this->request->post('timeLimit'));
|
$challenge->setTimeLimit($this->request->post('timeLimit'));
|
||||||
}
|
}
|
||||||
if($this->request->post('noMove') !== null) {
|
if($this->request->post('noMove') !== null) {
|
||||||
$challenge->setNoMove(true);
|
$challenge->setNoMove(true);
|
||||||
@ -135,7 +135,7 @@ class GameController
|
|||||||
$userInChallenge = new UserInChallenge();
|
$userInChallenge = new UserInChallenge();
|
||||||
$userInChallenge->setUserId($userId);
|
$userInChallenge->setUserId($userId);
|
||||||
$userInChallenge->setChallenge($challenge);
|
$userInChallenge->setChallenge($challenge);
|
||||||
$userInChallenge->setTimeLeft($challenge->getTimerSec());
|
$userInChallenge->setTimeLeft($challenge->getTimeLimit());
|
||||||
$userInChallenge->setIsOwner(true);
|
$userInChallenge->setIsOwner(true);
|
||||||
|
|
||||||
$this->pdm->saveToDb($userInChallenge);
|
$this->pdm->saveToDb($userInChallenge);
|
||||||
@ -147,12 +147,12 @@ class GameController
|
|||||||
|
|
||||||
$places = $this->placeRepository->getRandomNPlaces($mapId, static::NUMBER_OF_ROUNDS, $userId);
|
$places = $this->placeRepository->getRandomNPlaces($mapId, static::NUMBER_OF_ROUNDS, $userId);
|
||||||
|
|
||||||
$order = 1;
|
$round = 0;
|
||||||
foreach ($places as $place) {
|
foreach ($places as $place) {
|
||||||
$placeInChallenge = new PlaceInChallenge();
|
$placeInChallenge = new PlaceInChallenge();
|
||||||
$placeInChallenge->setPlace($place);
|
$placeInChallenge->setPlace($place);
|
||||||
$placeInChallenge->setChallenge($challenge);
|
$placeInChallenge->setChallenge($challenge);
|
||||||
$placeInChallenge->setOrder($order++);
|
$placeInChallenge->setRound($round++);
|
||||||
$this->pdm->saveToDb($placeInChallenge);
|
$this->pdm->saveToDb($placeInChallenge);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,7 +246,7 @@ class GameController
|
|||||||
$userInChallenge = new UserInChallenge();
|
$userInChallenge = new UserInChallenge();
|
||||||
$userInChallenge->setUserId($userId);
|
$userInChallenge->setUserId($userId);
|
||||||
$userInChallenge->setChallenge($challenge);
|
$userInChallenge->setChallenge($challenge);
|
||||||
$userInChallenge->setTimeLeft($challenge->getTimerSec());
|
$userInChallenge->setTimeLeft($challenge->getTimeLimit());
|
||||||
$this->pdm->saveToDb($userInChallenge);
|
$this->pdm->saveToDb($userInChallenge);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ use MapGuesser\Util\Geo\Position;
|
|||||||
use MapGuesser\Response\JsonContent;
|
use MapGuesser\Response\JsonContent;
|
||||||
use MapGuesser\Interfaces\Response\IContent;
|
use MapGuesser\Interfaces\Response\IContent;
|
||||||
use MapGuesser\Multi\MultiConnector;
|
use MapGuesser\Multi\MultiConnector;
|
||||||
use MapGuesser\PersistentData\Model\UserInChallenge;
|
use MapGuesser\PersistentData\Model\Challenge;
|
||||||
use MapGuesser\PersistentData\PersistentDataManager;
|
use MapGuesser\PersistentData\PersistentDataManager;
|
||||||
use MapGuesser\PersistentData\Model\Guess;
|
use MapGuesser\PersistentData\Model\Guess;
|
||||||
use MapGuesser\PersistentData\Model\UserPlayedPlace;
|
use MapGuesser\PersistentData\Model\UserPlayedPlace;
|
||||||
@ -141,6 +141,47 @@ class GameFlowController
|
|||||||
return new JsonContent(['ok' => true]);
|
return new JsonContent(['ok' => true]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function prepareChallengeResponse(int $userId, Challenge $challenge, int $currentRound): array
|
||||||
|
{
|
||||||
|
$allGuessesInChallenge = iterator_to_array($this->guessRepository->getAllInChallenge($challenge));
|
||||||
|
|
||||||
|
foreach ($allGuessesInChallenge as $guess) {
|
||||||
|
$round = $guess->getPlaceInChallenge()->getRound();
|
||||||
|
|
||||||
|
if ($guess->getUser()->getId() === $userId) {
|
||||||
|
$response['history'][$round]['position'] =
|
||||||
|
$guess->getPlaceInChallenge()->getPlace()->getPosition()->toArray();
|
||||||
|
$response['history'][$round]['result'] = [
|
||||||
|
'guessPosition' => $guess->getPosition()->toArray(),
|
||||||
|
'distance' => $guess->getDistance(),
|
||||||
|
'score' => $guess->getScore()
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
$response['history'][$round]['allResults'][] = [
|
||||||
|
'userName' => $guess->getUser()->getDisplayName(),
|
||||||
|
'guessPosition' => $guess->getPosition()->toArray(),
|
||||||
|
'distance' => $guess->getDistance(),
|
||||||
|
'score' => $guess->getScore()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$currentPlace = $this->placeRepository->getByRoundInChallenge($challenge, $currentRound);
|
||||||
|
|
||||||
|
if(!isset($currentPlace)) { // game finished
|
||||||
|
$response['finished'] = true;
|
||||||
|
|
||||||
|
} else { // continue game
|
||||||
|
$response['place'] = [
|
||||||
|
'panoId' => $currentPlace->getPanoIdCached(),
|
||||||
|
'pov' => [$currentPlace->getPov()->toArray()]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
public function challengeInitialData(): IContent
|
public function challengeInitialData(): IContent
|
||||||
{
|
{
|
||||||
$session = $this->request->session();
|
$session = $this->request->session();
|
||||||
@ -153,53 +194,9 @@ class GameFlowController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$challenge = $userInChallenge->getChallenge();
|
$challenge = $userInChallenge->getChallenge();
|
||||||
$currentRound = $userInChallenge->getRound();
|
$currentRound = $userInChallenge->getCurrentRound();
|
||||||
$currentPlace = $this->placeRepository->getByRoundInChallenge($challenge, $currentRound);
|
|
||||||
|
|
||||||
$response = [];
|
$response = $this->prepareChallengeResponse($userId, $challenge, $currentRound);
|
||||||
|
|
||||||
$response['history'] = [];
|
|
||||||
|
|
||||||
$allGuessesInChallenge = iterator_to_array($this->guessRepository->getAllInChallenge($challenge));
|
|
||||||
$guessesByUser = iterator_to_array($this->guessRepository->getAllInChallengeByUser($userId, $challenge));
|
|
||||||
$places = iterator_to_array($this->placeRepository->getAllInChallenge($challenge));
|
|
||||||
|
|
||||||
|
|
||||||
for($i = 0; $i < $currentRound; ++$i) {
|
|
||||||
|
|
||||||
$response['history'][] = [
|
|
||||||
'position' => $places[$i]->getPosition()->toArray(),
|
|
||||||
'result' => [
|
|
||||||
'guessPosition' => $guessesByUser[$i]->getPosition()->toArray(),
|
|
||||||
'distance' => $guessesByUser[$i]->getDistance(),
|
|
||||||
'score' => $guessesByUser[$i]->getScore()
|
|
||||||
],
|
|
||||||
'allResults' => []
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach($this->guessRepository->getAllInChallengeByRound($i, $challenge) as $guess) {
|
|
||||||
if($guess->getUserId() != $userId) {
|
|
||||||
$user = $this->userRepository->getByGuess($guess);
|
|
||||||
|
|
||||||
$response['history'][$i]['allResults'][] = [
|
|
||||||
'userName' => $user->getDisplayName(),
|
|
||||||
'guessPosition' => $guess->getPosition()->toArray(),
|
|
||||||
'distance' => $guess->getDistance(),
|
|
||||||
'score' => $guess->getScore()
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!isset($currentPlace)) { // game finished
|
|
||||||
$response['finished'] = true;
|
|
||||||
|
|
||||||
} else { // continue game
|
|
||||||
$response['place'] = [
|
|
||||||
'panoId' => $currentPlace->getPanoIdCached(),
|
|
||||||
'pov' => [$currentPlace->getPov()->toArray()]
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
return new JsonContent($response);
|
return new JsonContent($response);
|
||||||
}
|
}
|
||||||
@ -316,22 +313,11 @@ class GameFlowController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$challenge = $userInChallenge->getChallenge();
|
$challenge = $userInChallenge->getChallenge();
|
||||||
$currentRound = $userInChallenge->getRound();
|
$currentRound = $userInChallenge->getCurrentRound();
|
||||||
$currentPlace = $this->placeRepository->getByRoundInChallenge($challenge, $currentRound);
|
$currentPlaceInChallenge = $this->placeInChallengeRepository->getByRoundInChallenge($currentRound, $challenge);
|
||||||
$map = $this->mapRepository->getByPlace($currentPlace);
|
$currentPlace = $currentPlaceInChallenge->getPlace();
|
||||||
$placeInChallenge = $this->placeInChallengeRepository->getByPlaceAndChallenge($currentPlace, $challenge);
|
$map = $currentPlace->getMap();
|
||||||
|
|
||||||
// fill in all other results for the round
|
|
||||||
$response['allResults'] = [];
|
|
||||||
foreach($this->guessRepository->getAllInChallengeByRound($currentRound, $challenge) as $guess) {
|
|
||||||
$user = $this->userRepository->getByGuess($guess);
|
|
||||||
$response['allResults'][] = [
|
|
||||||
'userName' => $user->getDisplayName(),
|
|
||||||
'guessPosition' => $guess->getPosition()->toArray(),
|
|
||||||
'distance' => $guess->getDistance(),
|
|
||||||
'score' => $guess->getScore()
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
$guessPosition = new Position((float) $this->request->post('lat'), (float) $this->request->post('lng'));
|
$guessPosition = new Position((float) $this->request->post('lat'), (float) $this->request->post('lng'));
|
||||||
$result = $this->evaluateGuess($currentPlace->getPosition(), $guessPosition, $map->getArea());
|
$result = $this->evaluateGuess($currentPlace->getPosition(), $guessPosition, $map->getArea());
|
||||||
@ -339,67 +325,33 @@ class GameFlowController
|
|||||||
// save guess
|
// save guess
|
||||||
$guess = new Guess();
|
$guess = new Guess();
|
||||||
$guess->setUserId($userId);
|
$guess->setUserId($userId);
|
||||||
$guess->setPlaceInChallenge($placeInChallenge);
|
$guess->setPlaceInChallenge($currentPlaceInChallenge);
|
||||||
$guess->setPosition($guessPosition);
|
$guess->setPosition($guessPosition);
|
||||||
$guess->setDistance($result['distance']);
|
$guess->setDistance($result['distance']);
|
||||||
$guess->setScore($result['score']);
|
$guess->setScore($result['score']);
|
||||||
$this->pdm->saveToDb($guess);
|
$this->pdm->saveToDb($guess);
|
||||||
|
|
||||||
// $response = [
|
|
||||||
// 'position' => $currentPlace->getPosition()->toArray(),
|
|
||||||
// 'result' => $result
|
|
||||||
// ];
|
|
||||||
$response['position'] = $currentPlace->getPosition()->toArray();
|
|
||||||
$response['result'] = $result;
|
|
||||||
|
|
||||||
// update round
|
// update round
|
||||||
$nextRound = $currentRound + 1;
|
$nextRound = $currentRound + 1;
|
||||||
|
|
||||||
$userInChallenge->setRound($nextRound);
|
$userInChallenge->setCurrentRound($nextRound);
|
||||||
$this->pdm->saveToDb($userInChallenge);
|
$this->pdm->saveToDb($userInChallenge);
|
||||||
|
|
||||||
if ($nextRound < static::NUMBER_OF_ROUNDS) {
|
|
||||||
|
|
||||||
$nextPlace = $this->placeRepository->getByRoundInChallenge($challenge, $nextRound);
|
// creating response
|
||||||
|
$response = $this->prepareChallengeResponse($userId, $challenge, $nextRound);
|
||||||
|
|
||||||
$response['place'] = [
|
$response['position'] = $currentPlace->getPosition()->toArray();
|
||||||
'panoId' => $nextPlace->getPanoIdCached(),
|
$response['result'] = $result;
|
||||||
'pov' => $nextPlace->getPov()->toArray()
|
|
||||||
];
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
$guessesByUser = iterator_to_array($this->guessRepository->getAllInChallengeByUser($userId, $challenge));
|
|
||||||
$places = iterator_to_array($this->placeRepository->getAllInChallenge($challenge));
|
|
||||||
|
|
||||||
for($i = 0; $i < $nextRound; ++$i) {
|
|
||||||
|
|
||||||
$response['history'][] = [
|
|
||||||
'position' => $places[$i]->getPosition()->toArray(),
|
|
||||||
'result' => [
|
|
||||||
'guessPosition' => $guessesByUser[$i]->getPosition()->toArray(),
|
|
||||||
'distance' => $guessesByUser[$i]->getDistance(),
|
|
||||||
'score' => $guessesByUser[$i]->getScore()
|
|
||||||
],
|
|
||||||
'allResults' => []
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach($this->guessRepository->getAllInChallengeByRound($i, $challenge) as $guess) {
|
|
||||||
if($guess->getUserId() != $userId) {
|
|
||||||
$user = $this->userRepository->getByGuess($guess);
|
|
||||||
|
|
||||||
$response['history'][$i]['allResults'][] = [
|
|
||||||
'userName' => $user->getDisplayName(),
|
|
||||||
'guessPosition' => $guess->getPosition()->toArray(),
|
|
||||||
'distance' => $guess->getDistance(),
|
|
||||||
'score' => $guess->getScore()
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if(isset($response['history'][$currentRound]['allResults'])) {
|
||||||
|
$response['allResults'] = $response['history'][$currentRound]['allResults'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$this->saveVisit($currentPlace->getId());
|
$this->saveVisit($currentPlace->getId());
|
||||||
|
|
||||||
return new JsonContent($response);
|
return new JsonContent($response);
|
||||||
|
@ -6,13 +6,13 @@ class Challenge extends Model
|
|||||||
{
|
{
|
||||||
protected static string $table = 'challenges';
|
protected static string $table = 'challenges';
|
||||||
|
|
||||||
protected static array $fields = ['token', 'timer_sec', 'no_move', 'no_pan', 'no_zoom', 'created'];
|
protected static array $fields = ['token', 'time_limit', 'no_move', 'no_pan', 'no_zoom', 'created'];
|
||||||
|
|
||||||
protected static array $relations = [];
|
protected static array $relations = [];
|
||||||
|
|
||||||
private int $token;
|
private int $token;
|
||||||
|
|
||||||
private ?int $timerSec = null;
|
private ?int $timeLimit = null;
|
||||||
|
|
||||||
private bool $noMove = false;
|
private bool $noMove = false;
|
||||||
|
|
||||||
@ -27,10 +27,10 @@ class Challenge extends Model
|
|||||||
$this->token = $token;
|
$this->token = $token;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setTimerSec(?int $timerSec): void
|
public function setTimeLimit(?int $timeLimit): void
|
||||||
{
|
{
|
||||||
if(isset($timerSec)) {
|
if(isset($timeLimit)) {
|
||||||
$this->timerSec = $timerSec;
|
$this->timeLimit = $timeLimit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,9 +64,9 @@ class Challenge extends Model
|
|||||||
return $this->token;
|
return $this->token;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTimerSec(): ?int
|
public function getTimeLimit(): ?int
|
||||||
{
|
{
|
||||||
return $this->timerSec;
|
return $this->timeLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNoMove(): bool
|
public function getNoMove(): bool
|
||||||
|
@ -4,7 +4,7 @@ class PlaceInChallenge extends Model
|
|||||||
{
|
{
|
||||||
protected static string $table = 'place_in_challenge';
|
protected static string $table = 'place_in_challenge';
|
||||||
|
|
||||||
protected static array $fields = ['place_id', 'challenge_id', 'order'];
|
protected static array $fields = ['place_id', 'challenge_id', 'round'];
|
||||||
|
|
||||||
protected static array $relations = ['place' => Place::class, 'challenge' => Challenge::class];
|
protected static array $relations = ['place' => Place::class, 'challenge' => Challenge::class];
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ class PlaceInChallenge extends Model
|
|||||||
|
|
||||||
private ?int $challengeId = null;
|
private ?int $challengeId = null;
|
||||||
|
|
||||||
private int $order;
|
private int $round;
|
||||||
|
|
||||||
public function setPlace(Place $place): void
|
public function setPlace(Place $place): void
|
||||||
{
|
{
|
||||||
@ -38,9 +38,9 @@ class PlaceInChallenge extends Model
|
|||||||
$this->challengeId = $challengeId;
|
$this->challengeId = $challengeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setOrder(int $order): void
|
public function setRound(int $round): void
|
||||||
{
|
{
|
||||||
$this->order = $order;
|
$this->round = $round;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPlace(): ?Place
|
public function getPlace(): ?Place
|
||||||
@ -63,8 +63,8 @@ class PlaceInChallenge extends Model
|
|||||||
return $this->challengeId;
|
return $this->challengeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOrder(): int
|
public function getRound(): int
|
||||||
{
|
{
|
||||||
return $this->order;
|
return $this->round;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ class UserInChallenge extends Model
|
|||||||
{
|
{
|
||||||
protected static string $table = 'user_in_challenge';
|
protected static string $table = 'user_in_challenge';
|
||||||
|
|
||||||
protected static array $fields = ['user_id', 'challenge_id', 'round', 'time_left', 'is_owner'];
|
protected static array $fields = ['user_id', 'challenge_id', 'current_round', 'time_left', 'is_owner'];
|
||||||
|
|
||||||
protected static array $relations = ['user' => User::class, 'challenge' => Challenge::class];
|
protected static array $relations = ['user' => User::class, 'challenge' => Challenge::class];
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ class UserInChallenge extends Model
|
|||||||
|
|
||||||
private ?int $challengeId = null;
|
private ?int $challengeId = null;
|
||||||
|
|
||||||
private int $round = 0;
|
private int $currentRound = 0;
|
||||||
|
|
||||||
private ?int $timeLeft = null;
|
private ?int $timeLeft = null;
|
||||||
|
|
||||||
@ -42,9 +42,9 @@ class UserInChallenge extends Model
|
|||||||
$this->challengeId = $challengeId;
|
$this->challengeId = $challengeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setRound(int $round): void
|
public function setCurrentRound(int $currentRound): void
|
||||||
{
|
{
|
||||||
$this->round = $round;
|
$this->currentRound = $currentRound;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setTimeLeft(?int $timeLeft): void
|
public function setTimeLeft(?int $timeLeft): void
|
||||||
@ -79,9 +79,9 @@ class UserInChallenge extends Model
|
|||||||
return $this->challengeId;
|
return $this->challengeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRound(): int
|
public function getCurrentRound(): int
|
||||||
{
|
{
|
||||||
return $this->round;
|
return $this->currentRound;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTimeLeft(): ?int
|
public function getTimeLeft(): ?int
|
||||||
|
@ -45,7 +45,7 @@ class GuessRepository
|
|||||||
$select->innerJoin('place_in_challenge', ['place_in_challenge', 'id'], '=', ['guesses', 'place_in_challenge_id']);
|
$select->innerJoin('place_in_challenge', ['place_in_challenge', 'id'], '=', ['guesses', 'place_in_challenge_id']);
|
||||||
$select->where('user_id', '=', $userId);
|
$select->where('user_id', '=', $userId);
|
||||||
$select->where('challenge_id', '=', $challenge->getId());
|
$select->where('challenge_id', '=', $challenge->getId());
|
||||||
$select->orderBy('order');
|
$select->orderBy('round');
|
||||||
|
|
||||||
yield from $this->pdm->selectMultipleFromDb($select, Guess::class);
|
yield from $this->pdm->selectMultipleFromDb($select, Guess::class);
|
||||||
}
|
}
|
||||||
@ -55,20 +55,18 @@ class GuessRepository
|
|||||||
$select = new Select(\Container::$dbConnection);
|
$select = new Select(\Container::$dbConnection);
|
||||||
// $select->innerJoin('place_in_challenge', ['guesses', 'place_in_challenge_id'], '=', ['place_in_challenge', 'id']);
|
// $select->innerJoin('place_in_challenge', ['guesses', 'place_in_challenge_id'], '=', ['place_in_challenge', 'id']);
|
||||||
$select->where('challenge_id', '=', $challenge->getId());
|
$select->where('challenge_id', '=', $challenge->getId());
|
||||||
$select->orderBy('order');
|
$select->orderBy('round');
|
||||||
|
|
||||||
yield from $this->pdm->selectMultipleFromDb($select, Guess::class, true);
|
yield from $this->pdm->selectMultipleFromDb($select, Guess::class, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAllInChallengeByRound(int $round, Challenge $challenge): Generator
|
public function getAllInChallengeByRound(int $round, Challenge $challenge): Generator
|
||||||
{
|
{
|
||||||
$order = $round + 1;
|
|
||||||
|
|
||||||
$select = new Select(\Container::$dbConnection);
|
$select = new Select(\Container::$dbConnection);
|
||||||
$select->innerJoin('place_in_challenge', ['guesses', 'place_in_challenge_id'], '=', ['place_in_challenge', 'id']);
|
// $select->innerJoin('place_in_challenge', ['guesses', 'place_in_challenge_id'], '=', ['place_in_challenge', 'id']);
|
||||||
$select->where('challenge_id', '=', $challenge->getId());
|
$select->where('challenge_id', '=', $challenge->getId());
|
||||||
$select->where('order', '=', $order);
|
$select->where('round', '=', $round);
|
||||||
|
|
||||||
yield from $this->pdm->selectMultipleFromDb($select, Guess::class);
|
yield from $this->pdm->selectMultipleFromDb($select, Guess::class, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,4 +40,14 @@ class PlaceInChallengeRepository
|
|||||||
|
|
||||||
return $this->pdm->selectFromDb($select, PlaceInChallenge::class);
|
return $this->pdm->selectFromDb($select, PlaceInChallenge::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getByRoundInChallenge(int $round, Challenge $challenge): ?PlaceInChallenge
|
||||||
|
{
|
||||||
|
$select = new Select(\Container::$dbConnection);
|
||||||
|
$select->where('challenge_id', '=', $challenge->getId());
|
||||||
|
$select->orderBy('round');
|
||||||
|
$select->limit(1, $round);
|
||||||
|
|
||||||
|
return $this->pdm->selectFromDb($select, PlaceInChallenge::class, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -183,7 +183,7 @@ class PlaceRepository
|
|||||||
$select = new Select(\Container::$dbConnection);
|
$select = new Select(\Container::$dbConnection);
|
||||||
$select->innerJoin('place_in_challenge', ['places', 'id'], '=', ['place_in_challenge', 'place_id']);
|
$select->innerJoin('place_in_challenge', ['places', 'id'], '=', ['place_in_challenge', 'place_id']);
|
||||||
$select->where('challenge_id', '=', $challenge->getId());
|
$select->where('challenge_id', '=', $challenge->getId());
|
||||||
$select->orderBy('order');
|
$select->orderBy('round');
|
||||||
$select->limit(1, $round);
|
$select->limit(1, $round);
|
||||||
|
|
||||||
return $this->pdm->selectFromDb($select, Place::class);
|
return $this->pdm->selectFromDb($select, Place::class);
|
||||||
@ -194,7 +194,7 @@ class PlaceRepository
|
|||||||
$select = new Select(\Container::$dbConnection);
|
$select = new Select(\Container::$dbConnection);
|
||||||
$select->innerJoin('place_in_challenge', ['places', 'id'], '=', ['place_in_challenge', 'place_id']);
|
$select->innerJoin('place_in_challenge', ['places', 'id'], '=', ['place_in_challenge', 'place_id']);
|
||||||
$select->where('challenge_id', '=', $challenge->getId());
|
$select->where('challenge_id', '=', $challenge->getId());
|
||||||
$select->orderBy('order');
|
$select->orderBy('round');
|
||||||
|
|
||||||
yield from $this->pdm->selectMultipleFromDb($select, Place::class);
|
yield from $this->pdm->selectMultipleFromDb($select, Place::class);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user