/** * @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; }