Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace WIY\UserBundle\Entity;
- use Doctrine\ORM\Mapping as ORM;
- use FOS\UserBundle\Model\User as BaseUser;
- use Doctrine\Common\Collections\Collection;
- use Doctrine\Common\Collections\ArrayCollection;
- use Symfony\Component\HttpFoundation\File\UploadedFile;
- use Symfony\Component\Security\Core\Util\SecureRandom;
- use Symfony\Component\Validator\Constraints as Assert;
- /**
- * User
- *
- * @ORM\Table(name="fos_user")
- * @ORM\HasLifecycleCallbacks()
- * @ORM\Entity(repositoryClass="WIY\UserBundle\Entity\UserRepository")
- */
- class User extends BaseUser
- {
- /**
- * @var integer
- *
- * @ORM\Column(name="id", type="integer")
- * @ORM\Id
- * @ORM\GeneratedValue(strategy="AUTO")
- */
- protected $id;
- /**
- * @Assert\File(maxSize="2048k")
- * @Assert\Image(mimeTypesMessage="Please upload a valid image.")
- */
- protected $profilePictureFile;
- // for temporary storage
- private $tempProfilePicturePath;
- /**
- * @ORM\Column(type="string", length=255, nullable=true)
- */
- protected $profilePicturePath;
- /**
- * @ORM\OneToMany(targetEntity="WIY\ProductsBundle\Entity\Avis", mappedBy="user", cascade={"persist","remove"})
- */
- private $avis;
- /**
- * @var string
- *
- * @ORM\Column(name="sexe", type="string", length=32)
- * @Assert\NotBlank(message="Merci de remplir votre sexe.")
- * groups={"Registration"}
- */
- private $sexe;
- /**
- * @var string
- *
- * @ORM\Column(name="nom", type="string", length=64)*
- * @Assert\Length(
- * min=2,
- * max=64,
- * minMessage="Vous devez rentrer un nom.",
- * maxMessage="Le nom rentré semble trop long (max: 64 cararctères)",
- * groups={"Registration"}
- * )
- * @Assert\Regex(
- * pattern="/[a-z|ï|é|è|ö|\-]+/i",
- * message="Le nom renseigné semble invalide"
- *)
- */
- private $nom;
- /**
- * @var string
- *
- * @ORM\Column(name="prenom", type="string", length=64)
- * @Assert\Length(
- * min=3,
- * max=64,
- * minMessage="Vous devez rentrer un prénom.",
- * maxMessage="Le prénom rentré semble trop long (max: 64 caractères)",
- * groups={"Registration"}
- * )
- * @Assert\Regex(
- * pattern="/[a-z|ï|é|è|ö|\-]+/i",
- * message="Le prénom renseigné semble invalide"
- *)
- */
- private $prenom;
- /**
- * @var string
- *
- * @ORM\Column(name="naissance", type="string", length=4)
- * @Assert\Regex("/^[0-9]{4}$/", message="Votre année de naissance doit être composé de 4 chiffres", groups={"Registration"})
- */
- private $naissance;
- /**
- * @var string
- *
- * @ORM\Column(name="niveau", type="string", length=32)
- * @Assert\Length(
- * min=5,
- * max=32,
- * minMessage="Vous devez renseigner votre niveau.",
- * maxMessage="Vous devez renseigner votre niveau",
- * )
- */
- private $niveau;
- /**
- * @var string
- *
- * @ORM\Column(name="frequence", type="string", length=32)
- * @Assert\Length(
- * min=5,
- * max=32,
- * minMessage="Vous devez renseigner votre fréquence.",
- * maxMessage="Vous devez renseigner votre fréquence",
- * )
- */
- private $frequence;
- /**
- * @var string
- *
- * @ORM\Column(name="description", type="text", nullable=True)
- */
- private $description;
- /**
- * @var string
- *
- * @ORM\Column(name="facebookId", type="string", length=64, nullable=True)
- */
- private $facebookId;
- /**
- * @var string
- *
- * @ORM\Column(name="googleplusId", type="string", length=64, nullable=True)
- */
- private $googleplusId;
- /**
- * @var datetime
- *
- * @ORM\Column(name="createdOn", type="datetime")
- */
- private $createdOn;
- /**
- * @var datetime
- *
- * @ORM\Column(name="updatedOn", type="datetime", nullable=True)
- */
- private $updatedOn;
- /**
- * Constructor
- */
- public function __construct()
- {
- parent::__construct();
- $this->avis = new \Doctrine\Common\Collections\ArrayCollection();
- $this->createdOn = new \DateTime();
- }
- /**
- * Sets the file used for profile picture uploads
- *
- * @param UploadedFile $file
- * @return object
- */
- public function setProfilePictureFile(UploadedFile $file = null) {
- // set the value of the holder
- $this->profilePictureFile = $file;
- // check if we have an old image path
- if (isset($this->profilePicturePath)) {
- // store the old name to delete after the update
- $this->tempProfilePicturePath = $this->profilePicturePath;
- $this->profilePicturePath = null;
- } else {
- $this->profilePicturePath = 'initial';
- }
- return $this;
- }
- /**
- * Get the file used for profile picture uploads
- *
- * @return UploadedFile
- */
- public function getProfilePictureFile() {
- return $this->profilePictureFile;
- }
- /**
- * Set profilePicturePath
- *
- * @param string $profilePicturePath
- * @return User
- */
- public function setProfilePicturePath($profilePicturePath)
- {
- $this->profilePicturePath = $profilePicturePath;
- return $this;
- }
- /**
- * Get profilePicturePath
- *
- * @return string
- */
- public function getProfilePicturePath()
- {
- return $this->profilePicturePath;
- }
- /**
- * Get the absolute path of the profilePicturePath
- */
- public function getProfilePictureAbsolutePath() {
- return null === $this->profilePicturePath
- ? null
- : $this->getUploadRootDir().'/'.$this->profilePicturePath;
- }
- /**
- * Get root directory for file uploads
- *
- * @return string
- */
- protected function getUploadRootDir($type='profilePicture') {
- // the absolute directory path where uploaded
- // documents should be saved
- return __DIR__.'/../../../../web/'.$this->getUploadDir($type);
- }
- /**
- * Specifies where in the /web directory profile pic uploads are stored
- *
- * @return string
- */
- protected function getUploadDir($type='profilePicture') {
- // the type param is to change these methods at a later date for more file uploads
- // get rid of the __DIR__ so it doesn't screw up
- // when displaying uploaded doc/image in the view.
- return 'images/uploads';
- }
- /**
- * Get the web path for the user
- *
- * @return string
- */
- public function getWebProfilePicturePath() {
- return '/'.$this->getUploadDir().'/'.$this->getProfilePicturePath();
- }
- /**
- * @ORM\PrePersist()
- * @ORM\PreUpdate()
- */
- public function preUploadProfilePicture() {
- if (null !== $this->getProfilePictureFile()) {
- // a file was uploaded
- // generate a unique filename
- $filename = $this->generateRandomProfilePictureFilename();
- $this->setProfilePicturePath($filename.'.'.$this->getProfilePictureFile()->guessExtension());
- }
- }
- /**
- * Generates a 32 char long random filename
- *
- * @return string
- */
- public function generateRandomProfilePictureFilename() {
- $count = 0;
- do {
- $generator = new SecureRandom();
- $random = $generator->nextBytes(16);
- $randomString = bin2hex($random);
- $count++;
- }
- while(file_exists($this->getUploadRootDir().'/'.$randomString.'.'.$this->getProfilePictureFile()->guessExtension()) && $count < 50);
- return $randomString;
- }
- /**
- * @ORM\PostPersist()
- * @ORM\PostUpdate()
- *
- * Upload the profile picture
- *
- * @return mixed
- */
- public function uploadProfilePicture() {
- // check there is a profile pic to upload
- if ($this->getProfilePictureFile() === null) {
- return;
- }
- // if there is an error when moving the file, an exception will
- // be automatically thrown by move(). This will properly prevent
- // the entity from being persisted to the database on error
- $this->getProfilePictureFile()->move($this->getUploadRootDir(), $this->getProfilePicturePath());
- // check if we have an old image
- if (isset($this->tempProfilePicturePath) && file_exists($this->getUploadRootDir().'/'.$this->tempProfilePicturePath)) {
- // delete the old image
- unlink($this->getUploadRootDir().'/'.$this->tempProfilePicturePath);
- // clear the temp image path
- $this->tempProfilePicturePath = null;
- }
- $this->profilePictureFile = null;
- }
- /**
- * @ORM\PostRemove()
- */
- public function removeProfilePictureFile()
- {
- if ($file = $this->getProfilePictureAbsolutePath() && file_exists($this->getProfilePictureAbsolutePath())) {
- unlink($file);
- }
- }
- /**
- * Get id
- *
- * @return integer
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * Set sexe
- *
- * @param string $sexe
- * @return User
- */
- public function setSexe($sexe)
- {
- $this->sexe = $sexe;
- return $this;
- }
- /**
- * Get sexe
- *
- * @return string
- */
- public function getSexe()
- {
- return $this->sexe;
- }
- /**
- * Set nom
- *
- * @param string $nom
- * @return User
- */
- public function setNom($nom)
- {
- $this->nom = $nom;
- return $this;
- }
- /**
- * Get nom
- *
- * @return string
- */
- public function getNom()
- {
- return $this->nom;
- }
- /**
- * Set prenom
- *
- * @param string $prenom
- * @return User
- */
- public function setPrenom($prenom)
- {
- $this->prenom = $prenom;
- return $this;
- }
- /**
- * Get prenom
- *
- * @return string
- */
- public function getPrenom()
- {
- return $this->prenom;
- }
- /**
- * Set naissance
- *
- * @param string $naissance
- * @return User
- */
- public function setNaissance($naissance)
- {
- $this->naissance = $naissance;
- return $this;
- }
- /**
- * Get naissance
- *
- * @return string
- */
- public function getNaissance()
- {
- return $this->naissance;
- }
- /**
- * Set niveau
- *
- * @param string $niveau
- * @return User
- */
- public function setNiveau($niveau)
- {
- $this->niveau = $niveau;
- return $this;
- }
- /**
- * Get niveau
- *
- * @return string
- */
- public function getNiveau()
- {
- return $this->niveau;
- }
- /**
- * Set frequence
- *
- * @param string $frequence
- * @return User
- */
- public function setFrequence($frequence)
- {
- $this->frequence = $frequence;
- return $this;
- }
- /**
- * Get frequence
- *
- * @return string
- */
- public function getFrequence()
- {
- return $this->frequence;
- }
- /**
- * Set description
- *
- * @param string $description
- * @return User
- */
- public function setDescription($description)
- {
- $this->description = $description;
- return $this;
- }
- /**
- * Get description
- *
- * @return string
- */
- public function getDescription()
- {
- return $this->description;
- }
- /**
- * Set facebookId
- *
- * @param string $facebookId
- * @return User
- */
- public function setFacebookId($facebookId)
- {
- $this->facebookId = $facebookId;
- return $this;
- }
- /**
- * Get facebookId
- *
- * @return string
- */
- public function getFacebookId()
- {
- return $this->facebookId;
- }
- /**
- * Set googleplusId
- *
- * @param string $googleplusId
- * @return User
- */
- public function setGoogleplusId($googleplusId)
- {
- $this->googleplusId = $googleplusId;
- return $this;
- }
- /**
- * Get googleplusId
- *
- * @return string
- */
- public function getGoogleplusId()
- {
- return $this->googleplusId;
- }
- /**
- * Set createdOn
- *
- * @param \DateTime $createdOn
- * @return User
- */
- public function setCreatedOn($createdOn)
- {
- $this->createdOn = $createdOn;
- return $this;
- }
- /**
- * Get createdOn
- *
- * @return \DateTime
- */
- public function getCreatedOn()
- {
- return $this->createdOn;
- }
- /**
- * Set updatedOn
- *
- * @param \DateTime $updatedOn
- * @return User
- */
- public function setUpdatedOn($updatedOn)
- {
- $this->updatedOn = $updatedOn;
- return $this;
- }
- /**
- * Get updatedOn
- *
- * @return \DateTime
- */
- public function getUpdatedOn()
- {
- return $this->updatedOn;
- }
- /**
- * Add avis
- *
- * @param \WIY\ProductsBundle\Entity\Avis $avis
- * @return User
- */
- public function addAvi(\WIY\ProductsBundle\Entity\Avis $avis)
- {
- $this->avis[] = $avis;
- return $this;
- }
- /**
- * Remove avis
- *
- * @param \WIY\ProductsBundle\Entity\Avis $avis
- */
- public function removeAvi(\WIY\ProductsBundle\Entity\Avis $avis)
- {
- $this->avis->removeElement($avis);
- }
- /**
- * Get avis
- *
- * @return \Doctrine\Common\Collections\Collection
- */
- public function getAvis()
- {
- return $this->avis;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement