protected function execute(InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getHelper('question');
     $question = new ConfirmationQuestion('Are you sure you want to import symfony pack questions into the database ?', false);
     if (!$helper->ask($input, $output, $question)) {
         return;
     }
     $output->writeln('<info>=== Importing Symfony Pack Questions ===</info>');
     $yaml = new Parser();
     $filesToParse = ['architecture', 'automated-tests', 'bundles', 'cache-http', 'command-line', 'controllers', 'dependency-injection', 'forms', 'http', 'misc', 'php', 'routing', 'security', 'standardization', 'symfony3', 'templating', 'validation'];
     $em = $this->getContainer()->get('doctrine.orm.entity_manager');
     foreach ($filesToParse as $fileName) {
         $file = $yaml->parse(file_get_contents('app/Resources/symfony-pack-questions/' . $fileName . '.yml'));
         $category = new Category();
         $category->setName($file['category']);
         $em->persist($category);
         foreach ($file['questions'] as $question) {
             $questionEntity = new Question();
             $questionEntity->setCategory($category);
             $questionEntity->setStatement($question['question']);
             $em->persist($questionEntity);
             foreach ($question['answers'] as $answer) {
                 $answerEntity = new Answer();
                 $answerEntity->setStatement($answer['value']);
                 $answerEntity->setVeracity($answer['correct']);
                 $answerEntity->setQuestion($questionEntity);
                 $em->persist($answerEntity);
             }
         }
     }
     $em->flush();
     $output->writeln('<info>=== Import of Symfony Pack Questions Successful ===</info>');
 }
Exemplo n.º 2
0
 public function load(ObjectManager $manager)
 {
     // TODO: Implement load() method.
     $category = new Category();
     $category->setName('Default');
     $manager->persist($category);
     foreach (range(1, 100) as $i) {
         $post = new Post();
         $post->setTitle($this->getPostTitle());
         $post->setSlug($this->container->get('slugger')->slugify($post->getTitle()));
         $post->setImage('post.jpeg');
         $post->setContent($this->getPostContent());
         $post->setAuthor('gunyem');
         $post->setCreated(new \DateTime('now - ' . $i . 'days'));
         $post->setUpdated(new \DateTime('now - ' . $i . 'days'));
         $post->setCategory($category);
         foreach (range(1, 10) as $j) {
             $comment = new Comment();
             $comment->setPost($post);
             $comment->setContent($this->getPostTitle());
             $comment->setAuthor('gunyem');
             $comment->setCreated(new \DateTime('now + ' . ($i + $j) . 'seconds'));
             $manager->persist($comment);
             $post->createComment($comment);
         }
         $manager->persist($post);
     }
     $manager->flush();
 }
Exemplo n.º 3
0
 private function loadPosts(ObjectManager $manager)
 {
     $category = new Category();
     $category->setName('Improvements');
     foreach (range(1, 5) as $i) {
         $post = new Post();
         $post->setTitle($this->getRandomPostTitle());
         $post->setSummary($this->getRandomPostSummary());
         $post->setSlug($this->container->get('slugger')->slugify($post->getTitle()));
         $post->setContent($this->getPostContent());
         $post->setAuthorEmail('*****@*****.**');
         $post->setPublishedAt(new \DateTime('now - ' . $i . 'days'));
         $post->setState($this->getRandomState());
         $post->setCategory($category);
         foreach (range(1, 5) as $j) {
             $comment = new Comment();
             $comment->setAuthorEmail('*****@*****.**');
             $comment->setPublishedAt(new \DateTime('now + ' . ($i + $j) . 'seconds'));
             $comment->setContent($this->getRandomCommentContent());
             $comment->setPost($post);
             $manager->persist($comment);
             $post->addComment($comment);
         }
         if (rand(0, 1)) {
             $vote = new Vote();
             $vote->setAuthorEmail(rand(0, 1) ? '*****@*****.**' : '*****@*****.**');
             $vote->setPost($post);
             $vote->setVote(rand(0, 1));
         }
         $manager->persist($post);
         $category->addPost($post);
     }
     $manager->flush();
 }
