public function matcher($token, Photo $photo) { $rMatcher = $this->_em->getRepository('jgcompictureBundle:Matcher'); $rPhoto = $this->_em->getRepository('jgcompictureBundle:Photo'); $decryptToken = $this->_sCrypter->decrypt($token); if ($decryptToken) { $secondPhoto = null; $photoIds = explode(",", $decryptToken); if ($photoIds[0] == $photo->getId()) { $secondPhoto = $rPhoto->find($photoIds[1]); } else { if ($photoIds[1] == $photo->getId()) { $secondPhoto = $rPhoto->find($photoIds[0]); } } if ($secondPhoto != null) { $user = $this->getUser(); if ($rMatcher->findBy(array("author" => $user, "photo" => $photo)) == null) { // Traitements $matcher = new Matcher(); $matcher->setAuthor($user); $matcher->setPhoto($photo); $photo->setRate($photo->getRate() + 1); $secondPhoto->setRate($secondPhoto->getRate() - 1); $this->_em->persist($photo); $this->_em->persist($secondPhoto); $this->_em->persist($matcher); $this->_em->flush(); return true; } } } return false; }
/** * @Route("/post/{id}/list", requirements={"id" = "\d+"}) */ public function postListAction(Photo $photo, Request $request) { $response = new JsonResponse(null, 400); $data = array('status' => "failed", 'errors' => [], 'result' => array()); try { if ($request->isXmlHttpRequest()) { $post = $request->request; $list = []; foreach ($photo->getComments() as $comment) { $item = []; $item['pseudo'] = $comment->getPseudo(); $item['date'] = $comment->getDate()->format('d/m/Y H:i:s'); $item['body'] = $comment->getBody(); $list[] = $item; } $data['result'] = $list; $data['status'] = 'success'; $response->setStatusCode(200); } } catch (\Exception $e) { $response->setStatusCode(500); if ($this->container->getParameter('kernel.environment') == "dev") { throw $e; } } $response->setData($data); return $response; }
/** * @Route("/thumb/{id}", requirements={"id" = "\d+"}) */ public function downloadThumbAction(Photo $photo) { return $photo->getResponseDownload(true); }