mirror of
https://github.com/YGGverse/YGGtracker.git
synced 2025-03-13 05:51:10 +00:00
54 lines
1.4 KiB
PHP
54 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Service;
|
|
|
|
use App\Entity\Activity;
|
|
use App\Repository\ActivityRepository;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
|
|
|
class ActivityService
|
|
{
|
|
private EntityManagerInterface $entityManager;
|
|
private ActivityRepository $activityRepository;
|
|
private ParameterBagInterface $parameterBagInterface;
|
|
|
|
public function __construct(
|
|
EntityManagerInterface $entityManager,
|
|
ParameterBagInterface $parameterBagInterface
|
|
)
|
|
{
|
|
$this->entityManager = $entityManager;
|
|
$this->activityRepository = $entityManager->getRepository(Activity::class);
|
|
$this->parameterBagInterface = $parameterBagInterface;
|
|
}
|
|
|
|
public function addEvent(int $userId, string $event, array $data): ?Activity
|
|
{
|
|
$activity = new Activity();
|
|
|
|
$activity->setEvent($event);
|
|
$activity->setUserId($userId);
|
|
$activity->setApproved($approved);
|
|
$activity->setAdded(time());
|
|
|
|
$this->entityManager->persist($activity);
|
|
$this->entityManager->flush();
|
|
|
|
return $activity;
|
|
}
|
|
|
|
public function findLast(bool $moderator): ?array
|
|
{
|
|
if ($moderator)
|
|
{
|
|
return $this->activityRepository->findLast();
|
|
}
|
|
|
|
else
|
|
{
|
|
return $this->activityRepository->findLastByApprovedField(true);
|
|
}
|
|
}
|
|
} |