Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ doctrine:
dql:
datetime_functions:
UNIX_TIMESTAMP: DoctrineExtensions\Query\Mysql\UnixTimestamp
YEAR: DoctrineExtensions\Query\Mysql\Year
FROM_UNIXTIME: DoctrineExtensions\Query\Mysql\FromUnixtime
mappings:
Accounting:
type: attribute
Expand Down
4 changes: 0 additions & 4 deletions db/seeds/Articles.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

declare(strict_types=1);

use AppBundle\Site\Enum\ArticleContentType;
use AppBundle\Site\Model\Rubrique;
use Cocur\Slugify\Slugify;
use Faker\Factory;
Expand Down Expand Up @@ -32,7 +31,6 @@ public function run(): void
'date' => 1542150000,
'id_forum' => Event::ID_FORUM,
'etat' => 1,
'type_contenu' => ArticleContentType::Html->value,
],
];

Expand All @@ -50,7 +48,6 @@ public function run(): void
'id_site_rubrique' => Rubrique::ID_RUBRIQUE_ACTUALITES,
'date' => $faker->unixTime(new DateTime('2017-12-31T23:59:59')),
'etat' => 1,
'type_contenu' => ArticleContentType::Html->value,
];
}

Expand Down Expand Up @@ -88,7 +85,6 @@ private function createMarkdownArticle(): array
'date' => 1761859722,
'id_forum' => Event::ID_FORUM,
'etat' => 1,
'type_contenu' => ArticleContentType::Markdown->value,
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace AppBundle\Controller\Admin\Site\Article;

use AppBundle\AuditLog\Audit;
use AppBundle\Site\Entity\Article;
use AppBundle\Site\Entity\Repository\ArticleRepository;
use AppBundle\Site\Form\ArticleType;
use AppBundle\Site\Model\Article;
use AppBundle\Site\Model\Repository\ArticleRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -28,8 +28,8 @@ public function __invoke(Request $request): Response

if ($form->isSubmitted() && $form->isValid()) {
$this->articleRepository->save($article);
$this->audit->log('Ajout de l\'article ' . $article->getTitle());
$this->addFlash('notice', 'L\'article ' . $article->getTitle() . ' a été ajouté');
$this->audit->log('Ajout de l\'article ' . $article->titre);
$this->addFlash('notice', 'L\'article ' . $article->titre . ' a été ajouté');
return $this->redirectToRoute('admin_site_articles_list');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace AppBundle\Controller\Admin\Site\Article;

use AppBundle\AuditLog\Audit;
use AppBundle\Site\Model\Repository\ArticleRepository;
use AppBundle\Site\Entity\Repository\ArticleRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Security\Csrf\CsrfToken;
Expand All @@ -25,11 +25,15 @@ public function __invoke(int $id, string $token): RedirectResponse
$this->addFlash('error', 'Token invalide');
return $this->redirectToRoute('admin_site_articles_list');
}
$article = $this->articleRepository->get($id);
$name = $article->getTitle();

$article = $this->articleRepository->find($id);
if ($article === null) {
throw $this->createNotFoundException();
}

$this->articleRepository->delete($article);
$this->audit->log('Suppression de l\'article ' . $name);
$this->addFlash('notice', 'L\'article ' . $name . ' a été supprimé');
$this->audit->log('Suppression de l\'article ' . $article->titre);
$this->addFlash('notice', 'L\'article ' . $article->titre . ' a été supprimé');
return $this->redirectToRoute('admin_site_articles_list');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace AppBundle\Controller\Admin\Site\Article;

