Skip to content

Commit

Permalink
personne ratachée + email reset pass
Browse files Browse the repository at this point in the history
  • Loading branch information
Clément committed Nov 3, 2020
1 parent 6797c10 commit 1d7367f
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 2 deletions.
13 changes: 12 additions & 1 deletion config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ services:
arguments:
- ~
- App\Entity\User
- ~
- App\Controller\UserAdminController
calls:
- [ setTranslationDomain, [ GlukoseAdminContactBundle ] ]
- [ setLdapService, [ '@App\Controller\LdapController' ] ]
Expand All @@ -80,3 +80,14 @@ services:
- ~
calls:
- [ setTranslationDomain, [ GlukoseAdminContactBundle ] ]

sonata.admin.personne:
class: App\Admin\PersonneAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: "Gestion des membres", label: "Personnes intéréssées" }
arguments:
- ~
- App\Entity\Personne
- ~
calls:
- [ setTranslationDomain, [ GlukoseAdminContactBundle ] ]
131 changes: 131 additions & 0 deletions src/Admin/PersonneAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php

namespace App\Admin;

use ChouetteCoop\PersonnesInteresseesBundle\Entity\Personne;
use Exporter\Source\IteratorCallbackSourceIterator;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\Form\Type\DatePickerType;
use Sonata\Form\Type\DateRangePickerType;
use Symfony\Component\Form\Extension\Core\Type\TextType;

class PersonneAdmin extends AbstractAdmin
{
protected $datagridValues = [
'_sort_by' => 'nom',
];

protected $maxPerPage = 100;

protected $perPageOptions = array(10, 20, 50, 100, 500, 1000);

public function toString($object)
{
return $object instanceof Personne
? $object->getNomAffichage()
: 'Personne intéressée';
}

public function getExportFields()
{
return array('nom', 'prenom', 'email', 'exportDatePremiereReunion');
}

public function getDataSourceIterator()
{
return new IteratorCallbackSourceIterator(parent::getDataSourceIterator(), function($data) {
$data['nom'] = mb_strtoupper($data['nom']);
return $data;
});
}

protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->with('Civilité', array(
'class' => 'col-md-6',
'description' => '
Cette section contient les informations principales d’une personne.
<br>Dans un souci d’homogénéïté, merci de <strong>bien veiller à respecter le format proposé</strong> (majuscules, espaces…).
'
))
->add('nom', null, array(
'attr' => array('placeholder' => 'Tibou')
))
->add('prenom', null, array(
'label' => 'Prénom',
'attr' => array('placeholder' => 'Jean')
))
->add('email', null, array(
'attr' => array('placeholder' => 'j.tibou@example.com'),
'help' => "Utilisée pour recontacter cette personne et savoir qu'elle est déjà venue à une réunion si elle nous contacte."
))
->add('datePremiereReunion', DatePickerType::class, array(
'label' => 'Date de participation à sa première réunion',
'required' => false,
'format' => 'dd/MM/yyyy',
'attr' => array(
'data-date-format' => 'DD/MM/YYYY',
'placeholder' => '15/01/' . date('Y')
)
))
->end();
}

protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper
->add('full_text', 'doctrine_orm_callback', [
'label' => 'Recherche rapide',
'show_filter' => true,
'callback' => [$this, 'getFullTextFilter'],
'field_type' => TextType::class
])
->add('datePremiereReunion', 'doctrine_orm_date_range', [
'label' => 'Date de première réunion'
])
->add('nom')
->add('prenom', null, [
'label' => 'Prénom',
])
->add('email')
;
}

public function getFullTextFilter($queryBuilder, $alias, $field, $value)
{
if (!$value['value']) {
return;
}

$words = array_filter(
array_map('trim', explode(' ', $value['value']))
);

foreach ($words as $word) {
// Use `andWhere` instead of `where` to prevent overriding existing `where` conditions
$literal = $queryBuilder->expr()->literal('%' . $word . '%');
$queryBuilder->andWhere($queryBuilder->expr()->orX(
$queryBuilder->expr()->like($alias.'.nom', $literal),
$queryBuilder->expr()->like($alias.'.prenom', $literal),
$queryBuilder->expr()->like($alias.'.email', $literal)
));
}

return true;
}

protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('nom')
->add('prenom', null, array('label' => 'Prénom'))
->addIdentifier('email')
->add('datePremiereReunion', null, array('label' => 'Date de première réunion'))
;
}

}
1 change: 1 addition & 0 deletions src/Admin/UserAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ protected function configureDatagridFilters(DatagridMapper $datagridMapper)
'label' => 'Prénom',
])
->add('email')
->add('gh')
->add('carteImprimee', null, ['label' => 'Carte imprimée ?'])
->add('enabled', null, ['label' => 'Actif ?'])
;
Expand Down
17 changes: 17 additions & 0 deletions src/Controller/MainController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

Expand All @@ -15,4 +16,20 @@ public function index(): Response
{
return $this->render('main/index.html.twig', [ ]);
}

/**
* @Route("/api/export/gh", name="chouette_coop_admin_export_gh")
*/
public function exportGHCodeBarreAction()
{
$listGh = array();
$repositoryU = $this->getDoctrine()->getManager()->getRepository('App:User');

$users = $repositoryU->findBy(array('gh' => 1));
/** @var User $gh */
foreach ($users as $gh){
$listGh []= $gh->getCodeBarre();
}
return new JsonResponse($listGh);
}
}
2 changes: 1 addition & 1 deletion src/Controller/SecurityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function forgottenPassword(Request $request,
->from('bureau-des-membres@lachouettecoop.fr')
->to($user->getEmail())
->html(
"Bonjour,<br /><br /> Vous pouvez changer votre mot de passe en suivant le lien suivant <a href=\"" . $url. '">'.$url.'</a> <br /><br /> La Chouette Coop',
$this->renderView('security/resetting-email.html.twig', ['confirmationUrl' => $url, 'user' =>$user]),
'text/html'
);

Expand Down
42 changes: 42 additions & 0 deletions src/Controller/UserAdminController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace App\Controller;

use Sonata\AdminBundle\Controller\CRUDController;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;

class UserAdminController extends CRUDController
{

public function batchActionImprimeCarte(ProxyQueryInterface $selectedModelQuery)
{
if (!$this->admin->isGranted('EDIT')) {
throw new AccessDeniedException();
}

$modelManager = $this->admin->getModelManager();
$selectedModels = $selectedModelQuery->execute();
try {
foreach ($selectedModels as $selectedModel) {
$selectedModel->setCarteImprimee(true);
$modelManager->update($selectedModel);
}
} catch (\Exception $e) {
$this->addFlash('sonata_flash_error', 'Une erreur est survenue');

return new RedirectResponse(
$this->admin->generateUrl('list', $this->admin->getFilterParameters())
);
}

$this->addFlash('sonata_flash_success', 'Impeccable ! T’es au top, merci…');

return new RedirectResponse(
$this->admin->generateUrl('list', $this->admin->getFilterParameters())
);
}


}
15 changes: 15 additions & 0 deletions templates/security/resetting-email.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% autoescape false %}
Bonjour {{ user }} !
<br /><br />
Pour réinitialiser votre mot de passe, merci de vous rendre sur <a href="{{ confirmationUrl }}"> {{ confirmationUrl }}</a>
<br /><br />
Cordialement,<br />
L'équipe.<br />
<p>
<span style="color: red;">POUR VOTRE INFORMATION :</span> pour les Chouettos qui ont un profil Facebook, <i>n'hésitez pas à rejoindre le groupe des Chouettos
sur Facebook !</i> Ce groupe est réservé aux membres de La Chouette Coop pour échanger et fédérer les énergies autour du projet de supermarché coopératif et participatif.
Pour ce faire rendez vous sur <a href="https://www.facebook.com/groups/lesChouettos/">le Facebook les Chouettos</a>.
</p>
<br />
<img src="https://lachouettecoop.fr/wp-content/uploads/2017/07/bandeauresetting.jpg" />
{% endautoescape %}

0 comments on commit 1d7367f

Please sign in to comment.