public function reverseTransform($ftags) { $tags = new ArrayCollection(); $tag = strtok($ftags, ","); while ($tag !== false) { $itag = new Tag(); $itag->setLibTag($tag); if (!$tags->contains($itag)) { $tags[] = $itag; } $tag = strtok(","); } return $tags; }
public function addPhotoAction() { if (!$this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) { throw new AccessDeniedException('Accès limité.'); } $photo = new Photo(); $form = $this->createForm(new PhotoType(), $photo); $request = $this->get('request'); if ($request->getMethod() == 'POST') { $form->bind($request); if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); $photo->setUser($this->getUser()); //on va traiter les tags maintenant $recupTags = $form->get('myTags')->getData(); $tabRecupTags = explode(',', $recupTags); //on analyse pour chaque tag s'il existe foreach ($tabRecupTags as $eachTag) { $eachTagPure = trim($eachTag); if ($eachTagPure != '') { $tagTrouv = $em->getRepository('PersoGalerieBundle:Tag')->findOneBy(array('libTag' => $eachTagPure)); if (null === $tagTrouv) { //on ajoute dans l'entité Tag et on lie à la photo $newTag = new Tag(); $newTag->setLibTag($eachTagPure); $em->persist($newTag); $photo->addTag($newTag); } else { //on se contente de lier le tag existant à la photo $photo->addTag($tagTrouv); } } } $flash = $this->get('translator')->trans('alert.info.newPhotoOk'); $this->get('session')->getFlashBag()->add('success', $flash); //todo: remplacer les insultes dans les commentaires + legendes photos avant de flusher /*$censure = $this->container->get('perso_galerieBundle.censure'); if ($censure->isVulgaire($text)) { } */ $em->persist($photo); $em->flush(); return $this->redirect($this->generateUrl('perso_galerie_homepage')); } } return $this->render('PersoGalerieBundle:Galerie:addPhoto.html.twig', array('form' => $form->createView())); }