Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.36 KB | None | 0 0
  1. <?php
  2.  
  3. namespace AppBundle\Entity;
  4.  
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. use Gedmo\Mapping\Annotation as Gedmo;
  9.  
  10.  
  11. /**
  12.  * @ORM\Entity(repositoryClass="AppBundle\Repository\GenusRepository")
  13.  * @ORM\Table(name="genus")
  14.  */
  15. class Genus
  16. {
  17.     /**
  18.      * @ORM\Id
  19.      * @ORM\GeneratedValue(strategy="AUTO")
  20.      * @ORM\Column(type="integer")
  21.      */
  22.     private $id;
  23.  
  24.     /**
  25.      * @Assert\NotBlank()
  26.      * @ORM\Column(type="string")
  27.      */
  28.     private $name;
  29.  
  30.     /**
  31.      * @return mixed
  32.      */
  33.     public function getSlug()
  34.     {
  35.         return $this->slug;
  36.     }
  37.  
  38.     /**
  39.      * @param mixed $slug
  40.      */
  41.     public function setSlug($slug)
  42.     {
  43.         $this->slug = $slug;
  44.     }
  45.  
  46.     /**
  47.      * @Gedmo\Slug(fields={"name"})
  48.      * @ORM\Column(type="string", unique=true)
  49.      */
  50.     private $slug;
  51.  
  52.     /**
  53.      * @Assert\NotBlank()
  54.      * @ORM\ManyToOne(targetEntity="AppBundle\Entity\SubFamily")
  55.      * @ORM\JoinColumn(nullable=false)
  56.      */
  57.     private $subFamily;
  58.  
  59.     /**
  60.      * @Assert\NotBlank()
  61.      * @Assert\Range(min=0, minMessage="Negative species! Come on...")
  62.      * @ORM\Column(type="integer")
  63.      */
  64.     private $speciesCount;
  65.  
  66.     /**
  67.      * @ORM\Column(type="string", nullable=true)
  68.      */
  69.     private $funFact;
  70.  
  71.     /**
  72.      * @ORM\Column(type="boolean")
  73.      */
  74.     private $isPublished = true;
  75.  
  76.     /**
  77.      * @Assert\NotBlank()
  78.      * @ORM\Column(type="date")
  79.      */
  80.     private $firstDiscoveredAt;
  81.  
  82.     /**
  83.      * @ORM\OneToMany(targetEntity="GenusNote", mappedBy="genus")
  84.      * @ORM\OrderBy({"createdAt" = "DESC"})
  85.      */
  86.     private $notes;
  87.  
  88.     /**
  89.      * @ORM\ManyToMany(targetEntity="User", inversedBy="studiedGenuses", fetch="EXTRA_LAZY")
  90.      * @ORM\JoinTable(name="genus_scientist")
  91.      */
  92.     private $genusScientists;
  93.  
  94.     public function __construct()
  95.     {
  96.         $this->notes = new ArrayCollection();
  97.         $this->genusScientists = new ArrayCollection();
  98.     }
  99.  
  100.     public function getId()
  101.     {
  102.         return $this->id;
  103.     }
  104.  
  105.     public function getName()
  106.     {
  107.         return $this->name;
  108.     }
  109.  
  110.     public function setName($name)
  111.     {
  112.         $this->name = $name;
  113.     }
  114.  
  115.     /**
  116.      * @return SubFamily
  117.      */
  118.     public function getSubFamily()
  119.     {
  120.         return $this->subFamily;
  121.     }
  122.  
  123.     public function setSubFamily(SubFamily $subFamily = null)
  124.     {
  125.         $this->subFamily = $subFamily;
  126.     }
  127.  
  128.     public function getSpeciesCount()
  129.     {
  130.         return $this->speciesCount;
  131.     }
  132.  
  133.     public function setSpeciesCount($speciesCount)
  134.     {
  135.         $this->speciesCount = $speciesCount;
  136.     }
  137.  
  138.     public function getFunFact()
  139.     {
  140.         return $this->funFact;
  141.     }
  142.  
  143.     public function setFunFact($funFact)
  144.     {
  145.         $this->funFact = $funFact;
  146.     }
  147.  
  148.     public function getUpdatedAt()
  149.     {
  150.         return new \DateTime('-'.rand(0, 100).' days');
  151.     }
  152.  
  153.     public function setIsPublished($isPublished)
  154.     {
  155.         $this->isPublished = $isPublished;
  156.     }
  157.  
  158.     public function getIsPublished()
  159.     {
  160.         return $this->isPublished;
  161.     }
  162.  
  163.     /**
  164.      * @return ArrayCollection|GenusNote[]
  165.      */
  166.     public function getNotes()
  167.     {
  168.         return $this->notes;
  169.     }
  170.  
  171.     public function getFirstDiscoveredAt()
  172.     {
  173.         return $this->firstDiscoveredAt;
  174.     }
  175.  
  176.     public function setFirstDiscoveredAt(\DateTime $firstDiscoveredAt = null)
  177.     {
  178.         $this->firstDiscoveredAt = $firstDiscoveredAt;
  179.     }
  180.  
  181.     public function addGenusScientist(User $user){
  182.  
  183.         if($this->genusScientists->contains($user)) {
  184.             return;
  185.         }
  186.  
  187.         $this->genusScientists[] = $user;
  188.         // Not needed for persistence, just keeping both sides in sync
  189.         $user->addStudiedGenus($this);
  190.     }
  191.  
  192.     public function removeGenusScientist(User $user)
  193.     {
  194.         if(!$this->genusScientists->contains($user)) {
  195.             return;
  196.         }
  197.  
  198.         $this->genusScientists->removeElement($user);
  199.         // Not needed for persistence, just keeping both sides in sync
  200.         $user->removeStudiedGenus($this);
  201.     }
  202.  
  203.     /**
  204.      * @return ArrayCollection|User[]
  205.      */
  206.     public function getGenusScientists()
  207.     {
  208.         return $this->genusScientists;
  209.     }
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement