Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* ============== ENTITIES ================ */
- // src/PPost/SourceBundle/Entity/Source.php
- namespace PPost\SourceBundle\Entity;
- use Doctrine\ORM\Mapping as ORM;
- use Symfony\Component\Validator\Constraints as Assert;
- use Symfony\Bridge\Doctrine\Validator\Constraints as Unique;
- /**
- * PPost\SourceBundle\Entity\Source
- *
- * @ORM\Entity
- * @Unique\UniqueEntity(fields={"title"})
- * @Unique\UniqueEntity(fields={"url"})
- * @ORM\Table(name="ppost_source")
- */
- class Source
- {
- /**
- * @var integer $id
- *
- * @ORM\Id
- * @ORM\Column(name="id", type="integer")
- * @ORM\GeneratedValue(strategy="AUTO")
- */
- protected $id;
- /**
- * @var string $title
- *
- * @ORM\Column(name="title", type="string", length=255, nullable=false)
- * @Assert\NotBlank
- */
- protected $title;
- /**
- * @ORM\ManyToMany(targetEntity="Topic", inversedBy="sources", cascade={"persist"})
- * @ORM\JoinTable(name="ppost_source_topic",
- * joinColumns={@ORM\JoinColumn(name="source_id", referencedColumnName="id")},
- * inverseJoinColumns={@ORM\JoinColumn(name="topic_id", referencedColumnName="id")}
- * )
- */
- protected $topics;
- public function __construct()
- {
- $this->topics = new \Doctrine\Common\Collections\ArrayCollection();
- }
- /**
- * Set title
- *
- * @param string $title
- */
- public function setTitle($title)
- {
- $this->title = $title;
- }
- /**
- * Get title
- *
- * @return string
- */
- public function getTitle()
- {
- return $this->title;
- }
- /**
- * Add topic
- *
- * @param PPost\SourceBundle\Entity\Source $topic
- */
- public function addTopic(\PPost\SourceBundle\Entity\Topic $topic)
- {
- $this->topics[] = $topic;
- }
- /**
- * Get topic
- *
- * @return Doctrine\Common\Collections\Collection
- */
- public function getTopics()
- {
- return $this->topics;
- }
- }
- // src/PPost/SourceBundle/Entity/Topic.php
- namespace PPost\SourceBundle\Entity;
- use Doctrine\ORM\Mapping as ORM;
- use Symfony\Component\Validator\Constraints as Assert;
- use Symfony\Bridge\Doctrine\Validator\Constraints as Unique;
- /**
- * PPost\SourceBundle\Entity\Topic
- *
- * @ORM\Entity
- * @Unique\UniqueEntity(fields={"title"})
- * @ORM\Table(name="ppost_topic")
- */
- class Topic
- {
- /**
- * @ORM\Id
- * @ORM\Column(type="integer")
- * @ORM\GeneratedValue(strategy="AUTO")
- */
- protected $id;
- /**
- * @ORM\Column(type="string", unique=true, length=255, nullable=false)
- * @Assert\NotBlank
- */
- protected $title;
- /**
- * Inverse Side
- *
- * @ORM\ManyToMany(targetEntity="Source", mappedBy="topics")
- */
- protected $sources;
- public function __construct()
- {
- $this->sources = new \Doctrine\Common\Collections\ArrayCollection();
- }
- /**
- * Get id
- *
- * @return integer
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * Set title
- *
- * @param string $title
- */
- public function setTitle($title)
- {
- $this->title = $title;
- }
- /**
- * Get title
- *
- * @return string
- */
- public function getTitle()
- {
- return $this->title;
- }
- /**
- * Add sources
- *
- * @param PPost\SourceBundle\Entity\Source $sources
- */
- public function addSource(\PPost\SourceBundle\Entity\Source $sources)
- {
- $this->sources[] = $sources;
- }
- /**
- * Get sources
- *
- * @return Doctrine\Common\Collections\Collection
- */
- public function getSources()
- {
- return $this->sources;
- }
- }
- /* ============== FORM ================ */
- // src/PPost/SourceBundle/Form/SoureType.php
- namespace PPost\SourceBundle\Form;
- use Symfony\Component\Form\AbstractType;
- use Symfony\Component\Form\FormBuilder;
- class SourceType extends AbstractType
- {
- public function buildForm(FormBuilder $builder, array $options)
- {
- $builder
- ->add('title')
- ->add('topics', 'entity', array(
- 'class' => 'PPost\\SourceBundle\\Entity\\Topic',
- 'property' => 'title',
- ))
- ;
- }
- public function getDefaultOptions(array $options)
- {
- return array('data_class' => 'PPost\SourceBundle\Entity\Source');
- }
- public function getName()
- {
- return 'ppost_sourcebundle_sourcetype';
- }
- }
Add Comment
Please, Sign In to add comment