コード例 #1
0
 public function prePersist(LifecycleEventArgs $args)
 {
     $entity = $args->getObject();
     if ($entity instanceof PaymentInterface) {
         $generator = new UuidGenerator();
         $token = $generator->generate($args->getObjectManager(), null);
         $entity->setToken($token);
     }
 }
コード例 #2
0
 /**
  * @param EntityManager $manager
  * @param Entity        $entity
  *
  * @return string
  */
 public function generate(EntityManager $manager, $entity)
 {
     $connection = $manager->getConnection();
     $platform = $connection->getDatabasePlatform();
     if ($platform instanceof MySqlPlatform) {
         return $connection->query('SELECT UUID_SHORT()')->fetchColumn(0);
     } else {
         return parent::generate($manager, $entity);
     }
 }
コード例 #3
0
 public function getGeneratedValue(EntityManager $em, $entity)
 {
     return parent::generate($em, $entity);
 }
コード例 #4
0
 private function onEvent(\Doctrine\Common\Persistence\ObjectManager $om, $object, $event)
 {
     $className = get_class($object);
     if (!isset($this->configs[$className])) {
         return;
     }
     $conf =& $this->configs[$className];
     /**
      * @var $meta \Doctrine\ORM\Mapping\ClassMetadata
      */
     if (self::preUpdate === $event) {
         if (isset($conf['uuid'])) {
             $uow = $om->getUnitOfWork();
             $meta = $om->getClassMetadata($className);
             foreach ($conf['uuid'] as $property_name => $property_conf) {
                 $property = $meta->getReflectionProperty($property_name);
                 $oldValue = $property->getValue($object);
                 if (null === $oldValue) {
                     $newValue = $this->uuid_generator->generate($om, $object);
                     $property->setValue($object, $newValue);
                     if ($object instanceof NotifyPropertyChanged) {
                         $uow->propertyChanged($object, $property_name, $oldValue, $newValue);
                     }
                 }
             }
         }
     } else {
         if (self::onFlush === $event) {
         } else {
             if (self::postUpdate === $event) {
                 if (isset($conf['file'])) {
                     $meta = $om->getClassMetadata($className);
                     $object_id = $meta->getReflectionProperty($conf['id'])->getValue($object);
                     foreach ($conf['file'] as $property_name => $property_conf) {
                         $property = $meta->getReflectionProperty($property_name);
                         $oldValue = $property->getValue($object);
                         if ($oldValue) {
                             if ($object_id !== $oldValue->getEntityId()) {
                                 $oldValue->setEntityId($object_id);
                                 $om->persist($oldValue);
                                 $this->post_flush_persist_counter++;
                             }
                         }
                     }
                 }
                 if (isset($conf['html'])) {
                     $meta = $om->getClassMetadata($className);
                     $object_id = $meta->getReflectionProperty($conf['id'])->getValue($object);
                     $repo = $om->getRepository('Symforce\\AdminBundle\\Entity\\File');
                     foreach ($conf['html'] as $property_name => $property_conf) {
                         $property = $meta->getReflectionProperty($property_name);
                         $oldValue = $property->getValue($object);
                         if ($oldValue) {
                             preg_match_all($this->getRichTextFilesPattern(), $oldValue, $ms, PREG_SET_ORDER);
                             if ($ms) {
                                 foreach ($ms as $ma) {
                                     $file = $repo->loadByUUID($ma[1]);
                                     if ($file && $file->getIsHtmlFile() && $object_id !== $file->getEntityId()) {
                                         $file->setEntityId($object_id);
                                         $om->persist($file);
                                         $this->post_flush_persist_counter++;
                                     }
                                 }
                             }
                         }
                     }
                 }
             } else {
                 if (self::preRemove === $event) {
                     if (isset($conf['file'])) {
                         $meta = $om->getClassMetadata($className);
                         $object_id = $meta->getReflectionProperty($conf['id'])->getValue($object);
                         foreach ($conf['file'] as $property_name => $property_conf) {
                             $property = $meta->getReflectionProperty($property_name);
                             $oldValue = $property->getValue($object);
                             if ($oldValue && $object_id === $oldValue->getEntityId() && $className === $oldValue->getClassName() && $property_name === $oldValue->getPropertyName() && $object_id === $oldValue->getEntityId()) {
                                 $om->remove($oldValue);
                             }
                         }
                     }
                     if (isset($conf['html'])) {
                         $meta = $om->getClassMetadata($className);
                         $object_id = $meta->getReflectionProperty($conf['id'])->getValue($object);
                         $repo = $om->getRepository('Symforce\\AdminBundle\\Entity\\File');
                         foreach ($conf['html'] as $property_name => $property_conf) {
                             $property = $meta->getReflectionProperty($property_name);
                             $oldValue = $property->getValue($object);
                             if ($oldValue) {
                                 preg_match_all($this->getRichTextFilesPattern(), $oldValue, $ms, PREG_SET_ORDER);
                                 if ($ms) {
                                     foreach ($ms as $ma) {
                                         $file = $repo->loadByUUID($ma[1]);
                                         if ($file && $file->getIsHtmlFile() && $className === $file->getClassName() && $property_name === $file->getPropertyName() && $object_id === $file->getEntityId()) {
                                             $om->remove($file);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #5
0
 /**
  * @return bool|mixed|string
  */
 public function generateId()
 {
     return parent::generate($this->em, null);
 }
コード例 #6
0
 public function indexAction(Request $request)
 {
     $session = $request->getSession();
     $productIDs = $session->get('ids');
     $productIDs = json_decode($productIDs, true);
     $useBonus = false;
     if ($productIDs) {
         $productIDs = array_count_values($productIDs);
         $products = array();
         $basketSumm = 0;
         $basketCount = 0;
         foreach ($productIDs as $productId => $count) {
             $product = $this->getDoctrine()->getRepository('ShopBundle:Product')->find($productId);
             if (!$product) {
                 continue;
             }
             if (!$useBonus && $product->getCategory()->getId() == 1) {
                 $useBonus = true;
             }
             $product->setCount($count);
             $images = $product->getImages();
             if ($images && strpos($images, ',')) {
                 $product->setImages(strstr($images, ',', true));
             }
             $products[] = $product;
             $basketCount += $count;
             $basketSumm = $basketSumm + $product->getPrice() * $count;
         }
     } else {
         $products = array();
         $basketSumm = 0;
         $basketCount = 0;
     }
     $order = new Order();
     $orderForm = $this->get('shop.form.order');
     $form = $this->createForm($orderForm, $order);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $uuid = new UuidGenerator();
         $order->setUuid($uuid->generate($em, $order));
         /** @var User $user */
         $user = $this->getUser();
         if ($user) {
             $order->setUser($user);
         }
         // Уменьшение бонусов у пользователя
         $bonus = $order->getBonus();
         if ($bonus) {
             $bonuses = json_decode($user->getBonus(), true);
             $maxBonus = $user->getMaxBonus();
             $newBonus = (int) $maxBonus - (int) $bonus;
             if ($newBonus) {
                 $bonuses[$newBonus] = $bonuses[$maxBonus];
             }
             unset($bonuses[$maxBonus]);
             $user->setBonus($bonuses ? json_encode($bonuses) : null);
         }
         $em->persist($order);
         if ($user) {
             $em->persist($user);
         }
         $em->flush();
         $this->getDoctrine()->getRepository('ShopBundle:Order')->setOrderProductsArray($order);
         $session = $request->getSession();
         if ($session) {
             $session->clear();
         }
         $this->addFlash('success', '');
         $mailer = $this->get('mailer');
         $messageClient = \Swift_Message::newInstance()->setSubject('Спасибо за заказ на нашем сайте sweet-smoke.org')->setFrom(array('*****@*****.**' => 'SweetSmoke'))->setTo(array('*****@*****.**', $order->getEmail()))->setContentType('text/html')->setBody($this->renderView("@Shop/Messages/new_order_client.html.twig", array('order' => $order)));
         $messageAdmin = \Swift_Message::newInstance()->setSubject('Заказ в интернет магазине на сайте sweet-smoke.org')->setFrom(array('*****@*****.**' => 'SweetSmoke'))->setTo(array('*****@*****.**', '*****@*****.**'))->setContentType('text/html')->setBody($this->renderView("@Shop/Messages/new_order_admin.html.twig", array('order' => $order)));
         $mailer->send($messageClient);
         $mailer->send($messageAdmin);
         $user = $this->getUser();
         if ($user) {
             return new RedirectResponse($this->generateUrl('user_cabinet_orders'));
         } else {
             return new RedirectResponse($this->generateUrl('hookah_shop_order', array('uuid' => $order->getUuid())));
         }
     }
     /** @var User $user */
     $user = $this->getUser();
     $bonus = 0;
     if ($useBonus && $user) {
         $bonus = $user->getMaxBonus();
     }
     return $this->render('@Shop/basket.html.twig', array('products' => $products, 'basketCount' => $basketCount, 'basketSumm' => $basketSumm, 'deliveryTypes' => DeliveryType::map(), 'form' => $form->createView(), 'bonus' => $bonus));
 }