feature/MAPG-235-basic-challenge-mode #48
@ -48,6 +48,6 @@ CREATE TABLE `guesses` (
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `user_id` (`user_id`),
|
||||
KEY `place_in_challenge_id` (`place_in_challenge_id`),
|
||||
CONSTRAINT `guesses_user_id` FOREIGN KEY (`user_id`) REFERENCES `places` (`id`),
|
||||
CONSTRAINT `guesses_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`),
|
||||
CONSTRAINT `guesses_place_in_challenge_id` FOREIGN KEY (`place_in_challenge_id`) REFERENCES `place_in_challenge` (`id`)
|
||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
|
@ -9,7 +9,10 @@ use MapGuesser\Interfaces\Response\IRedirect;
|
||||
use MapGuesser\OAuth\GoogleOAuth;
|
||||
use MapGuesser\PersistentData\PersistentDataManager;
|
||||
use MapGuesser\PersistentData\Model\User;
|
||||
use MapGuesser\PersistentData\Model\UserInChallenge;
|
||||
use MapGuesser\Repository\GuessRepository;
|
||||
use MapGuesser\Repository\UserConfirmationRepository;
|
||||
use MapGuesser\Repository\UserInChallengeRepository;
|
||||
use MapGuesser\Repository\UserPasswordResetterRepository;
|
||||
use MapGuesser\Repository\UserPlayedPlaceRepository;
|
||||
use MapGuesser\Response\HtmlContent;
|
||||
@ -29,6 +32,10 @@ class UserController implements ISecured
|
||||
|
||||
private UserPlayedPlaceRepository $userPlayedPlaceRepository;
|
||||
|
||||
private UserInChallengeRepository $userInChallengeRepository;
|
||||
|
||||
private GuessRepository $guessRepository;
|
||||
|
||||
public function __construct(IRequest $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
@ -36,6 +43,8 @@ class UserController implements ISecured
|
||||
$this->userConfirmationRepository = new UserConfirmationRepository();
|
||||
$this->userPasswordResetterRepository = new UserPasswordResetterRepository();
|
||||
$this->userPlayedPlaceRepository = new UserPlayedPlaceRepository();
|
||||
$this->userInChallengeRepository = new UserInChallengeRepository();
|
||||
$this->guessRepository = new GuessRepository();
|
||||
}
|
||||
|
||||
public function authorize(): bool
|
||||
@ -209,6 +218,14 @@ class UserController implements ISecured
|
||||
$this->pdm->deleteFromDb($userPlayedPlace);
|
||||
}
|
||||
|
||||
foreach ($this->userInChallengeRepository->getAllByUser($user) as $userInChallenge) {
|
||||
$this->pdm->deleteFromDb($userInChallenge);
|
||||
}
|
||||
|
||||
foreach ($this->guessRepository->getAllByUser($user) as $guess) {
|
||||
$this->pdm->deleteFromDb($guess);
|
||||
}
|
||||
|
||||
$this->pdm->deleteFromDb($user);
|
||||
|
||||
\Container::$dbConnection->commit();
|
||||
|
@ -60,7 +60,7 @@ class PersistentDataManager
|
||||
if (strpos($key, '__') == false) {
|
||||
$method = 'set' . str_replace('_', '', ucwords($key, '_'));
|
||||
|
||||
if (method_exists($model, $method)) {
|
||||
if (method_exists($model, $method) && isset($value)) {
|
||||
$model->$method($value);
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ class PersistentDataManager
|
||||
|
||||
$method = 'set' . str_replace('_', '', ucwords($key, '_'));
|
||||
|
||||
if (method_exists($model, $method)) {
|
||||
if (method_exists($model, $method) && isset($value)) {
|
||||
$model->$method($value);
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,14 @@ class GuessRepository
|
||||
$this->pdm = new PersistentDataManager();
|
||||
}
|
||||
|
||||
public function getAllByUser(User $user): Generator
|
||||
{
|
||||
$select = new Select(\Container::$dbConnection);
|
||||
$select->where('user_id', '=', $user->getId());
|
||||
|
||||
yield from $this->pdm->selectMultipleFromDb($select, Guess::class);
|
||||
}
|
||||
|
||||
public function getAllByUserAndChallenge(User $user, Challenge $challenge): Generator
|
||||
{
|
||||
$select = new Select(\Container::$dbConnection);
|
||||
|
Loading…
Reference in New Issue
Block a user