mirror of
https://github.com/YGGverse/YGGtracker.git
synced 2025-01-22 12:44:25 +00:00
update page form dependencies #19
This commit is contained in:
parent
8df29ef605
commit
c0cc029350
6
.env
6
.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
|
||||
APP_PAGE_TORRENT_FILE_QUANTITY_MIN=1
|
||||
APP_PAGE_TORRENT_FILE_QUANTITY_MAX=100
|
||||
APP_TORRENT_FILE_SIZE_MAX=1024000
|
@ -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,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
@ -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',
|
||||
|
99
src/Entity/Activity.php
Normal file
99
src/Entity/Activity.php
Normal file
@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\ActivityRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: ActivityRepository::class)]
|
||||
class Activity
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $event = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?int $added = null;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?int $userId = null;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?int $pageId = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->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;
|
||||
}
|
||||
}
|
118
src/Entity/PageDescription.php
Normal file
118
src/Entity/PageDescription.php
Normal file
@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\PageDescriptionRepository;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: PageDescriptionRepository::class)]
|
||||
class PageDescription
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?int $pageId = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?int $userId = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?int $added = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $locale = null;
|
||||
|
||||
#[ORM\Column(type: Types::TEXT)]
|
||||
private ?string $value = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?bool $approved = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->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;
|
||||
}
|
||||
}
|
118
src/Entity/PageSensitive.php
Normal file
118
src/Entity/PageSensitive.php
Normal file
@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\PageSensitiveRepository;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: PageSensitiveRepository::class)]
|
||||
class PageSensitive
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?int $pageId = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?int $userId = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?int $added = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $locale = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?bool $value = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?bool $approved = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->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;
|
||||
}
|
||||
}
|
118
src/Entity/PageTitle.php
Normal file
118
src/Entity/PageTitle.php
Normal file
@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\PageTitleRepository;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: PageTitleRepository::class)]
|
||||
class PageTitle
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?int $pageId = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?int $userId = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?int $added = null;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $locale = null;
|
||||
|
||||
#[ORM\Column(type: Types::TEXT)]
|
||||
private ?string $value = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?bool $approved = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->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;
|
||||
}
|
||||
}
|
103
src/Entity/PageTorrents.php
Normal file
103
src/Entity/PageTorrents.php
Normal file
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\PageTorrentsRepository;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: PageTorrentsRepository::class)]
|
||||
class PageTorrents
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?int $pageId = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?int $userId = null;
|
||||
|
||||
#[ORM\Column(type: Types::ARRAY)]
|
||||
private array $torrentsId = [];
|
||||
|
||||
#[ORM\Column]
|
||||
private ?int $added = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?bool $approved = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->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;
|
||||
}
|
||||
}
|
47
src/Repository/ActivityRepository.php
Normal file
47
src/Repository/ActivityRepository.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Activity;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Activity>
|
||||
*
|
||||
* @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()
|
||||
;
|
||||
}
|
||||
}
|
23
src/Repository/PageDescriptionRepository.php
Normal file
23
src/Repository/PageDescriptionRepository.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\PageDescription;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<PageDescription>
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
}
|
@ -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()
|
||||
// ;
|
||||
// }
|
||||
}
|
||||
|
23
src/Repository/PageSensitiveRepository.php
Normal file
23
src/Repository/PageSensitiveRepository.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\PageSensitive;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<PageSensitive>
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
}
|
23
src/Repository/PageTitleRepository.php
Normal file
23
src/Repository/PageTitleRepository.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\PageTitle;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<PageTitle>
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
}
|
23
src/Repository/PageTorrentsRepository.php
Normal file
23
src/Repository/PageTorrentsRepository.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\PageTorrents;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<PageTorrents>
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
}
|
@ -40,13 +40,4 @@ class UserRepository extends ServiceEntityRepository
|
||||
->getOneOrNullResult()
|
||||
;
|
||||
}
|
||||
|
||||
public function findAllByAddedFieldDesc(): array
|
||||
{
|
||||
return $this->createQueryBuilder('u')
|
||||
->orderBy('u.added', 'DESC')
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
54
src/Service/ActivityService.php
Normal file
54
src/Service/ActivityService.php
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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,
|
||||
|
2
templates/default/page/info.html.twig
Normal file
2
templates/default/page/info.html.twig
Normal file
@ -0,0 +1,2 @@
|
||||
{% extends 'default/layout.html.twig' %}
|
||||
{% block title %}{{ title }} - {{ name }}{% endblock %}
|
@ -10,14 +10,14 @@
|
||||
<label for="locale">
|
||||
{{'Content language'|trans }}
|
||||
</label>
|
||||
<sub class="opacity-0 parent-hover-opacity-09" title="{{ form.locale.placeholder }}">
|
||||
<sub class="opacity-0 parent-hover-opacity-09" title="{{ form.locale.attribute.placeholder }}">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" fill="currentColor" class="bi bi-info-circle-fill" viewBox="0 0 16 16">
|
||||
<path d="M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16zm.93-9.412-1 4.705c-.07.34.029.533.304.533.194 0 .487-.07.686-.246l-.088.416c-.287.346-.92.598-1.465.598-.703 0-1.002-.422-.808-1.319l.738-3.468c.064-.293.006-.399-.287-.47l-.451-.081.082-.381 2.29-.287zM8 5.5a1 1 0 1 1 0-2 1 1 0 0 1 0 2z"/>
|
||||
</svg>
|
||||
</sub>
|
||||
<select class="width-100 margin-t-8-px" type="text" name="locale" id="locale">
|
||||
{% for locale in locales %}
|
||||
{% if locale == form.locale.value %}
|
||||
{% if locale == form.locale.attribute.value %}
|
||||
<option value="{{ locale }}" selected="selected">
|
||||
{{ locale|locale_name(locale)|u.title }}
|
||||
</option>
|
||||
|
@ -24,7 +24,7 @@
|
||||
</div>
|
||||
<div class="margin-y-16-px">
|
||||
<label for="locales">
|
||||
{{'Content language'|trans }}
|
||||
{{'Contains language'|trans }}
|
||||
</label>
|
||||
<sub class="opacity-0 parent-hover-opacity-09" title="{{ form.locales.attribute.placeholder }}">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" fill="currentColor" viewBox="0 0 16 16">
|
||||
|
@ -165,7 +165,7 @@
|
||||
</a>
|
||||
{% endif %}
|
||||
#}
|
||||
{% if route == 'page_submit' %}
|
||||
{% if route == 'page_submit' or route == 'torrent_submit' %}
|
||||
<span class="padding-x-16-px padding-y-8-px display-block background-color-green cursor-default text-color-white">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" fill="currentColor" viewBox="0 0 16 16">
|
||||
<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM8.5 4.5a.5.5 0 0 0-1 0v3h-3a.5.5 0 0 0 0 1h3v3a.5.5 0 0 0 1 0v-3h3a.5.5 0 0 0 0-1h-3v-3z"/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user