예제 #1
0
 public function addAction()
 {
     $news = new News();
     $news->setTitle('заголовок ' . rand());
     $news->setText('Поц поц');
     $news->setSmallText('Поц');
     $em = $this->getDoctrine()->getManager();
     $em->persist($news);
     $em->flush();
     return $this->render('AppBundle:News:add.html.twig', array());
 }
예제 #2
0
 public function postNewsAction()
 {
     $entityManager = $this->get('doctrine.orm.entity_manager');
     $news = new News();
     $news->setTitle('Test');
     $news->setSlug('test');
     $news->setMarkup('ot bedzie długi tekst o pisanie na komputerze...');
     $news->setIdAuthor(140);
     $entityManager->persist($news);
     $entityManager->flush();
     $view = $this->view($news, 201);
     return $this->handleView($view);
 }
예제 #3
0
 /**
  * @Route("/api-add-news", name="add-news")
  * @Security("has_role('ROLE_ADMIN')")
  */
 public function addNewsAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $news = new News();
     $news->setTitle($request->get('title'));
     $news->setBody($request->get('body'));
     $news->setHaveImage(false);
     $newsCategories = $news->getCategories();
     $decoder = new JsonDecode();
     $categories = $decoder->decode($request->get('categories'), JsonEncoder::FORMAT);
     foreach ($categories as $categoryData) {
         $category = $em->find('AppBundle\\Entity\\Category', $categoryData->id);
         $newsCategories->add($category);
     }
     if ($img = $request->files->get('image')) {
         $news->setHaveImage(true);
     }
     $em->persist($news);
     $em->flush();
     if ($img) {
         $img->move('bundles/app/image/', 'news-' . $news->getId() . '.jpg');
     }
     return new JsonResponse(array('success' => true, 'message' => 'news has been added'));
 }
예제 #4
0
 /**
  * @Given there are news:
  */
 public function thereAreNews(TableNode $table)
 {
     $em = $this->getContainer()->get('doctrine')->getManager();
     $i = 1;
     foreach ($table->getHash() as $row) {
         $news = new News();
         $news->setTitle($row['title']);
         //            $article->setCategory($this->findArticleCategory(['name' => $row['category']]));
         $news->setIdAuthor(1);
         $news->setSlug($row['title']);
         $em->persist($news);
         $em->flush();
         //            var_dump($news->getModificationDate());
         $this->getParameterBag()->set(sprintf('NEWS_%s_ID', $i), $news->getIdNews());
         $this->getParameterBag()->set(sprintf('NEWS_AUTHOR_%s_ID', $i), $news->getIdAuthor());
         //            $this->getParameterBag()->set('NEWS_MODIFICATION_DATE', $news->getModificationDate()->format(DATE_ISO8601));
         $i++;
     }
 }