/** * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { $em = $this->getContainer()->get('doctrine')->getManager(); $parser = $this->getContainer()->get('lke_core.parse_csv'); $rows = $parser->parse(self::FILE); foreach ($rows as $row) { $post = new Post(); $post->setTitle($row[self::TITLE]); $post->setContent($row[self::CONTENT]); $post->setPublishedAt($this->getDateTime($row[self::PUBLISHED_AT])); $post->setAuthor($this->getAuthor($row[self::AUTHOR])); $post->setCategory($this->getCategory($row[self::CATEGORY])); $post->setImage($this->getImage($row[self::IMAGE])); $tagsId = explode(';', $row[self::TAGS]); foreach ($tagsId as $tagId) { $tag = $this->getTag($tagId); if (!is_null($tag)) { $post->addTag($this->getTag($tagId)); } } $em->persist($post); } $em->flush(); $output->writeln("Posts loaded"); }
/** * @param Request $request * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response */ public function addAction(Request $request) { $post = new Post(); $post->setAuthor($this->getUser()); $form = $this->generateForm($post, $request); if ($this->processForm($form, $post)) { $this->addSuccess('lkeadmin.success.post.add'); return $this->redirectToRoute('lke_admin_index'); } else { return $this->render('LKEAdminBundle:Post:add.html.twig', ['form' => $form->createView()]); } }