Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
0
 /**
  * @param Blog     $blog
  * @param bool     $executeQuery
  * @param int|null $max
  *
  * @return array|\Doctrine\ORM\AbstractQuery
  */
 public function findByBlog(Blog $blog, $executeQuery = true, $max = null)
 {
     $query = $this->getEntityManager()->createQuery('
             SELECT t, COUNT(t.id) AS frequency, COUNT(p.id) as countPosts
             FROM IcapBlogBundle:Tag t
             JOIN t.posts p
             WHERE p.blog = :blogId
             AND p.status = :postStatus
             AND p.publicationDate IS NOT NULL
             GROUP BY t.id
             ORDER BY frequency DESC
         ')->setParameter('blogId', $blog->getId())->setParameter('postStatus', Statusable::STATUS_PUBLISHED);
     if ($max != null) {
         $query->setMaxResults($max);
     }
     return $executeQuery ? $query->getResult() : $query;
 }
Ejemplo n.º 3
0
 /**
  * @param Blog  $blog
  * @param array $changeSet
  *
  * @return Controller
  */
 protected function dispatchBlogUpdateEvent(Blog $blog, $changeSet)
 {
     $logEvent = new LogResourceUpdateEvent($blog->getResourceNode(), $changeSet);
     return $this->dispatch($logEvent);
 }
Ejemplo n.º 4
0
 /**
  * @Route("/rss/{blogId}", name="icap_blog_rss", requirements={"blogId" = "\d+"})
  * @ParamConverter("blog", class="IcapBlogBundle:Blog", options={"id" = "blogId"})
  */
 public function rssAction(Blog $blog)
 {
     $baseUrl = $this->get('request')->getSchemeAndHttpHost();
     $feed = ['title' => $blog->getResourceNode()->getName(), 'description' => $blog->getInfos(), 'siteUrl' => $baseUrl . $this->generateUrl('icap_blog_view', ['blogId' => $blog->getId()]), 'feedUrl' => $baseUrl . $this->generateUrl('icap_blog_rss', ['blogId' => $blog->getId()]), 'lang' => $this->get('claroline.config.platform_config_handler')->getParameter('locale_language')];
     /** @var \Icap\BlogBundle\Entity\Post[] $posts */
     $posts = $this->getDoctrine()->getRepository('IcapBlogBundle:Post')->findRssDatas($blog);
     $items = [];
     foreach ($posts as $post) {
         $items[] = ['title' => $post->getTitle(), 'url' => $baseUrl . $this->generateUrl('icap_blog_post_view', ['blogId' => $blog->getId(), 'postSlug' => $post->getSlug()]), 'date' => $post->getPublicationDate()->format('d/m/Y h:i:s'), 'intro' => $post->getContent(), 'author' => $post->getAuthor()->getFirstName() - $post->getAuthor()->getLastName()];
     }
     return new Response($this->renderView('IcapBlogBundle:Blog:rss.html.twig', ['feed' => $feed, 'items' => $items]), 200, ['Content-Type' => 'application/rss+xml', 'charset' => 'utf-8']);
 }
Ejemplo n.º 5
0
 private function persistCommentUpdate(Request $request, Blog $blog, Post $post, Comment $comment, User $user, array $messages)
 {
     $form = $this->createForm($this->get('icap_blog.form.comment'), $comment);
     if ($request->isXMLHttpRequest()) {
         return $this->render('IcapBlogBundle:Comment:inlineEdit.html.twig', array('_resource' => $blog, 'post' => $post, 'comment' => $comment, 'workspace' => $blog->getResourceNode()->getWorkspace(), 'form' => $form->createView()));
     } else {
         if ("POST" === $request->getMethod()) {
             $form->handleRequest($request);
             if ($form->isValid()) {
                 $flashBag = $this->get('session')->getFlashBag();
                 $entityManager = $this->getDoctrine()->getManager();
                 try {
                     $unitOfWork = $entityManager->getUnitOfWork();
                     $unitOfWork->computeChangeSets();
                     $changeSet = $unitOfWork->getEntityChangeSet($comment);
                     $entityManager->persist($comment);
                     $entityManager->flush();
                     $this->dispatchCommentUpdateEvent($post, $comment, $changeSet);
                     $flashBag->add('success', $messages['success']);
                 } catch (\Exception $exception) {
                     $flashBag->add('error', $messages['error']);
                 }
                 return $this->redirect($this->generateUrl('icap_blog_post_view', array('blogId' => $blog->getId(), 'postSlug' => $post->getSlug())));
             }
         }
     }
     return array('_resource' => $blog, 'bannerForm' => $this->getBannerForm($blog->getOptions()), 'user' => $user, 'post' => $post, 'comment' => $comment, 'form' => $form->createView());
 }
Ejemplo n.º 6
0
 public function getBlogBannerWebPath(Blog $blog)
 {
     return $blog->getOptions()->getBannerBackgroundImage() ? $this->webDirectory . '/' . $blog->getOptions()->getBannerBackgroundImage() : null;
 }
 /**
  * @param Blog $value
  *
  * @return int|string
  */
 public function transform($value)
 {
     return $value instanceof Blog ? $value->getId() : null;
 }
Ejemplo n.º 8
0
 /**
  * @param Blog $blog
  * @param bool $executeQuery
  *
  * @return Post[]|\Doctrine\ORM\AbstractQuery
  */
 public function findRssDatas(Blog $blog, $executeQuery = true)
 {
     $query = $this->createQueryBuilder('post')->select(array('post'))->andWhere('post.blog = :blogId')->andWhere('post.status = :postStatus')->andWhere('post.publicationDate IS NOT NULL')->setParameter('blogId', $blog->getId())->setParameter('postStatus', Statusable::STATUS_PUBLISHED)->getQuery();
     return $executeQuery ? $query->getResult() : $query;
 }