gamesshop/src/php/UserManager.php

41 lines
957 B
PHP
Raw Normal View History

2024-11-04 15:31:21 +00:00
<?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;
}
}