public function prePersist(Comment $comment, LifecycleEventArgs $event)
 {
     if ($comment->getMessage() != null) {
         $userPicker = new UserPickerContent($comment->getMessage());
         $comment->setUserPicker($userPicker);
         $comment->setMessage($userPicker->getFinalText());
     }
 }
 /**
  * @Route("/{blogId}/post/view/{postSlug}", name="icap_blog_post_view", requirements={"id" = "\d+"})
  *
  * @ParamConverter("blog", class="IcapBlogBundle:Blog", options={"id" = "blogId"})
  * @ParamConverter("post", class="IcapBlogBundle:Post", options={"mapping": {"blogId": "blog", "postSlug": "slug"}})
  * @Template()
  */
 public function viewAction(Request $request, Blog $blog, Post $post)
 {
     $this->checkAccess("OPEN", $blog);
     $user = $this->get('security.token_storage')->getToken()->getUser();
     if (!$this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
         $user = null;
     }
     $this->dispatchPostReadEvent($post);
     /** @var \Symfony\Component\HttpFoundation\Session\Session $session */
     $session = $request->getSession();
     $sessionViewCounterKey = 'blog_post_view_counter_' . $post->getId();
     $now = time();
     $notRepeatableLogTimeInSeconds = $this->container->getParameter('non_repeatable_log_time_in_seconds');
     $entityManager = $this->getDoctrine()->getManager();
     if ($now >= $session->get($sessionViewCounterKey, $now) + $notRepeatableLogTimeInSeconds) {
         $post->increaseViewCounter();
         $session->set($sessionViewCounterKey, $now);
         $entityManager->persist($post);
         $entityManager->flush();
     }
     $commentStatus = Comment::STATUS_UNPUBLISHED;
     if ($blog->isAutoPublishComment()) {
         $commentStatus = Comment::STATUS_PUBLISHED;
     }
     $form = null;
     if ($blog->isCommentsAuthorized()) {
         $comment = new Comment();
         $comment->setPost($post)->setAuthor($user)->setStatus($commentStatus);
         $form = $this->createForm(new CommentType(), $comment);
         if ("POST" === $request->getMethod()) {
             $form->handleRequest($request);
             if ($form->isValid()) {
                 $translator = $this->get('translator');
                 $flashBag = $this->get('session')->getFlashBag();
                 try {
                     $entityManager->persist($comment);
                     $entityManager->flush();
                     $this->dispatchCommentCreateEvent($post, $comment);
                     $flashBag->add('success', $translator->trans('icap_blog_comment_add_success', array(), 'icap_blog'));
                 } catch (\Exception $exception) {
                     $flashBag->add('error', $translator->trans('icap_blog_comment_add_error', array(), 'icap_blog'));
                 }
                 return $this->redirect($this->generateUrl('icap_blog_post_view', array('blogId' => $blog->getId(), 'postSlug' => $post->getSlug())) . '#comments');
             }
         }
         $form = $form->createView();
     }
     return array('_resource' => $blog, 'bannerForm' => $this->getBannerForm($blog->getOptions()), 'user' => $user, 'post' => $post, 'form' => $form);
 }
 public function onCopy(CopyResourceEvent $event)
 {
     $entityManager = $this->container->get('claroline.persistence.object_manager');
     /** @var \Icap\BlogBundle\Entity\Blog $blog */
     $blog = $event->getResource();
     $user = $this->container->get('security.token_storage')->getToken()->getUser();
     $newBlog = new Blog();
     $entityManager->persist($newBlog);
     $entityManager->flush($newBlog);
     foreach ($blog->getPosts() as $post) {
         /** @var \Icap\BlogBundle\Entity\Post $newPost */
         $newPost = new Post();
         $newPost->setTitle($post->getTitle())->setContent($post->getContent())->setAuthor($post->getAuthor())->setStatus($post->getStatus())->setBlog($newBlog);
         $newTags = $post->getTags();
         foreach ($newTags as $tag) {
             $newPost->addTag($tag);
         }
         $entityManager->persist($newPost);
         $entityManager->flush($newPost);
         foreach ($post->getComments() as $comment) {
             /** @var \Icap\BlogBundle\Entity\Comment $newComment */
             $newComment = new Comment();
             $newComment->setAuthor($comment->getAuthor())->setMessage($comment->getMessage())->setPost($newPost);
         }
     }
     $entityManager->persist($newBlog);
     $event->setCopy($newBlog);
     $event->stopPropagation();
 }
 /**
  * @param Post    $post
  * @param Comment $comment
  */
 public function __construct(Post $post, Comment $comment)
 {
     $this->blog = $post->getBlog();
     $this->comment = $comment;
     $this->post = $post;
     $this->details = array('post' => array('blog' => $this->blog->getId(), 'title' => $post->getTitle(), 'slug' => $post->getSlug()), 'comment' => array('id' => $comment->getId(), 'content' => $comment->getMessage(), 'published' => $comment->isPublished(), 'author' => $comment->getAuthor()->getFirstName() . " " . $post->getAuthor()->getLastName(), 'authorId' => $comment->getAuthor()->getId()));
     parent::__construct($this->blog->getResourceNode(), $this->details);
 }
 /**
  * @param Post    $post
  * @param Comment $comment
  */
 public function __construct(Post $post, Comment $comment)
 {
     $author = $comment->getAuthor();
     $blog = $post->getBlog();
     if (null === $author) {
         $author = "Anonyme";
     } else {
         $author = $comment->getAuthor()->getFirstName() . ' ' . $comment->getAuthor()->getLastName();
     }
     $details = array('post' => array('blog' => $blog->getId(), 'title' => $post->getTitle(), 'slug' => $post->getSlug()), 'comment' => array('id' => $comment->getId(), 'author' => $author, 'content' => $comment->getMessage()));
     parent::__construct($blog->getResourceNode(), $details);
 }
 /**
  * @Route("/{blogId}/{postSlug}/comment/edit/{commentId}", name="icap_blog_comment_edit", requirements={"blogId" = "\d+"})
  *
  * @ParamConverter("blog", class="IcapBlogBundle:Blog", options={"id" = "blogId"})
  * @ParamConverter("post", class="IcapBlogBundle:Post", options={"mapping": {"postSlug": "slug"}})
  * @ParamConverter("comment", class="IcapBlogBundle:Comment", options={"id" = "commentId"})
  * @Template()
  */
 public function editAction(Request $request, Blog $blog, Post $post, Comment $comment)
 {
     $user = $this->get('security.token_storage')->getToken()->getUser();
     $translator = $this->get('translator');
     if ($user != null && $user->getId() == $comment->getAuthor()->getId()) {
         $messages = array('success' => $translator->trans('icap_blog_comment_edit_success', array(), 'icap_blog'), 'error' => $translator->trans('icap_blog_comment_edit_error', array(), 'icap_blog'));
         return $this->persistCommentUpdate($request, $blog, $post, $comment, $user, $messages);
     } else {
         throw new AccessDeniedException($translator->trans('icap_blog_comment_access_denied', array(), 'icap_blog'));
     }
 }
