From ae8cbde3e1647bc80f56b831fb9a4f5fc23453ef Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Wed, 16 Mar 2016 22:03:08 +0300 Subject: [PATCH] Post entity update. PostRepository and TagRepository created. --- .../PointToolsBundle/Entity/Blogs/Post.php | 52 +++++++++++++++++-- .../Entity/Blogs/PostRepository.php | 10 ++++ .../PointToolsBundle/Entity/Blogs/Tag.php | 2 +- .../Entity/Blogs/TagRepository.php | 26 ++++++++++ 4 files changed, 85 insertions(+), 5 deletions(-) create mode 100644 src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/PostRepository.php create mode 100644 src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/TagRepository.php diff --git a/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Post.php b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Post.php index f472dbd..60a955d 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Post.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Post.php @@ -10,14 +10,18 @@ use Skobkin\Bundle\PointToolsBundle\Entity\User; * 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 * * @ORM\Column(name="id", type="string", length=16) * @ORM\Id @@ -45,6 +49,13 @@ class Post */ private $type; + /** + * @var bool + * + * @ORM\Column(name="private", type="boolean", nullable=true) + */ + private $private; + /** * @var bool * @@ -77,10 +88,20 @@ class 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; @@ -251,4 +272,27 @@ 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; + } } 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