Exemplo n.º 4
0
 protected function createCategory($name)
 {
     $category = new Category();
     $category->setName($name);
     $this->getEntityManager()->persist($category);
     $this->getEntityManager()->flush();
     return $category;
 }
Exemplo n.º 5
0
 /**
  * @Route("{_locale}/category/create/{name}", name="category_create")
  *  requirements={
  *     "name": "[A-Za-z0-9\s-]+",
  */
 public function createAction($name)
 {
     $category = new Category();
     $category->setName($name);
     $em = $this->getDoctrine()->getManager();
     $em->persist($category);
     $em->flush();
     return $this->render('dws/message.html.twig', array('message' => sprintf("Categoría %s(%d) creado!!", $category->getName(), $category->getId())));
 }
Exemplo n.º 6
0
 /**
  * @Route("/create-category", name="create-category")
  */
 public function createCategoryAction(Request $request)
 {
     $post = new Category();
     $post->setName('Nueva Categoria');
     $em = $this->getDoctrine()->getManager();
     $em->persist($post);
     $em->flush();
     return new Response('Created category id ' . $post->getId());
 }
Exemplo n.º 7
0
 /**
  * @param ObjectManager $manager
  */
 protected function loadCategories(ObjectManager $manager)
 {
     $categories = ['Fika', 'Bada', 'Symfony'];
     foreach ($categories as $i => $categoryName) {
         $category = new Category();
         $category->setName($categoryName);
         $manager->persist($category);
         $this->addReference(sprintf('category-%s', $i), $category);
     }
 }
Exemplo n.º 8
0
 /**
  * @param string $name
  * @return Category
  */
 public function addCategory($name)
 {
     $category = $this->getCategory($name);
     if ($category == null) {
         $category = new Category();
         $category->setName($name);
         $this->em->persist($category);
     }
     return $category;
 }
Exemplo n.º 9
0
 /**
  * @Route(path="/{id}")
  * @Method("PUT")
  */
 public function updateAction(Category $category, Request $request)
 {
     $data = $this->get('serializer')->decode($request->getContent(), JsonEncoder::FORMAT);
     $em = $this->getDoctrine()->getManager();
     $category->setName($data['name']);
     $em->flush();
     $response = new JsonResponse($this->get('serializer')->normalize($category), JsonResponse::HTTP_OK);
     $response->headers->set('Location', $this->generateUrl('app_api_category_show', ['id' => $category->getId()]));
     return $response;
 }
Exemplo n.º 10
0
 /**
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $category = new Category();
     $category->setName('First category');
     $manager->persist($category);
     $category = new Category();
     $category->setName('Second category');
     $manager->persist($category);
     $manager->flush();
 }
Exemplo n.º 11
0
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $names = array('Vestibulum', 'Dolorem', 'Nostrud', 'Reprehenderit', 'Excepteur');
     foreach ($names as $name) {
         $category = new Category();
         $category->setName($name);
         $manager->persist($category);
         $this->setReference('category-' . $name, $category);
     }
     $manager->flush();
 }
Exemplo n.º 12
0
 /**
  * @Route("/category", name="category_main")
  * @param Request $request
  * @return Response
  */
 public function indexAction(Request $request)
 {
     $form = $this->createForm(new CategoryType());
     $form->handleRequest($request);
     if ($form->isValid()) {
         $category = new Category();
         $category->setName($form['category_name']->getData());
         $this->get('category_manager')->save($category);
     }
     return $this->render('Category/category-main.html.twig', array('form' => $form->createView()));
 }
Exemplo n.º 13
0
 public function load(ObjectManager $manager)
 {
     $faker = \Faker\Factory::create();
     for ($i = 1; $i <= 100; $i++) {
         $category = new Category();
         $category->setName(ucfirst($faker->sentence(2)));
         $manager->persist($category);
         $this->addReference('category-' . $i, $category);
     }
     $manager->flush();
 }
