/** * @param ObjectManager $manager */ public function load(ObjectManager $manager) { $users = ['admin', 'info']; foreach ($users as $user) { $ref = $this->getReference($user); $thanks = new Thanks(); $thanks->setNumber(rand(1, 10)); $thanks->setHelper($ref); $manager->persist($thanks); } $manager->flush(); }
/** * @param Request $request * @param $arid * @return RedirectResponse|Response */ public function createReviewAction(Request $request, $arid) { $em = $this->getDoctrine()->getManager(); $currentUser = $this->getUser(); $assistanceRequest = $em->getRepository('NFQAssistanceBundle:AssistanceRequest')->find($arid); if ($assistanceRequest->getOwner() != $currentUser || $assistanceRequest->getHelper() == $currentUser || $assistanceRequest->getStatus() != AssistanceRequest::STATUS_TAKEN) { throw new Exception('problems'); } $review = new Review(); $review->setAssistanceRequest($assistanceRequest); $form = $this->createForm(new ReviewType(), $review, array('method' => 'POST')); $form->handleRequest($request); if ($request->isMethod('POST') && $form->isValid()) { $review->setHelper($assistanceRequest->getHelper()); $review->setHelpGetter($currentUser); $review->setAssistanceRequest($assistanceRequest); $review->setDate(new \DateTime('now')); $assistanceRequest->setStatus(AssistanceRequest::STATUS_DONE); $em->persist($assistanceRequest); if ($form->get('thank')->getData()) { $thank = $em->getRepository('NFQReviewsBundle:Thanks')->findOneByUser($assistanceRequest->getHelper()); if ($thank == null) { $thank = new Thanks(); $thank->setHelper($assistanceRequest->getHelper()); } $thank->incrementNumber(); $em->persist($thank); } if (!$form->get('reviewMessage')->getData()) { $this->get('session')->getFlashBag()->add('success', 'assistance_done'); } else { $em->persist($review); $this->get('session')->getFlashBag()->add('success', 'review_added'); } $em->flush(); return $this->redirectToRoute('nfq_assistance_request_list'); } return $this->render('NFQReviewsBundle:Review:createReview.html.twig', array('form' => $form->createView())); }