diff --git a/.env b/.env
index 284b058..ecdff9a 100644
--- a/.env
+++ b/.env
@@ -56,6 +56,6 @@ APP_PAGE_TITLE_LENGTH_MIN=10
APP_PAGE_TITLE_LENGTH_MAX=255
APP_PAGE_DESCRIPTION_LENGTH_MIN=0
APP_PAGE_DESCRIPTION_LENGTH_MAX=10000
-APP_PAGE_TORRENT_QUANTITY_MIN=1
-APP_PAGE_TORRENT_QUANTITY_MAX=100
-APP_PAGE_TORRENT_SIZE_MAX=1024000
\ No newline at end of file
+APP_PAGE_TORRENT_FILE_QUANTITY_MIN=1
+APP_PAGE_TORRENT_FILE_QUANTITY_MAX=100
+APP_TORRENT_FILE_SIZE_MAX=1024000
\ No newline at end of file
diff --git a/src/Controller/PageController.php b/src/Controller/PageController.php
index 1a580b2..60a3cf6 100644
--- a/src/Controller/PageController.php
+++ b/src/Controller/PageController.php
@@ -11,19 +11,54 @@ use Symfony\Component\HttpFoundation\Request;
use App\Service\UserService;
use App\Service\PageService;
+use App\Service\TorrentService;
use App\Service\TimeService;
class PageController extends AbstractController
{
#[Route(
- '/{_locale}/page/submit',
- name: 'page_submit'
+ '/{_locale}/page/{id}',
+ name: 'page_info',
+ requirements:
+ [
+ 'id' => '\d+'
+ ],
+ methods:
+ [
+ 'GET'
+ ]
+ )]
+ public function info(
+ Request $request,
+ TranslatorInterface $translator,
+ UserService $userService
+ ): Response
+ {
+ // Init user
+ $user = $userService->init(
+ $request->getClientIp()
+ );
+
+ return $this->render('default/page/info.html.twig', [
+ 'title' => 'test'
+ ]);
+ }
+
+ #[Route(
+ '/{_locale}/submit/page',
+ name: 'page_submit',
+ methods:
+ [
+ 'GET',
+ 'POST'
+ ]
)]
public function submit(
Request $request,
TranslatorInterface $translator,
UserService $userService,
PageService $pageService,
+ PageService $torrentService
): Response
{
// Init user
@@ -45,8 +80,11 @@ class PageController extends AbstractController
'locale' =>
[
'error' => [],
- 'value' => $request->get('_locale'),
- 'placeholder' => $translator->trans('Content language'),
+ 'attribute' =>
+ [
+ 'value' => $request->get('_locale'),
+ 'placeholder' => $translator->trans('Content language')
+ ]
],
'title' =>
[
@@ -57,7 +95,7 @@ class PageController extends AbstractController
'minlength' => $this->getParameter('app.page.title.length.min'),
'maxlength' => $this->getParameter('app.page.title.length.max'),
'placeholder' => sprintf(
- $translator->trans('Page title text (%s-%s chars)'),
+ $translator->trans('Page title (%s-%s chars)'),
number_format($this->getParameter('app.page.title.length.min')),
number_format($this->getParameter('app.page.title.length.max'))
),
@@ -72,7 +110,7 @@ class PageController extends AbstractController
'minlength' => $this->getParameter('app.page.description.length.min'),
'maxlength' => $this->getParameter('app.page.description.length.max'),
'placeholder' => sprintf(
- $translator->trans('Page description text (%s-%s chars)'),
+ $translator->trans('Page description (%s-%s chars)'),
number_format($this->getParameter('app.page.description.length.min')),
number_format($this->getParameter('app.page.description.length.max'))
),
@@ -83,7 +121,11 @@ class PageController extends AbstractController
'error' => [],
'attribute' =>
[
- 'placeholder' => $translator->trans('Select torrent files'),
+ 'placeholder' => sprintf(
+ $translator->trans('Append %s-%s torrent files'),
+ $this->getParameter('app.page.torrent.file.quantity.min'),
+ $this->getParameter('app.page.torrent.file.quantity.max')
+ )
]
],
'sensitive' =>
@@ -100,20 +142,12 @@ class PageController extends AbstractController
// Process request
if ($request->isMethod('post'))
{
- // Init new
- $page = $pageService->new();
-
/// Locale
if (!in_array($request->get('locale'), explode('|', $this->getParameter('app.locales'))))
{
$form['locale']['error'][] = $translator->trans('Requested locale not supported');
}
- else
- {
- // $request->get('locale')
- }
-
/// Title
if (mb_strlen($request->get('title')) < $this->getParameter('app.page.title.length.min') ||
mb_strlen($request->get('title')) > $this->getParameter('app.page.title.length.max'))
@@ -125,11 +159,6 @@ class PageController extends AbstractController
);
}
- else
- {
- // $request->get('title')
- }
-
/// Description
if (mb_strlen($request->get('description')) < $this->getParameter('app.page.description.length.min') ||
mb_strlen($request->get('description')) > $this->getParameter('app.page.description.length.max'))
@@ -141,13 +170,9 @@ class PageController extends AbstractController
);
}
- else
- {
- // $request->get('description')
- }
-
/// Torrents
$total = 0;
+ $torrents = [];
if ($files = $request->files->get('torrents'))
{
@@ -157,42 +182,79 @@ class PageController extends AbstractController
$total++;
//// File size
- if (filesize($file->getPathName()) > $this->getParameter('app.page.torrent.size.max'))
+ if (filesize($file->getPathName()) > $this->getParameter('app.torrent.size.max'))
{
$form['torrents']['error'][] = $translator->trans('Torrent file out of size limit');
+
+ continue;
+ }
+
+ if (empty($torrentService->getTorrentFilenameByFilepath($file->getPathName())))
+ {
+ $form['torrent']['error'][] = $translator->trans('Could not parse torrent file');
+
+ continue;
}
//// Content
- $decoder = new \BitTorrent\Decoder();
- $decodedFile = $decoder->decodeFile(
- $file->getPathName()
+ $torrent = $torrentService->submit(
+ $file->getPathName(),
+ $user->getId(),
+ time(),
+ (array) $locales,
+ (bool) $request->get('sensitive'),
+ $user->isApproved()
);
- // var_dump($decodedFile['info']['name']);
+ $torrents[] = $torrent->getId();
}
}
- if ($total < $this->getParameter('app.page.torrent.quantity.min') ||
- $total > $this->getParameter('app.page.torrent.quantity.max'))
+ if ($total < $this->getParameter('app.page.torrent.file.quantity.min') ||
+ $total > $this->getParameter('app.page.torrent.file.quantity.max'))
{
$form['torrents']['error'][] = sprintf(
$translator->trans('Torrents quantity out of %s-%s range'),
- number_format($this->getParameter('app.page.torrent.quantity.min')),
- number_format($this->getParameter('app.page.torrent.quantity.max'))
+ number_format($this->getParameter('app.page.torrent.file.quantity.min')),
+ number_format($this->getParameter('app.page.torrent.file.quantity.max'))
);
}
- if (empty($error))
+ if (empty($form['locale']['error']) &&
+ empty($form['title']['error']) &&
+ empty($form['description']['error']) &&
+ empty($form['torrents']['error'])
+ )
{
- // isset($request->get('sensitive'))
- // $pageService->save($page);
+ $page = $pageService->submit(
+ $user->getId(),
+ time(),
+ (string) $request->get('locale'),
+ (string) $request->get('title'),
+ (string) $request->get('description'),
+ (array) $torrents,
+ (bool) $request->get('sensitive'),
+ $user->isApproved()
+ );
+
+ // Redirect
+ return $this->redirectToRoute(
+ 'page_info',
+ [
+ '_locale' => $request->get('_locale'),
+ 'id' => $page->getId()
+ ]
+ );
}
}
- return $this->render('default/page/submit.html.twig', [
- 'locales' => explode('|', $this->getParameter('app.locales')),
- 'form' => $form,
- ]);
+ return $this->render(
+ 'default/page/submit.html.twig',
+ [
+ 'locales' => explode('|', $this->getParameter('app.locales')),
+ 'form' => $form,
+ ]
+ );
}
}
\ No newline at end of file
diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php
index 6c867f4..271b723 100644
--- a/src/Controller/UserController.php
+++ b/src/Controller/UserController.php
@@ -7,6 +7,7 @@ use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
+use App\Service\ActivityService;
use App\Service\UserService;
use App\Service\TimeService;
@@ -36,35 +37,48 @@ class UserController extends AbstractController
)]
public function index(
Request $request,
+ ActivityService $activityService,
UserService $userService,
TimeService $timeService
): Response
{
// Init user session
- $userService->init(
+ $user = $userService->init(
$request->getClientIp()
);
// Build activity history
$activities = [];
- foreach ($userService->getAllByAddedFieldDesc() as $user)
+
+ /*
+ foreach ($activityService->findLast($user->isModerator()) as $activity)
{
+ if (!$activity->getUserId())
+ {
+ continue;
+ }
+
+ $activityUser = $userService->get(
+ $activity->getUserId()
+ );
+
$activities[] =
[
'user' =>
[
- 'id' => $user->getId(),
+ 'id' => $activityUser->getId(),
'identicon' => $userService->identicon(
- $user->getAddress(),
+ $activityUser->getAddress(),
24
)
],
'type' => 'join',
'added' => $timeService->ago(
- $user->getAdded()
+ $activity->getAdded()
)
];
}
+ */
return $this->render(
'default/user/dashboard.html.twig',
diff --git a/src/Entity/Activity.php b/src/Entity/Activity.php
new file mode 100644
index 0000000..3d27fef
--- /dev/null
+++ b/src/Entity/Activity.php
@@ -0,0 +1,99 @@
+id;
+ }
+
+ public function setId(string $id): static
+ {
+ $this->id = $id;
+
+ return $this;
+ }
+
+ public function getEvent(): ?string
+ {
+ return $this->event;
+ }
+
+ public function setEvent(string $event): static
+ {
+ $this->event = $event;
+
+ return $this;
+ }
+
+ public function getAdded(): ?int
+ {
+ return $this->added;
+ }
+
+ public function setAdded(int $added): static
+ {
+ $this->added = $added;
+
+ return $this;
+ }
+
+ public function setApproved(bool $approved): static
+ {
+ $this->approved = $approved;
+
+ return $this;
+ }
+
+ public function getUserId(): ?int
+ {
+ return $this->userId;
+ }
+
+ public function setUserId(?int $userId): static
+ {
+ $this->userId = $userId;
+
+ return $this;
+ }
+
+ public function getPageId(): ?int
+ {
+ return $this->pageId;
+ }
+
+ public function setPageId(?int $pageId): static
+ {
+ $this->pageId = $pageId;
+
+ return $this;
+ }
+
+ public function isApproved(): ?bool
+ {
+ return $this->approved;
+ }
+}
diff --git a/src/Entity/PageDescription.php b/src/Entity/PageDescription.php
new file mode 100644
index 0000000..ae85a02
--- /dev/null
+++ b/src/Entity/PageDescription.php
@@ -0,0 +1,118 @@
+id;
+ }
+
+ public function setId(string $id): static
+ {
+ $this->id = $id;
+
+ return $this;
+ }
+
+ public function getPageId(): ?int
+ {
+ return $this->pageId;
+ }
+
+ public function setPageId(int $pageId): static
+ {
+ $this->pageId = $pageId;
+
+ return $this;
+ }
+
+ public function getUserId(): ?int
+ {
+ return $this->userId;
+ }
+
+ public function setUserId(int $userId): static
+ {
+ $this->userId = $userId;
+
+ return $this;
+ }
+
+ public function getAdded(): ?int
+ {
+ return $this->added;
+ }
+
+ public function setAdded(int $added): static
+ {
+ $this->added = $added;
+
+ return $this;
+ }
+
+ public function getLocale(): ?string
+ {
+ return $this->locale;
+ }
+
+ public function setLocale(string $locale): static
+ {
+ $this->locale = $locale;
+
+ return $this;
+ }
+
+ public function getValue(): ?string
+ {
+ return $this->value;
+ }
+
+ public function setValue(string $value): static
+ {
+ $this->value = $value;
+
+ return $this;
+ }
+
+ public function isApproved(): ?bool
+ {
+ return $this->approved;
+ }
+
+ public function setApproved(bool $approved): static
+ {
+ $this->approved = $approved;
+
+ return $this;
+ }
+}
diff --git a/src/Entity/PageSensitive.php b/src/Entity/PageSensitive.php
new file mode 100644
index 0000000..7af1e78
--- /dev/null
+++ b/src/Entity/PageSensitive.php
@@ -0,0 +1,118 @@
+id;
+ }
+
+ public function setId(string $id): static
+ {
+ $this->id = $id;
+
+ return $this;
+ }
+
+ public function getPageId(): ?int
+ {
+ return $this->pageId;
+ }
+
+ public function setPageId(int $pageId): static
+ {
+ $this->pageId = $pageId;
+
+ return $this;
+ }
+
+ public function getUserId(): ?int
+ {
+ return $this->userId;
+ }
+
+ public function setUserId(int $userId): static
+ {
+ $this->userId = $userId;
+
+ return $this;
+ }
+
+ public function getAdded(): ?int
+ {
+ return $this->added;
+ }
+
+ public function setAdded(int $added): static
+ {
+ $this->added = $added;
+
+ return $this;
+ }
+
+ public function getLocale(): ?string
+ {
+ return $this->locale;
+ }
+
+ public function setLocale(string $locale): static
+ {
+ $this->locale = $locale;
+
+ return $this;
+ }
+
+ public function isValue(): ?bool
+ {
+ return $this->value;
+ }
+
+ public function setValue(bool $value): static
+ {
+ $this->value = $value;
+
+ return $this;
+ }
+
+ public function isApproved(): ?bool
+ {
+ return $this->approved;
+ }
+
+ public function setApproved(bool $approved): static
+ {
+ $this->approved = $approved;
+
+ return $this;
+ }
+}
diff --git a/src/Entity/PageTitle.php b/src/Entity/PageTitle.php
new file mode 100644
index 0000000..1dbce61
--- /dev/null
+++ b/src/Entity/PageTitle.php
@@ -0,0 +1,118 @@
+id;
+ }
+
+ public function setId(string $id): static
+ {
+ $this->id = $id;
+
+ return $this;
+ }
+
+ public function getPageId(): ?int
+ {
+ return $this->pageId;
+ }
+
+ public function setPageId(int $pageId): static
+ {
+ $this->pageId = $pageId;
+
+ return $this;
+ }
+
+ public function getUserId(): ?int
+ {
+ return $this->userId;
+ }
+
+ public function setUserId(int $userId): static
+ {
+ $this->userId = $userId;
+
+ return $this;
+ }
+
+ public function getAdded(): ?int
+ {
+ return $this->added;
+ }
+
+ public function setAdded(int $added): static
+ {
+ $this->added = $added;
+
+ return $this;
+ }
+
+ public function getLocale(): ?string
+ {
+ return $this->locale;
+ }
+
+ public function setLocale(string $locale): static
+ {
+ $this->locale = $locale;
+
+ return $this;
+ }
+
+ public function getValue(): ?string
+ {
+ return $this->value;
+ }
+
+ public function setValue(string $value): static
+ {
+ $this->value = $value;
+
+ return $this;
+ }
+
+ public function isApproved(): ?bool
+ {
+ return $this->approved;
+ }
+
+ public function setApproved(bool $approved): static
+ {
+ $this->approved = $approved;
+
+ return $this;
+ }
+}
diff --git a/src/Entity/PageTorrents.php b/src/Entity/PageTorrents.php
new file mode 100644
index 0000000..81a3811
--- /dev/null
+++ b/src/Entity/PageTorrents.php
@@ -0,0 +1,103 @@
+id;
+ }
+
+ public function setId(string $id): static
+ {
+ $this->id = $id;
+
+ return $this;
+ }
+
+ public function getPageId(): ?int
+ {
+ return $this->pageId;
+ }
+
+ public function setPageId(int $pageId): static
+ {
+ $this->pageId = $pageId;
+
+ return $this;
+ }
+
+ public function getUserId(): ?int
+ {
+ return $this->userId;
+ }
+
+ public function setUserId(int $userId): static
+ {
+ $this->userId = $userId;
+
+ return $this;
+ }
+
+ public function getTorrentsId(): array
+ {
+ return $this->torrentsId;
+ }
+
+ public function setTorrentsId(array $torrentsId): static
+ {
+ $this->torrentsId = $torrentsId;
+
+ return $this;
+ }
+
+ public function getAdded(): ?int
+ {
+ return $this->added;
+ }
+
+ public function setAdded(int $added): static
+ {
+ $this->added = $added;
+
+ return $this;
+ }
+
+ public function isApproved(): ?bool
+ {
+ return $this->approved;
+ }
+
+ public function setApproved(bool $approved): static
+ {
+ $this->approved = $approved;
+
+ return $this;
+ }
+}
diff --git a/src/Repository/ActivityRepository.php b/src/Repository/ActivityRepository.php
new file mode 100644
index 0000000..6d26c74
--- /dev/null
+++ b/src/Repository/ActivityRepository.php
@@ -0,0 +1,47 @@
+
+ *
+ * @method Activity|null find($id, $lockMode = null, $lockVersion = null)
+ * @method Activity|null findOneBy(array $criteria, array $orderBy = null)
+ * @method Activity[] findAll()
+ * @method Activity[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
+ */
+class ActivityRepository extends ServiceEntityRepository
+{
+ public function __construct(ManagerRegistry $registry)
+ {
+ parent::__construct($registry, Activity::class);
+ }
+
+ public function findLast(int $start = 0, int $limit = 10): array
+ {
+ return $this->createQueryBuilder('a')
+ ->orderBy('a.id', 'DESC') // same to a.added
+ ->setFirstResult($start)
+ ->setMaxResults($limit)
+ ->getQuery()
+ ->getResult()
+ ;
+ }
+
+ public function findLastByApprovedField(bool $approved, int $start = 0, int $limit = 10): array
+ {
+ return $this->createQueryBuilder('a')
+ ->orderBy('a.id', 'DESC') // same to a.added
+ ->where('a.approved = :approved')
+ ->setParameter('approved', $approved)
+ ->setFirstResult($start)
+ ->setMaxResults($limit)
+ ->getQuery()
+ ->getResult()
+ ;
+ }
+}
diff --git a/src/Repository/PageDescriptionRepository.php b/src/Repository/PageDescriptionRepository.php
new file mode 100644
index 0000000..06d9036
--- /dev/null
+++ b/src/Repository/PageDescriptionRepository.php
@@ -0,0 +1,23 @@
+
+ *
+ * @method PageDescription|null find($id, $lockMode = null, $lockVersion = null)
+ * @method PageDescription|null findOneBy(array $criteria, array $orderBy = null)
+ * @method PageDescription[] findAll()
+ * @method PageDescription[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
+ */
+class PageDescriptionRepository extends ServiceEntityRepository
+{
+ public function __construct(ManagerRegistry $registry)
+ {
+ parent::__construct($registry, PageDescription::class);
+ }
+}
diff --git a/src/Repository/PageRepository.php b/src/Repository/PageRepository.php
index 985f0d6..f0baa09 100644
--- a/src/Repository/PageRepository.php
+++ b/src/Repository/PageRepository.php
@@ -20,29 +20,4 @@ class PageRepository extends ServiceEntityRepository
{
parent::__construct($registry, Page::class);
}
-
-// /**
-// * @return Page[] Returns an array of Page objects
-// */
-// public function findByExampleField($value): array
-// {
-// return $this->createQueryBuilder('p')
-// ->andWhere('p.exampleField = :val')
-// ->setParameter('val', $value)
-// ->orderBy('p.id', 'ASC')
-// ->setMaxResults(10)
-// ->getQuery()
-// ->getResult()
-// ;
-// }
-
-// public function findOneBySomeField($value): ?Page
-// {
-// return $this->createQueryBuilder('p')
-// ->andWhere('p.exampleField = :val')
-// ->setParameter('val', $value)
-// ->getQuery()
-// ->getOneOrNullResult()
-// ;
-// }
}
diff --git a/src/Repository/PageSensitiveRepository.php b/src/Repository/PageSensitiveRepository.php
new file mode 100644
index 0000000..9f8b321
--- /dev/null
+++ b/src/Repository/PageSensitiveRepository.php
@@ -0,0 +1,23 @@
+
+ *
+ * @method PageSensitive|null find($id, $lockMode = null, $lockVersion = null)
+ * @method PageSensitive|null findOneBy(array $criteria, array $orderBy = null)
+ * @method PageSensitive[] findAll()
+ * @method PageSensitive[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
+ */
+class PageSensitiveRepository extends ServiceEntityRepository
+{
+ public function __construct(ManagerRegistry $registry)
+ {
+ parent::__construct($registry, PageSensitive::class);
+ }
+}
diff --git a/src/Repository/PageTitleRepository.php b/src/Repository/PageTitleRepository.php
new file mode 100644
index 0000000..346ccd2
--- /dev/null
+++ b/src/Repository/PageTitleRepository.php
@@ -0,0 +1,23 @@
+
+ *
+ * @method PageTitle|null find($id, $lockMode = null, $lockVersion = null)
+ * @method PageTitle|null findOneBy(array $criteria, array $orderBy = null)
+ * @method PageTitle[] findAll()
+ * @method PageTitle[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
+ */
+class PageTitleRepository extends ServiceEntityRepository
+{
+ public function __construct(ManagerRegistry $registry)
+ {
+ parent::__construct($registry, PageTitle::class);
+ }
+}
diff --git a/src/Repository/PageTorrentsRepository.php b/src/Repository/PageTorrentsRepository.php
new file mode 100644
index 0000000..01c6627
--- /dev/null
+++ b/src/Repository/PageTorrentsRepository.php
@@ -0,0 +1,23 @@
+
+ *
+ * @method PageTorrents|null find($id, $lockMode = null, $lockVersion = null)
+ * @method PageTorrents|null findOneBy(array $criteria, array $orderBy = null)
+ * @method PageTorrents[] findAll()
+ * @method PageTorrents[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
+ */
+class PageTorrentsRepository extends ServiceEntityRepository
+{
+ public function __construct(ManagerRegistry $registry)
+ {
+ parent::__construct($registry, PageTorrents::class);
+ }
+}
diff --git a/src/Repository/UserRepository.php b/src/Repository/UserRepository.php
index 202d56d..49896f3 100644
--- a/src/Repository/UserRepository.php
+++ b/src/Repository/UserRepository.php
@@ -40,13 +40,4 @@ class UserRepository extends ServiceEntityRepository
->getOneOrNullResult()
;
}
-
- public function findAllByAddedFieldDesc(): array
- {
- return $this->createQueryBuilder('u')
- ->orderBy('u.added', 'DESC')
- ->getQuery()
- ->getResult()
- ;
- }
}
diff --git a/src/Service/ActivityService.php b/src/Service/ActivityService.php
new file mode 100644
index 0000000..268fb0b
--- /dev/null
+++ b/src/Service/ActivityService.php
@@ -0,0 +1,54 @@
+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);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Service/PageService.php b/src/Service/PageService.php
index ae50c44..97da0a5 100644
--- a/src/Service/PageService.php
+++ b/src/Service/PageService.php
@@ -3,35 +3,194 @@
namespace App\Service;
use App\Entity\Page;
+use App\Entity\PageTitle;
+use App\Entity\PageDescription;
+use App\Entity\PageTorrents;
+use App\Entity\PageSensitive;
+
use App\Repository\PageRepository;
-use Doctrine\ORM\EntityManagerInterface;
+use App\Repository\PageTitleRepository;
+use App\Repository\PageDescriptionRepository;
+use App\Repository\PageSensitiveRepository;
+use App\Repository\PageTorrentsRepository;
-use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
+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;
}
}
\ No newline at end of file
diff --git a/src/Service/UserService.php b/src/Service/UserService.php
index 033c459..c4ade42 100644
--- a/src/Service/UserService.php
+++ b/src/Service/UserService.php
@@ -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,
diff --git a/templates/default/page/info.html.twig b/templates/default/page/info.html.twig
new file mode 100644
index 0000000..3389f18
--- /dev/null
+++ b/templates/default/page/info.html.twig
@@ -0,0 +1,2 @@
+{% extends 'default/layout.html.twig' %}
+{% block title %}{{ title }} - {{ name }}{% endblock %}
\ No newline at end of file
diff --git a/templates/default/page/submit.html.twig b/templates/default/page/submit.html.twig
index 19d4cb6..2f1eea4 100644
--- a/templates/default/page/submit.html.twig
+++ b/templates/default/page/submit.html.twig
@@ -10,14 +10,14 @@
-
+