rename page to article

This commit is contained in:
ghost 2023-10-10 14:43:44 +03:00
parent 649838d4ee
commit c747166a30
43 changed files with 597 additions and 597 deletions

View file

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

View file

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