Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace AppBundle\Entity;
- use Doctrine\Common\Collections\ArrayCollection;
- use Doctrine\ORM\Mapping as ORM;
- use Symfony\Component\Validator\Constraints as Assert;
- use Gedmo\Mapping\Annotation as Gedmo;
- /**
- * @ORM\Entity(repositoryClass="AppBundle\Repository\GenusRepository")
- * @ORM\Table(name="genus")
- */
- class Genus
- {
- /**
- * @ORM\Id
- * @ORM\GeneratedValue(strategy="AUTO")
- * @ORM\Column(type="integer")
- */
- private $id;
- /**
- * @Assert\NotBlank()
- * @ORM\Column(type="string")
- */
- private $name;
- /**
- * @return mixed
- */
- public function getSlug()
- {
- return $this->slug;
- }
- /**
- * @param mixed $slug
- */
- public function setSlug($slug)
- {
- $this->slug = $slug;
- }
- /**
- * @Gedmo\Slug(fields={"name"})
- * @ORM\Column(type="string", unique=true)
- */
- private $slug;
- /**
- * @Assert\NotBlank()
- * @ORM\ManyToOne(targetEntity="AppBundle\Entity\SubFamily")
- * @ORM\JoinColumn(nullable=false)
- */
- private $subFamily;
- /**
- * @Assert\NotBlank()
- * @Assert\Range(min=0, minMessage="Negative species! Come on...")
- * @ORM\Column(type="integer")
- */
- private $speciesCount;
- /**
- * @ORM\Column(type="string", nullable=true)
- */
- private $funFact;
- /**
- * @ORM\Column(type="boolean")
- */
- private $isPublished = true;
- /**
- * @Assert\NotBlank()
- * @ORM\Column(type="date")
- */
- private $firstDiscoveredAt;
- /**
- * @ORM\OneToMany(targetEntity="GenusNote", mappedBy="genus")
- * @ORM\OrderBy({"createdAt" = "DESC"})
- */
- private $notes;
- /**
- * @ORM\ManyToMany(targetEntity="User", inversedBy="studiedGenuses", fetch="EXTRA_LAZY")
- * @ORM\JoinTable(name="genus_scientist")
- */
- private $genusScientists;
- public function __construct()
- {
- $this->notes = new ArrayCollection();
- $this->genusScientists = new ArrayCollection();
- }
- public function getId()
- {
- return $this->id;
- }
- public function getName()
- {
- return $this->name;
- }
- public function setName($name)
- {
- $this->name = $name;
- }
- /**
- * @return SubFamily
- */
- public function getSubFamily()
- {
- return $this->subFamily;
- }
- public function setSubFamily(SubFamily $subFamily = null)
- {
- $this->subFamily = $subFamily;
- }
- public function getSpeciesCount()
- {
- return $this->speciesCount;
- }
- public function setSpeciesCount($speciesCount)
- {
- $this->speciesCount = $speciesCount;
- }
- public function getFunFact()
- {
- return $this->funFact;
- }
- public function setFunFact($funFact)
- {
- $this->funFact = $funFact;
- }
- public function getUpdatedAt()
- {
- return new \DateTime('-'.rand(0, 100).' days');
- }
- public function setIsPublished($isPublished)
- {
- $this->isPublished = $isPublished;
- }
- public function getIsPublished()
- {
- return $this->isPublished;
- }
- /**
- * @return ArrayCollection|GenusNote[]
- */
- public function getNotes()
- {
- return $this->notes;
- }
- public function getFirstDiscoveredAt()
- {
- return $this->firstDiscoveredAt;
- }
- public function setFirstDiscoveredAt(\DateTime $firstDiscoveredAt = null)
- {
- $this->firstDiscoveredAt = $firstDiscoveredAt;
- }
- public function addGenusScientist(User $user){
- if($this->genusScientists->contains($user)) {
- return;
- }
- $this->genusScientists[] = $user;
- // Not needed for persistence, just keeping both sides in sync
- $user->addStudiedGenus($this);
- }
- public function removeGenusScientist(User $user)
- {
- if(!$this->genusScientists->contains($user)) {
- return;
- }
- $this->genusScientists->removeElement($user);
- // Not needed for persistence, just keeping both sides in sync
- $user->removeStudiedGenus($this);
- }
- /**
- * @return ArrayCollection|User[]
- */
- public function getGenusScientists()
- {
- return $this->genusScientists;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement