Advertisement
josk696

Genus

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