/** * Set featured image Unit * @param Request $request * @param Gallery $photo * @param $unitId * @return \Symfony\Component\HttpFoundation\RedirectResponse */ public function setFeaturedImageUnitAction(Request $request, UnitGallery $photo) { $em = $this->getDoctrine()->getManager(); $session = $request->getSession(); $galleryRep = $em->getRepository('AppBundle:UnitGallery'); $unit = $photo->getUnit(); $accommodationId = $unit->getAccommodation()->getId(); try { $gallery = $galleryRep->getGallery($unit->getId()); foreach ($gallery as $galleryPhoto) { $galleryPhoto->setFeaturedImage(0); } $photo->setFeaturedImage(1); $em->persist($photo); $em->flush(); $session->getFlashBag()->add('msgSuccess', $this->get('translator')->trans('featured_image_success')); if ($request->get('_route') == 'app_featuredImage_steps_unit') { return $this->redirect($this->generateUrl('app_profile_step_6', array('id' => $accommodationId))); } else { /** * TODO: Putanja do uređivanja Unit u profilu */ return $this->redirect($this->generateUrl('app_unit_edit', array('id' => $accommodationId))); } } catch (\Exception $e) { $session->getFlashBag()->add('msgError', $e->getMessage()); if ($request->get('_route') == 'app_featuredImage_steps_unit') { return $this->redirect($this->generateUrl('app_profile_step_6', array('id' => $accommodationId))); } else { return $this->redirect($this->generateUrl('app_unit_edit', array('id' => $accommodationId))); } } }
/** * Delete Unit photo * @param Request $request * @param UnitGallery $photo * @return \Symfony\Component\HttpFoundation\RedirectResponse */ public function deleteUnitPhotoAction(Request $request, UnitGallery $photo) { $em = $this->getDoctrine()->getManager(); $accommodation = $photo->getUnit()->getAccommodation(); $session = $request->getSession(); try { $em->remove($photo); $em->flush(); $session->getFlashBag()->add('msgSuccess', $this->get('translator')->trans('delete_success')); } catch (\Exception $e) { $session->getFlashBag()->add('msgError', $e->getMessage()); } return $this->redirect($this->generateUrl('app_profile_step_6', array('id' => $accommodation->getId()))); }