Post entity update. PostRepository and TagRepository created.

This commit is contained in:
Alexey Skobkin 2016-03-16 22:03:08 +03:00
parent 6e32fec5c1
commit ae8cbde3e1
4 changed files with 85 additions and 5 deletions

View file

@ -10,14 +10,18 @@ use Skobkin\Bundle\PointToolsBundle\Entity\User;
* Post * Post
* *
* @ORM\Table(name="posts.posts", schema="posts", indexes={ * @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 class Post
{ {
const TYPE_POST = 'post';
const TYPE_FEED = 'feed';
/** /**
* @var integer * @var int
* *
* @ORM\Column(name="id", type="string", length=16) * @ORM\Column(name="id", type="string", length=16)
* @ORM\Id * @ORM\Id
@ -45,6 +49,13 @@ class Post
*/ */
private $type; private $type;
/**
* @var bool
*
* @ORM\Column(name="private", type="boolean", nullable=true)
*/
private $private;
/** /**
* @var bool * @var bool
* *
@ -77,10 +88,20 @@ class Post
private $comments; 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->id = $id;
$this->type = $type; $this->type = $type;
$this->private = $private;
$this->createdAt = $createdAt; $this->createdAt = $createdAt;
$this->text = $text; $this->text = $text;
$this->author = $author; $this->author = $author;
@ -251,4 +272,27 @@ class Post
{ {
return $this->deleted; 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;
}
} }

View file

@ -0,0 +1,10 @@
<?php
namespace Skobkin\Bundle\PointToolsBundle\Entity\Blogs;
use Doctrine\ORM\EntityRepository;
class PostRepository extends EntityRepository
{
}

View file

@ -10,7 +10,7 @@ use Doctrine\ORM\Mapping as ORM;
* @ORM\Table(name="posts.tags", schema="posts", indexes={ * @ORM\Table(name="posts.tags", schema="posts", indexes={
* @ORM\Index(name="idx_tag_text", columns={"text"}) * @ORM\Index(name="idx_tag_text", columns={"text"})
* }) * })
* @ORM\Entity * @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\TagRepository")
*/ */
class Tag class Tag
{ {

View file

@ -0,0 +1,26 @@
<?php
namespace Skobkin\Bundle\PointToolsBundle\Entity\Blogs;
use Doctrine\ORM\EntityRepository;
class TagRepository extends EntityRepository
{
/**
* @param $text
* @return Tag|null
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function findOneByLowerText($text)
{
$qb = $this->createQueryBuilder('t');
return $qb
->where($qb->expr()->eq(
$qb->expr()->lower('t.text'),
$qb->expr()->lower(':text')
))
->setParameter('text', $text)
->getQuery()->getOneOrNullResult()
;
}
}