Created
December 1, 2016 21:39
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace AppBundle\Entity; | |
use Gedmo\Mapping\Annotation as Gedmo; | |
use Doctrine\Common\Collections\ArrayCollection; | |
use Doctrine\ORM\Mapping as ORM; | |
use Symfony\Component\Validator\Constraints as Assert; | |
/** | |
* @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; | |
/** | |
* @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\Column(type="string", unique=true) | |
* @Gedmo\Slug(fields={"name"}) | |
*/ | |
private $slug; | |
/** | |
* @ORM\OneToMany(targetEntity="AppBundle\Entity\GenusScientist", mappedBy="genus", fetch="EXTRA_LAZY") | |
*/ | |
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 getSlug() | |
{ | |
return $this->slug; | |
} | |
/** | |
* @param mixed $slug | |
*/ | |
public function setSlug($slug) | |
{ | |
$this->slug = $slug; | |
} | |
public function addGenusScientist(User $user) | |
{ | |
if ($this->genusScientists->contains($user)) { | |
return; | |
} | |
$this->genusScientists[] = $user; | |
// not needed for persistence,just keeping both sid in sync | |
$user->addStudiedGenus($this); | |
} | |
/** | |
* @return \Doctrine\Common\Collections\ArrayCollection| GenusScientist[] | |
*/ | |
public function getGenusScientists() | |
{ | |
return $this->genusScientists; | |
} | |
public function removeGenusScientist(User $user) | |
{ | |
if (!$this->genusScientists->contains($user)) { | |
return; | |
} | |
$this->genusScientists->removeElement($user); | |
// not needed for persistence,just keeping both sid in sync | |
$user->removeStudiedGenus($this); | |
} | |
} | |
// Class User | |
<?php | |
namespace AppBundle\Entity; | |
use Doctrine\Common\Collections\ArrayCollection; | |
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; | |
use Symfony\Component\Security\Core\Role\Role; | |
use Symfony\Component\Security\Core\User\UserInterface; | |
use Doctrine\ORM\Mapping as ORM; | |
use Symfony\Component\Validator\Constraints as Assert; | |
/** | |
* @ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository") | |
* @ORM\Table(name="user") | |
* @UniqueEntity(fields={"email"}, message="It looks like you already have an account!") | |
*/ | |
class User implements UserInterface | |
{ | |
/** | |
* @ORM\Id | |
* @ORM\GeneratedValue(strategy="AUTO") | |
* @ORM\Column(type="integer") | |
*/ | |
private $id; | |
/** | |
* @Assert\NotBlank() | |
* @Assert\Email() | |
* @ORM\Column(type="string", unique=true) | |
*/ | |
private $email; | |
/** | |
* The encoded password | |
* | |
* @ORM\Column(type="string") | |
*/ | |
private $password; | |
/** | |
* A non-persisted field that's used to create the encoded password. | |
* @Assert\NotBlank(groups={"Registration"}) | |
* | |
* @var string | |
*/ | |
private $plainPassword; | |
/** | |
* @ORM\Column(type="json_array") | |
*/ | |
private $roles = []; | |
/** | |
* @ORM\Column(type="boolean") | |
*/ | |
private $isScientist = false; | |
/** | |
* @ORM\Column(type="string", nullable=true) | |
*/ | |
private $firstName; | |
/** | |
* @ORM\Column(type="string", nullable=true) | |
*/ | |
private $lastName; | |
/** | |
* @ORM\Column(type="string", nullable=true) | |
*/ | |
private $avatarUri; | |
/** | |
* @ORM\Column(type="string", nullable=true) | |
*/ | |
private $universityName; | |
/** | |
* @ORM\OneToMany(targetEntity="AppBundle\Entity\GenusScientist", mappedBy="user") | |
*/ | |
private $studiedGenuses; | |
public function __construct() | |
{ | |
$this->studiedGenuses = new ArrayCollection(); | |
} | |
public function getId() | |
{ | |
return $this->id; | |
} | |
// needed by the security system | |
public function getUsername() | |
{ | |
return $this->email; | |
} | |
public function getRoles() | |
{ | |
$roles = $this->roles; | |
// give everyone ROLE_USER! | |
if (!in_array('ROLE_USER', $roles)) { | |
$roles[] = 'ROLE_USER'; | |
} | |
return $roles; | |
} | |
public function setRoles(array $roles) | |
{ | |
$this->roles = $roles; | |
} | |
public function getPassword() | |
{ | |
return $this->password; | |
} | |
public function getSalt() | |
{ | |
// leaving blank - I don't need/have a password! | |
} | |
public function eraseCredentials() | |
{ | |
$this->plainPassword = null; | |
} | |
public function getEmail() | |
{ | |
return $this->email; | |
} | |
public function setEmail($email) | |
{ | |
$this->email = $email; | |
} | |
public function setPassword($password) | |
{ | |
$this->password = $password; | |
} | |
public function getPlainPassword() | |
{ | |
return $this->plainPassword; | |
} | |
public function setPlainPassword($plainPassword) | |
{ | |
$this->plainPassword = $plainPassword; | |
// forces the object to look "dirty" to Doctrine. Avoids | |
// Doctrine *not* saving this entity, if only plainPassword changes | |
$this->password = null; | |
} | |
public function isScientist() | |
{ | |
return $this->isScientist; | |
} | |
public function setIsScientist($isScientist) | |
{ | |
$this->isScientist = $isScientist; | |
} | |
public function getFirstName() | |
{ | |
return $this->firstName; | |
} | |
public function setFirstName($firstName) | |
{ | |
$this->firstName = $firstName; | |
} | |
public function getLastName() | |
{ | |
return $this->lastName; | |
} | |
public function setLastName($lastName) | |
{ | |
$this->lastName = $lastName; | |
} | |
public function getAvatarUri() | |
{ | |
return $this->avatarUri; | |
} | |
public function setAvatarUri($avatarUri) | |
{ | |
$this->avatarUri = $avatarUri; | |
} | |
public function getUniversityName() | |
{ | |
return $this->universityName; | |
} | |
public function setUniversityName($universityName) | |
{ | |
$this->universityName = $universityName; | |
} | |
public function getFullName() | |
{ | |
return trim($this->getFirstName().' '.$this->getLastName()); | |
} | |
/** | |
* @return \Doctrine\Common\Collections\ArrayCollection|GenusScientist[] | |
*/ | |
public function getStudiedGenuses() | |
{ | |
return $this->studiedGenuses; | |
} | |
public function addStudiedGenus(Genus $genus) | |
{ | |
if($this->studiedGenuses->contains($genus)) { | |
return; | |
} | |
$this->studiedGenuses[] = $genus; | |
$genus->addGenusScientist($this); | |
} | |
public function removeStudiedGenus(Genus $genus) | |
{ | |
if (!$this->studiedGenuses->contains($genus)) { | |
return; | |
} | |
$this->studiedGenuses->removeElement($genus); | |
$genus->removeGenusScientist($this); | |
} | |
} | |
// Class GenusScientist | |
<?php | |
namespace AppBundle\Entity; | |
use Doctrine\ORM\Mapping as ORM; | |
/** | |
* @ORM\Entity | |
* @ORM\Table(name="genus_scientist") | |
*/ | |
class GenusScientist | |
{ | |
/** | |
* @ORM\Id | |
* @ORM\GeneratedValue(strategy="AUTO") | |
* @ORM\Column(type="integer") | |
*/ | |
private $id; | |
/** | |
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Genus", inversedBy="genusScientists") | |
* @ORM\JoinColumn(nullable=false) | |
*/ | |
private $genus; | |
/** | |
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="studiedGenuses") | |
* @ORM\JoinColumn(nullable=false) | |
*/ | |
private $user; | |
/** | |
* @ORM\Column(type="string") | |
*/ | |
private $yearsStudied; | |
public function getId() | |
{ | |
return $this->id; | |
} | |
public function getGenus() | |
{ | |
return $this->genus; | |
} | |
/** | |
* @param mixed $genus | |
*/ | |
public function setGenus($genus) | |
{ | |
$this->genus = $genus; | |
} | |
public function getUser() | |
{ | |
return $this->user; | |
} | |
/** | |
* @param mixed $user | |
*/ | |
public function setUser($user) | |
{ | |
$this->user = $user; | |
} | |
public function getYearsStudied() | |
{ | |
return $this->yearsStudied; | |
} | |
/** | |
* @param mixed $yearsStudied | |
*/ | |
public function setYearsStudied($yearsStudied) | |
{ | |
$this->yearsStudied = $yearsStudied; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment