feature/MAPG-235-basic-challenge-mode #48
@ -5,11 +5,16 @@ use MapGuesser\Interfaces\Authentication\IUser;
|
||||
use MapGuesser\Interfaces\Authorization\ISecured;
|
||||
use MapGuesser\Interfaces\Request\IRequest;
|
||||
use MapGuesser\Interfaces\Response\IContent;
|
||||
use MapGuesser\PersistentData\Model\Challenge;
|
||||
use MapGuesser\PersistentData\Model\Map;
|
||||
use MapGuesser\PersistentData\Model\Place;
|
||||
use MapGuesser\PersistentData\PersistentDataManager;
|
||||
use MapGuesser\Repository\ChallengeRepository;
|
||||
use MapGuesser\Repository\GuessRepository;
|
||||
use MapGuesser\Repository\MapRepository;
|
||||
use MapGuesser\Repository\PlaceInChallengeRepository;
|
||||
use MapGuesser\Repository\PlaceRepository;
|
||||
use MapGuesser\Repository\UserInChallengeRepository;
|
||||
use MapGuesser\Repository\UserPlayedPlaceRepository;
|
||||
use MapGuesser\Response\HtmlContent;
|
||||
use MapGuesser\Response\JsonContent;
|
||||
@ -30,6 +35,14 @@ class MapAdminController implements ISecured
|
||||
|
||||
private UserPlayedPlaceRepository $userPlayedPlaceRepository;
|
||||
|
||||
private ChallengeRepository $challengeRepository;
|
||||
|
||||
private GuessRepository $guessRepository;
|
||||
|
||||
private PlaceInChallengeRepository $placeInChallengeRepository;
|
||||
|
||||
private UserInChallengeRepository $userInChallengeRepository;
|
||||
|
||||
public function __construct(IRequest $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
@ -37,6 +50,10 @@ class MapAdminController implements ISecured
|
||||
$this->mapRepository = new MapRepository();
|
||||
$this->placeRepository = new PlaceRepository();
|
||||
$this->userPlayedPlaceRepository = new UserPlayedPlaceRepository();
|
||||
$this->challengeRepository = new ChallengeRepository();
|
||||
$this->guessRepository = new GuessRepository();
|
||||
$this->placeInChallengeRepository = new PlaceInChallengeRepository();
|
||||
$this->userInChallengeRepository = new UserInChallengeRepository();
|
||||
}
|
||||
|
||||
public function authorize(): bool
|
||||
@ -188,6 +205,10 @@ class MapAdminController implements ISecured
|
||||
$this->pdm->deleteFromDb($userPlayedPlace);
|
||||
}
|
||||
|
||||
foreach ($this->challengeRepository->getAllByPlace($place) as $challenge) {
|
||||
$this->deleteChallenge($challenge);
|
||||
}
|
||||
|
||||
$this->pdm->deleteFromDb($place);
|
||||
}
|
||||
|
||||
@ -198,6 +219,23 @@ class MapAdminController implements ISecured
|
||||
}
|
||||
}
|
||||
|
||||
private function deleteChallenge(Challenge $challenge): void
|
||||
{
|
||||
foreach ($this->userInChallengeRepository->getAllByChallenge($challenge) as $userInChallenge) {
|
||||
$this->pdm->deleteFromDb($userInChallenge);
|
||||
}
|
||||
|
||||
foreach ($this->guessRepository->getAllInChallenge($challenge, [PlaceInChallenge::class]) as $guess) {
|
||||
$this->pdm->deleteFromDb($guess);
|
||||
}
|
||||
|
||||
foreach ($this->placeInChallengeRepository->getAllByChallenge($challenge) as $placeInChallenge) {
|
||||
$this->pdm->deleteFromDb($placeInChallenge);
|
||||
}
|
||||
|
||||
$this->pdm->deleteFromDb($challenge);
|
||||
}
|
||||
|
||||
private function calculateMapBounds(Map $map): Bounds
|
||||
{
|
||||
$bounds = new Bounds();
|
||||
|
@ -3,6 +3,7 @@
|
||||
use Generator;
|
||||
use MapGuesser\Database\Query\Select;
|
||||
use MapGuesser\PersistentData\Model\Challenge;
|
||||
use MapGuesser\PersistentData\Model\Place;
|
||||
use MapGuesser\PersistentData\Model\User;
|
||||
use MapGuesser\PersistentData\PersistentDataManager;
|
||||
|
||||
@ -55,4 +56,13 @@ class ChallengeRepository
|
||||
|
||||
yield from $this->pdm->selectMultipleFromDb($select, Challenge::class);
|
||||
}
|
||||
|
||||
public function getAllByPlace(Place $place): Generator
|
||||
{
|
||||
$select = new Select(\Container::$dbConnection);
|
||||
$select->innerJoin('place_in_challenge', ['challenges', 'id'], '=', ['place_in_challenge', 'challenge_id']);
|
||||
$select->where('place_id', '=', $place->getId());
|
||||
|
||||
yield from $this->pdm->selectMultipleFromDb($select, Challenge::class);
|
||||
}
|
||||
}
|
@ -86,4 +86,13 @@ class GuessRepository
|
||||
|
||||
yield from $this->pdm->selectMultipleFromDb($select, Guess::class, true, $withRelations);
|
||||
}
|
||||
|
||||
public function getAllByPlace(Place $place): Generator
|
||||
{
|
||||
$select = new Select(\Container::$dbConnection);
|
||||
$select->innerJoin('place_in_challenge', ['place_in_challenge', 'id'], '=', ['guesses', 'place_in_challenge_id']);
|
||||
$select->where('place_id', '=', $place->getId());
|
||||
|
||||
yield from $this->pdm->selectMultipleFromDb($select, Guess::class);
|
||||
}
|
||||
}
|
||||
|
@ -17,12 +17,12 @@ class PlaceInChallengeRepository
|
||||
$this->pdm = new PersistentDataManager();
|
||||
}
|
||||
|
||||
public function getAllByPlace(Place $place) : Generator
|
||||
public function getAllByPlace(Place $place, array $withRelations = []) : Generator
|
||||
{
|
||||
$select = new Select(\Container::$dbConnection);
|
||||
$select->where('place_id', '=', $place->getId());
|
||||
|
||||
yield from $this->pdm->selectMultipleFromDb($select, PlaceInChallenge::class);
|
||||
yield from $this->pdm->selectMultipleFromDb($select, PlaceInChallenge::class, true, $withRelations);
|
||||
}
|
||||
|
||||
public function getAllByChallenge(Challenge $challenge) : Generator
|
||||
|
Loading…
Reference in New Issue
Block a user