/** * Set featured image Accommodation * @param Request $request * @param Gallery $photo * @param $accommodationId * @return \Symfony\Component\HttpFoundation\RedirectResponse */ public function setFeaturedImageAction(Request $request, Gallery $photo) { $em = $this->getDoctrine()->getManager(); $session = $request->getSession(); $galleryRep = $em->getRepository('AppBundle:Gallery'); $accommodationId = $photo->getAccommodation()->getId(); try { $gallery = $galleryRep->getGallery($accommodationId); 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_accommodation') { return $this->redirect($this->generateUrl('app_profile_step_6', array('id' => $accommodationId))); } else { return $this->redirect($this->generateUrl('app_accommodation_edit', array('id' => $accommodationId))); } } catch (\Exception $e) { $session->getFlashBag()->add('msgError', $e->getMessage()); if ($request->get('_route') == 'app_featuredImage_steps_accommodation') { return $this->redirect($this->generateUrl('app_profile_step_6', array('id' => $accommodationId))); } else { return $this->redirect($this->generateUrl('app_accommodation_edit', array('id' => $accommodationId))); } } }
/** * Adds an album to the database. * Returns a JSON with the updated list of galleries viewable by user * @return Response */ public function createGalleryAction() { //todo: change name to createAlbumAction $request = Request::createFromGlobals(); $galleryName = $request->request->get('gallery_name', 'Ikke navngitt galleri.'); $private = $request->request->get('private_gallery', 'public'); $gallery = new Gallery(); $gallery->setName($galleryName); $gallery->setPrivate($private != 'public'); $gallery->setDateCreated(new \DateTime("now")); $gallery->setCreatedByUser($this->get('security.context')->getToken()->getUser()); $em = $this->getDoctrine()->getManager(); $em->persist($gallery); $em->flush(); //return the updated list of galleries $response = $this->forward('AppBundle:Gallery:galleriesListGet'); return $response; }
/** * Finds and displays a Gallery entity. * * @Route("/show/{id}", name="admin_gallery_show") * @Method("GET") * @ParamConverter("gallery", class="AppBundle:Gallery") */ public function showAction(Gallery $gallery) { $images = $this->getDoctrine()->getRepository('AppBundle:Image')->findByGallery($gallery->getId()); return $this->render('AppBundle:Admin\\Gallery:show.html.twig', ['gallery' => $gallery, 'images' => $images]); }
/** * {@inheritDoc} */ public function setHref($href) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'setHref', array($href)); return parent::setHref($href); }
/** * Delete Accommodation photo * @param Request $request * @param Gallery $photo * @return \Symfony\Component\HttpFoundation\RedirectResponse */ public function deleteAccommodationPhotoAction(Request $request, Gallery $photo) { $em = $this->getDoctrine()->getManager(); $accommodation = $photo->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()))); }
/** * Edits an existing Gallery entity. * * @Route("/{id}", name="admin_gallery_update") * @Method("PUT") * @ParamConverter("gallery", class="AppBundle:Gallery") */ public function updateAction(Request $request, Gallery $gallery) { $em = $this->getDoctrine()->getManager(); $originalImages = new \Doctrine\Common\Collections\ArrayCollection(); foreach ($gallery->getImages() as $image) { $originalImages->add($image); } $editForm = $this->createEditForm($gallery); $editForm->handleRequest($request); if ($editForm->isValid()) { // remove the relationship between the tag and the Task foreach ($originalImages as $image) { if (false === $gallery->getImages()->contains($image)) { $this->get('liip_imagine.cache.manager')->remove($image->getUpload()->getWebPath()); $em->remove($image); } } $em->flush(); return $this->redirect($this->generateUrl('admin_gallery_edit', array('id' => $gallery->getId()))); } else { dump($editForm->getErrors()); } return $this->render('AppBundle:Admin\\Gallery:edit.html.twig', ['gallery' => $gallery, 'edit_form' => $editForm->createView()]); }