44 lines
1.5 KiB
PHP
44 lines
1.5 KiB
PHP
<?php namespace MapGuesser\Repository;
|
|
|
|
use Generator;
|
|
use SokoWeb\Database\Query\Select;
|
|
use MapGuesser\PersistentData\Model\User;
|
|
use MapGuesser\PersistentData\Model\Place;
|
|
use MapGuesser\PersistentData\Model\UserPlayedPlace;
|
|
|
|
class UserPlayedPlaceRepository
|
|
{
|
|
public function getByUser(User $user): Generator
|
|
{
|
|
$select = new Select(\Container::$dbConnection);
|
|
$select->where('user_id', '=', $user->getId());
|
|
|
|
yield from \Container::$persistentDataManager->selectMultipleFromDb($select, UserPlayedPlace::class);
|
|
}
|
|
|
|
public function getAllByPlace(Place $place): Generator
|
|
{
|
|
$select = new Select(\Container::$dbConnection);
|
|
$select->where('place_id', '=', $place->getId());
|
|
|
|
yield from \Container::$persistentDataManager->selectMultipleFromDb($select, UserPlayedPlace::class);
|
|
}
|
|
|
|
public function getAllByUser(User $user) : Generator
|
|
{
|
|
$select = new Select(\Container::$dbConnection);
|
|
$select->where('user_id', '=', $user->getId());
|
|
|
|
yield from \Container::$persistentDataManager->selectMultipleFromDb($select, UserPlayedPlace::class);
|
|
}
|
|
|
|
public function getByUserIdAndPlaceId(int $userId, int $placeId) : ?UserPlayedPlace
|
|
{
|
|
$select = new Select(\Container::$dbConnection);
|
|
$select->where('user_id', '=', $userId);
|
|
$select->where('place_id', '=', $placeId);
|
|
|
|
return \Container::$persistentDataManager->selectFromDb($select, UserPlayedPlace::class);
|
|
}
|
|
}
|