Merge branch 'feature_posts' of bitbucket.org:skobkin/point-tools into feature_posts

# Conflicts:
#	src/Skobkin/Bundle/PointToolsBundle/Entity/Blogs/Post.php
This commit is contained in:
Alexey Skobkin 2016-03-17 19:54:17 +03:00
commit 9779233e87
11 changed files with 568 additions and 6 deletions

View file

@ -6,6 +6,9 @@ imports:
framework: framework:
#esi: ~ #esi: ~
translator: { fallbacks: ["%locale%"] } translator: { fallbacks: ["%locale%"] }
serializer:
#enabled: true
enable_annotations: true
secret: "%secret%" secret: "%secret%"
router: router:
resource: "%kernel.root_dir%/config/routing.yml" resource: "%kernel.root_dir%/config/routing.yml"

View file

@ -0,0 +1,59 @@
<?php
namespace Skobkin\Bundle\PointToolsBundle\DTO\Api\Crawler;
use Symfony\Component\Serializer\Annotation as Serializer;
class MetaPost
{
/**
* @var Recommendation
*
* @Serializer\Groups({"import_post_page"})
*/
private $rec;
/**
* @var Post
*
* @Serializer\Groups({"import_post_page"})
*/
private $post;
/**
* @return Recommendation
*/
public function getRec()
{
return $this->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;
}
}

View file

@ -0,0 +1,184 @@
<?php
namespace Skobkin\Bundle\PointToolsBundle\DTO\Api\Crawler;
use Symfony\Component\Serializer\Annotation as Serializer;
class Post
{
/**
* @var string
*
* @Serializer\Groups({"import_post_page"})
*/
private $id;
/**
* @var string[]
*
* @Serializer\Groups({"import_post_page"})
*/
private $tags;
/**
* @var User
*
* @Serializer\Groups({"import_post_page"})
*/
private $author;
/**
* @var string
*
* @Serializer\Groups({"import_post_page"})
*/
private $text;
/**
* @var string
*
* @Serializer\Groups({"import_post_page"})
*/
private $created;
/**
* @var string
*
* @Serializer\Groups({"import_post_page"})
*/
private $type;
/**
* @var bool
*
* @Serializer\Groups({"import_post_page"})
*/
private $private;
/**
* @return string
*/
public function getId()
{
return $this->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;
}
}

View file

@ -0,0 +1,35 @@
<?php
namespace Skobkin\Bundle\PointToolsBundle\DTO\Api\Crawler;
use Symfony\Component\Serializer\Annotation as Serializer;
class PostsPage
{
/**
* @var MetaPost[]
*
* @Serializer\Groups({"import_post_page"})
*/
private $posts;
/**
* @return MetaPost[]
*/
public function getPosts()
{
return $this->posts;
}
/**
* @param MetaPost[] $posts
* @return PostsPage
*/
public function setPosts(array $posts)
{
$this->posts = $posts;
return $this;
}
}

View file

@ -0,0 +1,84 @@
<?php
namespace Skobkin\Bundle\PointToolsBundle\DTO\Api\Crawler;
use Symfony\Component\Serializer\Annotation as Serializer;
class Recommendation
{
/**
* @var string
*
* @Serializer\Groups({"import_post_page"})
*/
private $text;
/**
* @var int|null
*
* @Serializer\Groups({"import_post_page"})
*/
private $comment_id;
/**
* @var User
*
* @Serializer\Groups({"import_post_page"})
*/
private $author;
/**
* @return string
*/
public function getText()
{
return $this->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;
}
}

View file

@ -0,0 +1,84 @@
<?php
namespace Skobkin\Bundle\PointToolsBundle\DTO\Api\Crawler;
use Symfony\Component\Serializer\Annotation as Serializer;
class User
{
/**
* @var string
*
* @Serializer\Groups({"import_post_page"})
*/
private $id;
/**
* @var string
*
* @Serializer\Groups({"import_post_page"})
*/
private $login;
/**
* @var string
*
* @Serializer\Groups({"import_post_page"})
*/
private $name;
/**
* @return string
*/
public function getId()
{
return $this->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;
}
}

View file

@ -4,6 +4,7 @@ namespace Skobkin\Bundle\PointToolsBundle\Entity\Blogs;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Skobkin\Bundle\PointToolsBundle\Entity\User; use Skobkin\Bundle\PointToolsBundle\Entity\User;
use Symfony\Component\Serializer\Annotation as Serializer;
/** /**
* Comment * Comment
@ -18,6 +19,8 @@ class Comment
/** /**
* @var integer * @var integer
* *
* @Serializer\Groups("post_show")
*
* @ORM\Column(name="id", type="integer") * @ORM\Column(name="id", type="integer")
* @ORM\Id * @ORM\Id
*/ */
@ -26,6 +29,8 @@ class Comment
/** /**
* @var string * @var string
* *
* @Serializer\Groups("post_show")
*
* @ORM\Column(name="text", type="text") * @ORM\Column(name="text", type="text")
*/ */
private $text; private $text;
@ -33,6 +38,8 @@ class Comment
/** /**
* @var \DateTime * @var \DateTime
* *
* @Serializer\Groups("post_show")
*
* @ORM\Column(name="created_at", type="datetime") * @ORM\Column(name="created_at", type="datetime")
*/ */
private $createdAt; private $createdAt;
@ -40,6 +47,8 @@ class Comment
/** /**
* @var boolean * @var boolean
* *
* @Serializer\Groups("post_show")
*
* @ORM\Column(name="is_rec", type="boolean") * @ORM\Column(name="is_rec", type="boolean")
*/ */
private $rec; private $rec;
@ -47,6 +56,8 @@ class Comment
/** /**
* @var bool * @var bool
* *
* @Serializer\Groups("post_show")
*
* @ORM\Column(name="is_deleted", type="boolean") * @ORM\Column(name="is_deleted", type="boolean")
*/ */
private $deleted = false; private $deleted = false;
@ -63,6 +74,8 @@ class Comment
/** /**
* @var User * @var User
* *
* @Serializer\Groups("post_show")
*
* @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\User") * @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\User")
* @ORM\JoinColumn(name="author_id") * @ORM\JoinColumn(name="author_id")
*/ */
@ -71,6 +84,8 @@ class Comment
/** /**
* @var Comment|null * @var Comment|null
* *
* @Serializer\Groups("post_show")
*
* @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment") * @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Comment")
* @ORM\JoinColumn(name="to_comment_id", nullable=true) * @ORM\JoinColumn(name="to_comment_id", nullable=true)
*/ */

View file

@ -5,19 +5,26 @@ namespace Skobkin\Bundle\PointToolsBundle\Entity\Blogs;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Skobkin\Bundle\PointToolsBundle\Entity\User; use Skobkin\Bundle\PointToolsBundle\Entity\User;
use Symfony\Component\Serializer\Annotation as Serializer;
/** /**
* 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
*
* @Serializer\Groups({"posts_list", "post_show"})
* *
* @ORM\Column(name="id", type="string", length=16) * @ORM\Column(name="id", type="string", length=16)
* @ORM\Id * @ORM\Id
@ -27,6 +34,8 @@ class Post
/** /**
* @var string * @var string
* *
* @Serializer\Groups({"posts_list", "post_show"})
*
* @ORM\Column(name="text", type="text") * @ORM\Column(name="text", type="text")
*/ */
private $text; private $text;
@ -34,6 +43,8 @@ class Post
/** /**
* @var \DateTime * @var \DateTime
* *
* @Serializer\Groups({"posts_list", "post_show"})
*
* @ORM\Column(name="created_at", type="datetime") * @ORM\Column(name="created_at", type="datetime")
*/ */
private $createdAt; private $createdAt;
@ -41,10 +52,19 @@ class Post
/** /**
* @var string * @var string
* *
* @Serializer\Groups({"posts_list", "post_show"})
*
* @ORM\Column(name="type", type="string", length=6) * @ORM\Column(name="type", type="string", length=6)
*/ */
private $type; private $type;
/**
* @var bool
*
* @ORM\Column(name="private", type="boolean", nullable=true)
*/
private $private;
/** /**
* @var bool * @var bool
* *
@ -55,6 +75,8 @@ class Post
/** /**
* @var User * @var User
* *
* @Serializer\Groups({"posts_list", "post_show"})
*
* @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\User") * @ORM\ManyToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\User")
* @ORM\JoinColumn(name="author") * @ORM\JoinColumn(name="author")
*/ */
@ -63,6 +85,8 @@ class Post
/** /**
* @var Tag[]|ArrayCollection * @var Tag[]|ArrayCollection
* *
* @Serializer\Groups({"posts_list", "post_show"})
*
* @ORM\ManyToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Tag", fetch="EXTRA_LAZY") * @ORM\ManyToMany(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\Blogs\Tag", fetch="EXTRA_LAZY")
* @ORM\JoinTable(name="posts.posts_tags", * @ORM\JoinTable(name="posts.posts_tags",
* joinColumns={@ORM\JoinColumn(name="post_id")}, * joinColumns={@ORM\JoinColumn(name="post_id")},
@ -74,15 +98,27 @@ class Post
/** /**
* @var Comment[]|ArrayCollection * @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; 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;
@ -254,6 +290,29 @@ 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;
}
/** /**
* Add comments * Add comments
* *

View file

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

View file

@ -3,6 +3,7 @@
namespace Skobkin\Bundle\PointToolsBundle\Entity\Blogs; namespace Skobkin\Bundle\PointToolsBundle\Entity\Blogs;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation as Serializer;
/** /**
* Tag * Tag
@ -10,7 +11,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
{ {
@ -26,6 +27,8 @@ class Tag
/** /**
* @var string * @var string
* *
* @Serializer\Groups("post_show")
*
* @ORM\Column(name="text", type="text", unique=true) * @ORM\Column(name="text", type="text", unique=true)
*/ */
private $text; private $text;

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()
;
}
}