Exemplo n.º 14
0
 public function load(ObjectManager $manager)
 {
     static $list = array('Tournois Multijoueurs' => 'multi', 'Tournois Solos' => 'solo', 'Jeux Libres' => 'libre', 'Autre' => 'autre');
     foreach ($list as $name => $systname) {
         $category = new Category();
         $category->setName($name);
         $category->setSystName($systname);
         $manager->persist($category);
         $manager->flush();
     }
 }
Exemplo n.º 15
0
 /**
  * @Route("/create", name="create")
  */
 public function createAction()
 {
     $category = new Category();
     $category->setName('Apparel Women');
     $product = new Product();
     $product->setAliProductId('32251240493')->setAliProductTitle('DL vestido de renda 2016 Navy Lace Satin Patchwork Party Maxi Dress LC6809 dress party evening elegant vestido longo festa noite')->setCategory($category)->setAliProductUrl('productUrl')->setAliSalePrice('US $16.99')->setAli30DaysCommission('30daysCommission')->setAliVolume('volume')->setAliCategoryId('3')->setAliAffiliateUrl('promotionUrl')->setNumReviews('92')->setNumReviewPages('10')->setDateOfLatestReview(strtotime('07 Jan 2016 19:19'))->setDateLastCrawled(strtotime('01 Jan 2016 00:19'));
     $em = $this->getDoctrine()->getManager();
     $em->persist($product);
     $em->persist($category);
     $em->flush();
     return new Response('Created product id ' . $product->getId() . ' and category id ' . $category->getId());
 }
Exemplo n.º 16
0
 public function createAction($name)
 {
     // Creamos el objeto category
     $category = new Category();
     $category->setName($name);
     // asignamos su nombre
     // Alamcenamos en la base de datos
     $em = $this->getDoctrine()->getManager();
     $em->persist($category);
     $em->flush();
     return new Response('Categoría ' . $category->getName() . ' ' . ' creada correctamente');
 }
 public function load(ObjectManager $manager)
 {
     $category = new Category();
     $category->setName('Landscape');
     $manager->persist($category);
     $manager->flush();
     $this->addReference('landscape', $category);
     $category = new Category();
     $category->setName('Urbanism');
     $manager->persist($category);
     $manager->flush();
     $this->addReference('urbanism', $category);
 }
Exemplo n.º 18
0
 /**
  * @param ObjectManager $manager
  */
 protected function loadCategories(ObjectManager $manager)
 {
     $categories = ['Dans' => ['en' => 'Dancing'], 'Djur och Natur' => ['en' => 'Animals and nature'], 'Familj' => ['en' => 'Family'], 'Fika' => ['en' => 'Film/ TV'], 'Film' => ['en' => 'Literature'], 'Konst' => ['en' => 'Cooking'], 'Matlagning' => ['en' => 'Music'], 'Musik' => ['en' => 'Politics'], 'Politik' => ['en' => 'Go for a walk'], 'Resor' => ['en' => 'Travelling'], 'Sport' => ['en' => 'Sport'], 'Träning' => ['en' => 'Training']];
     $i = 0;
     $repository = $manager->getRepository('Gedmo\\Translatable\\Entity\\Translation');
     foreach ($categories as $categoryName => $translations) {
         $category = new Category();
         $category->setName($categoryName);
         foreach ($translations as $locale => $translation) {
             $repository->translate($category, 'name', $locale, $translation);
         }
         $manager->persist($category);
         $this->addReference(sprintf('category-%s', $i++), $category);
     }
 }
