Added the Taggable interface to blog posts

Signed-off-by: Gergely POLONKAI (W00d5t0ck) <polesz@w00d5t0ck.info>
This commit is contained in:
Gergely POLONKAI (W00d5t0ck)
2012-09-16 22:58:51 +02:00
parent 831f4ca317
commit 507a8a5721
7 changed files with 131 additions and 2 deletions

View File

@@ -7,6 +7,7 @@ use Gedmo\Mapping\Annotation as GedmoORM;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\Common\Collections\ArrayCollection;
use DoctrineExtensions\Taggable\Taggable;
use GergelyPolonkai\FrontBundle\Entity\Comment;
use GergelyPolonkai\FrontBundle\Entity\User;
@@ -19,7 +20,7 @@ use GergelyPolonkai\FrontBundle\Entity\User;
* @ORM\Entity
* @ORM\Table(name="blog_posts")
*/
class Post
class Post implements Taggable
{
/**
* @var integer $id
@@ -86,6 +87,8 @@ class Post
*/
private $comments;
private $tags;
/**
* Constructor
*/
@@ -273,4 +276,21 @@ class Post
{
return $this->comments;
}
public function getTags()
{
$this->tags = $this->tags ?: new ArrayCollection();
return $this->tags;
}
public function getTaggableType()
{
return 'gergelypolonkaifront_post';
}
public function getTaggableId()
{
return $this->id;
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace GergelyPolonkai\FrontBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FPN\TagBundle\Entity\Tag as BaseTag;
/**
* Description of Tag
*
* @author polesz
*
* @ORM\Entity
* @ORM\Table(name="tags")
*/
class Tag extends BaseTag
{
/**
*
* @var integer $id
*
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/
protected $id;
/**
*
* @var Doctrine\Common\Collections\ArrayCollection $tagging
*
* @ORM\OneToMany(targetEntity="Tagging", mappedBy="tag", fetch="EAGER")
*/
protected $tagging;
}

View File

@@ -0,0 +1,36 @@
<?php
namespace GergelyPolonkai\FrontBundle\Entity;
use FPN\TagBundle\Entity\Tagging as BaseTagging;
use Doctrine\ORM\Mapping as ORM;
/**
* Description of Tagging
*
* @author polesz
*
* @ORM\Entity
* @ORM\Table(name="tagging", uniqueConstraints={
* @ORM\UniqueConstraint(name="tagging_idx", columns={"tag_id", "resource_type", "resource_id"})
* })
*/
class Tagging extends BaseTagging
{
/**
*
* @var integer $id
*
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/
protected $id;
/**
*
* @var GergelyPolonkai\FrontBundle\Entity\Tag $tag
*
* @ORM\ManyToOne(targetEntity="Tag")
*/
protected $tag;
}