possibilité de profiler les alertes par items (fixes #31120)

This commit is contained in:
afornerot 2020-11-19 10:09:37 +01:00
parent f5633610a9
commit 9b877c2de0
8 changed files with 222 additions and 3 deletions

View File

@ -209,5 +209,34 @@ class AjaxController extends Controller
$response->headers->set('Content-Type', 'application/json'); $response->headers->set('Content-Type', 'application/json');
return $response; return $response;
} }
public function itemlistAction(Request $request)
{
// S'assurer que c'est un appel ajax
if (!$request->isXmlHttpRequest()) {
return new JsonResponse(array('message' => 'Interdit'), 400);
}
$output=array();
$em = $this->getDoctrine()->getManager();
$page_limit=$request->query->get('page_limit');
$q=$request->query->get('q');
$qb = $em->createQueryBuilder();
$qb->select('table')->from("CadolesPortalBundle:Item",'table')
->where('table.title LIKE :value')
->setParameter("value", "%".$q."%")
->orderBy('table.title');
$datas=$qb->setFirstResult(0)->setMaxResults($page_limit)->getQuery()->getResult();
foreach($datas as $data) {
array_push($output,array("id"=>$data->getId(),"text"=>$data->getTitle()));
}
$response = new Response(json_encode($output));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
} }

View File

@ -156,7 +156,10 @@ cadoles_core_ajax_group_list:
cadoles_core_ajax_group_read: cadoles_core_ajax_group_read:
path: /ajax/group/read path: /ajax/group/read
defaults: { _controller: CadolesCoreBundle:Ajax:groupread } defaults: { _controller: CadolesCoreBundle:Ajax:groupread }
cadoles_core_ajax_item_list:
path: /ajax/item/list
defaults: { _controller: CadolesCoreBundle:Ajax:itemlist }
#== Home Config ========================================================================================================== #== Home Config ==========================================================================================================
cadoles_core_config: cadoles_core_config:

View File

