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

@ -24,6 +24,7 @@ class AppKernel extends Kernel
new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(), new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(), new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
new Ivory\CKEditorBundle\IvoryCKEditorBundle(), new Ivory\CKEditorBundle\IvoryCKEditorBundle(),
new FPN\TagBundle\FPNTagBundle(),
new GergelyPolonkai\FrontBundle\GergelyPolonkaiFrontBundle(), new GergelyPolonkai\FrontBundle\GergelyPolonkaiFrontBundle(),
new GergelyPolonkai\GeshiBundle\GergelyPolonkaiGeshiBundle(), new GergelyPolonkai\GeshiBundle\GergelyPolonkaiGeshiBundle(),
); );

View File

@ -0,0 +1,32 @@
<?php
namespace Application\Migrations;
use Doctrine\DBAL\Migrations\AbstractMigration,
Doctrine\DBAL\Schema\Schema;
/**
* Auto-generated Migration: Please modify to your need!
*/
class Version20120916225801 extends AbstractMigration
{
public function up(Schema $schema)
{
// this up() migration is autogenerated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql");
$this->addSql("CREATE TABLE tagging (id INT AUTO_INCREMENT NOT NULL, tag_id INT DEFAULT NULL, resource_type VARCHAR(50) NOT NULL, resource_id VARCHAR(50) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX IDX_A4AED123BAD26311 (tag_id), UNIQUE INDEX tagging_idx (tag_id, resource_type, resource_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDB");
$this->addSql("CREATE TABLE tags (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(50) NOT NULL, slug VARCHAR(50) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, UNIQUE INDEX UNIQ_6FBC94265E237E06 (name), UNIQUE INDEX UNIQ_6FBC9426989D9B62 (slug), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDB");
$this->addSql("ALTER TABLE tagging ADD CONSTRAINT FK_A4AED123BAD26311 FOREIGN KEY (tag_id) REFERENCES tags (id)");
}
public function down(Schema $schema)
{
// this down() migration is autogenerated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql");
$this->addSql("ALTER TABLE tagging DROP FOREIGN KEY FK_A4AED123BAD26311");
$this->addSql("DROP TABLE tagging");
$this->addSql("DROP TABLE tags");
}
}

View File

@ -68,4 +68,9 @@ stof_doctrine_extensions:
orm: orm:
default: default:
sluggable: true sluggable: true
timestampable: true timestampable: true
fpn_tag:
model:
tag_class: GergelyPolonkai\FrontBundle\Entity\Tag
tagging_class: GergelyPolonkai\FrontBundle\Entity\Tagging

View File

@ -27,6 +27,7 @@
"easybook/geshi": "dev-master", "easybook/geshi": "dev-master",
"stof/doctrine-extensions-bundle": "dev-master", "stof/doctrine-extensions-bundle": "dev-master",
"doctrine/doctrine-migrations-bundle": "dev-master", "doctrine/doctrine-migrations-bundle": "dev-master",
"fpn/tag-bundle": "dev-master",
"egeloen/ckeditor-bundle": "dev-master", "egeloen/ckeditor-bundle": "dev-master",
"gergelypolonkai/tcpdfbundle": "dev-master" "gergelypolonkai/tcpdfbundle": "dev-master"
}, },

View File

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