Beispiel #1
0
 /**
  * Page create shop
  *
  * @param string $shopname
  *
  * @Route("/{shopname}", name="main_shop")
  * @Method({"GET"})
  *
  * @return mixed
  */
 public function indexAction($shopname)
 {
     $shop = $this->getDoctrine()->getRepository("ShopCreateBundle:Shops")->findOneByShop($shopname);
     $isShopManager = false;
     if ($this->getUser()) {
         if ($shop['manager'] == $this->getUser()->getId()) {
             $isShopManager = true;
         }
     }
     $products = $this->getDoctrine()->getRepository('ShopProductBundle:Product')->findByProductShop($shopname, 0);
     $shopEntity = $this->getDoctrine()->getRepository("ShopCreateBundle:Shops")->findOneBy(['uniqueName' => $shopname]);
     $comments = new Comments();
     $comments->setShops($shopEntity);
     $comments->setUsers($this->getUser());
     $comments = $this->createForm(CommentsType::class, $comments, ['method' => 'post']);
     $search = $this->createForm(SearchShopType::class, new Product());
     $message = $this->createForm(MessagesType::class, new Messages());
     return $this->render('ShopInformationBundle:Page:main.html.twig', ['comments' => $comments->createView(), 'message' => $message->createView(), 'search' => $search->createView(), 'isShopManager' => $isShopManager, 'shopname' => $shopname, 'products' => $products, 'shop' => $shop]);
 }
Beispiel #2
0
 /**
  * @ApiDoc(
  *     description="Добавляем коментарий",
  *     statusCodes={
  *         200="Нормальный ответ"
  *     }
  * )
  *
  * @param Request $request
  * @param string $shopname
  *
  * @Route("/{shopname}/addCommentsShop", name="add_comments_shops", defaults={"_format": "json"})
  * @Method({"POST"})
  *
  * @Rest\View(serializerGroups={"comments"})
  * @return mixed
  */
 public function addCommentsAction(Request $request, $shopname)
 {
     $user = $this->getUser();
     $em = $this->getDoctrine()->getManager();
     $shop = $em->getRepository("ShopCreateBundle:Shops")->findOneBy(['uniqueName' => $shopname]);
     $comments = new Comments();
     $comments->setUsers($user);
     $comments->setShops($shop);
     $form = $this->createForm(CommentsType::class, $comments);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em->persist($comments);
         $em->flush();
         if ($user->getPath()) {
             $avalancheService = $this->get('liip_imagine.cache.manager');
             $cachedImage = $avalancheService->getBrowserPath($user->getPath(), 'mini_avatar');
             $user->setPath($cachedImage);
         }
         return $comments;
     }
     return $form->getErrors();
 }