Exemplo n.º 1
0
 public function create(Request $request)
 {
     $fields = $this->getHydrationMap($request);
     $entity = new Article();
     if (!isset($fields['creation_date'])) {
         $entity->setCreationDate(new \DateTime());
     }
     //        $entity = $this->beforeHydration($entity, $fields);
     $entity = $this->hydrate($entity, $fields);
     if ($idArticleCategory = $request->request->get('id_article_category')) {
         $categoryEntity = $this->categoryRepository->find($idArticleCategory);
         $entity->setCategory($categoryEntity);
     }
     if ($idAuthor = $request->request->get('id_author')) {
         $userEntity = $this->userRepository->find($idAuthor);
         $entity->setAuthor($userEntity);
     }
     $this->entityRepository->save($entity);
     return $entity;
 }
Exemplo n.º 2
0
 public function postCategoryArticlesAction(Request $request, $category)
 {
     $entityManager = $this->getDoctrine()->getEntityManager();
     $repository = $entityManager->getRepository('AppBundle:ArticleCategory');
     $categoryEntity = $repository->findOneBy(['slug' => $category]);
     //        $category = new ArticleCategory();
     //        print_r($category);
     $title = $request->request->get('title');
     $slug = $request->request->get('slug');
     $number = random_int(1, 100);
     $article = new Article();
     $article->setCategory($categoryEntity);
     //        $article->setIdArticleTemplate(null);
     $article->setIdAuthor(140);
     $article->setTitle($title . $number);
     $article->setSlug($slug . $number);
     $article->setMarkup('<p>To bedzie długi artykul...</p>');
     $article->setMarkup('To bedzie długi artykul...');
     $article->setCreationDate(new \DateTime());
     //        $article->setModificationDate();
     //        $article->setRated();
     //        $article->getSum();
     //        print_r($article);
     //        $article->setIdArticleCategory(86);
     //        $article->setIdArticleTemplate(1);
     $entityManager->persist($article);
     $entityManager->flush();
     $view = $this->view($article, 201);
     return $this->handleView($view);
 }