public function testGetIdStartsWithNull()
 {
     // Arrange
     $article = new Article();
     $idBefore = null;
     // Act
     $idAfter = $article->getId();
     // Assert
     $this->assertEquals($idBefore, $idAfter);
 }
 /**
  * @Route("/{article}", name="articles_get_single")
  * @Method({"GET"})
  */
 public function getSingleAction(Request $request, Article $article)
 {
     $this->initializeJsonResponse();
     if (!$this->checkValidJsonApi($request)) {
         return $this->jsonResponse;
     }
     $articles = array_map(function ($article) {
         return array('type' => 'articles', 'id' => $article->getId(), 'attributes' => array('headline' => $article->getHeadline(), 'byline' => $article->getByline(), 'leadParagraph' => $article->getLeadParagraph(), 'body' => $article->getBody()));
     }, array($article));
     $this->jsonResponse->setData(array('data' => $articles[0]));
     return $this->jsonResponse;
 }
 /**
  *
  */
 public function putArticleAction(Article $article, Request $request)
 {
     // yes we replace totally the old article by a new one
     // except the id, because that's how PUT works
     // if you just want to "merge" you want to use PATCH, not PUT
     $id = $article->getId();
     $article = new Article();
     $article->setId($id);
     $errors = $this->treatAndValidateRequest($article, $request);
     if (count($errors) > 0) {
         return new View($errors, Response::HTTP_UNPROCESSABLE_ENTITY);
     }
     $this->persistAndFlush($article);
     return "";
 }
 /**
  * @Route("/{id}/review/new", name="article_new_review")
  * @Template("frontend/Article/new.html.twig")
  * @Security("is_granted('UPLOAD_NEW_ARTICLE_REVIEW', article)")
  * Función para enviar una nueva versión de un artículo
  */
 public function newReviewAction(Article $article, Request $request)
 {
     $conference = $article->getInscription()->getConference();
     $user = $this->getUser();
     $inscription = $this->getDoctrine()->getRepository('AppBundle:Inscription')->findOneBy(array('conference' => $conference, 'user' => $user));
     if (!$inscription) {
         $this->addFlash('alert', $this->get('translator')->trans('You are not registered in this conference'));
         return $this->redirectToRoute('conference_show');
     }
     $articles = $this->getDoctrine()->getRepository('AppBundle:Article')->findOneBy(array('id' => $article->getId()));
     $form = $this->createForm(new ArticleType(), $articles);
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $em->persist($article);
         $em->flush();
         $article_review = new ArticleReview();
         $article_review->setArticle($article);
         $article_review->setPath($form->get('path')->getData());
         $em = $this->getDoctrine()->getManager();
         $em->persist($article_review);
         $uploadableManager = $this->get('stof_doctrine_extensions.uploadable.manager');
         $uploadableManager->markEntityToUpload($article_review, $article_review->getPath());
         $em->flush();
         $this->get('session')->getFlashBag()->set('success', $this->get('translator')->trans('Your new article has been successfully send'));
         return $this->redirectToRoute('article_list');
     }
     return ['conference' => $conference, 'form' => $form->createView()];
 }
 /**
  * {@inheritDoc}
  */
 public function getId()
 {
     if ($this->__isInitialized__ === false) {
         return (int) parent::getId();
     }
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getId', array());
     return parent::getId();
 }
 /**
  * Returns a list of comments by an article sorted by DESC
  * @param Article $article
  * @return Comment array
  */
 public function getCommentsByArticle(Article $article)
 {
     return $this->commentRepository->findBy(array('article' => $article->getId()), array('date' => 'DESC'));
 }
Example #7
0
 /**
  * @param Article $article
  * @return \Symfony\Component\Form\Form
  */
 private function createDeleteArticleForm(Article $article)
 {
     return $this->createFormBuilder()->setAction($this->generateUrl('delete-article', array('id' => $article->getId())))->setMethod('DELETE')->getForm();
 }