41 lines
957 B
PHP
41 lines
957 B
PHP
|
<?php
|
||
|
|
||
|
namespace GamesShop;
|
||
|
|
||
|
use Doctrine\Common\Collections\ArrayCollection;
|
||
|
use Doctrine\Common\Collections\Collection;
|
||
|
use Doctrine\ORM\EntityManager;
|
||
|
use GamesShop\Entities\Account\User;
|
||
|
use GamesShop\Entities\GamesList;
|
||
|
|
||
|
class UserManager
|
||
|
{
|
||
|
|
||
|
public function __construct(
|
||
|
private readonly EntityManager $entityManager
|
||
|
)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
public function getApplicableGameLists(User $user): Collection {
|
||
|
|
||
|
$listRepo = $this->entityManager->getRepository(GamesList::class);
|
||
|
|
||
|
$allLists = $listRepo->findAll();
|
||
|
$applicableLists = new ArrayCollection();
|
||
|
foreach ($allLists as $list) {
|
||
|
if ($list->isPublic()) {
|
||
|
$applicableLists->add($list);
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
if (!$list->getClaimer()->contains($user)) {
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
$applicableLists->add($list);
|
||
|
}
|
||
|
|
||
|
return $applicableLists;
|
||
|
}
|
||
|
}
|