use AppBundle\AuditLog\Audit;
use AppBundle\Site\Entity\Repository\ArticleRepository;
use AppBundle\Site\Form\ArticleType;
use AppBundle\Site\Model\Repository\ArticleRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -20,13 +20,17 @@ public function __construct(

public function __invoke(int $id, Request $request): Response
{
$article = $this->articleRepository->get($id);
$article = $this->articleRepository->find($id);
if ($article === null) {
throw $this->createNotFoundException();
}

$form = $this->createForm(ArticleType::class, $article);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->articleRepository->save($article);
$this->audit->log('Modification de l\'article ' . $article->getTitle());
$this->addFlash('notice', 'L\'article ' . $article->getTitle() . ' a été modifié');
$this->audit->log('Modification de l\'article ' . $article->titre);
$this->addFlash('notice', 'L\'article ' . $article->titre . ' a été modifié');
return $this->redirectToRoute('admin_site_articles_list');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace AppBundle\Controller\Admin\Site\Article;

use AppBundle\Site\Model\Repository\ArticleRepository;
use AppBundle\Site\Entity\Repository\ArticleRepository;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Twig\Environment;
Expand All @@ -18,15 +18,15 @@ public function __construct(

public function __invoke(Request $request): Response
{
$fields = ['date', 'titre', 'etat'];
$fields = ['date', 'titre', 'nom_rubrique', 'etat'];

$sort = $request->query->get('sort', 'date');
if (in_array($sort, $fields) === false) {
$sort = 'date';
}
$direction = $request->query->get('direction', 'desc');
$filter = $request->query->get('filter', '');
$articles = $this->articleRepository->getAllArticlesWithCategoryAndTheme($sort, $direction, $filter);
$articles = $this->articleRepository->getAllArticlesWithRubriqueAndTheme($sort, $direction, $filter);

return new Response($this->twig->render('admin/site/article_list.html.twig', [
'articles' => $articles,
Expand Down
13 changes: 6 additions & 7 deletions sources/AppBundle/Controller/Website/Cms/DisplayAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace AppBundle\Controller\Website\Cms;

use AppBundle\Site\Model\Article;
use AppBundle\Site\Model\Repository\ArticleRepository;
use AppBundle\Site\Entity\Repository\RubriqueRepository;
use AppBundle\Site\Entity\Article;
use AppBundle\Site\Entity\Repository\ArticleRepository;
use AppBundle\Site\Entity\Rubrique;
use AppBundle\Site\Enum\ArticleEtat;
use AppBundle\Twig\ViewRenderer;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -17,7 +17,6 @@ final class DisplayAction extends AbstractController
public function __construct(
private readonly ViewRenderer $view,
private readonly ArticleRepository $articleRepository,
private readonly RubriqueRepository $rubriqueRepository,
) {}

public function __invoke(string $code): Response
Expand All @@ -28,13 +27,13 @@ public function __invoke(string $code): Response
throw $this->createNotFoundException();
}

if (false === $this->isGranted('ROLE_ADMIN') && $article->getState() !== 1) {
if (false === $this->isGranted('ROLE_ADMIN') && $article->etat !== ArticleEtat::EnLigne) {
throw $this->createAccessDeniedException();
}

$rubrique = $this->rubriqueRepository->find($article->getRubricId());
$rubrique = $article->rubrique;

if (!$this->isRubriqueAllowed($rubrique)) {
if ($rubrique === null || !$this->isRubriqueAllowed($rubrique)) {
throw $this->createNotFoundException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use AppBundle\Event\Model\Meetup;
use AppBundle\Event\Model\Repository\TalkRepository;
use AppBundle\Event\Model\Talk;
use AppBundle\Site\Model\Repository\ArticleRepository;
use AppBundle\Site\Entity\Repository\ArticleRepository;
use AppBundle\Site\Entity\Repository\FeuilleRepository;
use AppBundle\Twig\ViewRenderer;
use Psr\Cache\CacheItemPoolInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use AppBundle\Association\Model\Repository\CompanyMemberRepository;
use AppBundle\Event\Model\Repository\TalkRepository;
use AppBundle\Event\Model\Talk;
use AppBundle\Site\Model\Repository\ArticleRepository;
use AppBundle\Site\Entity\Repository\ArticleRepository;
use AppBundle\Site\Entity\Repository\FeuilleRepository;
use AppBundle\Twig\ViewRenderer;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
Expand Down Expand Up @@ -75,7 +75,7 @@ private function members(): array
private function news(): array
{
$news = [];
$newsList = $this->articleRepository->findAllPublishedNews();
$newsList = $this->articleRepository->findAllPublishedArticles();
foreach ($newsList as $newsItem) {
$url = $this->generateUrl('news_display', [
'code' => $newsItem->getSlug(),
Expand Down
17 changes: 9 additions & 8 deletions sources/AppBundle/Controller/Website/News/DisplayAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

use AppBundle\Event\Model\Event;
use AppBundle\Event\Model\Repository\EventRepository;
use AppBundle\Site\Model\Article;
use AppBundle\Site\Model\Repository\ArticleRepository;
use AppBundle\Site\Entity\Article;
use AppBundle\Site\Entity\Repository\ArticleRepository;
use AppBundle\Site\Enum\ArticleEtat;
use AppBundle\Twig\ViewRenderer;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
Expand All @@ -27,12 +28,12 @@ public function __construct(

public function __invoke(string $code): Response
{
$article = $this->articleRepository->findNewsBySlug($code);
$article = $this->articleRepository->findArticleBySlug($code);
if (null === $article) {
throw $this->createNotFoundException();
}

if (!$this->authorizationChecker->isGranted('ROLE_ADMIN') && ($article->getState() === 0 || $article->getPublishedAt() > new \DateTime())) {
if (!$this->authorizationChecker->isGranted('ROLE_ADMIN') && ($article->etat !== ArticleEtat::EnLigne || $article->datePublication > new \DateTime())) {
throw $this->createNotFoundException();
}

Expand All @@ -47,20 +48,20 @@ public function __invoke(string $code): Response

private function getRelatedEvent(Article $article): ?Event
{
if (null === ($eventId = $article->getEventId())) {
if (null === $article->idEvent) {
return null;
}

return $this->eventRepository->get($eventId);
return $this->eventRepository->get($article->idEvent);
}

private function getHeaderImageUrl(Article $article): ?string
{
if (null === ($theme = $article->getTheme())) {
if (null === $article->theme) {
return null;
}

$image = '/images/news/' . $theme . '.png';
$image = '/images/news/' . $article->theme->value . '.png';

$url = $this->projectDir . '/htdocs' . $image ;

Expand Down
6 changes: 3 additions & 3 deletions sources/AppBundle/Controller/Website/News/ListAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace AppBundle\Controller\Website\News;

use AppBundle\Site\Form\NewsFiltersType;
use AppBundle\Site\Model\Repository\ArticleRepository;
use AppBundle\Site\Entity\Repository\ArticleRepository;
use AppBundle\Twig\ViewRenderer;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -32,8 +32,8 @@ public function __invoke(Request $request): Response

return $this->view->render('site/news/list.html.twig', [
'filters' => $filters,
'articles' => $this->articleRepository->findPublishedNews($page, self::ARTICLES_PER_PAGE, $filters),
'total_items' => $this->articleRepository->countPublishedNews($filters),
'articles' => $this->articleRepository->findPublishedArticles($page, self::ARTICLES_PER_PAGE, $filters),
'total_items' => $this->articleRepository->countPublishedArticles($filters),
'current_page' => $page,
'articles_per_page' => self::ARTICLES_PER_PAGE,
'form' => $form->createView(),
Expand Down
12 changes: 5 additions & 7 deletions sources/AppBundle/Controller/Website/RssFeedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

namespace AppBundle\Controller\Website;

use AppBundle\Site\Model\Article;
use AppBundle\Site\Model\Repository\ArticleRepository;
use AppBundle\Site\Entity\Repository\ArticleRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;

Expand All @@ -15,15 +14,14 @@ public function __construct(private readonly ArticleRepository $articleRepositor

public function __invoke(): Response
{
$articles = $this->articleRepository->findPublishedNews(1, 20, []);
$articles = $this->articleRepository->findPublishedArticles(1, 20, []);
$derniersArticles = [];
foreach ($articles as $article) {
/** @var Article $article */
$derniersArticles[] = [
'titre' => $article->getTitle(),
'contenu' => $article->getFormatedContent(),
'titre' => $article->titre,
'contenu' => $article->getContenuFormate(),
'url' => $article->getSlug(),
'maj' => $article->getPublishedAt()->format(DATE_RSS),
'maj' => $article->datePublication->format(DATE_RSS),
];
}
$datas = [
Expand Down
5 changes: 5 additions & 0 deletions sources/AppBundle/Doctrine/EntityRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ final public function delete(object $entity): void
$this->getEntityManager()->remove($entity);
$this->getEntityManager()->flush();
}

final protected function hasColumn(string $column): bool
{
return in_array($column, $this->getClassMetadata()->getColumnNames(), true);
}
}
Loading
Loading