update page form dependencies #19

This commit is contained in:
ghost 2023-10-06 04:12:14 +03:00
parent 8df29ef605
commit c0cc029350
22 changed files with 1049 additions and 102 deletions

View file

@ -0,0 +1,54 @@
<?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);
}
}
}

View file

@ -3,35 +3,194 @@
namespace App\Service;
use App\Entity\Page;
use App\Repository\PageRepository;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\PageTitle;
use App\Entity\PageDescription;
use App\Entity\PageTorrents;
use App\Entity\PageSensitive;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use App\Repository\PageRepository;
use App\Repository\PageTitleRepository;
use App\Repository\PageDescriptionRepository;
use App\Repository\PageSensitiveRepository;
use App\Repository\PageTorrentsRepository;
use Doctrine\ORM\EntityManagerInterface;
class PageService
{
private EntityManagerInterface $entityManager;
private PageRepository $pageRepository;
private ParameterBagInterface $parameterBagInterface;
public function __construct(
EntityManagerInterface $entityManager,
ParameterBagInterface $parameterBagInterface
)
{
$this->entityManager = $entityManager;
$this->pageRepository = $entityManager->getRepository(Page::class);
$this->parameterBagInterface = $parameterBagInterface;
}
public function new(): ?Page
public function submit(
int $added,
int $userId,
string $locale,
string $title,
string $description,
array $torrents,
bool $sensitive,
bool $approved
): ?Page
{
return new Page();
$page = $this->addPage();
if (!empty($title))
{
$pageTitle = $this->addPageTitle(
$page->getId(),
$userId,
$added,
$locale,
$title,
$approved
);
}
if (!empty($description))
{
$pageDescription = $this->addPageDescription(
$page->getId(),
$userId,
$added,
$locale,
$description,
$approved
);
}
if (!empty($torrents))
{
$pageTorrents = $this->addPageTorrents(
$page->getId(),
$userId,
$added,
$locale,
$torrents,
$approved
);
}
// @TODO
$pageSensitive = $this->addPageSensitive(
$page->getId(),
$userId,
$added,
$locale,
$description,
$approved
);
return $page;
}
public function save(Page $page) : void
public function addPage(): ?Page
{
$page = new Page();
$this->entityManager->persist($page);
$this->entityManager->flush();
return $page;
}
public function addPageTitle(
int $pageId,
int $userId,
int $added,
string $locale,
string $value,
bool $approved
): ?PageTitle
{
$pageTitle = new PageTitle();
$pageTitle->setPageId($pageId);
$pageTitle->setUserId($userId);
$pageTitle->setLocale($locale);
$pageTitle->setValue($value);
$pageTitle->setAdded($added);
$pageTitle->setApproved($approved);
$this->entityManager->persist($pageTitle);
$this->entityManager->flush();
return $pageTitle;
}
public function addPageDescription(
int $pageId,
int $userId,
int $added,
string $locale,
string $value,
bool $approved
): ?PageDescription
{
$pageDescription = new PageDescription();
$pageDescription->setPageId($pageId);
$pageDescription->setUserId($userId);
$pageDescription->setAdded($added);
$pageDescription->setLocale($locale);
$pageDescription->setValue($value);
$pageDescription->setApproved($approved);
$this->entityManager->persist($pageDescription);
$this->entityManager->flush();
return $pageDescription;
}
public function addPageTorrents(
int $pageId,
int $userId,
int $added,
array $torrentsId,
bool $approved
): ?PageTorrents
{
$pageTorrents = new PageTorrents();
$pageTorrents->setPageId($pageId);
$pageTorrents->setUserId($userId);
$pageTorrents->setAdded($added);
$pageTorrents->setTorrentsId($torrentsId);
$pageTorrents->setApproved($approved);
$this->entityManager->persist($pageTorrents);
$this->entityManager->flush();
return $pageTorrents;
}
public function addPageSensitive(
int $pageId,
int $userId,
int $added,
string $locale,
string $value,
bool $approved
): ?PageSensitive
{
$pageSensitive = new PageSensitive();
$pageSensitive->setPageId($pageId);
$pageSensitive->setUserId($userId);
$pageSensitive->setAdded($added);
$pageSensitive->setLocale($locale);
$pageSensitive->setValue($value);
$pageSensitive->setApproved($approved);
$this->entityManager->persist($pageSensitive);
$this->entityManager->flush();
return $pageSensitive;
}
}

View file

@ -58,11 +58,6 @@ class UserService
return $this->userRepository->findOneByIdField($id);
}
public function getAllByAddedFieldDesc(): array
{
return $this->userRepository->findAllByAddedFieldDesc();
}
public function identicon(
mixed $value,
int $size = 16,