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); $select->innerJoin('place_in_challenge', ['place_in_challenge', 'id'], '=', ['guesses', 'place_in_challenge_id']); $select->where('user_id', '=', $user->getId()); $select->where('challenge_id', '=', $challenge->getId()); yield from $this->pdm->selectMultipleFromDb($select, Guess::class); } public function getByUserAndPlaceInChallenge(User $user, Challenge $challenge, Place $place): ?Guess { $select = new Select(\Container::$dbConnection); $select->innerJoin('place_in_challenge', ['place_in_challenge', 'id'], '=', ['guesses', 'place_in_challenge_id']); $select->where('user_id', '=', $user->getId()); $select->where('challenge_id', '=', $challenge->getId()); $select->where('place_id', '=', $place->getId()); return $this->pdm->selectFromDb($select, Guess::class); } public function getAllInChallengeByUser(int $userId, Challenge $challenge): Generator { $select = new Select(\Container::$dbConnection); $select->innerJoin('place_in_challenge', ['place_in_challenge', 'id'], '=', ['guesses', 'place_in_challenge_id']); $select->where('user_id', '=', $userId); $select->where('challenge_id', '=', $challenge->getId()); $select->orderBy('round'); yield from $this->pdm->selectMultipleFromDb($select, Guess::class); } public function getAllInChallenge(Challenge $challenge, array $withRelations = []): Generator { if (count($withRelations)) { $necessaryRelations = [PlaceInChallenge::class]; $withRelations = array_unique(array_merge($withRelations, $necessaryRelations)); } $select = new Select(\Container::$dbConnection); $select->where('challenge_id', '=', $challenge->getId()); $select->orderBy('round'); yield from $this->pdm->selectMultipleFromDb($select, Guess::class, true, $withRelations); } public function getAllInChallengeByRound(int $round, Challenge $challenge, array $withRelations = []): Generator { if (count($withRelations)) { $necessaryRelations = [PlaceInChallenge::class]; $withRelations = array_unique(array_merge($withRelations, $necessaryRelations)); } $select = new Select(\Container::$dbConnection); $select->where('challenge_id', '=', $challenge->getId()); $select->where('round', '=', $round); yield from $this->pdm->selectMultipleFromDb($select, Guess::class, true, $withRelations); } }