2018-06-28 22:40:14 +00:00
|
|
|
<?php
|
2022-07-10 13:51:26 +00:00
|
|
|
declare(strict_types=1);
|
2018-06-28 22:40:14 +00:00
|
|
|
|
|
|
|
namespace App\User;
|
|
|
|
|
|
|
|
use App\Entity\{Invite, User};
|
|
|
|
use App\Repository\InviteRepository;
|
|
|
|
|
|
|
|
class InviteManager
|
|
|
|
{
|
2022-07-10 13:51:26 +00:00
|
|
|
public function __construct(
|
|
|
|
private readonly InviteRepository $inviteRepo,
|
|
|
|
private readonly int $newUserInvites = 0
|
|
|
|
) {
|
2018-06-28 22:40:14 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Invite[]
|
|
|
|
*/
|
|
|
|
public function createInvitesForUser(User $user, int $forceAmount = null): iterable
|
|
|
|
{
|
|
|
|
if (!in_array('ROLE_USER', $user->getRoles(), true)) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2022-07-10 13:51:26 +00:00
|
|
|
$amount = $forceAmount ?? $this->newUserInvites;
|
2018-06-28 22:40:14 +00:00
|
|
|
|
|
|
|
$invites = [];
|
|
|
|
|
|
|
|
for ($i = 0; $i < $amount; $i++) {
|
|
|
|
$invite = new Invite($user);
|
|
|
|
$this->inviteRepo->add($invite);
|
|
|
|
$invites[] = $invite;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $invites;
|
|
|
|
}
|
2022-07-10 13:51:26 +00:00
|
|
|
}
|