/** * @param Request $request * @param Review $review * @return \Symfony\Component\HttpFoundation\RedirectResponse * @Route("/{id}", requirements={"id": "\d+"}, name="delete_review") * @Method("DELETE") */ public function deleteAction(Request $request, Review $review) { $form = $this->get('app.delete_form_service')->createEntityDeleteForm($review->getId(), 'delete_review'); $form->handleRequest($request); if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->remove($review); $em->flush(); } return $this->redirect($this->generateUrl('admin_reviews')); }
/** * Change Review status * @param Request $request * @param Review $review * @return \Symfony\Component\HttpFoundation\RedirectResponse */ public function changeStatusAction(Request $request, Review $review) { $em = $this->getDoctrine()->getManager(); $session = $request->getSession(); try { $status = $review->getStatus() ? 0 : 1; $review->setStatus($status); $em->persist($review); $em->flush(); $this->get('AccommodationService')->calculateReviewRate($review); $session->getFlashBag()->add('msgSuccess', $this->get('translator')->trans('change_status_success')); } catch (\Exception $e) { $session->getFlashBag()->add('msgError', $e->getMessage()); } return $this->redirect($this->generateUrl('admin_reviews')); }
/** * @param Request $request * @param Product $product * @Route("/{slug}", name="create_review") * @Method("POST") * @Security("has_role('ROLE_USER')") * @Template("AppBundle:shop/Review:form.html.twig") * @return array|\Symfony\Component\HttpFoundation\RedirectResponse */ public function createAction(Request $request, Product $product) { $user = $this->getUser(); $Review = new Review(); $Review->setProduct($product); $Review->setUser($user); $form = $this->createForm(ReviewType::class, $Review, ['action' => $this->generateUrl('create_review', ['slug' => $product->getSlug()]), 'method' => 'POST'])->add('save', SubmitType::class, ['label' => 'review.send']); $form->handleRequest($request); if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($Review); $em->flush(); return $this->redirect($this->generateUrl('product_view', ['slug' => $product->getSlug(), 'tab' => 'reviews'])); } return ['form' => $form->createView()]; }
public function postAction(Request $request) { /* @var $em \Doctrine\ORM\EntityManager */ $em = $this->getDoctrine()->getManager(); /* @var $user \AppBundle\Entity\User */ $user = $this->getUser(); if (!$user) { throw $this->createAccessDeniedException("You are not logged in."); } // a user cannot post more reviews than her reputation if (count($user->getReviews()) >= $user->getReputation()) { throw new \Exception("Your reputation doesn't allow you to write more reviews."); } $card_id = filter_var($request->get('card_id'), FILTER_SANITIZE_NUMBER_INT); /* @var $card Card */ $card = $em->getRepository('AppBundle:Card')->find($card_id); if (!$card) { throw new \Exception("This card does not exist."); } if (!$card->getPack()->getDateRelease()) { throw new \Exception("You may not write a review for an unreleased card."); } // checking the user didn't already write a review for that card $review = $em->getRepository('AppBundle:Review')->findOneBy(array('card' => $card, 'user' => $user)); if ($review) { throw new \Exception("You cannot write more than 1 review for a given card."); } $review_raw = trim($request->get('review')); $review_raw = preg_replace('%(?<!\\()\\b(?:(?:https?|ftp)://)(?:((?:(?:[a-z\\d\\x{00a1}-\\x{ffff}]+-?)*[a-z\\d\\x{00a1}-\\x{ffff}]+)(?:\\.(?:[a-z\\d\\x{00a1}-\\x{ffff}]+-?)*[a-z\\d\\x{00a1}-\\x{ffff}]+)*(?:\\.[a-z\\x{00a1}-\\x{ffff}]{2,6}))(?::\\d+)?)(?:[^\\s]*)?%iu', '[$1]($0)', $review_raw); $review_html = $this->get('texts')->markdown($review_raw); if (!$review_html) { throw new \Exception("Your review is empty."); } $review = new Review(); $review->setCard($card); $review->setUser($user); $review->setTextMd($review_raw); $review->setTextHtml($review_html); $review->setNbVotes(0); $em->persist($review); $em->flush(); return new JsonResponse(['success' => TRUE]); }
/** * Create new Review * @param Request $request * @param Accommodation $accommodation * @return \Symfony\Component\HttpFoundation\RedirectResponse */ public function reviewAddAction(Request $request, Accommodation $accommodation) { $em = $this->getDoctrine()->getManager(); $session = $request->getSession(); $review = new Review(); $reviewForm = $this->createForm(new ReviewType()); $reviewForm->handleRequest($request); if ($reviewForm->isValid()) { $data = $reviewForm->getData(); $total = array($data->getCleanliness(), $data->getComfort(), $data->getLocation(), $data->getFacilities(), $data->getStaff(), $data->getValueForMoney()); # If review is active - depanding on rate $total = array_sum($total) / 6; $status = $total < 4 ? 0 : 1; $review->setTotal($total); $review->setAccommodation($accommodation); $review->setTourist($this->getUser()); $review->setText($data->getText()); $review->setCleanliness($data->getCleanliness()); $review->setComfort($data->getComfort()); $review->setLocation($data->getLocation()); $review->setFacilities($data->getFacilities()); $review->setStaff($data->getStaff()); $review->setValueForMoney($data->getValueForMoney()); $review->setStatus($status); $em->persist($review); $em->flush(); # Calculate total accommodation rate with new review if ($status) { $this->get('AccommodationService')->calculateReviewRate($review); } return $this->redirect($this->generateUrl('app_accommodation_single', array('id' => $accommodation->getId()))); } $session->getFlashBag()->add('reviewFormErrors', (string) $reviewForm->getErrors(true, false)); return $this->redirect($this->generateUrl('app_accommodation_single', array('id' => $accommodation->getId()))); }
/** * Add reviews * * @param \AppBundle\Entity\Review $review * @return Reader */ public function addReview(\AppBundle\Entity\Review $review) { $review->addReader($this); $this->reviews[] = $review; return $this; }