Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
kohinos-tav
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
6
Merge Requests
6
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
agplv3
kohinos-tav
Commits
3e2b4a88
Commit
3e2b4a88
authored
Jan 04, 2022
by
Julien Jorry
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #103 - Gestion des actualités / Amélioration
parent
de50573c
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
109 additions
and
12 deletions
+109
-12
common.css
assets/css/common.css
+4
-0
services.yaml
config/services.yaml
+1
-1
NewsAdmin.php
src/Admin/NewsAdmin.php
+23
-2
News.php
src/Entity/News.php
+27
-0
Version20220104155035.php
src/Migrations/Version20220104155035.php
+31
-0
NewsRepository.php
src/Repository/NewsRepository.php
+9
-5
AppExtension.php
src/Twig/AppExtension.php
+1
-1
news.html.twig
templates/themes/kohinos/common/news.html.twig
+13
-3
No files found.
assets/css/common.css
View file @
3e2b4a88
...
...
@@ -10,4 +10,7 @@
}
.btn-primary
,
.btn-secondary
{
border-radius
:
10px
;
}
.nounderline
:hover
{
text-decoration
:
none
;
}
\ No newline at end of file
config/services.yaml
View file @
3e2b4a88
...
...
@@ -356,7 +356,7 @@ services:
admin.news.gerer
:
class
:
App\Admin\NewsAdmin
arguments
:
[
~
,
App\Entity\News
,
~
]
arguments
:
[
~
,
App\Entity\News
,
'
PixSortableBehaviorBundle:SortableAdmin'
]
tags
:
-
name
:
sonata.admin
manager_type
:
orm
...
...
src/Admin/NewsAdmin.php
View file @
3e2b4a88
...
...
@@ -5,9 +5,11 @@ namespace App\Admin;
use
App\Entity\User
;
use
FOS\CKEditorBundle\Form\Type\CKEditorType
;
use
Sonata\AdminBundle\Admin\AbstractAdmin
;
use
Sonata\AdminBundle\Datagrid\DatagridInterface
;
use
Sonata\AdminBundle\Datagrid\ListMapper
;
use
Sonata\AdminBundle\Form\FormMapper
;
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\HiddenType
;
use
Symfony\Component\Form\Extension\Core\Type\TextType
;
...
...
@@ -23,10 +25,17 @@ class NewsAdmin extends AbstractAdmin
{
protected
$translator
;
protected
$datagridValues
=
[
'_sort_order'
=>
'
DE
SC'
,
'_sort_by'
=>
'
createdAt
'
,
'_sort_order'
=>
'
A
SC'
,
'_sort_by'
=>
'
position
'
,
];
// protected function configureDefaultSortValues(array &$sortValues): void
// {
// $sortValues[DatagridInterface::PAGE] = 1;
// $sortValues[DatagridInterface::SORT_ORDER] = 'ASC';
// $sortValues[DatagridInterface::SORT_BY] = 'position';
// }
/**
* {@inheritdoc}
*/
...
...
@@ -66,6 +75,11 @@ class NewsAdmin extends AbstractAdmin
;
}
protected
function
configureRoutes
(
RouteCollectionInterface
$collection
)
:
void
{
$collection
->
add
(
'move'
,
$this
->
getRouterIdParameter
()
.
'/move/{position}'
);
}
/**
* {@inheritdoc}
*/
...
...
@@ -77,6 +91,13 @@ class NewsAdmin extends AbstractAdmin
->
addIdentifier
(
'content'
,
'html'
,
[
'truncate'
=>
[
'length'
=>
80
],
'label'
=>
'Description'
])
->
addIdentifier
(
'media'
,
null
,
[
'label'
=>
'Fichier'
])
->
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'
],
]
]);
;
}
...
...
src/Entity/News.php
View file @
3e2b4a88
...
...
@@ -6,6 +6,7 @@ use ApiPlatform\Core\Annotation\ApiResource;
use
App\Entity\EntityTrait\EnablableEntityTrait
;
use
App\Entity\EntityTrait\NameSlugContentEntityTrait
;
use
Doctrine\ORM\Mapping
as
ORM
;
use
Gedmo\Mapping\Annotation
as
Gedmo
;
use
Gedmo\Timestampable\Traits\TimestampableEntity
;
use
Ramsey\Uuid\Doctrine\UuidGenerator
;
use
Symfony\Component\Serializer\Annotation\Groups
;
...
...
@@ -65,6 +66,12 @@ class News
*/
private
$user
;
/**
* @Gedmo\SortablePosition
* @ORM\Column(name="position", type="integer")
*/
private
$position
;
public
function
getId
()
{
return
$this
->
id
;
...
...
@@ -137,4 +144,24 @@ class News
return
$this
;
}
/**
* Get position
* @return
*/
public
function
getPosition
()
{
return
$this
->
position
;
}
/**
* Set position
* @return $this
*/
public
function
setPosition
(
$position
)
{
$this
->
position
=
$position
;
return
$this
;
}
}
src/Migrations/Version20220104155035.php
0 → 100644
View file @
3e2b4a88
<?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'
);
}
}
src/Repository/NewsRepository.php
View file @
3e2b4a88
...
...
@@ -22,15 +22,19 @@ class NewsRepository extends ServiceEntityRepository
/**
* @return News[] Returns an array of News objects
*/
public
function
findLatest
()
public
function
findLatest
(
$limit
=
0
)
{
$qb
=
$this
->
createQueryBuilder
(
'n'
);
return
$qb
$qb
->
where
(
'n.enabled = :enabled'
)
->
setParameter
(
'enabled'
,
true
)
->
orderBy
(
'n.createdAt'
,
'DESC'
)
->
getQuery
()
;
->
orderBy
(
'n.position'
,
'ASC'
);
if
(
$limit
>
0
)
{
$qb
->
setMaxResults
(
$limit
);
}
return
$qb
->
getQuery
();
}
}
src/Twig/AppExtension.php
View file @
3e2b4a88
...
...
@@ -231,7 +231,7 @@ class AppExtension extends AbstractExtension
public
function
getLastNews
(
$limit
=
5
)
{
return
$this
->
em
->
getRepository
(
News
::
class
)
->
find
By
([
'enabled'
=>
true
],
[
'createdAt'
=>
'DESC'
],
$limit
);
return
$this
->
em
->
getRepository
(
News
::
class
)
->
find
Latest
(
$limit
)
->
getResult
(
);
}
public
function
getAllPrestataires
(
$orderBy
=
'raison'
,
$direction
=
'ASC'
,
$limit
=
null
)
...
...
templates/themes/kohinos/common/news.html.twig
View file @
3e2b4a88
<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>
{%
for
news
in
getLastNews
(
3
)
%}
<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-text"
>
{%
if
news.media
%}
...
...
@@ -15,7 +20,12 @@
{%
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
class=
"card-footer text-muted"
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment