alert profilée par niveau01 (fixes #62)

This commit is contained in:
afornerot 2019-12-13 16:52:12 +01:00
parent 6741bfffe6
commit 6729035f15
8 changed files with 131 additions and 12 deletions

View File

@ -91,6 +91,10 @@ class Niveau01
*/ */
protected $items; protected $items;
/**
* @ORM\ManyToMany(targetEntity="Cadoles\PortalBundle\Entity\Alert", mappedBy="niveau01s")
*/
protected $alerts;
/** /**
* Constructor * Constructor
@ -427,4 +431,38 @@ class Niveau01
{ {
return $this->items; return $this->items;
} }
/**
* Add alert
*
* @param \Cadoles\PortalBundle\Entity\Alert $alert
*
* @return Niveau01
*/
public function addAlert(\Cadoles\PortalBundle\Entity\Alert $alert)
{
$this->alerts[] = $alert;
return $this;
}
/**
* Remove alert
*
* @param \Cadoles\PortalBundle\Entity\Alert $alert
*/
public function removeAlert(\Cadoles\PortalBundle\Entity\Alert $alert)
{
$this->alerts->removeElement($alert);
}
/**
* Get alerts
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getAlerts()
{
return $this->alerts;
}
} }

View File

@ -274,7 +274,7 @@ span.item-drag {
.grid-item .item-link img { .grid-item .item-link img {
display: block; display: block;
max-width: 100%; max-width: 100%;
max-height: 110px; //max-height: 110px;
height: auto; height: auto;
} }
@ -500,7 +500,7 @@ a.item-heart {
word-wrap: break-word; word-wrap: break-word;
width: 100%; width: 100%;
display: block; display: block;
line-height: initial; line-height: 14px;
padding: 0px; padding: 0px;
} }
@ -513,9 +513,9 @@ a.item-heart {
.grid .grid-preview .grid-item-title small { .grid .grid-preview .grid-item-title small {
margin-bottom: 10px; margin-bottom: 10px;
font-size:9px;
} }
@media (max-width: 991px) { @media (max-width: 991px) {
.grid .grid-preview { .grid .grid-preview {
width:32.666666667%; width:32.666666667%;

View File

@ -64,14 +64,7 @@ body.simple {
min-width: 138px; min-width: 138px;
} }
.grid .grid-preview .grid-item-title {
font-size:14px;
line-height: 8px;
}
.grid .grid-preview .grid-item-title small {
font-size:9px;
}
.widget-bordered .grid-preview img { .widget-bordered .grid-preview img {
border-radius: 0px; border-radius: 0px;

View File

@ -69,7 +69,7 @@ class AlertController extends Controller
$data = new Alert(); $data = new Alert();
// Création du formulaire // Création du formulaire
$form = $this->createForm(AlertType::class,$data,array("mode"=>"submit")); $form = $this->createForm(AlertType::class,$data,array("mode"=>"submit","labelniveau01" => $this->GetParameter("labelsniveau01")));
// Récupération des data du formulaire // Récupération des data du formulaire
$form->handleRequest($request); $form->handleRequest($request);
@ -111,7 +111,8 @@ class AlertController extends Controller
// Création du formulaire // Création du formulaire
$form = $this->createForm(AlertType::class,$data,array( $form = $this->createForm(AlertType::class,$data,array(
"mode" => "update" "mode" => "update",
"labelniveau01" => $this->GetParameter("labelsniveau01")
)); ));
// Récupération des data du formulaire // Récupération des data du formulaire

View File

@ -737,6 +737,7 @@ class PagewidgetController extends Controller
// Profilage // Profilage
$user=$this->getUser(); $user=$this->getUser();
$roles=($user?$user->getRoles():["ROLE_ANONYME"]); $roles=($user?$user->getRoles():["ROLE_ANONYME"]);
$niveau01=($user?$user->getNiveau01():null);
$groups=($user?$user->getGroups():[]); $groups=($user?$user->getGroups():[]);
// Initialisation du calcul des alerts // Initialisation du calcul des alerts
@ -765,6 +766,28 @@ class PagewidgetController extends Controller
} }
} }
// Récupération par Niveau01
$qb = $em->createQueryBuilder();
$qb->select('alert')
->from("CadolesPortalBundle:Alert", 'alert')
->where(":niveau01 MEMBER OF alert.niveau01s")
->andWhere('alert.publishedat <= :today')
->andWhere($qb->expr()->orX(
$qb->expr()->gt('alert.unpublishedat', ':today'),
$qb->expr()->isNull('alert.unpublishedat')
))
->setParameter("niveau01",$niveau01)
->setParameter('today', date('Y-m-d'));
if($idalertcategory && $alertcategoryfilter) {
$qb->andWhere("alert.alertcategory=:alertcategory")
->setParameter("alertcategory",$alertcategoryfilter);
}
$alertsniveau01s=$qb->getQuery()->getResult();
foreach($alertsniveau01s as $alertsniveau01) {
if(!$alerts->contains($alertsniveau01s)) $alerts->add($alertsniveau01);
}
// Récupération des alerts par group // Récupération des alerts par group
foreach($groups as $group) { foreach($groups as $group) {
$qb = $em->createQueryBuilder(); $qb = $em->createQueryBuilder();

View File

@ -82,6 +82,16 @@ class Alert
*/ */
protected $groups; protected $groups;
/**
* @ORM\ManyToMany(targetEntity="Cadoles\CoreBundle\Entity\Niveau01", inversedBy="alerts", cascade={"persist"})
* @ORM\JoinTable(name="alertniveau01",
* joinColumns={@ORM\JoinColumn(name="alert", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="niveau01", referencedColumnName="id")}
* )
*/
protected $niveau01s;
// Is Online // Is Online
public function isOnline() public function isOnline()
{ {
@ -346,4 +356,38 @@ class Alert
{ {
return $this->groups; return $this->groups;
} }
/**
* Add niveau01
*
* @param \Cadoles\CoreBundle\Entity\Niveau01 $niveau01
*
* @return Alert
*/
public function addNiveau01(\Cadoles\CoreBundle\Entity\Niveau01 $niveau01)
{
$this->niveau01s[] = $niveau01;
return $this;
}
/**
* Remove niveau01
*
* @param \Cadoles\CoreBundle\Entity\Niveau01 $niveau01
*/
public function removeNiveau01(\Cadoles\CoreBundle\Entity\Niveau01 $niveau01)
{
$this->niveau01s->removeElement($niveau01);
}
/**
* Get niveau01s
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getNiveau01s()
{
return $this->niveau01s;
}
} }

View File

@ -57,6 +57,24 @@ class AlertType extends AbstractType
"disabled" => ($options["mode"]=="delete"?true:false), "disabled" => ($options["mode"]=="delete"?true:false),
]) ])
->add('niveau01s', Select2EntityType::class, [
'label' => 'Visible pour les '.$options["labelniveau01"],
'class' => 'CadolesCoreBundle:Niveau01',
'text_property' => 'label',
'multiple' => true,
'remote_route' => 'cadoles_core_ajax_niveau01_list',
'primary_key' => 'id',
'text_property' => 'label',
'minimum_input_length' => 0,
'page_limit' => 100,
'allow_clear' => true,
'delay' => 250,
'cache' => false,
'cache_timeout' => 60000,
'language' => 'fr',
'placeholder' => 'Selectionner des '.$options["labelniveau01"],
])
->add('groups', Select2EntityType::class, [ ->add('groups', Select2EntityType::class, [
'label' => 'Visible pour les Groupes', 'label' => 'Visible pour les Groupes',
'class' => 'CadolesCoreBundle:Group', 'class' => 'CadolesCoreBundle:Group',
@ -106,6 +124,7 @@ class AlertType extends AbstractType
$resolver->setDefaults([ $resolver->setDefaults([
'data_class' => 'Cadoles\PortalBundle\Entity\Alert', 'data_class' => 'Cadoles\PortalBundle\Entity\Alert',
'mode' => "string", 'mode' => "string",
'labelniveau01' => "string",
]); ]);
} }
} }

View File

@ -60,6 +60,7 @@
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
{{ form_row(form.roles) }} {{ form_row(form.roles) }}
{{ form_row(form.niveau01s) }}
{{ form_row(form.groups) }} {{ form_row(form.groups) }}
</div> </div>