@ -105,6 +105,15 @@ class Alert
*/ */
protected $readers; protected $readers;
/**
* @ORM\ManyToMany(targetEntity="Cadoles\PortalBundle\Entity\Item", inversedBy="alerts", cascade={"persist"})
* @ORM\JoinTable(name="alertitem",
* joinColumns={@ORM\JoinColumn(name="alert", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="item", referencedColumnName="id")}
* )
*/
protected $items;
// Is Online // Is Online
public function isOnline() public function isOnline()
{ {
@ -461,4 +470,38 @@ class Alert
{ {
return $this->readers; return $this->readers;
} }
/**
* Add item
*
* @param \Cadoles\PortalBundle\Entity\Item $item
*
* @return Alert
*/
public function addItem(\Cadoles\PortalBundle\Entity\Item $item)
{
$this->items[] = $item;
return $this;
}
/**
* Remove item
*
* @param \Cadoles\PortalBundle\Entity\Item $item
*/
public function removeItem(\Cadoles\PortalBundle\Entity\Item $item)
{
$this->items->removeElement($item);
}
/**
* Get items
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getItems()
{
return $this->items;
}
} }

View File

@ -140,6 +140,11 @@ class Item
*/ */
protected $niveau01s; protected $niveau01s;
/**
* @ORM\ManyToMany(targetEntity="Cadoles\PortalBundle\Entity\Alert", mappedBy="items")
*/
protected $alerts;
// A garder pour forcer l'id en init // A garder pour forcer l'id en init
public function setId($id) public function setId($id)
{ {
@ -580,4 +585,38 @@ class Item
{ {
return $this->essential; return $this->essential;
} }
/**
* Add alert
*
* @param \Cadoles\PortalBundle\Entity\Alert $alert
*
* @return Item
*/
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

@ -98,6 +98,24 @@ class AlertType extends AbstractType
'placeholder' => 'Selectionner un groupe', 'placeholder' => 'Selectionner un groupe',
]) ])
->add('items', Select2EntityType::class, [
'label' => 'Visible pour les Items',
'class' => 'CadolesPortalBundle:Item',
'text_property' => 'label',
'multiple' => true,
'remote_route' => 'cadoles_core_ajax_item_list',
'primary_key' => 'id',
'text_property' => 'title',
'minimum_input_length' => 0,
'page_limit' => 100,
'allow_clear' => true,
'delay' => 250,
'cache' => false,
'cache_timeout' => 60000,
'language' => 'fr',
'placeholder' => 'Selectionner des items',
])
->add('publishedat', DateType::class, [ ->add('publishedat', DateType::class, [
'label' => 'Publier du', 'label' => 'Publier du',
'input' => 'datetime', 'input' => 'datetime',

View File

@ -45,7 +45,7 @@ class AlertRepository extends EntityRepository
$roles=($user?$user->getRoles():["ROLE_ANONYME"]); $roles=($user?$user->getRoles():["ROLE_ANONYME"]);
$niveau01=($user?$user->getNiveau01():null); $niveau01=($user?$user->getNiveau01():null);
$groups=($user?$user->getGroups():[]); $groups=($user?$user->getGroups():[]);
// Initialisation du calcul des alerts // Initialisation du calcul des alerts
$alerts=new ArrayCollection(); $alerts=new ArrayCollection();
@ -118,6 +118,34 @@ class AlertRepository extends EntityRepository
} }
} }
// Récupération des alerts par item
$bookmarks=null;
$items=null;
$itemcategorys=null;
$this->_em->getRepository("CadolesPortalBundle:Item")->getUserItems($user,$bookmarks,$items,$itemcategorys,null,4);
foreach($items as $item) {
$qb = $this->createQueryBuilder('a');
$qb->select('alert')
->from("CadolesPortalBundle:Alert", 'alert')
->where(":item MEMBER OF alert.items")
->andWhere('alert.publishedat <= :today')
->andWhere($qb->expr()->orX(
$qb->expr()->gt('alert.unpublishedat', ':today'),
$qb->expr()->isNull('alert.unpublishedat')
))
->setParameter("item",$item)
->setParameter('today', date('Y-m-d'));
if($idalertcategory && $alertcategoryfilter) {
$qb->andWhere("alert.alertcategory=:alertcategory")
->setParameter("alertcategory",$alertcategoryfilter);
}
$alertsitems=$qb->getQuery()->getResult();
foreach($alertsitems as $alertitem) {
if(!$alerts->contains($alertitem)&&!$alertitem->getReaders()->contains($user)) $alerts->add($alertitem);
}
}
// Trie des alerts // Trie des alerts
$alertsordered = $alerts->getIterator(); $alertsordered = $alerts->getIterator();
$alertsordered->uasort(function ($first, $second) { $alertsordered->uasort(function ($first, $second) {

View File

@ -63,6 +63,7 @@
{{ form_row(form.roles) }} {{ form_row(form.roles) }}
{{ form_row(form.niveau01s) }} {{ form_row(form.niveau01s) }}
{{ form_row(form.groups) }} {{ form_row(form.groups) }}
{{ form_row(form.items) }}
</div> </div>
</div> </div>

View File

@ -69,6 +69,64 @@
<div class="panel-body"> <div class="panel-body">
{{ alert.content|raw }} {{ alert.content|raw }}
{% if not alert.items is empty %}
{% if app.user %}
{% set username = app.user.username %}
{% else %}
{% set username = "" %}
{% endif %}
<div class="grid clearfix fitWidth" style="width:auto; margin: 0 auto;">
<div class="grid-sizer grid-small"></div>
<div class="grid-gutter-sizer"></div>
{% for item in alert.items %}
<div class="grid-item grid-list">
<div class="grid-item-content" style="background-color: {{ item.color ? "#"~item.color : '#'~colormain }};">
{% if item.protected and not app.user %}
{% if mode_auth == "SAML" %}
<a href="{{ path('lightsaml_sp.login') }}" {% if access=="user" %}target="_top"{% endif %}>
{% elseif mode_auth == "CAS" %}
<a href="{{ path('cas_sp.login') }}" {% if access=="user" %}target="_top"{% endif %}>
{% elseif mode_auth == "MYSQL" %}
<a href="{{ path('cnous_portal_user_login') }}" {% if access=="user" %}target="_top"{% endif %}>
{% endif %}
{% else %}
{% if item.target == 'frame' %}
<a class="linktosonde" data-sonde="{{ item.title }}" style="cursor:pointer" onClick="showFrameitem({{ item.id }},'{{ item.url|replace({'#login#': username}) }}')">
{% elseif item.target == "_self" %}
<a class="linktosonde" data-sonde="{{ item.title }}" href="{{ item.url|replace({'#login#': username}) }}" target="{% if access=="user" %}_top{% else %}{{ item.target }}{% endif %}">
{% else %}
<a class="linktosonde" data-sonde="{{ item.title }}" href="{{ item.url|replace({'#login#': username}) }}" target="{{ item.target }}">
{% endif %}
{% endif %}
<div class="item-link clearfix">
<div class="grid-item-logo" title="{{ item.subtitle|nl2br }}">
{% if item.icon %}
<img class="grid-item-img" height="110" src="/{{ alias }}/{{ item.icon.label }}">
{% else %}
<img class="grid-item-img" height="110" src="/{{ alias }}/uploads/icon/icon_pin.png">
{% endif %}
</div>
<div class="grid-item-title">
<h2>{{ item.title }}</h2>
<span>{{ item.subtitle|nl2br }}</<span>
</div>
</div>
</a>
<div class="grid-item-body" style="display:none">
{{ item.content|raw }}
</div>
</div>
</div>
{% endfor %}
</div>
{% endif %}
</div> </div>
</div> </div>