/** * @Route("/create", name="create_objects") * * @Rest\View() * * @return Response */ public function createAction() { // We need an entity manager here $em = $this->getDoctrine()->getManager(); // First, we try to create a post $post = new Post(); $post->setTitle('Hello World'); $post->setContent('This is a hello world post'); $post->setCreated(new \DateTime()); $em->persist($post); // Create new post log object $postLog = new PostLog(); $postLog->setMessage('A new post was created'); $postLog->setCreated(new \DateTime()); $postLog->setParent($post); $em->persist($postLog); // Try to create a category $category = new Category(); $category->setTitle('A Category'); $category->setDescription('A category to created'); $em->persist($category); // Create new category log object $categoryLog = new CategoryLog(); $categoryLog->setMessage('A new category was created'); $categoryLog->setCreated(new \DateTime()); $categoryLog->setParent($category); $em->persist($categoryLog); // Actually store all the entities to the database // to get id of the post and the category $em->flush(); return ['Done']; }
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(); }
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>'); }
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(); }
/** * @test * @expectedException \InvalidArgumentException */ public function throws_an_exception_when_adding_a_category_whose_name_already_exists_in_the_activity() { $defaultCategory = (new Category())->setTitle('default'); $activity = new Activity($defaultCategory); $duplicateCategory = new Category(); $duplicateCategory->setTitle('default'); $activity->addCategory($duplicateCategory); }
/** * @test * @expectedException \InvalidArgumentException */ public function throws_an_exception_when_adding_a_child_whose_name_already_exists_in_its_children() { $category = new Category(); $child = (new Category())->setTitle('foo'); $duplicate = (new Category())->setTitle('foo'); $category->addChild($child); $category->addChild($duplicate); }
protected function createCategory($name) { $category = new Category(); $category->setName($name); $this->getEntityManager()->persist($category); $this->getEntityManager()->flush(); return $category; }
/** * @Route("/show_category/{slug}", name="show_category") * @ParamConverter("category", class="AppBundle\Entity\Category", options={"mapping": {"slug": "title"}}) */ public function showCategoryAction(Request $request, Category $category) { $em = $this->getDoctrine()->getManager(); $estates = $em->getRepository('AppBundle\\Entity\\Estate')->getEstateFromCategory($category->getTitle()); $paginator = $this->get('knp_paginator'); $pagination = $paginator->paginate($estates, $request->query->getInt('page', 1), 5); $this->container->get('app.breadcrumps_maker')->makeBreadcrumps($category); return $this->render("AppBundle::site/index.html.twig", array('pagination' => $pagination)); }
/** * @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()))); }
/** * @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()); }
private function createAndPersistCategory($label, $parentCategory = null) { $this->categoriesCount++; $category = new Category(); $category->setLabel($label)->setParentCategory($parentCategory); $this->manager->persist($category); $this->setReference(sprintf('category_%s', $this->categoriesCount), $category); return $category; }
/** * @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(); }
/** * @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; }
/** * @param Category $category * @param $limit * @param $page * @return \Doctrine\ORM\QueryBuilder */ public function getPostsByCategoryQuery(Category $category, $limit, $page) { $query = $this->createQueryBuilder('p'); $categoriesIds[] = $category->getId(); $categories = $category->getChildren(); foreach ($categories as $cat) { $categoriesIds[] = $cat->getId(); } return $query->select('p')->where($query->expr()->eq('p.isPublished', true))->andWhere($query->expr()->in('p.category', $categoriesIds))->orderBy('p.updated', 'DESC')->setMaxResults($limit)->setFirstResult($page); }
/** * {@inheritdoc} */ public function load(ObjectManager $manager) { $categories = array('Apéritif', 'Entrée', 'Sur le pouce', 'Pâtes', 'Plats', 'Desserts'); foreach ($categories as $pos => $name) { $category = new Category(); $category->setPosition($pos + 1)->setName($name); $manager->persist($category); } $manager->flush(); }
/** * @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; }
/** * @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); } }
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(); }
private function createAndPersistProducts(Category $category) { for ($i = 1; $i <= $this->productsPerCategory; $i++) { $this->productsCount++; $product = new Product(); $product->setCode(sprintf('code_%s_%s', $category->getId(), $i))->setTitle(sprintf('title %s %s %s', $category->getId(), $i, uniqid()))->setDescription(sprintf('product description %s', $i)); $category->addProduct($product); $this->manager->persist($product); $this->setReference(sprintf('product_%s', $this->productsCount), $product); } }
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(); } }
/** * @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())); }
/** * {@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(); }
/** * @Route("/category/create") */ public function createActionCategory() { $category = new Category(); $category->setCategoryName('A Foo Bar'); $em = $this->getDoctrine()->getManager(); $em->persist($category); $em->flush(); $categoryArray[] = $category->getId(); $categoryArray[] = $category->getcategoryName(); return new Response(json_encode($categoryArray)); }
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'); }
/** * @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()); }
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); }
/** * @Route("/categorie/{id}/question/ajouter", name="question_add") */ public function addAction(Request $request, Category $category) { $question = new Question(); $category->addQuestion($question); $form = $this->createForm(new QuestionType(), $question); $form->handleRequest($request); if ($form->isValid() && $form->isSubmitted()) { $em = $this->getDoctrine()->getEntityManager(); $em->persist($question); $em->flush(); return $this->redirect($this->generateUrl('category_show', ['id' => $category->getId()])); } return $this->render(':question:add.html.twig', ['form' => $form->createView()]); }
/** * @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); }
/** * @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); } }
public function testSubmitValidData() { $formData = array('title' => 'Test title'); $form = $this->factory->create(CategoryType::class); $object = new Category(); $object->setTitle('Test title'); $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); } }