Commit 7f1c5e1b by Damien Moulard

display informative modale to user, customable by admin, only 1 active at a time

parent 560f9676
......@@ -342,7 +342,7 @@ sonata_admin:
sonata.admin.informationPopup:
keep_open: false
on_top: true
label: "Popup d'information"
label: "Popups d'information"
label_catalogue: SonataAdminBundle
icon: '<i class="fa fa-exclamation-circle"></i>'
items:
......
......@@ -686,8 +686,8 @@ services:
tags:
- name: sonata.admin
manager_type: orm
group: "Popup d'information"
label: "Popup d'information"
group: "Popups d'information"
label: "Popups d'information"
public: true
sonata.media.provider.csv:
......
......@@ -16,8 +16,6 @@ use FOS\CKEditorBundle\Form\Type\CKEditorType;
* et s'ouvrent automatiquement au lancement de l'application,
* tant que l'utilisateur n'a pas cliqué sur le bouton de confirmation
*
* TODO: make sure only one popup is active at a given time (use post save hook)
*
* KOHINOS : Outil de gestion de Monnaie Locale Complémentaire
*/
class InformationPopupAdmin extends AbstractAdmin
......@@ -53,6 +51,38 @@ class InformationPopupAdmin extends AbstractAdmin
]);
}
public function postPersist($informationPopup)
{
$this->disableOtherPopups($informationPopup);
}
public function preUpdate($informationPopup)
{
$this->disableOtherPopups($informationPopup);
}
/**
* Only one popup should be enabled at a time.
* If enableling a popup in the admin, disable the rest.
*/
private function disableOtherPopups($informationPopup)
{
if (true == $informationPopup->getEnabled()) {
$em = $this->getConfigurationPool()->getContainer()->get('doctrine')->getManager();
$qb = $em->createQueryBuilder();
$qb->update('App\Entity\InformationPopup', 'e')
->set('e.enabled', ':newValue')
->where('e.id != :id')
->setParameter('newValue', 0)
->setParameter('id', $informationPopup->getId());
$query = $qb->getQuery();
$query->execute();
}
}
protected function configureDatagridFilters(DatagridMapper $datagrid): void
{
$datagrid
......
......@@ -61,6 +61,11 @@ class InformationPopup
$this->informationPopupUsers = new ArrayCollection();
}
public function __toString(): string
{
return $this->getTitle();
}
public function getId()
{
return $this->id;
......
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