/** * Creates a form to delete a Post entity by id. * * @param Club $club * @param Post $post * @return \Symfony\Component\Form\Form The form */ private function createDeleteForm(Club $club, Post $post) { return $this->createFormBuilder()->setAction($this->generateUrl('club_post_delete', array('slug' => $club->getSlug(), 'post_slug' => $post->getSlug())))->setMethod('DELETE')->add('submit', 'submit', array('label' => 'Eliminar', 'attr' => array('class' => 'confirm', 'data-type' => 'submit_delete', 'data-text' => "¿Está usted seguro de que quiere eliminar este post?")))->getForm(); }
/** * Proces new or updated posts * * @param Post $post */ private function processForm(Post $post) { if ($post->getSlug() == null) { $em = $this->getDoctrine()->getManager(); $i = 1; $slug = Slug::slugify($post->getTitle()); $exists = $em->getRepository("OesteveGrupetaBundle:Post")->findOneBy(array('slug' => $slug)); while ($exists != null) { $slug = Slug::slugify($post->getTitle() . '-' . $i++); $exists = $em->getRepository("OesteveGrupetaBundle:Post")->findOneBy(array('slug' => $slug)); } $post->setSlug($slug); } //All post in this secction are in the front $post->setFront(true); return $post; }
/** * Remove post * * @param \Oesteve\Bundle\GrupetaBundle\Entity\Post $post */ public function removePost(\Oesteve\Bundle\GrupetaBundle\Entity\Post $post) { $this->posts->removeElement($post); }
/** * Proces club before form handleRequest * * @param Post $post */ private function processPost(Post $post) { $em = $this->getDoctrine()->getManager(); // Define slug for this post if ($post->getSlug() == null) { $em = $this->getDoctrine()->getManager(); $i = 1; $slug = Slug::slugify($post->getTitle()); $exists = $em->getRepository("OesteveGrupetaBundle:Post")->findOneBy(array('slug' => $slug)); while ($exists != null) { $slug = Slug::slugify($post->getTitle() . ' ' . $i++); $exists = $em->getRepository("OesteveGrupetaBundle:Post")->findOneBy(array('slug' => $slug)); } $post->setSlug($slug); } // Check author always will be the athlete if ($post->getAuthor() == null) { $post->setAuthor($this->getUser()); } // Check if gallery exists if ($post->getGallery() == null) { $gallery = new Gallery(); $gallery->setName($post->getTitle()); $post->setGallery($gallery); } $em->persist($post); $em->flush(); return $post; }