diff --git a/app/config/config.yml b/app/config/config.yml index 9cb2514..b502b3e 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -6,6 +6,9 @@ imports: framework: #esi: ~ translator: { fallbacks: ["%locale%"] } + serializer: + #enabled: true + enable_annotations: true secret: "%secret%" router: resource: "%kernel.root_dir%/config/routing.yml" diff --git a/src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/MetaPost.php b/src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/MetaPost.php new file mode 100644 index 0000000..c885785 --- /dev/null +++ b/src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/MetaPost.php @@ -0,0 +1,59 @@ +rec; + } + + /** + * @param Recommendation $rec + * @return MetaPost + */ + public function setRec(Recommendation $rec) + { + $this->rec = $rec; + return $this; + } + + /** + * @return Post + */ + public function getPost() + { + return $this->post; + } + + /** + * @param Post $post + * @return MetaPost + */ + public function setPost(Post $post) + { + $this->post = $post; + return $this; + } +} \ No newline at end of file diff --git a/src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/Post.php b/src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/Post.php new file mode 100644 index 0000000..cd7fd8b --- /dev/null +++ b/src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/Post.php @@ -0,0 +1,184 @@ +id; + } + + /** + * @param string $id + * @return Post + */ + public function setId($id) + { + $this->id = $id; + return $this; + } + + /** + * @return string[] + */ + public function getTags() + { + return $this->tags; + } + + /** + * @param string[] $tags + * @return Post + */ + public function setTags(array $tags) + { + $this->tags = $tags; + return $this; + } + + /** + * @return User + */ + public function getAuthor() + { + return $this->author; + } + + /** + * @param User $author + * @return Post + */ + public function setAuthor(User $author) + { + $this->author = $author; + return $this; + } + + /** + * @return string + */ + public function getText() + { + return $this->text; + } + + /** + * @param string $text + * @return Post + */ + public function setText($text) + { + $this->text = $text; + return $this; + } + + /** + * @return string + */ + public function getCreated() + { + return $this->created; + } + + /** + * @param string $created + * @return Post + */ + public function setCreated($created) + { + $this->created = $created; + return $this; + } + + /** + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * @param string $type + * @return Post + */ + public function setType($type) + { + $this->type = $type; + return $this; + } + + /** + * @return boolean + */ + public function isPrivate() + { + return $this->private; + } + + /** + * @param boolean $private + * @return Post + */ + public function setPrivate($private) + { + $this->private = $private; + return $this; + } +} \ No newline at end of file diff --git a/src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/PostsPage.php b/src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/PostsPage.php new file mode 100644 index 0000000..6096bd6 --- /dev/null +++ b/src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/PostsPage.php @@ -0,0 +1,35 @@ +posts; + } + + /** + * @param MetaPost[] $posts + * @return PostsPage + */ + public function setPosts(array $posts) + { + $this->posts = $posts; + return $this; + } + + +} \ No newline at end of file diff --git a/src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/Recommendation.php b/src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/Recommendation.php new file mode 100644 index 0000000..087cc01 --- /dev/null +++ b/src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/Recommendation.php @@ -0,0 +1,84 @@ +text; + } + + /** + * @param string $text + * @return Recommendation + */ + public function setText($text) + { + $this->text = $text; + return $this; + } + + /** + * @return int|null + */ + public function getComment_id() + { + return $this->comment_id; + } + + /** + * @param int|null $comment_id + * @return Recommendation + */ + public function setComment_id($comment_id) + { + $this->comment_id = $comment_id; + return $this; + } + + /** + * @return User + */ + public function getAuthor() + { + return $this->author; + } + + /** + * @param User $author + * @return Recommendation + */ + public function setAuthor(User $author) + { + $this->author = $author; + return $this; + } +} \ No newline at end of file diff --git a/src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/User.php b/src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/User.php new file mode 100644 index 0000000..e70bb0a --- /dev/null +++ b/src/Skobkin/Bundle/PointToolsBundle/DTO/Api/Crawler/User.php @@ -0,0 +1,84 @@ +id; + } + + /** + * @param string $id + * @return User + */ + public function setId($id) + { + $this->id = $id; + return $this; + } + + /** + * @return string + */ + public function getLogin() + { + return $this->login; + } + + /** + * @param string $login + * @return User + */ + public function setLogin($login) + { + $this->login = $login; + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + * @return User + */ + public function setName($name) + { + $this->name = $name; + return $this; + } +} \ No newline at end of file diff --git a/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Comment.php b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Comment.php index f10d227..7d3836b 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Comment.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Comment.php @@ -4,6 +4,7 @@ namespace Skobkin\Bundle\PointToolsBundle\Entity\Blogs; use Doctrine\ORM\Mapping as ORM; use Skobkin\Bundle\PointToolsBundle\Entity\User; +use Symfony\Component\Serializer\Annotation as Serializer; /** * Comment @@ -18,6 +19,8 @@ class Comment /** * @var integer * + * @Serializer\Groups("post_show") + * * @ORM\Column(name="id", type="integer") * @ORM\Id */ @@ -26,6 +29,8 @@ class Comment /** * @var string * + * @Serializer\Groups("post_show") + * * @ORM\Column(name="text", type="text") */ private $text; @@ -33,6 +38,8 @@ class Comment /** * @var \DateTime * + * @Serializer\Groups("post_show") + * * @ORM\Column(name="created_at", type="datetime") */ private $createdAt; @@ -40,6 +47,8 @@ class Comment /** * @var boolean * + * @Serializer\Groups("post_show") + * * @ORM\Column(name="is_rec", type="boolean") */ private $rec; @@ -47,6 +56,8 @@ class Comment /** * @var bool * + * @Serializer\Groups("post_show") + * * @ORM\Column(name="is_deleted", type="boolean") */ private $deleted = false; @@ -63,6 +74,8 @@ class Comment /** * @var User * + * @Serializer\Groups("post_show") + * * @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\User") * @ORM\JoinColumn(name="author_id") */ @@ -71,6 +84,8 @@ class Comment /** * @var Comment|null * + * @Serializer\Groups("post_show") + * * @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment") * @ORM\JoinColumn(name="to_comment_id", nullable=true) */ diff --git a/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Post.php b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Post.php index 7cb6ec0..8c98d97 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Post.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Post.php @@ -5,19 +5,26 @@ namespace Skobkin\Bundle\PointToolsBundle\Entity\Blogs; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; use Skobkin\Bundle\PointToolsBundle\Entity\User; +use Symfony\Component\Serializer\Annotation as Serializer; /** * Post * * @ORM\Table(name="posts.posts", schema="posts", indexes={ - * @ORM\Index(name="idx_post_created_at", columns={"created_at"}) + * @ORM\Index(name="idx_post_created_at", columns={"created_at"}), + * @ORM\Index(name="idx_post_private", columns={"private"}), * }) - * @ORM\Entity + * @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\PostRepository") */ class Post { + const TYPE_POST = 'post'; + const TYPE_FEED = 'feed'; + /** - * @var integer + * @var int + * + * @Serializer\Groups({"posts_list", "post_show"}) * * @ORM\Column(name="id", type="string", length=16) * @ORM\Id @@ -27,6 +34,8 @@ class Post /** * @var string * + * @Serializer\Groups({"posts_list", "post_show"}) + * * @ORM\Column(name="text", type="text") */ private $text; @@ -34,6 +43,8 @@ class Post /** * @var \DateTime * + * @Serializer\Groups({"posts_list", "post_show"}) + * * @ORM\Column(name="created_at", type="datetime") */ private $createdAt; @@ -41,10 +52,19 @@ class Post /** * @var string * + * @Serializer\Groups({"posts_list", "post_show"}) + * * @ORM\Column(name="type", type="string", length=6) */ private $type; + /** + * @var bool + * + * @ORM\Column(name="private", type="boolean", nullable=true) + */ + private $private; + /** * @var bool * @@ -55,6 +75,8 @@ class Post /** * @var User * + * @Serializer\Groups({"posts_list", "post_show"}) + * * @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\User") * @ORM\JoinColumn(name="author") */ @@ -63,6 +85,8 @@ class Post /** * @var Tag[]|ArrayCollection * + * @Serializer\Groups({"posts_list", "post_show"}) + * * @ORM\ManyToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Tag", fetch="EXTRA_LAZY") * @ORM\JoinTable(name="posts.posts_tags", * joinColumns={@ORM\JoinColumn(name="post_id")}, @@ -74,15 +98,27 @@ class Post /** * @var Comment[]|ArrayCollection * - * @ORM\OneToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment", mappedBy="post", fetch="EXTRA_LAZY") + * @Serializer\Groups({"post_show"}) + * + * @ORM\OneToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment", mappedBy="post") */ private $comments; - public function __construct($id, $type, $text, \DateTime $createdAt, User $author = null) + /** + * Post constructor. + * @param string $id + * @param string $type + * @param bool $private + * @param string $text + * @param \DateTime $createdAt + * @param User|null $author + */ + public function __construct($id, $type, $private, $text, \DateTime $createdAt, User $author = null) { $this->id = $id; $this->type = $type; + $this->private = $private; $this->createdAt = $createdAt; $this->text = $text; $this->author = $author; @@ -254,6 +290,29 @@ class Post return $this->deleted; } + /** + * Set private + * + * @param boolean $private + * @return Post + */ + public function setPrivate($private) + { + $this->private = $private; + + return $this; + } + + /** + * Get private + * + * @return boolean + */ + public function getPrivate() + { + return $this->private; + } + /** * Add comments * diff --git a/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/PostRepository.php b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/PostRepository.php new file mode 100644 index 0000000..14429bc --- /dev/null +++ b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/PostRepository.php @@ -0,0 +1,10 @@ +createQueryBuilder('t'); + return $qb + ->where($qb->expr()->eq( + $qb->expr()->lower('t.text'), + $qb->expr()->lower(':text') + )) + ->setParameter('text', $text) + ->getQuery()->getOneOrNullResult() + ; + } +} \ No newline at end of file