Пример #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 create(Request $request)
 {
     $fields = $this->getHydrationMap($request);
     $entity = new News();
     if (!isset($fields['creation_date'])) {
         $entity->setCreationDate(new \DateTime());
     }
     $entity = $this->hydrate($entity, $fields);
     $this->entityRepository->save($entity);
     return $entity;
 }
Пример #3
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);
 }
Пример #4
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'));
 }
Пример #5
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++;
     }
 }
Пример #6
0
 /**
  * Creates a form to delete a News entity.
  *
  * @param News $news The News entity
  *
  * @return \Symfony\Component\Form\Form The form
  */
 private function createDeleteForm(News $news)
 {
     return $this->createFormBuilder()->setAction($this->generateUrl('news_delete', array('id' => $news->getId())))->setMethod('DELETE')->getForm();
 }