diff --git a/Api/Factory/NewsApiDtoFactory.php b/Api/Factory/NewsApiDtoFactory.php
new file mode 100644
index 0000000..503d40d
--- /dev/null
+++ b/Api/Factory/NewsApiDtoFactory.php
@@ -0,0 +1,32 @@
+getId(),
+ title: $entity->getTitle(),
+ teaser: $entity->getTeaser(),
+ content: $entity->getContent(),
+ enabled: $entity->isEnabled(),
+ publishedAt: $entity->getPublishedAt(),
+ route: $entity->getRoute()?->getPath(),
+ tags: $entity->getTagNameArray(),
+ header: [
+ 'id' => $entity->getHeader()?->getId(),
+ ],
+ authored: $entity->getCreated(),
+ created: $entity->getCreated(),
+ changed: $entity->getChanged(),
+ author: $entity->getCreator()?->getId(),
+ ext: $entity->getSeo(),
+ locale: $locale
+ );
+ }
+}
diff --git a/Api/News.php b/Api/News.php
index 14c602f..aad6a1c 100644
--- a/Api/News.php
+++ b/Api/News.php
@@ -13,211 +13,27 @@
namespace TheCadien\Bundle\SuluNewsBundle\Api;
-use JMS\Serializer\Annotation\ExclusionPolicy;
-use JMS\Serializer\Annotation\Groups;
-use JMS\Serializer\Annotation\SerializedName;
-use JMS\Serializer\Annotation\VirtualProperty;
-use Sulu\Component\Rest\ApiWrapper;
-use TheCadien\Bundle\SuluNewsBundle\Entity\News as NewsEntity;
+use Symfony\Component\Validator\Constraints as Assert;
-/**
- * The News class which will be exported to the API.
- *
- * @ExclusionPolicy("all")
- */
-class News extends ApiWrapper
+final class News
{
- public function __construct(NewsEntity $contact, $locale)
- {
- // @var NewsEntity entity
- $this->entity = $contact;
- $this->locale = $locale;
- }
-
- /**
- * Get id.
- *
- * @VirtualProperty
- *
- * @SerializedName("id")
- * @Groups({"fullNews"})
- */
- public function getId(): ?int
- {
- return $this->entity->getId();
- }
-
- /**
- * @VirtualProperty
- *
- * @SerializedName("title")
- * @Groups({"fullNews"})
- */
- public function getTitle(): ?string
- {
- return $this->entity?->getTitle();
- }
-
- /**
- * @VirtualProperty
- *
- * @SerializedName("teaser")
- * @Groups({"fullNews"})
- */
- public function getTeaser(): ?string
- {
- return $this->entity->getTeaser();
- }
-
- /**
- * @VirtualProperty
- *
- * @SerializedName("content")
- * @Groups({"fullNews"})
- */
- public function getContent(): array
- {
- if (!$this->entity->getContent()) {
- return [];
- }
-
- return $this->entity->getContent();
- }
-
- /**
- * @VirtualProperty
- *
- * @SerializedName("enabled")
- * @Groups({"fullNews"})
- */
- public function isEnabled(): bool
- {
- return $this->entity?->isEnabled();
- }
-
- /**
- * @VirtualProperty
- *
- * @SerializedName("publishedAt")
- * @Groups({"fullNews"})
- */
- public function getPublishedAt(): ?\DateTime
- {
- return $this->entity?->getPublishedAt();
- }
-
- /**
- * @VirtualProperty
- *
- * @SerializedName("route")
- * @Groups({"fullNews"})
- */
- public function getRoutePath(): ?string
- {
- if ($this->entity?->getRoute()) {
- return $this->entity->getRoute()?->getPath();
- }
-
- return '';
- }
-
- /**
- * Get tags.
- *
- * @VirtualProperty
- *
- * @SerializedName("tags")
- * @Groups({"fullNews"})
- */
- public function getTags(): array
- {
- return $this->entity->getTagNameArray();
- }
-
- /**
- * Get the contacts avatar and return the array of different formats.
- *
- * @VirtualProperty
- *
- * @SerializedName("header")
- * @Groups({"fullNews"})
- */
- public function getHeader(): array
- {
- if ($this->entity->getHeader()) {
- return [
- 'id' => $this->entity->getHeader()->getId(),
- ];
- }
-
- return [];
- }
-
- /**
- * Get tags.
- *
- * @VirtualProperty
- *
- * @SerializedName("authored")
- * @Groups({"fullNews"})
- */
- public function getAuthored(): \DateTime
- {
- return $this->entity->getCreated();
- }
-
- /**
- * Get tags.
- *
- * @VirtualProperty
- *
- * @SerializedName("created")
- * @Groups({"fullNews"})
- */
- public function getCreated(): \DateTime
- {
- return $this->entity->getCreated();
- }
-
- /**
- * Get tags.
- *
- * @VirtualProperty
- *
- * @SerializedName("changed")
- * @Groups({"fullNews"})
- */
- public function getChanged(): \DateTime
- {
- return $this->entity->getChanged();
- }
-
- /**
- * Get tags.
- *
- * @VirtualProperty
- *
- * @SerializedName("author")
- * @Groups({"fullNews"})
- */
- public function getAuthor(): ?int
- {
- return $this->entity?->getCreator()?->getId();
- }
-
- /**
- * Get tags.
- *
- * @VirtualProperty
- *
- * @SerializedName("ext")
- * @Groups({"fullNews"})
- */
- public function getSeo(): array
- {
- $seo = ['seo'];
- $seo['seo'] = $this->getEntity()->getSeo();
-
- return $seo;
+ public function __construct(
+ #[Assert\NotBlank(groups: ['edit'])]
+ public ?int $id,
+ public string $title,
+ public ?string $teaser,
+ public ?array $content,
+ public ?bool $enabled,
+ public ?\DateTime $publishedAt = null,
+ public ?string $route,
+ public ?array $tags,
+ public ?array $header,
+ public ?\DateTime $authored = null,
+ public ?\DateTime $created = null,
+ public ?\DateTime $changed = null,
+ public ?int $author,
+ public ?string $ext,
+ public ?string $locale = null
+ ) {
}
}
diff --git a/Admin/DoctrineListRepresentationFactory.php b/Common/DoctrineListRepresentationFactory.php
similarity index 93%
rename from Admin/DoctrineListRepresentationFactory.php
rename to Common/DoctrineListRepresentationFactory.php
index 9fdb1e0..84ed605 100644
--- a/Admin/DoctrineListRepresentationFactory.php
+++ b/Common/DoctrineListRepresentationFactory.php
@@ -11,7 +11,7 @@
* with this source code in the file LICENSE.
*/
-namespace TheCadien\Bundle\SuluNewsBundle\Admin;
+namespace TheCadien\Bundle\SuluNewsBundle\Common;
use Sulu\Bundle\MediaBundle\Media\Manager\MediaManagerInterface;
use Sulu\Component\Rest\ListBuilder\Doctrine\DoctrineListBuilderFactoryInterface;
@@ -67,10 +67,6 @@ public function createDoctrineListRepresentation(
);
}
- /**
- * Takes an array of contacts and resets the avatar containing the media id with
- * the actual urls to the avatars thumbnail.
- */
private function addHeader(array $news, string $locale): array
{
$ids = \array_filter(\array_column($news, 'header'));
diff --git a/Content/NewsDataProvider.php b/Content/NewsDataProvider.php
index 7f43556..04e0d07 100644
--- a/Content/NewsDataProvider.php
+++ b/Content/NewsDataProvider.php
@@ -15,13 +15,14 @@
use JMS\Serializer\Context;
use JMS\Serializer\SerializationContext;
+use Sulu\Component\SmartContent\Configuration\ProviderConfigurationInterface;
use Sulu\Component\SmartContent\Orm\BaseDataProvider;
class NewsDataProvider extends BaseDataProvider
{
public function getConfiguration()
{
- if (null === $this->configuration) {
+ if (!$this->configuration instanceof ProviderConfigurationInterface) {
$this->configuration = self::createConfigurationBuilder()
->enableLimit()
->enablePagination()
diff --git a/Controller/Admin/NewsController.php b/Controller/Admin/NewsController.php
index d49dd08..c6c5772 100644
--- a/Controller/Admin/NewsController.php
+++ b/Controller/Admin/NewsController.php
@@ -13,153 +13,92 @@
namespace TheCadien\Bundle\SuluNewsBundle\Controller\Admin;
-use Doctrine\ORM\OptimisticLockException;
-use Doctrine\ORM\ORMException;
-use FOS\RestBundle\Context\Context;
-use FOS\RestBundle\Controller\Annotations as Rest;
-use FOS\RestBundle\Routing\ClassResourceInterface;
-use FOS\RestBundle\View\View;
-use FOS\RestBundle\View\ViewHandlerInterface;
-use Sulu\Component\Rest\AbstractRestController;
-use Sulu\Component\Rest\Exception\EntityNotFoundException;
+use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
-use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
-use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
-use TheCadien\Bundle\SuluNewsBundle\Admin\DoctrineListRepresentationFactory;
+use Symfony\Component\HttpKernel\Attribute\AsController;
+use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
+use Symfony\Component\Routing\Annotation\Route;
+use TheCadien\Bundle\SuluNewsBundle\Api\Factory\NewsApiDtoFactory;
use TheCadien\Bundle\SuluNewsBundle\Api\News as NewsApi;
+use TheCadien\Bundle\SuluNewsBundle\Common\DoctrineListRepresentationFactory;
use TheCadien\Bundle\SuluNewsBundle\Entity\News;
-use TheCadien\Bundle\SuluNewsBundle\Repository\NewsRepository;
+use TheCadien\Bundle\SuluNewsBundle\Exception\NewsException;
use TheCadien\Bundle\SuluNewsBundle\Service\News\NewsService;
-class NewsController extends AbstractRestController implements ClassResourceInterface
+#[AsController]
+final class NewsController extends AbstractController
{
- // serialization groups for contact
- protected static $oneNewsSerializationGroups = [
- 'partialMedia',
- 'fullNews',
- ];
-
- /**
- * NewsController constructor.
- */
public function __construct(
- ViewHandlerInterface $viewHandler,
- TokenStorageInterface $tokenStorage,
- private readonly NewsRepository $repository,
private readonly NewsService $newsService,
private readonly DoctrineListRepresentationFactory $doctrineListRepresentationFactory,
+ private readonly NewsApiDtoFactory $apiDtoFactory
) {
- parent::__construct($viewHandler, $tokenStorage);
}
- public function cgetAction(Request $request): Response
+ #[Route('/news', name: 'app.cget_news', methods: ['GET'])]
+ public function cget(Request $request): Response
{
- $locale = $request->query->get('locale');
$listRepresentation = $this->doctrineListRepresentationFactory->createDoctrineListRepresentation(
News::RESOURCE_KEY,
[],
- ['locale' => $locale]
+ ['locale' => $request->query->get('locale')]
);
- return $this->handleView($this->view($listRepresentation));
+ return $this->json($listRepresentation->toArray());
}
- public function getAction(int $id, Request $request): Response
+ #[Route('/news/{id}', name: 'app.get_news', methods: ['GET'])]
+ public function get(News $news, Request $request): Response
{
- if (($entity = $this->repository->findById($id)) === null) {
- throw new NotFoundHttpException();
- }
-
- $apiEntity = $this->generateApiNewsEntity($entity, $this->getLocale($request));
-
- $view = $this->generateViewContent($apiEntity);
-
- return $this->handleView($view);
- }
-
- /**
- * @throws ORMException
- * @throws OptimisticLockException
- */
- public function postAction(Request $request): Response
- {
- $news = $this->newsService->saveNewNews($request->request->all(), $this->getLocale($request));
-
- $apiEntity = $this->generateApiNewsEntity($news, $this->getLocale($request));
-
- $view = $this->generateViewContent($apiEntity);
-
- return $this->handleView($view);
+ return $this->json($this->apiDtoFactory->generate($news, $request->query->get('locale')));
}
- /**
- * @Rest\Post("/news/{id}")
- */
- public function postTriggerAction(int $id, Request $request): Response
+ #[Route('/news', name: 'app.post_news', methods: ['POST'])]
+ public function post(#[MapRequestPayload(acceptFormat: 'json')] NewsApi $newsApi, Request $request): Response
{
- $news = $this->repository->findById($id);
- if (!$news instanceof News) {
- throw new NotFoundHttpException();
+ try {
+ $news = $this->newsService->saveNewNews($newsApi, $request->query->get('locale'));
+ } catch (NewsException) {
+ throw new NewsException();
}
- $news = $this->newsService->updateNewsPublish($news, $request->query->all());
-
- $apiEntity = $this->generateApiNewsEntity($news, $this->getLocale($request));
- $view = $this->generateViewContent($apiEntity);
-
- return $this->handleView($view);
+ return $this->json($this->apiDtoFactory->generate($news, $request->query->get('locale')), 200, [], ['fullNews']);
}
- /**
- * @throws ORMException
- * @throws OptimisticLockException
- */
- public function putAction(int $id, Request $request): Response
+ #[Route('/news/{id}', name: 'app.post_news_trigger', methods: ['POST'])]
+ public function postTrigger(News $news, Request $request): Response
{
- $entity = $this->repository->findById($id);
- if (!$entity instanceof News) {
- throw new NotFoundHttpException();
+ try {
+ $news = $this->newsService->updateNewsPublish($news, $request->query->all());
+ } catch (NewsException) {
+ throw new NewsException();
}
- $updatedEntity = $this->newsService->updateNews($request->request->all(), $entity, $this->getLocale($request));
- $apiEntity = $this->generateApiNewsEntity($updatedEntity, $this->getLocale($request));
- $view = $this->generateViewContent($apiEntity);
-
- return $this->handleView($view);
+ return $this->json($this->apiDtoFactory->generate($news, $request->query->get('locale')));
}
- /**
- * @throws ORMException
- * @throws OptimisticLockException
- */
- public function deleteAction(int $id): Response
+ #[Route('/news/{id}', name: 'app.put_news', methods: ['PUT'])]
+ public function put(News $news, #[MapRequestPayload(acceptFormat: 'json')] NewsApi $newsApi, Request $request): Response
{
try {
- $this->newsService->removeNews($id);
- } catch (\Exception) {
- throw new EntityNotFoundException(self::$entityName, $id);
+ $updatedEntity = $this->newsService->updateNews($newsApi, $news, $request->query->get('locale'));
+ } catch (NewsException) {
+ throw new NewsException();
}
- return $this->handleView($this->view());
- }
-
- public static function getPriority(): int
- {
- return 0;
+ return $this->json($this->apiDtoFactory->generate($updatedEntity, $request->query->get('locale')));
}
- protected function generateApiNewsEntity(News $entity, string $locale): NewsApi
+ #[Route('/news/{id}', name: 'app.delete_news', methods: ['DELETE'])]
+ public function delete(News $news): Response
{
- return new NewsApi($entity, $locale);
- }
-
- protected function generateViewContent(NewsApi $entity): View
- {
- $view = $this->view($entity);
- $context = new Context();
- $context->setGroups(static::$oneNewsSerializationGroups);
+ try {
+ $this->newsService->removeNews($news->getId());
+ } catch (NewsException) {
+ throw new NewsException();
+ }
- return $view->setContext($context);
+ return $this->json(null, 204);
}
}
diff --git a/Controller/NewsWebsiteController.php b/Controller/Website/NewsController.php
similarity index 79%
rename from Controller/NewsWebsiteController.php
rename to Controller/Website/NewsController.php
index b207c0f..b78a69b 100644
--- a/Controller/NewsWebsiteController.php
+++ b/Controller/Website/NewsController.php
@@ -11,27 +11,26 @@
* with this source code in the file LICENSE.
*/
-namespace TheCadien\Bundle\SuluNewsBundle\Controller;
+namespace TheCadien\Bundle\SuluNewsBundle\Controller\Website;
use Sulu\Bundle\PreviewBundle\Preview\Preview;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use TheCadien\Bundle\SuluNewsBundle\Entity\News;
-/**
- * Class NewsWebsiteController.
- */
-class NewsWebsiteController extends AbstractController
+#[AsController]
+final class NewsController extends AbstractController
{
- public function indexAction(News $news, $attributes = [], $preview = false, $partial = false): Response
+ public function index(News $news, $attributes = [], $preview = false, $partial = false): Response
{
if (!$news) {
throw new NotFoundHttpException();
}
if ($partial) {
- $content = $this->renderBlock(
+ $content = $this->renderBlockView(
'news/index.html.twig',
'content',
['news' => $news]
@@ -62,7 +61,7 @@ protected function renderPreview(string $view, array $parameters = []): string
/**
* Returns rendered part of template specified by block.
*/
- protected function renderBlock(mixed $template, mixed $block, mixed $attributes = [])
+ protected function renderBlockView(mixed $template, mixed $block, mixed $attributes = []): string
{
$twig = $this->container->get('twig');
$attributes = $twig->mergeGlobals($attributes);
@@ -73,7 +72,7 @@ protected function renderBlock(mixed $template, mixed $block, mixed $attributes
\ob_start();
try {
- $rendered = $template->renderBlock($block, $attributes);
+ $rendered = $template->renderBlockView($block, $attributes);
\ob_end_clean();
return $rendered;
diff --git a/DependencyInjection/NewsExtension.php b/DependencyInjection/NewsExtension.php
index aae4765..a6065d1 100644
--- a/DependencyInjection/NewsExtension.php
+++ b/DependencyInjection/NewsExtension.php
@@ -17,7 +17,7 @@
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
-use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
+use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use TheCadien\Bundle\SuluNewsBundle\Admin\NewsAdmin;
use TheCadien\Bundle\SuluNewsBundle\Entity\News;
@@ -90,7 +90,7 @@ public function prepend(ContainerBuilder $container): void
'resources' => [
'news' => [
'routes' => [
- 'list' => 'app.get_news',
+ 'list' => 'app.cget_news',
'detail' => 'app.get_news',
],
],
@@ -144,9 +144,8 @@ public function load(array $configs, ContainerBuilder $container): void
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
- $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
- $loader->load('services.xml');
- $loader->load('controller.xml');
+ $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
+ $loader->load('services.yaml');
$this->configurePersistence($config['objects'], $container);
}
diff --git a/Entity/Factory/AbstractFactory.php b/Entity/Factory/AbstractFactory.php
deleted file mode 100644
index 576cb96..0000000
--- a/Entity/Factory/AbstractFactory.php
+++ /dev/null
@@ -1,33 +0,0 @@
-getProperty($data, 'title')) {
- $news->setTitle($this->getProperty($data, 'title'));
- }
-
- if ($this->getProperty($data, 'teaser')) {
- $news->setTeaser($this->getProperty($data, 'teaser'));
- }
-
- if ($this->getProperty($data, 'header')) {
- $news->setHeader($this->mediaFactory->generateMedia($data['header']));
- }
-
- if ($this->getProperty($data, 'publishedAt')) {
- $news->setPublishedAt(new \DateTime($this->getProperty($data, 'publishedAt')));
- }
-
- if ($this->getProperty($data, 'content')) {
- $news->setContent($this->getProperty($data, 'content'));
- }
-
- if ($this->getProperty($data, 'ext')) {
- $news->setSeo($this->getProperty($data['ext'], 'seo'));
- }
-
- if ($tags = $this->getProperty($data, 'tags')) {
- $this->tagFactory->processTags($news, $tags);
+ $news->setTitle($data->title);
+ $news->setTeaser($data->teaser);
+ $news->setHeader($data->header);
+ $news->setPublishedAt($data->publishedAt);
+ $news->setContent($data->content);
+ $news->setSeo($data->ext);
+
+ if ($data->tags) {
+ $this->tagFactory->processTags($news, $data->tags);
}
if (!$news->getId()) {
@@ -75,13 +59,12 @@ public function generateNewsFromRequest(News $news, array $data, string $locale
$news->setEnabled($state);
}
- if ($authored = $this->getProperty($data, 'authored')) {
- $news->setCreated(new \DateTime($authored));
+ if ($data->authored) {
+ $news->setCreated($data->authored);
}
- if ($author = $this->getProperty($data, 'author')) {
- // @var Contact $contact
- $news->setCreator($this->contactRepository->find($author));
+ if ($data->author) {
+ $news->setCreator($this->contactRepository->find($data->author));
}
return $news;
diff --git a/Entity/Factory/NewsFactoryInterface.php b/Entity/Factory/NewsFactoryInterface.php
index c9ad720..33d2294 100644
--- a/Entity/Factory/NewsFactoryInterface.php
+++ b/Entity/Factory/NewsFactoryInterface.php
@@ -13,9 +13,10 @@
namespace TheCadien\Bundle\SuluNewsBundle\Entity\Factory;
+use TheCadien\Bundle\SuluNewsBundle\Api\News as NewsApi;
use TheCadien\Bundle\SuluNewsBundle\Entity\News;
interface NewsFactoryInterface
{
- public function generateNewsFromRequest(News $news, array $data, string $locale): News;
+ public function generateNewsFromRequest(News $news, NewsApi $data, string $locale): News;
}
diff --git a/Entity/Factory/NewsRouteFactory.php b/Entity/Factory/NewsRouteFactory.php
index c0c937d..d1fcec4 100644
--- a/Entity/Factory/NewsRouteFactory.php
+++ b/Entity/Factory/NewsRouteFactory.php
@@ -13,16 +13,13 @@
namespace TheCadien\Bundle\SuluNewsBundle\Entity\Factory;
-use Sulu\Bundle\RouteBundle\Manager\RouteManager;
+use Sulu\Bundle\RouteBundle\Manager\RouteManagerInterface;
use Sulu\Bundle\RouteBundle\Model\RouteInterface;
use TheCadien\Bundle\SuluNewsBundle\Entity\News;
class NewsRouteFactory implements NewsRouteFactoryInterface
{
- /**
- * NewsFactory constructor.
- */
- public function __construct(private readonly RouteManager $routeManager)
+ public function __construct(private readonly RouteManagerInterface $routeManager)
{
}
diff --git a/Entity/Factory/TagFactory.php b/Entity/Factory/TagFactory.php
index 30dc22f..e848049 100644
--- a/Entity/Factory/TagFactory.php
+++ b/Entity/Factory/TagFactory.php
@@ -17,7 +17,7 @@
use Sulu\Component\Persistence\RelationTrait;
use TheCadien\Bundle\SuluNewsBundle\Entity\News;
-class TagFactory extends AbstractFactory implements TagFactoryInterface
+class TagFactory implements TagFactoryInterface
{
use RelationTrait;
@@ -35,17 +35,25 @@ public function __construct(private readonly TagManagerInterface $tagManager)
*/
public function processTags(News $news, $tags)
{
- $get = fn ($tag) => $tag->getId();
+ $get = function ($tag) {
+ return $tag->getId();
+ };
- $delete = fn ($tag) => $news->removeTag($tag);
+ $delete = function ($tag) use ($news) {
+ return $news->removeTag($tag);
+ };
- $update = fn () => true;
+ $update = function () {
+ return true;
+ };
- $add = fn ($tag) => $this->addTag($news, $tag);
+ $add = function ($tag) use ($news) {
+ return $this->addTag($news, $tag);
+ };
$entities = $news->getTags();
- return $this->processSubEntities(
+ $result = $this->processSubEntities(
$entities,
$tags,
$get,
@@ -53,6 +61,10 @@ public function processTags(News $news, $tags)
$update,
$delete
);
+
+ $this->resetIndexOfSubentites($entities);
+
+ return $result;
}
/**
diff --git a/Entity/News.php b/Entity/News.php
index 7b38386..4db2c5c 100644
--- a/Entity/News.php
+++ b/Entity/News.php
@@ -13,7 +13,6 @@
namespace TheCadien\Bundle\SuluNewsBundle\Entity;
-use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use JMS\Serializer\Annotation\Accessor;
@@ -103,9 +102,6 @@ public function setEnabled(bool $enabled): void
$this->enabled = $enabled;
}
- /**
- * @return string
- */
public function getTitle(): ?string
{
return $this->title;
@@ -121,33 +117,27 @@ public function getContent()
return $this->content ?: [];
}
- public function setContent($content): void
+ public function setContent(mixed $content): void
{
$this->content = $content;
}
- /**
- * @return DateTime
- */
- public function getCreated(): ?DateTime
+ public function getCreated(): ?\DateTime
{
return $this->created;
}
- public function setCreated(DateTime $created): void
+ public function setCreated(\DateTime $created): void
{
$this->created = $created;
}
- /**
- * @return DateTime
- */
- public function getPublishedAt(): ?DateTime
+ public function getPublishedAt(): ?\DateTime
{
return $this->publishedAt;
}
- public function setPublishedAt(DateTime $publishedAt): void
+ public function setPublishedAt(\DateTime $publishedAt): void
{
$this->publishedAt = $publishedAt;
}
@@ -157,7 +147,7 @@ public function getTeaser(): ?string
return $this->teaser;
}
- public function setTeaser(string $teaser): void
+ public function setTeaser(?string $teaser): void
{
$this->teaser = $teaser;
}
@@ -196,7 +186,7 @@ public function getTagNameArray(): array
{
$tags = [];
- if (null !== $this->getTags()) {
+ if ($this->getTags() instanceof Collection) {
foreach ($this->getTags() as $tag) {
$tags[] = $tag->getName();
}
@@ -231,12 +221,12 @@ public function setchanger(mixed $changer): void
$this->changer = $changer;
}
- public function getChanged(): DateTime
+ public function getChanged(): ?\DateTime
{
return $this->changed;
}
- public function setChanged(DateTime $changed): void
+ public function setChanged(\DateTime $changed): void
{
$this->changed = $changed;
}
diff --git a/Exception/NewsException.php b/Exception/NewsException.php
new file mode 100644
index 0000000..803b31f
--- /dev/null
+++ b/Exception/NewsException.php
@@ -0,0 +1,9 @@
+select('n')
->from('NewsBundle:News', 'n')
->where('n.enabled = 1')
- ->andWhere('n.publishedAt <= :created')
- ->setParameter('created', \date('Y-m-d H:i:s'))
+ ->andWhere('n.publishedAt <= :published')
+ ->setParameter('published', \date('Y-m-d H:i:s'))
->orderBy('n.publishedAt', 'DESC');
- $news = $qb->getQuery()->getResult();
-
- if (!$news) {
- return [];
- }
-
- return $news;
+ return $qb->getQuery()->getResult();
}
public function findById(int $id): ?News
@@ -62,8 +64,8 @@ public function findById(int $id): ?News
}
/**
- * @throws \Doctrine\ORM\ORMException
- * @throws \Doctrine\ORM\OptimisticLockException
+ * @throws ORMException
+ * @throws OptimisticLockException
*/
public function remove(int $id): void
{
diff --git a/Resources/config/controller.xml b/Resources/config/controller.xml
deleted file mode 100644
index cfec162..0000000
--- a/Resources/config/controller.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-