diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php index 7cb84b14d..1621471b8 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php @@ -791,48 +791,6 @@ class ChillMainExtension extends Extension implements ], ], ], - /* [ - 'class' => \Chill\MainBundle\Entity\DashboardConfigItem::class, - 'controller' => \Chill\MainBundle\Controller\DashboardApiController::class, - 'name' => 'dashboard-config-item', - 'base_path' => '/api/1.0/main/dashboard-config-item', - 'base_role' => 'ROLE_USER', - 'actions' => [ - '_index' => [ - 'methods' => [ - Request::METHOD_GET => true, - Request::METHOD_HEAD => true, - ], - ], - '_entity' => [ - 'methods' => [ - Request::METHOD_GET => true, - Request::METHOD_HEAD => true, - ], - ], - ], - ], - [ - 'class' => \Chill\MainBundle\Entity\NewsItem::class, - 'controller' => \Chill\MainBundle\Controller\NewsItemApiController::class, - 'name' => 'news-items', - 'base_path' => '/api/1.0/main/news', - 'base_role' => 'ROLE_USER', - 'actions' => [ - '_index' => [ - 'methods' => [ - Request::METHOD_GET => true, - Request::METHOD_HEAD => true, - ], - ], - '_entity' => [ - 'methods' => [ - Request::METHOD_GET => true, - Request::METHOD_HEAD => true, - ], - ], - ], - ],*/ ], ]); } diff --git a/src/Bundle/ChillMainBundle/Entity/DashboardConfigItem.php b/src/Bundle/ChillMainBundle/Entity/DashboardConfigItem.php index 122202f96..5ad1107c5 100644 --- a/src/Bundle/ChillMainBundle/Entity/DashboardConfigItem.php +++ b/src/Bundle/ChillMainBundle/Entity/DashboardConfigItem.php @@ -54,10 +54,10 @@ class DashboardConfigItem /** * @ORM\ManyToOne(targetEntity=User::class) */ - private User $user; + private ?User $user = null; /** - * @ORM\Column(type="json") + * @ORM\Column(type="json" "jsonb"=true, options={"default": "[]"}) * * @Serializer\Groups({"dashboardConfigItem:read"}) */ diff --git a/src/Bundle/ChillMainBundle/Entity/NewsItem.php b/src/Bundle/ChillMainBundle/Entity/NewsItem.php index 10eca8f54..6ca58afd1 100644 --- a/src/Bundle/ChillMainBundle/Entity/NewsItem.php +++ b/src/Bundle/ChillMainBundle/Entity/NewsItem.php @@ -12,7 +12,9 @@ declare(strict_types=1); namespace Chill\MainBundle\Entity; use Chill\MainBundle\Doctrine\Model\TrackCreationInterface; +use Chill\MainBundle\Doctrine\Model\TrackCreationTrait; use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface; +use Chill\MainBundle\Doctrine\Model\TrackUpdateTrait; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Validator\Constraints as Assert; @@ -24,6 +26,10 @@ use Symfony\Component\Validator\Constraints as Assert; */ class NewsItem implements TrackCreationInterface, TrackUpdateInterface { + use TrackCreationTrait; + + use TrackUpdateTrait; + /** * @ORM\Id * @@ -71,78 +77,6 @@ class NewsItem implements TrackCreationInterface, TrackUpdateInterface */ private ?\DateTimeImmutable $endDate = null; - /** - * @ORM\Column(type="datetime_immutable", nullable=true) - */ - private ?\DateTimeInterface $createdAt = null; - - /** - * @ORM\ManyToOne(targetEntity=User::class) - * - * @ORM\JoinColumn(nullable=true) - */ - private ?User $createdBy = null; - - /** - * @ORM\Column(type="datetime_immutable", nullable=true) - */ - private ?\DateTimeInterface $updatedAt = null; - - /** - * @ORM\ManyToOne(targetEntity=User::class) - * - * @ORM\JoinColumn(nullable=true) - */ - private ?User $updatedBy = null; - - public function getCreatedAt(): ?\DateTimeInterface - { - return $this->createdAt; - } - - public function getCreatedBy(): ?User - { - return $this->createdBy; - } - - public function getUpdatedAt(): ?\DateTimeInterface - { - return $this->updatedAt; - } - - public function getUpdatedBy(): ?User - { - return $this->updatedBy; - } - - public function setCreatedAt(\DateTimeInterface $datetime): self - { - $this->createdAt = $datetime; - - return $this; - } - - public function setCreatedBy(User $user): self - { - $this->createdBy = $user; - - return $this; - } - - public function setUpdatedAt(\DateTimeInterface $datetime): self - { - $this->updatedAt = $datetime; - - return $this; - } - - public function setUpdatedBy(User $user): self - { - $this->updatedBy = $user; - - return $this; - } - public function getTitle(): string { return $this->title; diff --git a/src/Bundle/ChillMainBundle/Repository/NewsItemRepository.php b/src/Bundle/ChillMainBundle/Repository/NewsItemRepository.php index bb2128b25..042c052c5 100644 --- a/src/Bundle/ChillMainBundle/Repository/NewsItemRepository.php +++ b/src/Bundle/ChillMainBundle/Repository/NewsItemRepository.php @@ -16,12 +16,13 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\QueryBuilder; use Doctrine\Persistence\ObjectRepository; +use Symfony\Component\Clock\ClockInterface; class NewsItemRepository implements ObjectRepository { private readonly EntityRepository $repository; - public function __construct(EntityManagerInterface $entityManager) + public function __construct(EntityManagerInterface $entityManager, private ClockInterface $clock) { $this->repository = $entityManager->getRepository(NewsItem::class); } @@ -58,6 +59,9 @@ class NewsItemRepository implements ObjectRepository public function findWithDateFilter() { + dump($this->buildQueryWithDateFilter() + ->getQuery() + ->getResult()); return $this->buildQueryWithDateFilter() ->getQuery() ->getResult(); @@ -73,13 +77,13 @@ class NewsItemRepository implements ObjectRepository public function buildQueryWithDateFilter(): QueryBuilder { - $now = new \DateTime('now'); + $now = $this->clock->now(); $qb = $this->createQueryBuilder('n'); $qb ->where( $qb->expr()->andX( - $qb->expr()->gte('n.startDate', ':now'), + $qb->expr()->lte('n.startDate', ':now'), $qb->expr()->orX( $qb->expr()->lt('n.endDate', ':now'), $qb->expr()->isNull('n.endDate') diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/DashboardWidgets/News.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/DashboardWidgets/News.vue index 272a57e9b..e11338c4a 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/DashboardWidgets/News.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/DashboardWidgets/News.vue @@ -5,8 +5,8 @@
  • {{ item.title }}

    -
    - Read more +
    + {{ $t('widget.news.readMore') }}
    @@ -64,9 +64,9 @@ const convertMarkdownToHtml = (markdown: string): string => { return DOMPurify.sanitize(rawHtml) }; -const truncateMarkdownContent = (content: string, maxLength = 100): string => { - const htmlContent = convertMarkdownToHtml(content); - return truncateContent(htmlContent, maxLength); +const prepareContent = (content: string, maxLength = 100): string => { + const truncatedContent = truncateContent(content, maxLength); + return convertMarkdownToHtml(truncatedContent); }; const formatDate = (datetime: { date: string }): string => { @@ -76,9 +76,10 @@ const formatDate = (datetime: { date: string }): string => { onMounted(() => { makeFetch('GET', '/api/1.0/main/news.json') .then((response: {results: NewsItem[]}) => { + // console.log('news articles', response.results) newsItems.value = response.results }) - .catch((error) => { + .catch((error: string) => { console.error('Error fetching news items', error); }) }) diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/MyCustoms.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/MyCustoms.vue index 5df7fb787..65bed73ef 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/MyCustoms.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/MyCustoms.vue @@ -41,7 +41,7 @@
    - +
    @@ -76,7 +76,7 @@ export default { mounted() { const elem = document.querySelector('#dashboards'); const masonry = new Masonry(elem, {}); - //Fetch the dashboard items configured for user. Currently response is still hardcoded and no user id passed. + //Fetch the dashboard items configured for user. Currently response is still hardcoded makeFetch('GET', '/api/1.0/main/dashboard-config-item.json') .then((response) => { this.dashboardItems = response; diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/_js/i18n.ts b/src/Bundle/ChillMainBundle/Resources/public/vuejs/_js/i18n.ts index c43586915..54e136e08 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/_js/i18n.ts +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/_js/i18n.ts @@ -54,7 +54,8 @@ const messages = { }, widget: { news: { - title: "Actualités" + title: "Actualités", + readMore: "Lire la suite" } } } diff --git a/src/Bundle/ChillMainBundle/Resources/views/Admin/indexDashboard.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Admin/indexDashboard.html.twig index 6f79e3d2a..8049f3430 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Admin/indexDashboard.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Admin/indexDashboard.html.twig @@ -8,6 +8,6 @@ {% block layout_wvm_content %} {% block admin_content %} -

    {{ 'News configuration' |trans }}

    +

    {{ 'News configuration' | trans }}

    {% endblock %} {% endblock %} diff --git a/src/Bundle/ChillMainBundle/Resources/views/NewsItem/index.html.twig b/src/Bundle/ChillMainBundle/Resources/views/NewsItem/index.html.twig index 25c1555fb..307073496 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/NewsItem/index.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/NewsItem/index.html.twig @@ -4,8 +4,8 @@ {% embed '@ChillMain/CRUD/_index.html.twig' %} {% block table_entities_thead_tr %} {{ 'Title'|trans }} - {{ 'news.startdate'|trans }} - {{ 'news.enddate'|trans }} + {{ 'dashboard.news.startDate'|trans }} + {{ 'dashboard.news.endDate'|trans }} {% endblock %} {% block table_entities_tbody %} {% for entity in entities %} @@ -15,7 +15,7 @@ {% if entity.endDate is not null %} {{ entity.endDate|date }} {% else %} - Pas de date de fin + {{ 'dashboard.news.noDate'|trans }} {% endif %}