Exemplo n.º 19
0
 public function createAction()
 {
     $category = new Category();
     $category->setName('Good stuff');
     $product = new Product();
     $product->setName('Brown stuff');
     $product->setPrice('9.99');
     $product->setDescription('Coffee from Kenya');
     $product->setCategory($category);
     $em = $this->getDoctrine()->getManager();
     $em->persist($category);
     $em->persist($product);
     $em->flush();
     return new Response('Created product id ' . $product->getId() . ' and category id ' . $category->getId());
 }
Exemplo n.º 20
0
 /**
  * @Route("/ajax", name="AppBundle_ajax_update", options={"expose"=true})
  */
 public function ajaxAction(Request $request)
 {
     $postData = $request->request->get('data1');
     if (!$postData) {
         $response = array("code" => 500, "success" => false);
         return new JsonResponse($response);
     }
     $category = new Category();
     $category->setName($postData);
     $em = $this->getDoctrine()->getManager();
     $em->persist($category);
     $em->flush();
     $response = array("code" => 100, "success" => true);
     return new JsonResponse($response);
 }
Exemplo n.º 21
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     /*for ($i=0; $i < 9; $i++) {
                 $category = new Category();
                 $category->setName($this->genstr(rand(2,5)));
                 $manager->persist($category);
                 $parent1 = $category;
                 for ($l=0; $l < rand(1,4); $l++) { 
                     $product = $this->generateProduct();
                     $product->setCategory($category);
                     $manager->persist($product);
                 }
     
                 for ($j=0; $j < rand(4, 7); $j++) {
                     $category = new Category();
                     $category->setName($this->genstr(rand(2,5)));
                     $category->setParent($parent1);
                     $manager->persist($category);
                     $parent2 = $category;
                     for ($l=0; $l < rand(1,4); $l++) { 
                         $product = $this->generateProduct();
                         $product->setCategory($category);
                         $manager->persist($product);
                     }
     
                     for ($k=0; $k < rand(4, 7); $k++) {
                         $category = new Category();
                         $category->setName($this->genstr(rand(2,5)));
                         $category->setParent($parent2);
                         $manager->persist($category);
                         for ($l=0; $l < rand(1,4); $l++) { 
                             $product = $this->generateProduct();
                             $product->setCategory($category);
                             $manager->persist($product);
                         }
                     }
                 }
             }*/
     for ($i = 0; $i < 9; $i++) {
         $category = new Category();
         $category->setName('分类' . $i);
         $manager->persist($category);
         $product = $this->generateProduct();
         $product->setCategory($category);
         $manager->persist($product);
     }
     $manager->flush();
 }
Exemplo n.º 22
0
 public function load(ObjectManager $manager)
 {
     $symbonfy_base_dir = $this->container->getParameter('kernel.root_dir');
     $data_dir = $symbonfy_base_dir . '/Resources/data/';
     $fd = fopen($data_dir . 'categories.csv', "r");
     if ($fd) {
         while (($data = fgetcsv($fd)) !== false) {
             $category = new Category();
             $category->setName($data[0]);
             $manager->persist($category);
             $this->addReference($data[0], $category);
         }
         fclose($fd);
     }
     $manager->flush();
 }
 /**
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     for ($i = 0; $i < 2; $i++) {
         $category = new Category();
         $category->setName('Catégorie ' . $i);
         $category->setSlug($category->getName());
         $category->setContent($this->categoryContent[$i]);
         $category->setPictureName('default-image-' . $i . '.jpg');
         $manager->persist($category);
         // Reference added once
         if ($i == 0) {
             $this->addReference('category', $category);
         }
     }
     $manager->flush();
 }
Exemplo n.º 24
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $category1 = new Category();
     $category1->setName('Masculino');
     $category2 = new Category();
     $category2->setName('Roupas');
     $category3 = new Category();
     $category3->setName('Beleza');
     $manager->persist($category1);
     $manager->persist($category2);
     $manager->persist($category3);
     $manager->flush();
     $this->addReference('category1', $category1);
     $this->addReference('category2', $category2);
     $this->addReference('category3', $category3);
 }
Exemplo n.º 25
0
 /**
  * Relation controller.
  *
  * @Route("/relation")
  */
 public function relationAction()
 {
     $category = new Category();
     $category->setName('Prodotti principali');
     $product = new Product();
     $product->setName('Test');
     $product->setPrice(19.99);
     $product->setDescription('prodotto di test');
     // correlare questo prodotto alla categoria
     $product->setCategory($category);
     $em = $this->getDoctrine()->getManager();
     $em->persist($category);
     $em->persist($product);
     $em->flush();
     return new Response('Creati prodotto con id: ' . $product->getId() . ' e categoria con id: ' . $category->getId());
 }
 /**
  * @Route("/db/create_relationship/")
  * @return Response
  */
 public function createProductAction()
 {
     $category = new Category();
     $category->setName('Main Products');
     $product = new Product();
     $product->setName('Foo');
     $product->setPrice(19.99);
     $product->setDescription('Lorem ipsum dolor');
     // relate this product to the category
     $product->setCategory($category);
     $em = $this->getDoctrine()->getManager();
     $em->persist($category);
     $em->persist($product);
     $em->flush();
     return new Response('Created product id: ' . $product->getId() . ' and category id: ' . $category->getId());
 }
