mirror of
https://github.com/YGGverse/YGGtracker.git
synced 2026-03-31 17:15:38 +00:00
remove article drafts (feature moved to new releases)
This commit is contained in:
parent
da1e869be5
commit
ea9f7f1589
35 changed files with 9 additions and 4606 deletions
|
|
@ -10,7 +10,6 @@ use Symfony\Component\HttpFoundation\Request;
|
|||
|
||||
use App\Service\ActivityService;
|
||||
use App\Service\UserService;
|
||||
use App\Service\ArticleService;
|
||||
use App\Service\TorrentService;
|
||||
|
||||
class ActivityController extends AbstractController
|
||||
|
|
@ -63,7 +62,6 @@ class ActivityController extends AbstractController
|
|||
$activity,
|
||||
ActivityService $activityService,
|
||||
UserService $userService,
|
||||
ArticleService $articleService,
|
||||
TorrentService $torrentService,
|
||||
): Response
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,281 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
use App\Service\UserService;
|
||||
use App\Service\ArticleService;
|
||||
use App\Service\TorrentService;
|
||||
|
||||
class ArticleController extends AbstractController
|
||||
{
|
||||
#[Route(
|
||||
'/{_locale}/article/{id}',
|
||||
name: 'article_info',
|
||||
requirements:
|
||||
[
|
||||
'id' => '\d+'
|
||||
],
|
||||
methods:
|
||||
[
|
||||
'GET'
|
||||
]
|
||||
)]
|
||||
public function info(
|
||||
Request $request,
|
||||
UserService $userService,
|
||||
ActivityService $activityService
|
||||
): Response
|
||||
{
|
||||
// Init user
|
||||
$user = $this->initUser(
|
||||
$request,
|
||||
$userService,
|
||||
$activityService
|
||||
);
|
||||
|
||||
return $this->render('default/article/info.html.twig', [
|
||||
'title' => 'test'
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route(
|
||||
'/{_locale}/submit/article',
|
||||
name: 'article_submit',
|
||||
methods:
|
||||
[
|
||||
'GET',
|
||||
'POST'
|
||||
]
|
||||
)]
|
||||
public function submit(
|
||||
Request $request,
|
||||
TranslatorInterface $translator,
|
||||
UserService $userService,
|
||||
ArticleService $articleService,
|
||||
ArticleService $torrentService,
|
||||
ActivityService $activityService
|
||||
): Response
|
||||
{
|
||||
// Init user
|
||||
$user = $this->initUser(
|
||||
$request,
|
||||
$userService,
|
||||
$activityService
|
||||
);
|
||||
|
||||
if (!$user->isStatus())
|
||||
{
|
||||
// @TODO
|
||||
throw new \Exception(
|
||||
$translator->trans('Access denied')
|
||||
);
|
||||
}
|
||||
|
||||
// Init form
|
||||
$form =
|
||||
[
|
||||
'locale' =>
|
||||
[
|
||||
'error' => [],
|
||||
'attribute' =>
|
||||
[
|
||||
'value' => $request->get('_locale'),
|
||||
'placeholder' => $translator->trans('Content language')
|
||||
]
|
||||
],
|
||||
'title' =>
|
||||
[
|
||||
'error' => [],
|
||||
'attribute' =>
|
||||
[
|
||||
'value' => $request->get('title'),
|
||||
'minlength' => $this->getParameter('app.article.title.length.min'),
|
||||
'maxlength' => $this->getParameter('app.article.title.length.max'),
|
||||
'placeholder' => sprintf(
|
||||
$translator->trans('Article title (%s-%s chars)'),
|
||||
number_format($this->getParameter('app.article.title.length.min')),
|
||||
number_format($this->getParameter('app.article.title.length.max'))
|
||||
),
|
||||
]
|
||||
],
|
||||
'description' =>
|
||||
[
|
||||
'error' => [],
|
||||
'attribute' =>
|
||||
[
|
||||
'value' => $request->get('description'),
|
||||
'minlength' => $this->getParameter('app.article.description.length.min'),
|
||||
'maxlength' => $this->getParameter('app.article.description.length.max'),
|
||||
'placeholder' => sprintf(
|
||||
$translator->trans('Article description (%s-%s chars)'),
|
||||
number_format($this->getParameter('app.article.description.length.min')),
|
||||
number_format($this->getParameter('app.article.description.length.max'))
|
||||
),
|
||||
]
|
||||
],
|
||||
'torrents' =>
|
||||
[
|
||||
'error' => [],
|
||||
'attribute' =>
|
||||
[
|
||||
'placeholder' => $translator->trans('Select torrent file')
|
||||
]
|
||||
],
|
||||
'sensitive' =>
|
||||
[
|
||||
'error' => [],
|
||||
'attribute' =>
|
||||
[
|
||||
'value' => $request->get('sensitive'),
|
||||
'placeholder' => $translator->trans('Apply sensitive filters to publication'),
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
// Process request
|
||||
if ($request->isMethod('post'))
|
||||
{
|
||||
/// Locale
|
||||
if (!in_array($request->get('locale'), explode('|', $this->getParameter('app.locales'))))
|
||||
{
|
||||
$form['locale']['error'][] = $translator->trans('Requested locale not supported');
|
||||
}
|
||||
|
||||
/// Title
|
||||
if (mb_strlen($request->get('title')) < $this->getParameter('app.article.title.length.min') ||
|
||||
mb_strlen($request->get('title')) > $this->getParameter('app.article.title.length.max'))
|
||||
{
|
||||
$form['title']['error'][] = sprintf(
|
||||
$translator->trans('Article title out of %s-%s chars'),
|
||||
number_format($this->getParameter('app.article.title.length.min')),
|
||||
number_format($this->getParameter('app.article.title.length.max'))
|
||||
);
|
||||
}
|
||||
|
||||
/// Description
|
||||
if (mb_strlen($request->get('description')) < $this->getParameter('app.article.description.length.min') ||
|
||||
mb_strlen($request->get('description')) > $this->getParameter('app.article.description.length.max'))
|
||||
{
|
||||
$form['description']['error'][] = sprintf(
|
||||
$translator->trans('Article description out of %s-%s chars'),
|
||||
number_format($this->getParameter('app.article.description.length.min')),
|
||||
number_format($this->getParameter('app.article.description.length.max'))
|
||||
);
|
||||
}
|
||||
|
||||
/// Torrents
|
||||
$torrents = [];
|
||||
|
||||
if ($files = $request->files->get('torrents'))
|
||||
{
|
||||
foreach ($files as $file)
|
||||
{
|
||||
/// Torrent
|
||||
if ($file = $request->files->get('torrent'))
|
||||
{
|
||||
//// Validate torrent file
|
||||
if (filesize($file->getPathName()) > $this->getParameter('app.torrent.size.max'))
|
||||
{
|
||||
$form['torrents']['error'][] = $translator->trans('Torrent file out of size limit');
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
//// Validate torrent format
|
||||
if (!$torrentService->readTorrentFileByFilepath($file->getPathName()))
|
||||
{
|
||||
$form['torrents']['error'][] = $translator->trans('Could not parse torrent file');
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
//// Content
|
||||
$torrent = $torrentService->add(
|
||||
$file->getPathName(),
|
||||
$user->getId(),
|
||||
time(),
|
||||
[$request->get('locale')],
|
||||
(bool) $request->get('sensitive'),
|
||||
$user->isApproved()
|
||||
);
|
||||
|
||||
$torrents[] = $torrent->getId();
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($form['locale']['error']) &&
|
||||
empty($form['title']['error']) &&
|
||||
empty($form['description']['error']) &&
|
||||
empty($form['torrents']['error'])
|
||||
)
|
||||
{
|
||||
$article = $articleService->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(
|
||||
'article_info',
|
||||
[
|
||||
'_locale' => $request->get('_locale'),
|
||||
'id' => $article->getId()
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'default/article/submit.html.twig',
|
||||
[
|
||||
'locales' => explode('|', $this->getParameter('app.locales')),
|
||||
'form' => $form,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
private function initUser(
|
||||
Request $request,
|
||||
UserService $userService,
|
||||
ActivityService $activityService
|
||||
): ?\App\Entity\User
|
||||
{
|
||||
// Init user
|
||||
if (!$user = $userService->findUserByAddress($request->getClientIp()))
|
||||
{
|
||||
$user = $userService->addUser(
|
||||
$request->getClientIp(),
|
||||
time(),
|
||||
$this->getParameter('app.locale'),
|
||||
explode('|', $this->getParameter('app.locales')),
|
||||
$activityService->getEventCodes(),
|
||||
$this->getParameter('app.theme'),
|
||||
$this->getParameter('app.sensitive'),
|
||||
$this->getParameter('app.yggdrasil'),
|
||||
$this->getParameter('app.approved')
|
||||
);
|
||||
|
||||
// Add user join event
|
||||
$activityService->addEventUserAdd(
|
||||
$user->getId(),
|
||||
time()
|
||||
);
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
|
|
@ -123,7 +123,6 @@ class TorrentController extends AbstractController
|
|||
$torrent->getId()
|
||||
)
|
||||
],
|
||||
'articles' => [],
|
||||
'contributors' => $contributors
|
||||
],
|
||||
'file' =>
|
||||
|
|
@ -1070,7 +1069,7 @@ class TorrentController extends AbstractController
|
|||
$torrentSensitive->getId()
|
||||
);
|
||||
|
||||
// Redirect to info article created
|
||||
// Redirect to info page created
|
||||
return $this->redirectToRoute(
|
||||
'torrent_info',
|
||||
[
|
||||
|
|
@ -1171,7 +1170,7 @@ class TorrentController extends AbstractController
|
|||
$torrentSensitive->getId()
|
||||
);
|
||||
|
||||
// Redirect to info article created
|
||||
// Redirect
|
||||
return $this->redirectToRoute(
|
||||
'torrent_sensitive_edit',
|
||||
[
|
||||
|
|
@ -1244,7 +1243,7 @@ class TorrentController extends AbstractController
|
|||
$torrentSensitive->getId()
|
||||
);
|
||||
|
||||
// Redirect to info article created
|
||||
// Redirect
|
||||
return $this->redirectToRoute(
|
||||
'torrent_sensitive_edit',
|
||||
[
|
||||
|
|
@ -1323,7 +1322,7 @@ class TorrentController extends AbstractController
|
|||
);
|
||||
}
|
||||
|
||||
// Redirect to info article created
|
||||
// Redirect
|
||||
return $this->redirectToRoute(
|
||||
'torrent_info',
|
||||
[
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ use Symfony\Component\HttpFoundation\Request;
|
|||
|
||||
use App\Service\ActivityService;
|
||||
use App\Service\UserService;
|
||||
use App\Service\ArticleService;
|
||||
use App\Service\TorrentService;
|
||||
|
||||
class UserController extends AbstractController
|
||||
|
|
@ -325,7 +324,7 @@ class UserController extends AbstractController
|
|||
);
|
||||
}
|
||||
|
||||
// Redirect to info article created
|
||||
// Redirect
|
||||
return $this->redirectToRoute(
|
||||
'user_info',
|
||||
[
|
||||
|
|
@ -399,7 +398,7 @@ class UserController extends AbstractController
|
|||
);
|
||||
}
|
||||
|
||||
// Redirect to info article created
|
||||
// Redirect
|
||||
return $this->redirectToRoute(
|
||||
'user_info',
|
||||
[
|
||||
|
|
@ -473,7 +472,7 @@ class UserController extends AbstractController
|
|||
);
|
||||
}
|
||||
|
||||
// Redirect to info article created
|
||||
// Redirect
|
||||
return $this->redirectToRoute(
|
||||
'user_info',
|
||||
[
|
||||
|
|
@ -499,7 +498,6 @@ class UserController extends AbstractController
|
|||
Request $request,
|
||||
TranslatorInterface $translator,
|
||||
UserService $userService,
|
||||
ArticleService $articleService,
|
||||
TorrentService $torrentService,
|
||||
ActivityService $activityService
|
||||
): Response
|
||||
|
|
@ -570,7 +568,7 @@ class UserController extends AbstractController
|
|||
);
|
||||
}
|
||||
|
||||
// Redirect to info article created
|
||||
// Redirect
|
||||
return $this->redirectToRoute(
|
||||
'user_info',
|
||||
[
|
||||
|
|
|
|||
|
|
@ -54,16 +54,11 @@ class Activity
|
|||
|
||||
public const EVENT_TORRENT_DOWNLOAD_MAGNET_ADD = 2500;
|
||||
|
||||
/// Article
|
||||
public const EVENT_ARTICLE_ADD = 3000;
|
||||
// ...
|
||||
|
||||
#[ORM\Column]
|
||||
private ?int $userId = null;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?int $articleId = null;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?int $torrentId = null;
|
||||
|
||||
|
|
@ -109,18 +104,6 @@ class Activity
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function getArticleId(): ?int
|
||||
{
|
||||
return $this->articleId;
|
||||
}
|
||||
|
||||
public function setArticleId(int $articleId): static
|
||||
{
|
||||
$this->articleId = $articleId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTorrentId(): ?int
|
||||
{
|
||||
return $this->torrentId;
|
||||
|
|
|
|||
|
|
@ -1,72 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\ArticleRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: ArticleRepository::class)]
|
||||
class Article
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?int $userId = null;
|
||||
|
||||
#[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 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 isApproved(): ?bool
|
||||
{
|
||||
return $this->approved;
|
||||
}
|
||||
|
||||
public function setApproved(bool $approved): static
|
||||
{
|
||||
$this->approved = $approved;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,118 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\ArticleDescriptionRepository;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: ArticleDescriptionRepository::class)]
|
||||
class ArticleDescription
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?int $articleId = 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 getArticleId(): ?int
|
||||
{
|
||||
return $this->articleId;
|
||||
}
|
||||
|
||||
public function setArticleId(int $articleId): static
|
||||
{
|
||||
$this->articleId = $articleId;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,118 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\ArticleSensitiveRepository;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: ArticleSensitiveRepository::class)]
|
||||
class ArticleSensitive
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?int $articleId = 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 getArticleId(): ?int
|
||||
{
|
||||
return $this->articleId;
|
||||
}
|
||||
|
||||
public function setArticleId(int $articleId): static
|
||||
{
|
||||
$this->articleId = $articleId;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,118 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\ArticleTitleRepository;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: ArticleTitleRepository::class)]
|
||||
class ArticleTitle
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?int $articleId = 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 getArticleId(): ?int
|
||||
{
|
||||
return $this->articleId;
|
||||
}
|
||||
|
||||
public function setArticleId(int $articleId): static
|
||||
{
|
||||
$this->articleId = $articleId;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -65,20 +65,4 @@ class ActivityRepository extends ServiceEntityRepository
|
|||
->getSingleScalarResult()
|
||||
;
|
||||
}
|
||||
|
||||
public function findActivitiesTotalByArticleId(
|
||||
int $articleId,
|
||||
array $whitelist
|
||||
): int
|
||||
{
|
||||
return $this->createQueryBuilder('a')
|
||||
->select('count(a.id)')
|
||||
->where('a.articleId = :articleId')
|
||||
->andWhere('a.event IN (:event)')
|
||||
->setParameter(':articleId', $articleId)
|
||||
->setParameter(':event', $whitelist)
|
||||
->getQuery()
|
||||
->getSingleScalarResult()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\ArticleDescription;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<ArticleDescription>
|
||||
*
|
||||
* @method ArticleDescription|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method ArticleDescription|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method ArticleDescription[] findAll()
|
||||
* @method ArticleDescription[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class ArticleDescriptionRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, ArticleDescription::class);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Article;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Article>
|
||||
*
|
||||
* @method Article|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method Article|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method Article[] findAll()
|
||||
* @method Article[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class ArticleRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Article::class);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\ArticleSensitive;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<ArticleSensitive>
|
||||
*
|
||||
* @method ArticleSensitive|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method ArticleSensitive|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method ArticleSensitive[] findAll()
|
||||
* @method ArticleSensitive[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class ArticleSensitiveRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, ArticleSensitive::class);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\ArticleTitle;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<ArticleTitle>
|
||||
*
|
||||
* @method ArticleTitle|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method ArticleTitle|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method ArticleTitle[] findAll()
|
||||
* @method ArticleTitle[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class ArticleTitleRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, ArticleTitle::class);
|
||||
}
|
||||
}
|
||||
|
|
@ -58,9 +58,6 @@ class ActivityService
|
|||
|
||||
Activity::EVENT_TORRENT_DOWNLOAD_FILE_ADD,
|
||||
Activity::EVENT_TORRENT_DOWNLOAD_MAGNET_ADD,
|
||||
|
||||
// Articles
|
||||
Activity::EVENT_ARTICLE_ADD,
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -341,19 +338,6 @@ class ActivityService
|
|||
] = $code;
|
||||
|
||||
break;
|
||||
|
||||
// Article
|
||||
case Activity::EVENT_TORRENT_ADD:
|
||||
|
||||
$events
|
||||
[
|
||||
$this->translatorInterface->trans('Articles')
|
||||
]
|
||||
[
|
||||
$this->translatorInterface->trans('Added')
|
||||
] = $code;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -424,28 +408,6 @@ class ActivityService
|
|||
);
|
||||
}
|
||||
|
||||
public function findLastActivitiesByArticleId(
|
||||
int $articleId,
|
||||
array $whitelist,
|
||||
int $limit = 10,
|
||||
int $offset = 0
|
||||
): array
|
||||
{
|
||||
return $this->entityManagerInterface
|
||||
->getRepository(Activity::class)
|
||||
->findBy(
|
||||
[
|
||||
'articleId' => $articleId,
|
||||
'event' => $whitelist,
|
||||
],
|
||||
[
|
||||
'id' => 'DESC'
|
||||
],
|
||||
$limit,
|
||||
$offset
|
||||
);
|
||||
}
|
||||
|
||||
public function findActivitiesTotal(
|
||||
array $whitelist
|
||||
): int
|
||||
|
|
@ -481,19 +443,6 @@ class ActivityService
|
|||
);
|
||||
}
|
||||
|
||||
public function findActivitiesTotalByArticleId(
|
||||
int $articleId,
|
||||
array $whitelist
|
||||
): int
|
||||
{
|
||||
return $this->entityManagerInterface
|
||||
->getRepository(Activity::class)
|
||||
->findActivitiesTotalByArticleId(
|
||||
$articleId,
|
||||
$whitelist
|
||||
);
|
||||
}
|
||||
|
||||
// User
|
||||
public function addEventUserAdd(
|
||||
int $userId,
|
||||
|
|
|
|||
|
|
@ -1,196 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Entity\Article;
|
||||
use App\Entity\ArticleTitle;
|
||||
use App\Entity\ArticleDescription;
|
||||
use App\Entity\ArticleTorrents;
|
||||
use App\Entity\ArticleSensitive;
|
||||
|
||||
use App\Repository\ArticleRepository;
|
||||
use App\Repository\ArticleTitleRepository;
|
||||
use App\Repository\ArticleDescriptionRepository;
|
||||
use App\Repository\ArticleSensitiveRepository;
|
||||
use App\Repository\ArticleTorrentsRepository;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
class ArticleService
|
||||
{
|
||||
private EntityManagerInterface $entityManager;
|
||||
private ParameterBagInterface $parameterBagInterface;
|
||||
|
||||
public function __construct(
|
||||
EntityManagerInterface $entityManager,
|
||||
)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
|
||||
public function submit(
|
||||
int $added,
|
||||
int $userId,
|
||||
string $locale,
|
||||
string $title,
|
||||
string $description,
|
||||
array $torrents,
|
||||
bool $sensitive,
|
||||
bool $approved
|
||||
): ?Article
|
||||
{
|
||||
$article = $this->addArticle();
|
||||
|
||||
if (!empty($title))
|
||||
{
|
||||
$articleTitle = $this->addArticleTitle(
|
||||
$article->getId(),
|
||||
$userId,
|
||||
$added,
|
||||
$locale,
|
||||
$title,
|
||||
$approved
|
||||
);
|
||||
}
|
||||
|
||||
if (!empty($description))
|
||||
{
|
||||
$articleDescription = $this->addArticleDescription(
|
||||
$article->getId(),
|
||||
$userId,
|
||||
$added,
|
||||
$locale,
|
||||
$description,
|
||||
$approved
|
||||
);
|
||||
}
|
||||
|
||||
if (!empty($torrents))
|
||||
{
|
||||
$articleTorrents = $this->addArticleTorrents(
|
||||
$article->getId(),
|
||||
$userId,
|
||||
$added,
|
||||
$locale,
|
||||
$torrents,
|
||||
$approved
|
||||
);
|
||||
}
|
||||
|
||||
// @TODO
|
||||
$articleSensitive = $this->addArticleSensitive(
|
||||
$article->getId(),
|
||||
$userId,
|
||||
$added,
|
||||
$locale,
|
||||
$description,
|
||||
$approved
|
||||
);
|
||||
|
||||
return $article;
|
||||
}
|
||||
|
||||
public function addArticle(): ?Article
|
||||
{
|
||||
$article = new Article();
|
||||
|
||||
$this->entityManager->persist($article);
|
||||
$this->entityManager->flush();
|
||||
|
||||
return $article;
|
||||
}
|
||||
|
||||
public function addArticleTitle(
|
||||
int $articleId,
|
||||
int $userId,
|
||||
int $added,
|
||||
string $locale,
|
||||
string $value,
|
||||
bool $approved
|
||||
): ?ArticleTitle
|
||||
{
|
||||
$articleTitle = new ArticleTitle();
|
||||
|
||||
$articleTitle->setArticleId($articleId);
|
||||
$articleTitle->setUserId($userId);
|
||||
$articleTitle->setLocale($locale);
|
||||
$articleTitle->setValue($value);
|
||||
$articleTitle->setAdded($added);
|
||||
$articleTitle->setApproved($approved);
|
||||
|
||||
$this->entityManager->persist($articleTitle);
|
||||
$this->entityManager->flush();
|
||||
|
||||
return $articleTitle;
|
||||
}
|
||||
|
||||
public function addArticleDescription(
|
||||
int $articleId,
|
||||
int $userId,
|
||||
int $added,
|
||||
string $locale,
|
||||
string $value,
|
||||
bool $approved
|
||||
): ?ArticleDescription
|
||||
{
|
||||
$articleDescription = new ArticleDescription();
|
||||
|
||||
$articleDescription->setArticleId($articleId);
|
||||
$articleDescription->setUserId($userId);
|
||||
$articleDescription->setAdded($added);
|
||||
$articleDescription->setLocale($locale);
|
||||
$articleDescription->setValue($value);
|
||||
$articleDescription->setApproved($approved);
|
||||
|
||||
$this->entityManager->persist($articleDescription);
|
||||
$this->entityManager->flush();
|
||||
|
||||
return $articleDescription;
|
||||
}
|
||||
|
||||
public function addArticleTorrents(
|
||||
int $articleId,
|
||||
int $userId,
|
||||
int $added,
|
||||
array $torrentsId,
|
||||
bool $approved
|
||||
): ?ArticleTorrents
|
||||
{
|
||||
$articleTorrents = new ArticleTorrents();
|
||||
|
||||
$articleTorrents->setArticleId($articleId);
|
||||
$articleTorrents->setUserId($userId);
|
||||
$articleTorrents->setAdded($added);
|
||||
$articleTorrents->setTorrentsId($torrentsId);
|
||||
$articleTorrents->setApproved($approved);
|
||||
|
||||
$this->entityManager->persist($articleTorrents);
|
||||
$this->entityManager->flush();
|
||||
|
||||
return $articleTorrents;
|
||||
}
|
||||
|
||||
public function addArticleSensitive(
|
||||
int $articleId,
|
||||
int $userId,
|
||||
int $added,
|
||||
string $locale,
|
||||
string $value,
|
||||
bool $approved
|
||||
): ?ArticleSensitive
|
||||
{
|
||||
$articleSensitive = new ArticleSensitive();
|
||||
|
||||
$articleSensitive->setArticleId($articleId);
|
||||
$articleSensitive->setUserId($userId);
|
||||
$articleSensitive->setAdded($added);
|
||||
$articleSensitive->setLocale($locale);
|
||||
$articleSensitive->setValue($value);
|
||||
$articleSensitive->setApproved($approved);
|
||||
|
||||
$this->entityManager->persist($articleSensitive);
|
||||
$this->entityManager->flush();
|
||||
|
||||
return $articleSensitive;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue