Commit 3e2b4a88 by Julien Jorry

Fix #103 - Gestion des actualités / Amélioration

parent de50573c
...@@ -10,4 +10,7 @@ ...@@ -10,4 +10,7 @@
} }
.btn-primary, .btn-secondary { .btn-primary, .btn-secondary {
border-radius: 10px; border-radius: 10px;
}
.nounderline:hover {
text-decoration: none;
} }
\ No newline at end of file
...@@ -356,7 +356,7 @@ services: ...@@ -356,7 +356,7 @@ services:
admin.news.gerer: admin.news.gerer:
class: App\Admin\NewsAdmin class: App\Admin\NewsAdmin
arguments: [~, App\Entity\News, ~] arguments: [~, App\Entity\News, 'PixSortableBehaviorBundle:SortableAdmin']
tags: tags:
- name: sonata.admin - name: sonata.admin
manager_type: orm manager_type: orm
......
...@@ -5,9 +5,11 @@ namespace App\Admin; ...@@ -5,9 +5,11 @@ namespace App\Admin;
use App\Entity\User; use App\Entity\User;
use FOS\CKEditorBundle\Form\Type\CKEditorType; use FOS\CKEditorBundle\Form\Type\CKEditorType;
use Sonata\AdminBundle\Admin\AbstractAdmin; use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\DatagridInterface;
use Sonata\AdminBundle\Datagrid\ListMapper; use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper; use Sonata\AdminBundle\Form\FormMapper;
use Sonata\MediaBundle\Form\Type\MediaType; use Sonata\MediaBundle\Form\Type\MediaType;
use Sonata\AdminBundle\Route\RouteCollectionInterface;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType; use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
...@@ -23,10 +25,17 @@ class NewsAdmin extends AbstractAdmin ...@@ -23,10 +25,17 @@ class NewsAdmin extends AbstractAdmin
{ {
protected $translator; protected $translator;
protected $datagridValues = [ protected $datagridValues = [
'_sort_order' => 'DESC', '_sort_order' => 'ASC',
'_sort_by' => 'createdAt', '_sort_by' => 'position',
]; ];
// protected function configureDefaultSortValues(array &$sortValues): void
// {
// $sortValues[DatagridInterface::PAGE] = 1;
// $sortValues[DatagridInterface::SORT_ORDER] = 'ASC';
// $sortValues[DatagridInterface::SORT_BY] = 'position';
// }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -66,6 +75,11 @@ class NewsAdmin extends AbstractAdmin ...@@ -66,6 +75,11 @@ class NewsAdmin extends AbstractAdmin
; ;
} }
protected function configureRoutes(RouteCollectionInterface $collection): void
{
$collection->add('move', $this->getRouterIdParameter().'/move/{position}');
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -77,6 +91,13 @@ class NewsAdmin extends AbstractAdmin ...@@ -77,6 +91,13 @@ class NewsAdmin extends AbstractAdmin
->addIdentifier('content', 'html', ['truncate' => ['length' => 80], 'label' => 'Description']) ->addIdentifier('content', 'html', ['truncate' => ['length' => 80], 'label' => 'Description'])
->addIdentifier('media', null, ['label' => 'Fichier']) ->addIdentifier('media', null, ['label' => 'Fichier'])
->addIdentifier('enabled', null, ['label' => 'Activé', 'datatype' => 'App.Document', 'template' => '@kohinos/bundles/SonataAdminBundle/Boolean/editable_boolean.html.twig']) ->addIdentifier('enabled', null, ['label' => 'Activé', 'datatype' => 'App.Document', 'template' => '@kohinos/bundles/SonataAdminBundle/Boolean/editable_boolean.html.twig'])
->add('_action', null, [
'actions' => [
'move' => [
'template' => '@PixSortableBehavior/Default/_sort.html.twig'
],
]
]);
; ;
} }
......
...@@ -6,6 +6,7 @@ use ApiPlatform\Core\Annotation\ApiResource; ...@@ -6,6 +6,7 @@ use ApiPlatform\Core\Annotation\ApiResource;
use App\Entity\EntityTrait\EnablableEntityTrait; use App\Entity\EntityTrait\EnablableEntityTrait;
use App\Entity\EntityTrait\NameSlugContentEntityTrait; use App\Entity\EntityTrait\NameSlugContentEntityTrait;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\Timestampable\Traits\TimestampableEntity; use Gedmo\Timestampable\Traits\TimestampableEntity;
use Ramsey\Uuid\Doctrine\UuidGenerator; use Ramsey\Uuid\Doctrine\UuidGenerator;
use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Serializer\Annotation\Groups;
...@@ -65,6 +66,12 @@ class News ...@@ -65,6 +66,12 @@ class News
*/ */
private $user; private $user;
/**
* @Gedmo\SortablePosition
* @ORM\Column(name="position", type="integer")
*/
private $position;
public function getId() public function getId()
{ {
return $this->id; return $this->id;
...@@ -137,4 +144,24 @@ class News ...@@ -137,4 +144,24 @@ class News
return $this; return $this;
} }
/**
* Get position
* @return
*/
public function getPosition()
{
return $this->position;
}
/**
* Set position
* @return $this
*/
public function setPosition($position)
{
$this->position = $position;
return $this;
}
} }
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20220104155035 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE news ADD position INT NOT NULL');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE news DROP position');
}
}
...@@ -22,15 +22,19 @@ class NewsRepository extends ServiceEntityRepository ...@@ -22,15 +22,19 @@ class NewsRepository extends ServiceEntityRepository
/** /**
* @return News[] Returns an array of News objects * @return News[] Returns an array of News objects
*/ */
public function findLatest() public function findLatest($limit = 0)
{ {
$qb = $this->createQueryBuilder('n'); $qb = $this->createQueryBuilder('n');
return $qb $qb
->where('n.enabled = :enabled') ->where('n.enabled = :enabled')
->setParameter('enabled', true) ->setParameter('enabled', true)
->orderBy('n.createdAt', 'DESC') ->orderBy('n.position', 'ASC');
->getQuery()
; if ($limit > 0) {
$qb->setMaxResults($limit);
}
return $qb->getQuery();
} }
} }
...@@ -231,7 +231,7 @@ class AppExtension extends AbstractExtension ...@@ -231,7 +231,7 @@ class AppExtension extends AbstractExtension
public function getLastNews($limit = 5) public function getLastNews($limit = 5)
{ {
return $this->em->getRepository(News::class)->findBy(['enabled' => true], ['createdAt' => 'DESC'], $limit); return $this->em->getRepository(News::class)->findLatest($limit)->getResult();
} }
public function getAllPrestataires($orderBy = 'raison', $direction = 'ASC', $limit = null) public function getAllPrestataires($orderBy = 'raison', $direction = 'ASC', $limit = null)
......
<div class="lastnewslist"> <div class="lastnewslist">
<h4> <i class="fa fa-newspaper"></i> {{ 'Actualités'|trans }}</h4> <h4><a href="{{ path('news')}}" class='nounderline'><i class="fa fa-newspaper"></i> {{ 'Actualités'|trans }}</a></h4>
<p> <p>
{% for news in getLastNews(3) %} {% for news in getLastNews(3) %}
<div class="card mb-2"> <div class="card mb-2">
<div class="card-header" style='cursor:pointer;'>{{news.title}}</div> <div class="card-header" style='cursor:pointer;'>
<a href='{{path('show_news', {'slug': news.slug})}}'>{{news.title}}</a>
{% if app.user and (is_granted('ROLE_SUPER_ADMIN') or is_granted('ROLE_ADMIN_NEWS_GERER_ALL')) %}
<a class='text-warning float-right' href='{{ path('admin_app_news_edit', {id: news.id})}}'>Editer</a>
{% endif %}
</div>
<div class="card-body"> <div class="card-body">
<div class="card-text"> <div class="card-text">
{% if news.media %} {% if news.media %}
...@@ -15,7 +20,12 @@ ...@@ -15,7 +20,12 @@
{% endif %} {% endif %}
{% endif %} {% endif %}
{{news.content|raw}} {% if news.content|striptags|length < 150 %}
{{ news.content|striptags|raw }}
{% else %}
{{ news.content|striptags|truncate(150, true, "...")|raw }}
<br/><a class='btn btn-xs btn-primary w-100' href='{{path('show_news', {'slug': news.slug})}}'>Lire la suite</a>
{% endif %}
</div> </div>
</div> </div>
<div class="card-footer text-muted"> <div class="card-footer text-muted">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment