public function reverseTransform($string) { if (!$string) { return; } $tags = new ArrayCollection(); foreach (explode(',', $string) as $tagTitle) { $tag = $this->om->getRepository('AppBundle:Tag')->findOneByTitle($tagTitle); if (!$tag && ($tagTranslation = $this->om->getRepository('AppBundle:Translations\\TagTranslation')->findOneByContent($tagTitle))) { $tag = $tagTranslation->getObject(); } if (!$tag) { $tag = new Tag(); $tag->setTitle($tagTitle); $tag->setLocale($this->defaultLocale); foreach ($this->localeCollection as $locale) { if ($locale !== $this->defaultLocale) { $tagTranslation = new TagTranslation(); $tagTranslation->setLocale($locale); $tagTranslation->setField('title'); $tagTranslation->setContent($tagTitle); $tagTranslation->setObject($tag); $tag->addTranslation($tagTranslation); $this->om->persist($tagTranslation); } } $this->om->persist($tag); } $tags->add($tag); } return $tags; }
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) { // $tag = new Tag(); // $tag->setTitle('Frontend'); // $tag->setDescription('CSS and JS'); // $manager->persist($tag); // $manager->flush(); // // $tag = new Tag(); // $tag->setTitle('Backend'); // $tag->setDescription('PHP / C# / Java asf.'); // $manager->persist($tag); // $manager->flush(); $tag = new Tag(); $tag->setTitle('Framework'); $tag->setDescription('Symfony / Zend / Movico'); $manager->persist($tag); $manager->flush(); // $tag = new Tag(); // $tag->setTitle('Empty Tag'); // $tag->setDescription('Empty / Tag'); // $manager->persist($tag); // $manager->flush(); // $userAdmin = new User(); // $userAdmin->setUsername('admin'); // $userAdmin->setPassword('test'); // // $manager->persist($userAdmin); // $manager->flush(); }
/** * @Route("/ajax", name="oktothek_tag_ajax") * @Method({"GET", "POST"}) */ public function ajaxTagAction(Request $request) { if ($request->isXmlHttpRequest()) { $em = $this->getDoctrine()->getManager(); if ($request->getMethod() == "GET") { $tags = $em->getRepository('AppBundle:Tag')->findAll(); $json = []; foreach ($tags as $tag) { $json[] = $tag->getText(); } return new Response(json_encode($json)); } else { //Posts tag $action = $request->request->get('action'); if ($action = "add") { // add new tag $tag = $em->getRepository('AppBundle:Tag')->findOneBy(['text' => $request->request->get('text')]); if (!$tag) { $tag = new Tag(); $tag->setText($request->request->get('text')); $em->persist($tag); $em->flush(); } return new Response(); } else { // delete tag $tag = $em->getRepository('AppBundle:Tag')->findOneBy(['text' => $request->request->get('text')]); $em->remove($tag); $em->flush(); return new Response(); } } } return $this->redirect('oktothek_tag_index'); }
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(); } }
/** * {@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) { $tags = ['company', 'home', 'important']; foreach ($tags as $tag) { $obj = new Tag(); $obj->setName($tag); $manager->persist($obj); $this->addReference('tag:' . $tag, $obj); } $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(); }
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(); }
/** * @Route("/insert/tag", name="insert_tag") */ public function insertTagAction(Request $request) { $tag = new Tag(); $tag->setAdded(new \DateTime('now')); $tag->setAdminId($this->getUser()->getId()); $form = $this->createForm(TagType::class, $tag); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($tag); $em->flush(); return $this->redirectToRoute('insert_tag'); } $repository = $this->getDoctrine()->getRepository('AppBundle:Tag'); $tags = $repository->findAll(); return $this->render('tag/insert.html.twig', array('form' => $form->createView(), 'tags' => $tags)); }
/** * @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(); }
/** * @Route("/add/{type}", name="add_item") */ public function addItemAction($type, Request $request) { $repository = $this->getDoctrine()->getRepository('AppBundle:Item'); if (!$repository->setType($type)) { throw new \AppBundle\Exception\InvalidItemTypeException($type); } switch ($type) { case "restaurant": $item = new \AppBundle\Entity\Items\Restaurant(); case "doctor": $item = new \AppBundle\Entity\Items\Doctor(); } $tag = new Tag(); $tag->setContent("Test"); // $item->addTag($tag); $form = $this->createForm(ItemType::class, $item); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $item->setCreationDate(new \DateTime('now')); $item->setModificationDate(new \DateTime('now')); $item->setLocation(new Point($form->get('longitude')->getData(), $form->get('latitude')->getData())); //FIXME: This is a workaround, mapping should be automatical foreach ($form->get('tags') as $tag) { $t = new Tag(); $t->setType($tag->get('type')->getData()); $t->setContent($tag->get('content')->getData()); $t->setItem($item); $item->addTag($t); } $em = $this->getDoctrine()->getManager(); $em->persist($item); $em->flush(); return $this->redirectToRoute('display', array("id" => $item->getId())); /* return $this->render('add/' . $type . '.html.twig', [ 'form' => $form->createView(), 'item' => $item, ]); */ } else { return $this->render('add/' . $type . '.html.twig', ['form' => $form->createView()]); } }
public function reverseTransform($tagString) { $tagCollection = new ArrayCollection(); if (empty($tagString)) { return $tagCollection; } $slugify = new Slugify(); foreach (explode(',', $tagString) as $tag) { $tag = trim($tag); $tagSlugged = $slugify->slugify($tag); $tagEntity = $this->em->getRepository('AppBundle:Tag')->findOneBy(array('tag' => $tagSlugged)); if (!$tagEntity instanceof Tag) { $tagEntity = new Tag(); $tagEntity->setTag($tagSlugged); } $tagCollection->add($tagEntity); } return $tagCollection; }
/** * 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())); }
public function load(ObjectManager $manager) { $titles = ['sport', 'nature', 'fishing', 'finance', 'religion', 'hobby', 'gossip', 'technology', 'money', 'resorts']; //$faker = Factory::create(); for ($i = 0; $i < 10; $i++) { $tag = new Tag(); $tag->setTitle($titles[$i]); $manager->persist($tag); $manager->flush(); $arrayId = null; $arrayId = array(); while (count($arrayId) < rand(5, 13)) { $id = rand(1, 50); if (array_search($id, $arrayId) === false) { $arrayId[] = $id; $postFromBase = $this->getReference("{$id}"); $postFromBase->getTags()->add($tag); $tag->getPosts()->add($postFromBase); } } $manager->flush(); } }
/** * Extract tags in an Article * @param LifecycleEventArgs $args */ public function postPersist(LifecycleEventArgs $args) { $entity = $args->getEntity(); $em = $args->getEntityManager(); if (!$entity instanceof Article) { return; } $length = $this->setLimitFrequency($entity->getContent()); $tags = $this->extractTags($entity->getContent()); // Add Tags to an Article foreach ($tags as $key => $value) { // Check the frequency of the a given tag if ($value >= $length) { $tag = new Tag(); $tag->setSlug($key); $tag->setFrequency($value); $tag->addArticle($entity); $entity->addTag($tag); $em->persist($tag); $em->persist($entity); } } $em->flush(); }
public function load(ObjectManager $manager) { $faker = Factory::create(); $wordsExist = array(); for ($i = 1; $i <= 50; $i++) { $tag = new Tag(); do { $tag->setTitle($faker->word); } while (in_array($tag->getTitle(), $wordsExist)); $wordsExist[] = $tag->getTitle(); $slug = $this->container->get('app.slugger')->slugify($tag->getTitle()); $tag->setSlug($slug); $this->setReference("tag {$i}", $tag); $manager->persist($tag); } $manager->flush(); }
/** * @param Tag $tag * @return \Symfony\Component\Form\Form */ private function createDeleteTagForm(Tag $tag) { return $this->createFormBuilder()->setAction($this->generateUrl('delete-tag', array('id' => $tag->getId())))->setMethod('DELETE')->getForm(); }
/** * {@inheritDoc} */ public function getName() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getName', array()); return parent::getName(); }
/** * Creates a form to delete a Tag entity. * * @param Tag $tag The Tag entity * * @return \Symfony\Component\Form\Form The form */ private function createDeleteForm(Tag $tag) { return $this->createFormBuilder()->setAction($this->generateUrl('admin_tag_delete', array('id' => $tag->getId())))->setMethod('DELETE')->add('submit', SubmitType::class, ['label' => ' ', 'attr' => ['class' => 'glyphicon glyphicon-trash btn-link']])->getForm(); }
/** * Creates a form to delete a Post entity. * * @param Tag $tag The Tag entity * * @return \Symfony\Component\Form\Form The form */ private function createDeleteForm(Tag $tag) { return $this->createFormBuilder()->setAction($this->generateUrl('admin_tag_delete', array('id' => $tag->getId())))->setMethod('DELETE')->add('submit', SubmitType::class, ['label' => ' ', 'attr' => ['class' => 'btn btn-xs btn-danger ace-icon fa fa-trash-o bigger-120']])->getForm(); }
/** * @Route("/remove/{tag}", name="tag_remove",options={"expose"=true}) * @param Tag $tag * @ParamConverter("tag", class="AppBundle:Tag") * @return Response */ public function removeAction(Request $request, Tag $tag) { //todo send confimration message if ($tag->isRemovable()) { $em = $this->getDoctrine()->getEntityManager(); $em->remove($tag); $em->flush(); } return $this->redirect($this->generateUrl('tag_list')); }
/** * Add tags * * @param \AppBundle\Entity\Tag $tag * @return Post */ public function addTag($tag) { $this->tags[] = $tag; $tag->addPost($this); return $this; }
/** * @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; }
public function createTagDeleteForm(Tag $tag) { //$builder = $this->formFactory->createBuilder(); $form = $this->builder->setAction($this->router->generate('remove_tag', array('id' => $tag->getId())))->setMethod('DELETE')->add('submit', SubmitType::class, ['label' => ' ', 'attr' => ['class' => 'glyphicon glyphicon-trash btn-link']])->getForm(); return $form; }
/** * @Route("admin/edit/post/{slug}", name="edit_post") * @Template("@App/admin/editPost.html.twig") */ public function editPostAction(Request $request, $slug) { $em = $this->getDoctrine()->getManager(); $post = $em->getRepository('AppBundle:Post')->findOneBy(array('slug' => $slug)); if (!$post) { return $this->redirectToRoute('page404'); } $oldImage = $post->getPathImage(); $form = $this->createForm(PostType::class, $post); $form_delete_image = []; $form_delete_image[$post->getSlug()] = $this->createFormDeleteImage($post->getSlug())->createView(); $form->handleRequest($request); if ($form->isValid()) { $newTags = $post->getNewTags(); if (null !== $newTags) { $newTags = explode(',', trim($newTags)); foreach ($newTags as $item) { $tag = new Tag(); $tag->setTagName(trim($item)); $em->persist($tag); $post->addTag($tag); } } $newCategory = $post->getNewCategory(); if (null !== $newCategory) { $category = new Category(); $category->setCategoryName(trim($newCategory)); $em->persist($category); $post->setCategory($category); } $post->uploadImage(); $post->setNewTags(null); $post->setNewCategory(null); $em->flush(); $this->updateTagsCloud(); return $this->redirectToRoute('admin_show'); } return ['form' => $form->createView(), 'oldImage' => $oldImage, 'formDeleteImage' => $form_delete_image, 'slug' => $post->getSlug()]; }