Advertisement
Guest User

Untitled

a guest
Feb 13th, 2013
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.51 KB | None | 0 0
  1. <?php
  2.  
  3. namespace My\MoviesBundle\Entity;
  4.  
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Gedmo\Mapping\Annotation as Gedmo;
  7.  
  8. /**
  9.  * Movie
  10.  *
  11.  * @ORM\Table()
  12.  * @ORM\Entity(repositoryClass="My\MoviesBundle\Entity\MovieRepository")
  13.  * @ORM\HasLifecycleCallbacks
  14.  */
  15. class Movie
  16. {
  17.     /**
  18.      * @var integer
  19.      * @ORM\Column(name="id", type="integer")
  20.      * @ORM\Id
  21.      * @ORM\GeneratedValue(strategy="AUTO")
  22.      */
  23.     private $id;
  24.  
  25.     /**
  26.      * @var string
  27.      * @ORM\Column(name="name", type="string", length=255)
  28.      */
  29.     private $name;
  30.    
  31.     /**
  32.      * @var string
  33.      * @ORM\Column(name="slug", type="string", length=48, unique=true)
  34.      * @Gedmo\Slug(fields={"year", "name"}, separator="-", updatable=true, unique=true)
  35.      */
  36.     private $slug;
  37.  
  38.     /**
  39.      * @var string
  40.      * @ORM\Column(name="description", type="text")
  41.      */
  42.    
  43.     private $description;
  44.    
  45.      /**
  46.       * Year has to be string for slugable reason
  47.      * @var string
  48.      * @ORM\Column(name="year", type="string", length=4)
  49.      */
  50.      private $year;
  51.  
  52.     /**
  53.      * @var Entity ProductionCountry
  54.      * @ORM\ManyToMany(targetEntity="ProductionCountry", inversedBy="movie")
  55.      * @ORM\JoinTable(name="movie__has_production")
  56.      */
  57.     private $production;
  58.  
  59.     /**
  60.      * @var Category
  61.      * @ORM\ManyToOne(targetEntity="Category", inversedBy="movies")
  62.      */
  63.     private $category;
  64.    
  65.     /**
  66.      * @var CategorySub
  67.      * @ORM\ManyToOne(targetEntity="CategorySub", inversedBy="movies")
  68.      */
  69.     private $categorysub;
  70.    
  71.    
  72.     /**
  73.      * @var integer
  74.      * @ORM\Column(name="length", type="smallint")
  75.      */
  76.     private $length;
  77.    
  78.     /**
  79.      * @var Entity MovieInfo
  80.      * @ORM\OneToOne(targetEntity="MovieInfo", inversedBy="movie", orphanRemoval=true, cascade={"persist", "remove"}, fetch="EAGER")
  81.      * @ORM\JoinColumn(name="info_id", referencedColumnName="id", onDelete="cascade")
  82.      */
  83.     private $info;
  84.    
  85.     /**
  86.      * @var Entity Media
  87.      * @ORM\OneToOne(targetEntity="\Application\Sonata\MediaBundle\Entity\Media")
  88.      */
  89.     private $media;
  90.    
  91.     /**
  92.      * @var Entity Gallery
  93.      * @ORM\OneToOne(targetEntity="\Application\Sonata\MediaBundle\Entity\Gallery")
  94.      * @ORM\JoinColumn(name="gallery_id", referencedColumnName="id", nullable=false)
  95.      */
  96.     private $gallery;
  97.    
  98.      
  99.     /**
  100.      * @var Entity MovieHasOrder
  101.      * @ORM\OneToMany(targetEntity="MovieHasOrder" , mappedBy="movie" , cascade={"all"})
  102.      */
  103.     private $movieOrder;
  104.  
  105.     /**
  106.      * Convert object to string name
  107.      * @return string $name
  108.      */
  109.     public function __toString() {
  110.         return $this->name;
  111.     }
  112.     /**
  113.      * Check category include given sub-category
  114.      * @return boolean
  115.      */
  116.     public function isCategoryLegal()
  117.     {
  118.         if (!isset($this->categorysub)) return 1;
  119.         $categoryParent = $this->categorysub->getCategory();
  120.         return ($categoryParent->getId() == $this->category->getId());
  121.     }
  122.    
  123.     /**
  124.      * Get id
  125.      * @return integer
  126.      */
  127.     public function getId()
  128.     {
  129.         return $this->id;
  130.     }
  131.  
  132.     /**
  133.      * Set name
  134.      * @param string $name
  135.      * @return Movie
  136.      */
  137.     public function setName($name)
  138.     {
  139.         $this->name = $name;
  140.         return $this;
  141.     }
  142.  
  143.     /**
  144.      * Get name
  145.      * @return string
  146.      */
  147.     public function getName()
  148.     {
  149.         return $this->name;
  150.     }
  151.  
  152.     /**
  153.      * Set slug
  154.      * @param string $slug
  155.      * @return Movie
  156.      */
  157.     public function setSlug($slug)
  158.     {
  159.         $this->slug = $slug;
  160.         return $this;
  161.     }
  162.  
  163.     /**
  164.      * Get slug
  165.      * @return string
  166.      */
  167.     public function getSlug()
  168.     {
  169.         return $this->slug;
  170.     }
  171.  
  172.     /**
  173.      * Set description
  174.      * @param string $description
  175.      * @return Movie
  176.      */
  177.     public function setDescription($description)
  178.     {
  179.         $this->description = $description;
  180.         return $this;
  181.     }
  182.  
  183.     /**
  184.      * Get description
  185.      * @return string
  186.      */
  187.     public function getDescription()
  188.     {
  189.         return $this->description;
  190.     }
  191.  
  192.     /**
  193.      * Set premiere
  194.      * @param \DateTime $premiere
  195.      * @return Movie
  196.      */
  197.     public function setPremiere($premiere)
  198.     {
  199.         $this->premiere = $premiere;
  200.         return $this;
  201.     }
  202.  
  203.     /**
  204.      * Get premiere
  205.      * @return \DateTime
  206.      */
  207.     public function getPremiere()
  208.     {
  209.         return $this->premiere;
  210.     }
  211.  
  212.     /**
  213.      * Set category
  214.      * @param \My\MoviesBundle\Entity\Category $category
  215.      * @return Movie
  216.      */
  217.     public function setCategory(\My\MoviesBundle\Entity\Category $category = null)
  218.     {
  219.         $this->category = $category;
  220.         return $this;
  221.     }
  222.  
  223.     /**
  224.      * Get category
  225.      * @return \My\MoviesBundle\Entity\Category
  226.      */
  227.     public function getCategory()
  228.     {
  229.         return $this->category;
  230.     }
  231.  
  232.     /**
  233.      * Set categorysub
  234.      * @param \My\MoviesBundle\Entity\CategorySub $categorysub
  235.      * @return Movie
  236.      */
  237.     public function setCategorysub(\My\MoviesBundle\Entity\CategorySub $categorysub = null)
  238.     {
  239.         $this->categorysub = $categorysub;
  240.         return $this;
  241.     }
  242.  
  243.     /**
  244.      * Get categorysub
  245.      * @return \My\MoviesBundle\Entity\CategorySub
  246.      */
  247.     public function getCategorysub()
  248.     {
  249.         return $this->categorysub;
  250.     }
  251.  
  252.     /**
  253.      * Set year
  254.      * @param string $year
  255.      * @return Movie
  256.      */
  257.     public function setYear($year)
  258.     {
  259.         $this->year = $year;
  260.         return $this;
  261.     }
  262.  
  263.     /**
  264.      * Get year
  265.      * @return string
  266.      */
  267.     public function getYear()
  268.     {
  269.         return $this->year;
  270.     }
  271.  
  272.     /**
  273.      * Set length
  274.      * @param integer $length
  275.      * @return Movie
  276.      */
  277.     public function setLength($length)
  278.     {
  279.         $this->length = $length;
  280.         return $this;
  281.     }
  282.  
  283.     /**
  284.      * Get length
  285.      * @return integer
  286.      */
  287.     public function getLength()
  288.     {
  289.         return $this->length;
  290.     }
  291.  
  292.  
  293.     /**
  294.      * Add production
  295.      * @param \My\MoviesBundle\Entity\ProductionCountry $production
  296.      * @return Movie
  297.      */
  298.     public function addProduction(\My\MoviesBundle\Entity\ProductionCountry $production)
  299.     {
  300.         $this->production[] = $production;
  301.         return $this;
  302.     }
  303.  
  304.     /**
  305.      * Remove production
  306.      * @param \My\MoviesBundle\Entity\ProductionCountry $production
  307.      */
  308.     public function removeProduction(\My\MoviesBundle\Entity\ProductionCountry $production)
  309.     {
  310.         $this->production->removeElement($production);
  311.     }
  312.  
  313.     /**
  314.      * Get production
  315.      * @return \Doctrine\Common\Collections\Collection
  316.      */
  317.     public function getProduction()
  318.     {
  319.         return $this->production;
  320.     }
  321.    
  322.     /**
  323.      * Update year data
  324.      * @ORM\PrePersist
  325.      */
  326.     public function preUpload()
  327.     {
  328.         $this->year = $this->info->getPremiereYear();
  329.     }
  330.    
  331.     /**
  332.      * Update year data
  333.      * @ORM\preUpdate
  334.      */
  335.     public function preUpdate()
  336.     {
  337.         if ($this->year != $this->info->getPremiereYear()) {
  338.             $this->year = $this->info->getPremiereYear();
  339.         }
  340.     }
  341.  
  342.     /*
  343.      * Constructor
  344.      */
  345.     public function __construct()
  346.     {
  347.         $this->production = new \Doctrine\Common\Collections\ArrayCollection();
  348.     }
  349.    
  350.     /**
  351.      * Set info
  352.      * @param \My\MoviesBundle\Entity\MovieInfo $info
  353.      * @return Movie
  354.      */
  355.     public function setInfo(\My\MoviesBundle\Entity\MovieInfo $info = null)
  356.     {
  357.         $this->info = $info;
  358.         return $this;
  359.     }
  360.  
  361.     /**
  362.      * Get info
  363.      * @return \My\MoviesBundle\Entity\MovieInfo
  364.      */
  365.     public function getInfo()
  366.     {
  367.         return $this->info;
  368.     }
  369.  
  370.     /**
  371.      * Set media
  372.      * @param \Application\Sonata\MediaBundle\Entity\Media $media
  373.      * @return Movie
  374.      */
  375.     public function setMedia(\Application\Sonata\MediaBundle\Entity\Media $media = null)
  376.     {
  377.         $this->media = $media;
  378.         return $this;
  379.     }
  380.  
  381.     /**
  382.      * Get media
  383.      * @return \Application\Sonata\MediaBundle\Entity\Media
  384.      */
  385.     public function getMedia()
  386.     {
  387.         return $this->media;
  388.     }
  389.  
  390.     /**
  391.      * Set gallery
  392.      * @param \Application\Sonata\MediaBundle\Entity\Gallery $gallery
  393.      * @return Movie
  394.      */
  395.     public function setGallery(\Application\Sonata\MediaBundle\Entity\Gallery $gallery = null)
  396.     {
  397.         $this->gallery = $gallery;
  398.         return $this;
  399.     }
  400.  
  401.     /**
  402.      * Get gallery
  403.      * @return \Application\Sonata\MediaBundle\Entity\Gallery
  404.      */
  405.     public function getGallery()
  406.     {
  407.         return $this->gallery;
  408.     }
  409.  
  410.    
  411.  
  412.     /**
  413.      * Add movieOrder
  414.      * @param \My\MoviesBundle\Entity\MovieHasOrder $movieOrder
  415.      * @return Movie
  416.      */
  417.     public function addMovieOrder(\My\MoviesBundle\Entity\MovieHasOrder $movieOrder)
  418.     {
  419.         $this->movieOrder[] = $movieOrder;
  420.         return $this;
  421.     }
  422.  
  423.     /**
  424.      * Remove movieOrder
  425.      * @param \My\MoviesBundle\Entity\MovieHasOrder $movieOrder
  426.      */
  427.     public function removeMovieOrder(\My\MoviesBundle\Entity\MovieHasOrder $movieOrder)
  428.     {
  429.         $this->movieOrder->removeElement($movieOrder);
  430.     }
  431.  
  432.     /**
  433.      * Get movieOrder
  434.      * @return \Doctrine\Common\Collections\Collection
  435.      */
  436.     public function getMovieOrder()
  437.     {
  438.         return $this->movieOrder;
  439.     }
  440. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement