Esempio n. 1
0
 /**
  * Cette methode sera appelé depuis mon services.yml
  * ET reçoie en argument mon evenement Doctrine 2
  * @param LifecycleEventArgs $args
  */
 public function postUpdate(LifecycleEventArgs $args)
 {
     // Je récupère mon objet après modification (update)
     $entity = $args->getEntity();
     $em = $args->getEntityManager();
     // récupérer l'Entité Manager
     // Si mon objet est un objet de mon entité Product
     if ($entity instanceof Product) {
         // récupéré le titre de mion produit
         $title = $entity->getTitle();
         # 2 tableaux avec accents
         $a = array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'Ð', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', '?', '?', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', '?', '?', 'L', 'l', 'N', 'n', 'N', 'n', 'N', 'n', '?', 'O', 'o', 'O', 'o', 'O', 'o', 'Œ', 'œ', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'Š', 'š', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Ÿ', 'Z', 'z', 'Z', 'z', 'Ž', 'ž', '?', 'ƒ', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', '?', '?', '?', '?', '?', '?');
         $b = array('A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 's', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'D', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'IJ', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'l', 'l', 'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o');
         // slugifier mon titre stocké dans une variable slug
         $slug = strtolower(preg_replace(array('/[^a-zA-Z0-9 -]/', '/[ -]+/', '/^-|-$/'), array('', '-', ''), str_replace($a, $b, $title)));
         // setSlug me permet de modifier le slug de mon product
         $entity->setSlug($slug);
         $em->persist($entity);
         //j'enregistre en base de données
         $em->flush();
         // quand la quantité sera égal à 1
         if ($entity->getQuantity() == 1) {
             $this->notification->notify($entity->getId(), 'Attention, votre produit ' . $entity->getTitle() . '  a une seule quantité', 'product', 'danger');
         } else {
             if ($entity->getQuantity() < 5) {
                 // je notifie la quantité de ce produit
                 // avec la methode notify()
                 $this->notification->notify($entity->getId(), 'Attention, votre produit ' . $entity->getTitle() . '  a un stocke bientôt épuisé', 'product', 'warning');
             }
         }
     }
 }
 /**
  * Methode qui est déclenché après l'événement InteractiveLogin
  * qui est  l'action de login dans la sécurité
  * @param InteractiveLoginEvent $event
  */
 public function onAuthenticationSuccess(InteractiveLoginEvent $event)
 {
     $now = new \DateTime('now');
     // récupére l'utilisateur  courant connecté
     $user = $this->securityContext->getToken()->getUser();
     //recupere tous les produits de l'utilisateur via le repository ProductRepository
     // et via getProductsQuantityIsLower() qui on une quantité < 5
     $products = $this->em->getRepository('StoreBackendBundle:Product')->getProductsQuantityIsLower($user);
     //pour chaque produit
     foreach ($products as $product) {
         // si la quantité du produit est égal à 1
         if ($product->getQuantity() == 1) {
             $this->notification->notify($product->getId(), 'Attention, votre produit ' . $product->getTitle() . '  a une seule quantité', 'product', 'danger');
         } else {
             $this->notification->notify($product->getId(), 'Attention, votre produit ' . $product->getTitle() . '  a quantité bientot épuisé', 'product', 'warning');
         }
     }
     // declencher une notification dans mes produits
     $date = $user->getDateAuth();
     $oldyear = new \DateTime('-2 month');
     $route = 'store_backend_index';
     // Long time to control use account
     if ($date < $oldyear || !$date) {
         $this->session->set('first', true);
         $route = 'store_backend_jeweler_myaccount';
     }
     // met à jour la date de connexion de l'utilisateur
     $user->setDateAuth($now);
     //enregistre mon utilisateur avec sa date modifié
     $this->em->persist($user);
     $this->em->flush();
     return new RedirectResponse($this->router->generate($route));
 }