/**
  * Perform a single access check operation on a given attribute, object and (optionally) user
  * It is safe to assume that $attribute and $object's class pass supportsAttribute/supportsClass
  * $user can be one of the following:
  *   a UserInterface object (fully authenticated user)
  *   a string               (anonymously authenticated user)
  *
  * @param string $attribute
  * @param ArticleReview $object
  * @param UserInterface|string $user
  *
  * @return bool
  */
 protected function isGranted($attribute, $object, $user = null)
 {
     if ($user == $object->getArticle()->getInscription()->getUser()) {
         return true;
     }
     /** @var Reviewer $reviewer */
     foreach ($object->getArticle()->getReviewers() as $reviewer) {
         if ($reviewer->getUser() == $user) {
             return true;
         }
     }
     return false;
 }
 /**
  * @Route("/{id}", name="article_review_see")
  * @Template("frontend/ArticleReview/show.html.twig")
  * Función para obtener los comentarios de los artículos
  */
 public function commentsAction(ArticleReview $articleReview)
 {
     $conference = $this->getConference();
     $user = $this->getUser();
     $exist = $articleReview->getArticle()->getInscription()->getUser();
     if ($user != $exist) {
         $this->addFlash('alert', $this->get('translator')->trans('You can not see other comments'));
         return $this->redirectToRoute('article_list');
     }
     $comments = $this->getDoctrine()->getRepository('AppBundle:ReviewComments')->findBy(array('articleReview' => $articleReview));
     if ($articleReview->getState() == 'sent') {
         $this->addFlash('alert', $this->get('translator')->trans('There are not any comments'));
         return $this->redirectToRoute('article_list');
     }
     return ['conference' => $conference, 'comments' => $comments];
 }
 /**
  *@Given there are following articleReviews:
  *
  *@param TableNode $tableNode
  */
 public function createArticleReview(TableNode $tableNode)
 {
     $em = $this->getEntityManager();
     foreach ($tableNode->getHash() as $articleReviewHash) {
         $articleReview = new ArticleReview();
         $articleReview->setFile('file');
         $articleReview->setMimeType('mimeType');
         $articleReview->setState($articleReviewHash['state']);
         $articleReview->setPath($articleReviewHash['path']);
         $articleReview->setArticle($this->findArticle($articleReviewHash['article']));
         $em->persist($articleReview);
     }
     $em->flush();
 }
 /**
  * @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()];
 }