public function map(EntityContract $entity, array $data) { $entity->setId($data['ID']); $entity->setDate($data['post_date']); $entity->setContent($data['post_content']); $entity->setTitle($data['post_title']); $entity->setExcerpt($data['post_excerpt']); $entity->setStatus($data['post_status']); $entity->setCommentStatus($data['comment_status']); $entity->setPingStatus($data['ping_status']); $entity->setPassword($data['post_password']); $entity->setSlug($data['post_name']); $entity->setModified($data['post_modified']); $entity->setMenuOrder($data['menu_order']); $entity->setType($data['post_type']); $entity->setNative($data); // Relations $entity->setAuthorId($id = $data['post_author']); $entity->setAuthor(function () use($id) { return $this->userRepository->userOfId($id); }); $id = $data['ID']; $entity->setFeaturedImage(function () use($id) { $upload = null; if ($uId = get_post_thumbnail_id($id)) { $upload = $this->uploadRepository->uploadOfId($uId); } return $upload; }); if ($this->commentRepository) { $entity->setComments(function () use($id) { return $this->commentRepository->commentsForPost($id); }); } }
public function map(EntityContract $entity, array $data) { $entity->setId($data['comment_ID']); $entity->setPostId($id = $data['comment_post_ID']); $entity->setPost(function () use($id) { return $this->postRepository->postOfId($id); }); $entity->setAuthorName($data['comment_author']); $entity->setAuthorEmail($data['comment_author_email']); $entity->setAuthorUrl($data['comment_author_url']); $entity->setAuthorIp($data['comment_author_IP']); $entity->setDate($data['comment_date']); $entity->setContent($data['comment_content']); $entity->setStatus($data['comment_approved']); $entity->setUserAgent($data['comment_agent']); $entity->setType($data['comment_type']); $entity->setParentId($id = $data['comment_parent']); $entity->setParent(function () use($id) { $parent = null; if ($id) { $parent = $this->commentRepository->commentOfId($id); } return $parent; }); $entity->setUserId($id = $data['user_id']); $entity->setUser(function () use($id) { $user = null; if ($id) { $user = $this->userRepository->userOfId($id); } return $user; }); }