Exemple #1
0
 /**
  * @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");
 }
Exemple #2
0
 /**
  * @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()]);
     }
 }
Exemple #3
0
 /**
  * @param Post $post
  * @param \LKE\UserBundle\Entity\User $user
  * @return bool
  */
 protected function canView($post, $user)
 {
     return $post->isPublished();
 }