Exemplo n.º 27
0
 /**
  * @Route("/test-form", name="test-form")
  */
 public function newAction(Request $request)
 {
     // create a task and give it some dummy data for this example
     $category = new Category();
     $category->setName('Write a blog post');
     $form = $this->createFormBuilder($category)->add('name', TextType::class)->add('save', SubmitType::class, array('label' => 'Create Category'))->getForm();
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         // ... perform some action, such as saving the task to the database
         echo "<pre>";
         print_r($request);
         echo "</pre>";
         exit;
         return $this->redirectToRoute('task_success');
     }
     return $this->render('AppBundle:test-form:new.html.twig', array('form' => $form->createView()));
 }
Exemplo n.º 28
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $categoryData = ['sport' => ['soccer_ball', 'tennis', 'billiards', 'skiing'], 'make_up' => ['perfume', 'pomade', 'powder', 'shampoo'], 'clothes' => ['dresses', 'costumes', 'coat', 'hats'], 'mobile' => ['smartphone', 'flash_drive', 'camera', 'the_tablet']];
     foreach ($categoryData as $categoryName => $productList) {
         $category = new Category();
         $category->setName($categoryName);
         $manager->persist($category);
         $manager->flush();
         foreach ($productList as $productName) {
             $product = new Product();
             $product->setName($productName);
             $manager->persist($product);
             $manager->flush();
             $category->addProduct($product);
         }
     }
 }
Exemplo n.º 29
0
 public function load(ObjectManager $manager)
 {
     foreach (range(0, 9) as $i) {
         $category = new Category();
         $category->setName('Category #' . $i);
         $this->addReference('category-' . $i, $category);
         $manager->persist($category);
     }
     $manager->flush();
     foreach (range(0, 99) as $i) {
         $category = new Category();
         $category->setName('Subcategory #' . $i);
         $category->setParent($this->getReference('category-' . $i % 10));
         $this->addReference('subcategory-' . $i, $category);
         $manager->persist($category);
     }
     $manager->flush();
 }
Exemplo n.º 30
0
 public function load(ObjectManager $manager)
 {
     $category1 = new Category();
     $category1->setName("Android and API");
     $this->addReference('category_1', $category1);
     $manager->persist($category1);
     $category2 = new Category();
     $category2->setName("Elasticsearch");
     $this->addReference('category_2', $category2);
     $manager->persist($category2);
     $category3 = new Category();
     $category3->setName("Symfony2");
     $this->addReference('category_3', $category3);
     $manager->persist($category3);
     $category4 = new Category();
     $category4->setName("Java");
     $this->addReference('category_4', $category4);
     $manager->persist($category4);
     $manager->flush();
 }