diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/AjaxController.php b/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/AjaxController.php index 8d71d856..730a74d6 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/AjaxController.php +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Controller/AjaxController.php @@ -209,5 +209,34 @@ class AjaxController extends Controller $response->headers->set('Content-Type', 'application/json'); 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; + + } } diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/config/routing.yml b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/config/routing.yml index 7d3c8d84..0511a6ba 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/config/routing.yml +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Resources/config/routing.yml @@ -156,7 +156,10 @@ cadoles_core_ajax_group_list: cadoles_core_ajax_group_read: path: /ajax/group/read defaults: { _controller: CadolesCoreBundle:Ajax:groupread } - + +cadoles_core_ajax_item_list: + path: /ajax/item/list + defaults: { _controller: CadolesCoreBundle:Ajax:itemlist } #== Home Config ========================================================================================================== cadoles_core_config: diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Entity/Alert.php b/src/ninegate-1.0/src/Cadoles/PortalBundle/Entity/Alert.php index f34d4863..8d4cc2b5 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Entity/Alert.php +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Entity/Alert.php @@ -105,6 +105,15 @@ class Alert */ 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 public function isOnline() { @@ -461,4 +470,38 @@ class Alert { 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; + } } diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Entity/Item.php b/src/ninegate-1.0/src/Cadoles/PortalBundle/Entity/Item.php index a3f0cf40..3f9e15e6 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Entity/Item.php +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Entity/Item.php @@ -140,6 +140,11 @@ class Item */ protected $niveau01s; + /** + * @ORM\ManyToMany(targetEntity="Cadoles\PortalBundle\Entity\Alert", mappedBy="items") + */ + protected $alerts; + // A garder pour forcer l'id en init public function setId($id) { @@ -580,4 +585,38 @@ class Item { 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; + } } diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Form/AlertType.php b/src/ninegate-1.0/src/Cadoles/PortalBundle/Form/AlertType.php index 8cf68ba1..daae87a9 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Form/AlertType.php +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Form/AlertType.php @@ -98,6 +98,24 @@ class AlertType extends AbstractType '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, [ 'label' => 'Publier du', 'input' => 'datetime', diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Repository/AlertRepository.php b/src/ninegate-1.0/src/Cadoles/PortalBundle/Repository/AlertRepository.php index b59e0ad6..f628fa9a 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Repository/AlertRepository.php +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Repository/AlertRepository.php @@ -45,7 +45,7 @@ class AlertRepository extends EntityRepository $roles=($user?$user->getRoles():["ROLE_ANONYME"]); $niveau01=($user?$user->getNiveau01():null); $groups=($user?$user->getGroups():[]); - + // Initialisation du calcul des alerts $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 $alertsordered = $alerts->getIterator(); $alertsordered->uasort(function ($first, $second) { diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Alert/edit.html.twig b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Alert/edit.html.twig index c836ef1c..34a97203 100755 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Alert/edit.html.twig +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Alert/edit.html.twig @@ -63,6 +63,7 @@ {{ form_row(form.roles) }} {{ form_row(form.niveau01s) }} {{ form_row(form.groups) }} + {{ form_row(form.items) }} diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Pagewidget/viewalert.html.twig b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Pagewidget/viewalert.html.twig index 72e7fdbb..42a7d975 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Pagewidget/viewalert.html.twig +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Pagewidget/viewalert.html.twig @@ -69,6 +69,64 @@