Commit be698485 by Julien Jorry

Add news on front

parent e190a36b
...@@ -36,8 +36,8 @@ class NewsAdmin extends AbstractAdmin ...@@ -36,8 +36,8 @@ class NewsAdmin extends AbstractAdmin
)) ))
->add('media', MediaType::class, array( ->add('media', MediaType::class, array(
'provider' => 'sonata.media.provider.file', 'provider' => 'sonata.media.provider.file',
'context' => 'document', 'context' => 'actualites',
'label' => 'Document' 'label' => 'Image'
)) ))
->add('name', TextType::class, array( ->add('name', TextType::class, array(
'label' => 'Titre :' 'label' => 'Titre :'
......
...@@ -4,6 +4,7 @@ namespace App\Twig; ...@@ -4,6 +4,7 @@ namespace App\Twig;
use App\Entity\Flux; use App\Entity\Flux;
use App\Entity\Groupe; use App\Entity\Groupe;
use App\Entity\News;
use App\Entity\Rubrique; use App\Entity\Rubrique;
use App\Entity\User; use App\Entity\User;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
...@@ -27,16 +28,21 @@ class AppExtension extends AbstractExtension ...@@ -27,16 +28,21 @@ class AppExtension extends AbstractExtension
public function getFunctions() public function getFunctions()
{ {
return [ return [
new \Twig_SimpleFunction('getLastNews', array($this, 'getLastNews')),
new \Twig_SimpleFunction('getAllRubriques', array($this, 'getAllRubriques')), new \Twig_SimpleFunction('getAllRubriques', array($this, 'getAllRubriques')),
new \Twig_SimpleFunction('getAllGroupes', array($this, 'getAllGroupes')), new \Twig_SimpleFunction('getAllGroupes', array($this, 'getAllGroupes')),
new \Twig_SimpleFunction('getAllFlux', array($this, 'getAllFlux')), new \Twig_SimpleFunction('getAllFlux', array($this, 'getAllFlux')),
new \Twig_SimpleFunction('parameter', function($name) new \Twig_SimpleFunction('parameter', function ($name) {
{
return $this->container->getParameter($name); return $this->container->getParameter($name);
}) })
]; ];
} }
public function getLastNews($limit = 5)
{
return $this->container->get('doctrine')->getRepository(News::class)->findBy(array('enabled' => true), array('createdAt' => 'DESC'), $limit);
}
public function getAllRubriques() public function getAllRubriques()
{ {
return $this->container->get('doctrine')->getRepository(Rubrique::class)->findBy(array('enabled' => true)); return $this->container->get('doctrine')->getRepository(Rubrique::class)->findBy(array('enabled' => true));
...@@ -102,14 +108,14 @@ class AppExtension extends AbstractExtension ...@@ -102,14 +108,14 @@ class AppExtension extends AbstractExtension
public function safeEmailFilter($str) public function safeEmailFilter($str)
{ {
$email = ''; $email = '';
for ( $i = 0, $len = strlen( $str ); $i < $len; $i++ ) { for ($i=0, $len = strlen($str); $i < $len; $i++) {
$j = mt_rand( 0, 1); $j = mt_rand(0, 1);
if ( $j === 0 ) { if ($j === 0) {
$email .= '&#' . ord( $str[$i] ) . ';'; $email .= '&#'.ord($str[$i]).';';
} elseif ( $j === 1 ) { } else if ($j === 1) {
$email .= $str[$i]; $email .= $str[$i];
} }
} }
return str_replace( '@', '&#64;', $email ); return str_replace('@', '&#64;', $email);
} }
} }
<div class="rubriques"> <div class="rubriques">
<h4> <i class="fa fa-paperclip"></i> </i> Groupes Locaux</h4> <h4> <i class="fa fa-paperclip"></i> Groupes Locaux</h4>
<p> <p>
{% for groupe in getAllGroupes() %} {% for groupe in getAllGroupes() %}
<a class='groupe' href='{{ path('show_groupe', {'slug': groupe.slug}) }}'>{{groupe.name}}</a>{% if not loop.last %}{% endif %} <a class='groupe' href='{{ path('show_groupe', {'slug': groupe.slug}) }}'>{{groupe.name}}</a>{% if not loop.last %}{% endif %}
......
<div class="rubriques">
<h4> <i class="fa fa-newspaper"></i> Actualités</h4>
<p>
{% for news in getLastNews() %}
<div class="card mb-2">
<div class="card-header" style='cursor:pointer;' onmouseover="$(this).addClass('border-primary');" onmouseout="$(this).removeClass('border-primary');">{{news.title}}</div>
<div class="card-body">
<h6 class="card-subtitle text-muted mb-3">Le {{news.createdAt|date('d/m/Y')}}</h6>
<div class="card-text">
{% if news.media %}
<img src="{% path news.media, 'reference' %}" style="max-width: 100%;"/>
{% endif %}
{{news.content|raw}}
</div>
</div>
</div>
{% endfor %}
</p>
</div>
\ No newline at end of file
<div class="rubriques"> <div class="rubriques">
<h4> <i class="fa fa-flag"></i> </i> Rubriques</h4> <h4> <i class="fa fa-flag"></i> Rubriques</h4>
<p> <p>
{% for rubrique in getAllRubriques() %} {% for rubrique in getAllRubriques() %}
<a class='rubrique' href='{{ path('show_rubrique', {'slug': rubrique.slug}) }}'>{{rubrique.name}}</a>{% if not loop.last %}{% endif %} <a class='rubrique' href='{{ path('show_rubrique', {'slug': rubrique.slug}) }}'>{{rubrique.name}}</a>{% if not loop.last %}{% endif %}
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
{% endif %} {% endif %}
</div> </div>
<div class='col-3'> <div class='col-3'>
SIDEBAR {% include 'common/news.html.twig' %}
</div> </div>
</div> </div>
</div> </div>
......
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