Commit 5be8540f by Julien Jorry

Fix cascade persist User#flux et Cotisation#CotisationInfos + update homepage +…

Fix cascade persist User#flux et Cotisation#CotisationInfos + update homepage + update comptoir views
parent 50274c70
...@@ -65,6 +65,11 @@ services: ...@@ -65,6 +65,11 @@ services:
autowire: false autowire: false
arguments: ["@doctrine.orm.entity_manager", "@prodigious_sonata_menu.manager"] arguments: ["@doctrine.orm.entity_manager", "@prodigious_sonata_menu.manager"]
app.twig.stats.extension:
class: App\Twig\StatsExtension
autowire: false
arguments: ["@doctrine.orm.entity_manager"]
App\Controller\RegistrationController: App\Controller\RegistrationController:
autowire: false autowire: false
......
...@@ -199,14 +199,14 @@ class AdherentAdmin extends AbstractAdmin ...@@ -199,14 +199,14 @@ class AdherentAdmin extends AbstractAdmin
$bytes = random_bytes(64); $bytes = random_bytes(64);
$password = rtrim(strtr(base64_encode($bytes), '+/', '-_'), '='); $password = rtrim(strtr(base64_encode($bytes), '+/', '-_'), '=');
$adherent->getUser()->setPassword($password); $adherent->getUser()->setPassword($password);
// send email to user // @TODO : send email to user
} }
$this->userManager->updateUser($adherent->getUser()); $this->userManager->updateUser($adherent->getUser());
$adherent->getUser()->createEmailToken(); $adherent->getUser()->createEmailToken();
$em->persist($adherent->getUser()); $em->persist($adherent->getUser());
$em->persist($adherent); $em->persist($adherent);
$em->flush(); $em->flush();
// TODO : envoyer un mail au nouvel utilisateur avec l'emailtoken via le dispatch d'un event // @TODO : envoyer un mail au nouvel utilisateur avec l'emailtoken via le dispatch d'un event
// $this->eventDispatcher->dispatch(FOSUserEvents::REGISTRATION_COMPLETED, new FilterUserResponseEvent($adherent->getUser(), $this->getRequest(), $response)); // $this->eventDispatcher->dispatch(FOSUserEvents::REGISTRATION_COMPLETED, new FilterUserResponseEvent($adherent->getUser(), $this->getRequest(), $response));
} }
......
...@@ -2,18 +2,27 @@ ...@@ -2,18 +2,27 @@
namespace App\Controller; namespace App\Controller;
use App\Entity\Comptoir;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
class ComptoirController extends AbstractController class ComptoirController extends AbstractController
{ {
private $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
/** /**
* @Route("/comptoirs/liste", name="comptoirs_liste") * @Route("/comptoirs/liste", name="comptoirs_liste")
*/ */
public function listeComptoirAction() public function listeComptoirAction()
{ {
return $this->render('comptoir/liste.html.twig', array( return $this->render('comptoir/liste.html.twig', array(
'user' => $this->getUser() 'comptoirs' => $this->em->getRepository(Comptoir::class)->findBy(array('enabled' => true), array('createdAt' => 'DESC'))
)); ));
} }
...@@ -23,7 +32,18 @@ class ComptoirController extends AbstractController ...@@ -23,7 +32,18 @@ class ComptoirController extends AbstractController
public function carteComptoirAction() public function carteComptoirAction()
{ {
return $this->render('comptoir/carte.html.twig', array( return $this->render('comptoir/carte.html.twig', array(
'user' => $this->getUser() 'comptoirs' => $this->em->getRepository(Comptoir::class)->findBy(array('enabled' => true), array('createdAt' => 'DESC'))
)); ));
} }
/**
* @Route("/comptoir/{slug}", name="show_comptoir")
*/
public function showGroupeAction(Comptoir $comptoir)
{
return $this->render('comptoir/show.html.twig', array(
'comptoir' => $comptoir
));
}
} }
<?php
namespace App\Controller;
use App\Entity\Groupe;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
class GroupeController extends AbstractController
{
private $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
/**
* @Route("/groupes", name="liste_groupe")
*/
public function listeGroupeAction()
{
return $this->render('groupe/liste.html.twig', array(
'groupes' => $this->em->getRepository(Groupe::class)->findBy(array('enabled' => true), array('createdAt' => 'DESC'))
));
}
/**
* @Route("/groupe/{slug}", name="show_groupe")
*/
public function showGroupeAction(Groupe $groupe)
{
return $this->render('groupe/show.html.twig', array(
'groupe' => $groupe
));
}
}
...@@ -20,7 +20,7 @@ class Cotisation extends Flux ...@@ -20,7 +20,7 @@ class Cotisation extends Flux
protected $destinataire; protected $destinataire;
/** /**
* @ORM\OneToOne(targetEntity="CotisationInfos", inversedBy="cotisation") * @ORM\OneToOne(targetEntity="CotisationInfos", inversedBy="cotisation", cascade={"persist"})
* @ORM\JoinColumn(name="cotisationinfos_id", referencedColumnName="id", nullable=true) * @ORM\JoinColumn(name="cotisationinfos_id", referencedColumnName="id", nullable=true)
*/ */
protected $cotisationInfos; protected $cotisationInfos;
...@@ -30,6 +30,7 @@ class Cotisation extends Flux ...@@ -30,6 +30,7 @@ class Cotisation extends Flux
*/ */
public function __construct() public function __construct()
{ {
parent::__construct();
$this->cotisationInfos = new CotisationInfos(); $this->cotisationInfos = new CotisationInfos();
} }
...@@ -42,6 +43,14 @@ class Cotisation extends Flux ...@@ -42,6 +43,14 @@ class Cotisation extends Flux
} }
/** /**
* @return string
*/
public function getType(): string
{
return 'cotisation';
}
/**
* Get cotisationInfos * Get cotisationInfos
* @return cotisationInfos * @return cotisationInfos
*/ */
......
...@@ -26,4 +26,12 @@ trait GeolocEntityTrait ...@@ -26,4 +26,12 @@ trait GeolocEntityTrait
$this->geoloc = $geoloc; $this->geoloc = $geoloc;
return $this; return $this;
} }
public function getFullAddresse()
{
if ($this->geoloc != null) {
return $this->geoloc->getAdresse().' '.$this->geoloc->getCpostal().' '.$this->geoloc->getVille();
}
return '';
}
} }
\ No newline at end of file
...@@ -80,6 +80,7 @@ abstract class Flux ...@@ -80,6 +80,7 @@ abstract class Flux
public function __construct() public function __construct()
{ {
$this->parenttype = $this->getParenttype(); $this->parenttype = $this->getParenttype();
$this->type = $this->getType();
} }
public function getId(): int public function getId(): int
......
...@@ -67,7 +67,7 @@ class User extends BaseUser ...@@ -67,7 +67,7 @@ class User extends BaseUser
private $faqs; private $faqs;
/** /**
* @ORM\OneToMany(targetEntity="Flux", mappedBy="operateur") * @ORM\OneToMany(targetEntity="Flux", mappedBy="operateur", cascade={"persist"})
* @ORM\OrderBy({"createdAt" = "DESC"}) * @ORM\OrderBy({"createdAt" = "DESC"})
*/ */
protected $flux; protected $flux;
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
namespace App\Twig; namespace App\Twig;
use App\Entity\Groupe;
use App\Entity\Rubrique;
use Twig\Extension\AbstractExtension; use Twig\Extension\AbstractExtension;
use Twig\TwigFilter; use Twig\TwigFilter;
use Twig\TwigFunction; use Twig\TwigFunction;
...@@ -19,6 +21,8 @@ class AppExtension extends AbstractExtension ...@@ -19,6 +21,8 @@ class AppExtension extends AbstractExtension
public function getFunctions() public function getFunctions()
{ {
return [ return [
new \Twig_SimpleFunction('getAllRubriques', array($this, 'getAllRubriques')),
new \Twig_SimpleFunction('getAllGroupes', array($this, 'getAllGroupes')),
new \Twig_SimpleFunction('parameter', function($name) new \Twig_SimpleFunction('parameter', function($name)
{ {
return $this->container->getParameter($name); return $this->container->getParameter($name);
...@@ -26,6 +30,27 @@ class AppExtension extends AbstractExtension ...@@ -26,6 +30,27 @@ class AppExtension extends AbstractExtension
]; ];
} }
public function getAllRubriques()
{
return $this->container->get('doctrine')->getRepository(Rubrique::class)->findBy(array('enabled' => true));
}
/**
* Return a list of all filters.
*
* @return array
*/
public function getFilters()
{
return [
new \Twig_SimpleFilter('safe_email', [$this, 'safeEmailFilter']),
];
}
public function getAllGroupes()
{
return $this->container->get('doctrine')->getRepository(Groupe::class)->findBy(array('enabled' => true));
}
public function getTests(): array public function getTests(): array
{ {
return [ return [
...@@ -38,4 +63,26 @@ class AppExtension extends AbstractExtension ...@@ -38,4 +63,26 @@ class AppExtension extends AbstractExtension
$reflexionClass = new \ReflectionClass($instance); $reflexionClass = new \ReflectionClass($instance);
return $reflexionClass->isInstance($var); return $reflexionClass->isInstance($var);
} }
/**
* Protects email address.
* (inspired by : https://github.com/getgrav/grav/blob/develop/system/src/Grav/Common/Twig/TwigExtension.php )
*
* @param string $str
*
* @return string
*/
public function safeEmailFilter($str)
{
$email = '';
for ( $i = 0, $len = strlen( $str ); $i < $len; $i++ ) {
$j = mt_rand( 0, 1);
if ( $j === 0 ) {
$email .= '&#' . ord( $str[$i] ) . ';';
} elseif ( $j === 1 ) {
$email .= $str[$i];
}
}
return str_replace( '@', '&#64;', $email );
}
} }
<?php
namespace App\Twig;
use App\Entity\TypePrestataire;
use App\Entity\User;
use Doctrine\ORM\EntityManagerInterface;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
use Twig\TwigFunction;
use Twig\TwigTest;
class StatsExtension extends AbstractExtension
{
protected $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
/**
* {@inheritdoc}
*/
public function getFunctions()
{
return array(
new \Twig_SimpleFunction('showMlcStats', array($this, 'showMlcStats'))
);
}
public function showMlcStats($stats)
{
$class = '';
switch($stats) {
case 'user':
$class = 'App\Entity\User';
break;
case 'prestataire':
$class = 'App\Entity\Prestataire';
$typepresta = $this->em->getRepository(TypePrestataire::class)->findOneBySlug('prestataire');
$query = $this->em->createQuery(
'SELECT count(distinct p.id)
FROM '.$class.' p
WHERE p.enabled = true AND p.typeprestataire = :typepresta
')
->setParameter('typepresta', $typepresta)
;
$val = $query->getSingleScalarResult();
break;
case 'partenaire':
$class = 'App\Entity\Prestataire';
$typepresta = $this->em->getRepository(TypePrestataire::class)->findOneBySlug('partenaire');
$query = $this->em->createQuery(
'SELECT count(distinct p.id)
FROM '.$class.' p
WHERE p.enabled = true AND p.typeprestataire = :typepresta
')
->setParameter('typepresta', $typepresta)
;
$val = $query->getSingleScalarResult();
break;
case 'adherent':
$class = 'App\Entity\Adherent';
break;
case 'comptoir':
$class = 'App\Entity\Comptoir';
break;
case 'groupe':
$class = 'App\Entity\Groupe';
break;
}
if (!empty($class)) {
$query2 = $this->em->createQuery(
'SELECT count(distinct u.id)
FROM '.$class.' u
WHERE u.enabled = true
')
;
$val = $query2->getSingleScalarResult();
}
return $val;
}
}
<div class="rubriques">
<h4> <i class="fa fa-paperclip"></i> </i> Groupes Locaux</h4>
<p>
{% for groupe in getAllGroupes() %}
<a class='groupe' href='{{ path('show_groupe', {'slug': groupe.slug}) }}'>{{groupe.name}}</a>{% if not loop.last %}{% endif %}
{% endfor %}
</p>
</div>
\ No newline at end of file
<div class='onecomptoir col-12 clearfix mb-4 rounded bg-white'>
{{comptoir.name}}<br/>
{{comptoir.getFullAddresse()}}<br/>
{{comptoir.tel}}<br/>
Mail: {{ comptoir.email|safe_email|raw }}
</div>
\ No newline at end of file
<div class="rubriques">
<h4> <i class="fa fa-flag"></i> </i> Rubriques</h4>
<p>
{% for rubrique in getAllRubriques() %}
<a class='rubrique' href='{{ path('show_rubrique', {'slug': rubrique.slug}) }}'>{{rubrique.name}}</a>{% if not loop.last %}{% endif %}
{% endfor %}
</p>
</div>
\ No newline at end of file
<div class="stats">
<h4> <i class="fa fa-bars"></i> À ce jour</h4>
<p>
<i class="fas fa-check"> </i> {{ showMlcStats('user') }} utilisateurs<br>
</p>
<p>
<i class="fa fa-check"> </i> {{ showMlcStats('prestataire') }} <a href="{{ path('liste_prestataire') }}" title="Les prestataires de la doume">prestataires</a> et {{ showMlcStats('partenaire') }} <a href="{{ path('liste_partenaire') }}" title="Les partenaires de la doume">partenaires</a>
</p>
<p>
<i class="fa fa-check"> </i> {{ showMlcStats('groupe') }} <a href="{#{ path('groupe_liste') }#}" title="Les groupes locaux de la doume">groupes locaux</a>
</p>
<p>
<i class="fa fa-check"> </i> {{ showMlcStats('comptoir') }} <a href="{{ path('comptoirs_liste') }}" title="Les comptoirs de la doume">comptoirs</a>
</p>
{# <p>
<i class="fa fa-check"> </i> 527029 Doumes émises
</p>
<p>
<i class="fa fa-check"> </i> 350304 Doumes reconverties
</p>
<p>
<i class="fa fa-check"> </i> 174778 Doumes en circulation
</p>
<p>
<i class="fa fa-check"> </i> 192923 d'échanges numériques
</p> #}
</div>
\ No newline at end of file
{% extends 'common/layout.html.twig' %} {% extends 'common/layout.html.twig' %}
{% block content %} {% block content %}
Liste des comptoirs : <div class='container comptoirslist mt-5'>
<h1 class='pagetitle'>Comptoirs</h1>
<div class="my-3 p-5 bg-secondary rounded box-shadow row">
{% for comptoir in comptoirs %}
{% include 'common/one_comptoir.html.twig' %}
{% endfor %}
</div>
</div>
{% endblock %} {% endblock %}
{% extends 'common/layout.html.twig' %}
{% block content %}
<div class='container groupeshow mt-5'>
<h1>{{comptoir.name}}</h1>
<div class="my-3 p-3 bg-white rounded box-shadow">
<div class="contentgroupe p-4 mt-5">
{{comptoir.content|raw}}
</div>
<div class="contentgroupe p-4 mt-5">
<h2>Prestataires ({{ showMlcStats('prestataire') }}):</h2>
<ul>
{% for presta in comptoir.prestataires %}
<a href='{{ path('show_prestataire', {'slug': presta.slug}) }}'>{{presta.raison}}</a>
{% endfor %}
</ul>
</div>
</div>
</div>
{% endblock %}
{% extends 'common/layout.html.twig' %}
{% block content %}
<div class='container groupeslist mt-5'>
<h1>Groupes locaux</h1>
{% for groupe in groupes %}
<div class="my-3 p-3 bg-white rounded box-shadow">
<h2><a href="{{ path('groupe_show', {'slug': groupe.slug}) }}">{{groupe.name}}</a></h2>
</div>
{% endfor %}
</div>
{% endblock %}
{% extends 'common/layout.html.twig' %}
{% block content %}
<div class='container groupeshow mt-5'>
<h1>{{groupe.name}}</h1>
<div class="my-3 p-3 bg-white rounded box-shadow">
<div class="contentgroupe p-4 mt-5">
{{groupe.content|raw}}
</div>
<div class="contentgroupe p-4 mt-5">
<h2>Comptoirs :</h2>
<ul>
{% for comptoir in groupe.comptoirs %}
<a href='{{ path('show_comptoir', {'slug': comptoir.slug}) }}'>{{comptoir.name}}</a>
{% endfor %}
</ul>
</div>
</div>
</div>
{% endblock %}
{% extends 'common/layout.html.twig' %} {% extends 'common/layout.html.twig' %}
{% block content %} {% block content %}
Page d'accueil <div class='container homepage'>
<h1 class='homepage_title'>OUTIL DE GESTION DE MONNAIE LOCALE COMPLEMENTAIRE</h1>
<div class='row'>
<div class='col-3'>
{% include 'common/stats.html.twig' %}
{% include 'common/groupes.html.twig' %}
{% include 'common/rubriques.html.twig' %}
</div>
<div class='col-6 text-center'>
COLONNE PRINCIPALE
</div>
<div class='col-3'>
SIDEBAR
</div>
</div>
</div>
{% endblock %} {% endblock %}
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