Exemple #1
0
 public function newAction(Request $request)
 {
     $task = new Task();
     // dummy code - this is here just so that the Task has some tags
     // otherwise, this isn't an interesting example
     $tag1 = new Tag();
     $tag1->setName('tag1');
     $tag1->addTask($task);
     $task->getTags()->add($tag1);
     $form = $this->createForm(TaskType::class, $task, array('roles' => 1));
     $form->handleRequest($request);
     //        $tags = $description->getTa
     if ($form->isValid()) {
         $data = $form->getData();
         $description = $data->getDescription();
         $tags = new ArrayCollection();
         $tags = $data->getTags();
         foreach ($tags as $tag) {
             $tag->addTask($description);
         }
         $em = $this->getDoctrine()->getManager();
         $em->persist($tag);
         $em->flush();
     }
     return $this->render('AppBundle:Task:new.html.twig', array('form' => $form->createView()));
 }
 public function load(ObjectManager $manager)
 {
     $liste = array('maths', 'symfony', 'robotique', 'auto-hébergement', 'serveur', 'mail', 'outil');
     foreach ($liste as $nom) {
         $tag = new Tag();
         $tag->setName($nom);
         $manager->persist($tag);
         $manager->flush();
     }
 }
Exemple #3
0
 public function load(ObjectManager $manager)
 {
     $tags = ['company', 'home', 'important'];
     foreach ($tags as $tag) {
         $obj = new Tag();
         $obj->setName($tag);
         $manager->persist($obj);
         $this->addReference('tag:' . $tag, $obj);
     }
     $manager->flush();
 }
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $names = array('volutpat', 'enim', 'bibendum', 'augue', 'ullamcorper', 'lacinia', 'imperdiet', 'finibus', 'pellentesque', 'libero', 'uspendisse', 'ultricies', 'lacus', 'aliquam', 'eumassa', 'utnunc', 'gravida', 'blandit', 'idvitae', 'quam', 'maecenas', 'eget', 'justo', 'etiam', 'consectetur', 'facilisis');
     foreach ($names as $name) {
         $tag = new Tag();
         $tag->setName($name);
         $manager->persist($tag);
         $this->setReference('tag-' . $name, $tag);
     }
     $manager->flush();
 }
 public function load(ObjectManager $manager)
 {
     $tag = new Tag();
     $tag->setName('Photo');
     $manager->persist($tag);
     $anotherTag = new Tag();
     $anotherTag->setName('Second');
     $manager->persist($anotherTag);
     $photo = $this->getReference('photo');
     $photo->addTag($tag);
     $photo->addTag($anotherTag);
     $manager->flush();
 }
Exemple #6
0
 public function load(ObjectManager $manager)
 {
     $task = new Task();
     $task->setDescription('task one');
     // dummy code - this is here just so that the Task has some tags
     // otherwise, this isn't an interesting example
     $tag1 = new Tag();
     $tag1->setName('tag1');
     $tag1->addTask($task);
     $task->getTags()->add($tag1);
     $manager->persist($task);
     $manager->flush();
 }
 /**
  * Adds tags to photo.
  *
  * @param Photo $photo
  * @param array $tags
  */
 public function addTagsToPhoto(Photo $photo, array $tags)
 {
     $photo->removeTags();
     $em = $this->getEntityManager();
     foreach ($tags as $name) {
         $tag = $this->findOneBy(['name' => $name]);
         if (!$tag instanceof Tag) {
             $tag = new Tag();
             $tag->setName($name);
             $em->persist($tag);
             $em->flush();
         }
         $photo->addTag($tag);
     }
 }
 public function testSubmitValidData()
 {
     $formData = array('name' => 'test');
     $form = $this->factory->create(TagType::class);
     $object = new Tag();
     $object->setName('test');
     $form->submit($formData);
     $this->assertTrue($form->isSynchronized());
     $this->assertEquals($object, $form->getData());
     $view = $form->createView();
     $children = $view->children;
     foreach (array_keys($formData) as $key) {
         $this->assertArrayHasKey($key, $children);
     }
 }
 public function load(ObjectManager $manager)
 {
     $featured = new Tag();
     $featured->setName("Featured");
     $manager->persist($featured);
     $important = new Tag();
     $important->setName("Important");
     $manager->persist($important);
     $new = new Tag();
     $new->setName("New");
     $manager->persist($new);
     $openSource = new Tag();
     $openSource->setName("Open Source");
     $manager->persist($openSource);
     $manager->flush();
 }
