Guest User

Untitled

a guest
Oct 23rd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.61 KB | None | 0 0
  1. <?php
  2.  
  3. /* ============== ENTITIES ================ */
  4.  
  5. // src/PPost/SourceBundle/Entity/Source.php
  6.  
  7. namespace PPost\SourceBundle\Entity;
  8.  
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. use Symfony\Bridge\Doctrine\Validator\Constraints as Unique;
  12.  
  13. /**
  14.  * PPost\SourceBundle\Entity\Source
  15.  *
  16.  * @ORM\Entity
  17.  * @Unique\UniqueEntity(fields={"title"})
  18.  * @Unique\UniqueEntity(fields={"url"})
  19.  * @ORM\Table(name="ppost_source")
  20.  */
  21. class Source
  22. {
  23.     /**
  24.      * @var integer $id
  25.      *
  26.      * @ORM\Id
  27.      * @ORM\Column(name="id", type="integer")
  28.      * @ORM\GeneratedValue(strategy="AUTO")
  29.      */
  30.     protected $id;
  31.  
  32.     /**
  33.      * @var string $title
  34.      *
  35.      * @ORM\Column(name="title", type="string", length=255, nullable=false)
  36.      * @Assert\NotBlank
  37.      */
  38.     protected $title;
  39.  
  40.     /**
  41.      * @ORM\ManyToMany(targetEntity="Topic", inversedBy="sources", cascade={"persist"})
  42.      * @ORM\JoinTable(name="ppost_source_topic",
  43.      *      joinColumns={@ORM\JoinColumn(name="source_id", referencedColumnName="id")},
  44.      *      inverseJoinColumns={@ORM\JoinColumn(name="topic_id", referencedColumnName="id")}
  45.      *      )
  46.      */
  47.     protected $topics;
  48.  
  49.     public function __construct()
  50.     {
  51.         $this->topics = new \Doctrine\Common\Collections\ArrayCollection();
  52.     }
  53.  
  54.     /**
  55.      * Set title
  56.      *
  57.      * @param string $title
  58.      */
  59.     public function setTitle($title)
  60.     {
  61.         $this->title = $title;
  62.     }
  63.  
  64.     /**
  65.      * Get title
  66.      *
  67.      * @return string
  68.      */
  69.     public function getTitle()
  70.     {
  71.         return $this->title;
  72.     }
  73.    
  74.     /**
  75.      * Add topic
  76.      *
  77.      * @param PPost\SourceBundle\Entity\Source $topic
  78.      */
  79.     public function addTopic(\PPost\SourceBundle\Entity\Topic $topic)
  80.     {
  81.         $this->topics[] = $topic;
  82.     }
  83.  
  84.     /**
  85.      * Get topic
  86.      *
  87.      * @return Doctrine\Common\Collections\Collection
  88.      */
  89.     public function getTopics()
  90.     {
  91.         return $this->topics;
  92.     }
  93. }
  94.  
  95.  
  96.  
  97. // src/PPost/SourceBundle/Entity/Topic.php
  98.  
  99. namespace PPost\SourceBundle\Entity;
  100.  
  101. use Doctrine\ORM\Mapping as ORM;
  102. use Symfony\Component\Validator\Constraints as Assert;
  103. use Symfony\Bridge\Doctrine\Validator\Constraints as Unique;
  104.  
  105. /**
  106.  * PPost\SourceBundle\Entity\Topic
  107.  *
  108.  * @ORM\Entity
  109.  * @Unique\UniqueEntity(fields={"title"})
  110.  * @ORM\Table(name="ppost_topic")
  111.  */
  112. class Topic
  113. {
  114.     /**
  115.      * @ORM\Id
  116.      * @ORM\Column(type="integer")
  117.      * @ORM\GeneratedValue(strategy="AUTO")
  118.      */
  119.     protected $id;
  120.  
  121.     /**
  122.      * @ORM\Column(type="string", unique=true, length=255, nullable=false)
  123.      * @Assert\NotBlank
  124.      */
  125.     protected $title;
  126.  
  127.     /**
  128.      * Inverse Side
  129.      *
  130.      * @ORM\ManyToMany(targetEntity="Source", mappedBy="topics")
  131.      */
  132.     protected $sources;
  133.  
  134.     public function __construct()
  135.     {
  136.         $this->sources = new \Doctrine\Common\Collections\ArrayCollection();
  137.     }
  138.  
  139.     /**
  140.      * Get id
  141.      *
  142.      * @return integer
  143.      */
  144.     public function getId()
  145.     {
  146.         return $this->id;
  147.     }
  148.  
  149.     /**
  150.      * Set title
  151.      *
  152.      * @param string $title
  153.      */
  154.     public function setTitle($title)
  155.     {
  156.         $this->title = $title;
  157.     }
  158.  
  159.     /**
  160.      * Get title
  161.      *
  162.      * @return string
  163.      */
  164.     public function getTitle()
  165.     {
  166.         return $this->title;
  167.     }
  168.    
  169.     /**
  170.      * Add sources
  171.      *
  172.      * @param PPost\SourceBundle\Entity\Source $sources
  173.      */
  174.     public function addSource(\PPost\SourceBundle\Entity\Source $sources)
  175.     {
  176.         $this->sources[] = $sources;
  177.     }
  178.  
  179.     /**
  180.      * Get sources
  181.      *
  182.      * @return Doctrine\Common\Collections\Collection
  183.      */
  184.     public function getSources()
  185.     {
  186.         return $this->sources;
  187.     }
  188. }
  189.  
  190.  
  191.  
  192. /* ============== FORM ================ */
  193.  
  194. // src/PPost/SourceBundle/Form/SoureType.php
  195.  
  196. namespace PPost\SourceBundle\Form;
  197.  
  198. use Symfony\Component\Form\AbstractType;
  199. use Symfony\Component\Form\FormBuilder;
  200.  
  201. class SourceType extends AbstractType
  202. {
  203.     public function buildForm(FormBuilder $builder, array $options)
  204.     {
  205.         $builder
  206.             ->add('title')
  207.             ->add('topics', 'entity', array(
  208.                 'class' => 'PPost\\SourceBundle\\Entity\\Topic',
  209.                 'property' => 'title',
  210.             ))
  211.         ;
  212.     }
  213.  
  214.     public function getDefaultOptions(array $options)
  215.     {
  216.         return array('data_class' => 'PPost\SourceBundle\Entity\Source');
  217.     }
  218.  
  219.     public function getName()
  220.     {
  221.         return 'ppost_sourcebundle_sourcetype';
  222.     }
  223. }
Add Comment
Please, Sign In to add comment