Ejemplo n.º 1
0
 /**
  * @param Workspace $workspace
  * @param array     $files
  * @param Blog      $object
  *
  * @return array
  */
 public function exportBlog(Workspace $workspace, array &$files, Blog $object)
 {
     $data = [];
     $data['options'] = ['authorize_comment' => $object->getOptions()->getAuthorizeComment(), 'authorize_anonymous_comment' => $object->getOptions()->getAuthorizeAnonymousComment(), 'post_per_page' => $object->getOptions()->getPostPerPage(), 'auto_publish_post' => $object->getOptions()->getAutoPublishPost(), 'auto_publish_comment' => $object->getOptions()->getAutoPublishComment(), 'display_title' => $object->getOptions()->getDisplayTitle(), 'banner_activate' => $object->getOptions()->isBannerActivate(), 'display_post_view_counter' => $object->getOptions()->getDisplayPostViewCounter(), 'banner_background_color' => $object->getOptions()->getBannerBackgroundColor(), 'banner_height' => $object->getOptions()->getBannerHeight(), 'banner_background_image' => $object->getOptions()->getBannerBackgroundImage(), 'banner_background_image_position' => $object->getOptions()->getBannerBackgroundImagePosition(), 'banner_background_image_repeat' => $object->getOptions()->getBannerBackgroundImageRepeat(), 'tag_cloud' => null === $object->getOptions()->getTagCloud() ? 0 : $object->getOptions()->getTagCloud()];
     $data['posts'] = [];
     foreach ($object->getPosts() as $post) {
         $postUid = uniqid() . '.txt';
         $postTemporaryPath = $this->ch->getParameter('tmp_dir') . DIRECTORY_SEPARATOR . $postUid;
         file_put_contents($postTemporaryPath, $post->getContent());
         $files[$postUid] = $postTemporaryPath;
         $tags = [];
         foreach ($post->getTags() as $tag) {
             $tags[] = ['name' => $tag->getName()];
         }
         $comments = [];
         foreach ($post->getComments() as $comment) {
             $commentUid = uniqid() . '.txt';
             $commentTemporaryPath = $this->ch->getParameter('tmp_dir') . DIRECTORY_SEPARATOR . $commentUid;
             file_put_contents($commentTemporaryPath, $comment->getMessage());
             $files[$commentUid] = $commentTemporaryPath;
             $comments[] = ['message' => $commentUid, 'author' => $comment->getAuthor()->getMail(), 'creation_date' => $comment->getCreationDate()->format(\DateTime::ATOM), 'update_date' => null !== $comment->getUpdateDate() ? $comment->getUpdateDate()->format(\DateTime::ATOM) : null, 'publication_date' => null !== $comment->getPublicationDate() ? $comment->getPublicationDate()->format(\DateTime::ATOM) : null, 'status' => $comment->getStatus()];
         }
         $postArray = ['title' => $post->getTitle(), 'content' => $postUid, 'author' => $post->getAuthor()->getMail(), 'status' => $post->getStatus(), 'creation_date' => $post->getCreationDate()->format(\DateTime::ATOM), 'modification_date' => null !== $post->getModificationDate() ? $post->getModificationDate()->format(\DateTime::ATOM) : null, 'publication_date' => null !== $post->getPublicationDate() ? $post->getPublicationDate()->format(\DateTime::ATOM) : null, 'tags' => $tags, 'comments' => $comments];
         $data['posts'][] = $postArray;
     }
     return $data;
 }