Exemple #10
0
 /**
  * @Route("/tags.json", name="tags_new")
  * @Method("POST")
  */
 public function newAction(Request $request)
 {
     $name = $request->get('name');
     $repeated = $this->getDoctrine()->getRepository('AppBundle:Tag')->findOneByName($name);
     if (!$repeated) {
         if (!empty($name)) {
             $tag = new Tag();
             $tag->setName($name);
             $this->getDoctrine()->getManager()->persist($tag);
             $this->getDoctrine()->getManager()->flush();
             return new JsonResponse(['status' => true, 'message' => 'Etiqueta creada']);
         }
     } else {
         return new JsonResponse(['status' => false, 'message' => 'La etiqueta ya existe']);
     }
     return new JsonResponse();
 }
Exemple #11
0
 /**
  * Transforms a string to a tag list.
  *
  * @param  string $csvTags
  * @return Tags|null
  */
 public function reverseTransform($csvTags)
 {
     if (!$csvTags) {
         return [];
     }
     $output = [];
     $tags_array = explode(',', $csvTags);
     foreach ($tags_array as $tagName) {
         $tagName = trim($tagName);
         $tag = $this->em->getRepository('AppBundle:Tag')->findOneBy(['name' => $tagName]);
         if (!$tag) {
             $tag = new Tag();
             $tag->setName($tagName);
             $this->em->persist($tag);
         }
         $output[] = $tag;
     }
     return $output;
 }
 /**
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  * @Route("/new-task")
  */
 public function newAction(Request $request)
 {
     $task = new Task();
     // dummy code - this is here just so that the Task has some tags
     // otherwise, this isn't an interesting example
     $tag1 = new Tag();
     $tag1->setName('tag1');
     $task->getTags()->add($tag1);
     $tag2 = new Tag();
     $tag2->setName('tag2');
     $task->getTags()->add($tag2);
     // end dummy code
     $form = $this->createForm(new TaskType(), $task);
     $form->handleRequest($request);
     if ($form->isValid()) {
         // ... maybe do some form processing, like saving the Task and Tag objects
         $em = $this->getDoctrine()->getManager();
         $task = $form->getData();
         $em->persist($task);
         $em->flush();
     }
     return $this->render('new.html.twig', array('form' => $form->createView()));
 }
 /**
  * {@inheritDoc}
  */
 public function setName($name)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setName', array($name));
     return parent::setName($name);
 }
 /**
  * @Route("/ajax/bookmark/create", name="ajax_create_bookmark")
  */
 public function ajaxCreateAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $repository = $em->getRepository('AppBundle:Bookmark');
     $tagRepository = $em->getRepository('AppBundle:Tag');
     $openGraph = $this->container->get('open_graph');
     $url = $request->request->get('url');
     $tags = $request->request->get('tags');
     $user = $this->get('security.context')->getToken()->getUser();
     if (!$url) {
         $data = array('error' => 'invalid_url', 'errorMsg' => 'URL is required');
         $json = \json_encode($data);
         $response = new Response($json, 404);
         $response->headers->set('Content-Type', 'application/json');
         return $response;
     }
     $tags = explode(',', $tags);
     try {
         $data = $openGraph->read($url);
     } catch (RequestException $e) {
         $context = $e->getHandlerContext();
         $data = array('error' => 'invalid_url');
         if (isset($context['error'])) {
             $data['errorMsg'] = $context['error'];
         }
         $json = \json_encode($data);
         $response = new Response($json, 404);
         $response->headers->set('Content-Type', 'application/json');
         return $response;
     } catch (ConnectException $e) {
         $data = array('error' => 'invalid_page', 'exception' => $e->getMessage());
         $json = \json_encode($data);
         $response = new Response($json, 404);
         $response->headers->set('Content-Type', 'application/json');
         return $response;
     } catch (\Exception $e) {
         $data = array('error' => 'exception', 'exception' => $e->getMessage());
         $json = \json_encode($data);
         $response = new Response($json, 500);
         $response->headers->set('Content-Type', 'application/json');
         return $response;
     }
     $title = $data['title'];
     $description = $data['description'];
     if (isset($data['og:title']) && $data['og:title']) {
         $title = $data['og:title'];
     }
     if (isset($data['og:description']) && $data['og:description']) {
         $description = $data['og:description'];
     }
     $bookmark = new Bookmark();
     $bookmark->setUrl($url);
     $bookmark->setTitle($title);
     $bookmark->setUser($user);
     $bookmark->setDescription($description);
     if (isset($data['og:image'])) {
         $bookmark->setImage($data['og:image']);
     }
     $bookmarkTags = array();
     foreach ($tags as $tagName) {
         $tag = new Tag();
         $tag->setName($tagName);
         $tag->setUser($user);
         $em->persist($tag);
         $bookmarkTags[] = $tag;
     }
     $bookmark->setTags($bookmarkTags);
     $em->persist($bookmark);
     $em->flush();
     $normalizer = new ObjectNormalizer();
     $normalizer->setCircularReferenceHandler(function ($object) {
         return $object->getId();
     });
     $json = \json_encode($bookmark);
     $response = new Response($json);
     $response->headers->set('Content-Type', 'application/json');
     return $response;
 }