Example #7
0
 /**
  * @param array  $data
  * @param string $rootPath
  * @param User   $owner
  *
  * @return Blog
  */
 public function importBlog(array $data, $rootPath, User $owner)
 {
     $blogDatas = $data['data'];
     $optionsData = $blogDatas['options'];
     $blogOptions = new BlogOptions();
     $blogOptions->setAuthorizeComment($optionsData['authorize_comment'])->setAuthorizeAnonymousComment($optionsData['authorize_anonymous_comment'])->setPostPerPage($optionsData['post_per_page'])->setAutoPublishPost($optionsData['auto_publish_post'])->setAutoPublishComment($optionsData['auto_publish_comment'])->setDisplayTitle($optionsData['display_title'])->setBannerActivate($optionsData['banner_activate'])->setDisplayPostViewCounter($optionsData['display_post_view_counter'])->setBannerBackgroundColor($optionsData['banner_background_color'])->setBannerHeight($optionsData['banner_height'])->setBannerBackgroundImage($optionsData['banner_background_image'])->setBannerBackgroundImagePosition($optionsData['banner_background_image_position'])->setBannerBackgroundImageRepeat($optionsData['banner_background_image_repeat'])->setTagCloud($optionsData['tag_cloud']);
     $blog = new Blog();
     $blog->setOptions($blogOptions);
     $postsDatas = $blogDatas['posts'];
     $posts = new ArrayCollection();
     foreach ($postsDatas as $postsData) {
         $post = new Post();
         $tagsDatas = $postsData['tags'];
         $tags = new ArrayCollection();
         foreach ($tagsDatas as $tagsData) {
             $tag = $this->retrieveTag($tagsData['name']);
             $tags->add($tag);
         }
         $commentsDatas = $postsData['comments'];
         $comments = new ArrayCollection();
         foreach ($commentsDatas as $commentsData) {
             $comment = new Comment();
             $commentMessage = file_get_contents($rootPath . DIRECTORY_SEPARATOR . $commentsData['message']);
             $comment->setMessage($commentMessage)->setAuthor($this->retrieveUser($commentsData['author'], $owner))->setCreationDate(new \DateTime($commentsData['creation_date']))->setUpdateDate(new \DateTime($commentsData['update_date']))->setPublicationDate(new \DateTime($commentsData['publication_date']))->setStatus($commentsData['status']);
             $comments->add($comment);
         }
         $postContent = file_get_contents($rootPath . DIRECTORY_SEPARATOR . $postsData['content']);
         $post->setTitle($postsData['title'])->setContent($postContent)->setAuthor($this->retrieveUser($postsData['author'], $owner))->setCreationDate(new \DateTime($postsData['creation_date']))->setModificationDate(new \DateTime($postsData['modification_date']))->setPublicationDate(new \DateTime($postsData['publication_date']))->setTags($tags)->setComments($comments)->setStatus($postsData['status']);
         $posts->add($post);
     }
     $blog->setPosts($posts);
     return $blog;
 }
Example #8
0
 /**
  * Remove comments
  *
  * @param Comment $comments
  *
  * @return Post
  */
 public function removeComment(Comment $comments)
 {
     $this->comments->removeElement($comments);
     return $this;
 }