<?php
namespace AppBundle\Entity;
use Doctrine\Common\Collections\Collection;
use AppBundle\Entity\Traits\TimestampableTrait;
use AppBundle\Entity\Traits\IsActiveTrait;
use AppBundle\Entity\Traits\PictureTrait;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Security\Core\User\UserInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
/**
* Website
*
* @ORM\Table(name="Website")
* @ORM\Entity(repositoryClass="AppBundle\Entity\Repository\WebsiteRepository")
* @Vich\Uploadable
* @ORM\HasLifecycleCallbacks
* @UniqueEntity("email", groups={"creation", "configuration"}, message="Adresse e-mail déjà utilisée")
* @UniqueEntity("url", groups={"creation"}, message="Ce nom de domaine est déjà utilisé")
*/
class Website implements UserInterface, \Serializable, PasswordAuthenticatedUserInterface
{
use TimestampableTrait;
use IsActiveTrait;
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="club_name", type="string", length=255, nullable=true)
* @Assert\NotBlank(groups={"admin", "creation", "configuration"})
* @Assert\Length(max="35", maxMessage="Le nom du club doit faire au maximum {{ limit }} caractères", groups={"admin", "creation", "configuration"})
*/
private $clubName;
/**
* @var string
*
* @ORM\Column(name="url", type="string", length=255, nullable=true)
*/
private $url;
/**
* @var string
*
* @ORM\Column(name="club_number", type="string", length=255, nullable=true)
* @Assert\NotBlank(groups={"admin", "creation", "configuration"})
*/
private $clubNumber;
/**
* @var string
*
* @ORM\Column(name="address", type="string", length=255, nullable=true)
*/
private $address;
/**
* @var string
*
* @ORM\Column(name="zipcode", type="string", length=255, nullable=true)
*/
private $zipcode;
/**
* @var string
*
* @ORM\Column(name="city", type="string", length=255, nullable=true)
*/
private $city;
/**
* @var string
*
* @ORM\Column(name="latitude", type="float", nullable=true)
*/
private $latitude;
/**
* @var string
*
* @ORM\Column(name="longitude", type="float", nullable=true)
*/
private $longitude;
/**
* @var string
*
* @ORM\Column(name="phone", type="string", length=255, nullable=true)
*/
private $phone;
/**
* @var string
*
* @ORM\Column(name="contact_email", type="string", length=255, nullable=true)
* @Assert\NotBlank(groups={"admin", "configuration"})
*/
private $contactEmail;
/**
* @var string
*
* @ORM\Column(name="contact_name", type="string", length=255, nullable=true)
* @Assert\NotBlank(groups={"admin", "configuration"})
*/
private $contactName;
/**
* @var string
*
* @ORM\Column(name="responsable_lastname", type="string", length=255, nullable=true)
*/
private $responsableLastname;
/**
* @var string
*
* @ORM\Column(name="responsable_firstname", type="string", length=255, nullable=true)
*/
private $responsableFirstname;
/**
* @var string
*
* @ORM\Column(name="responsable_email", type="string", length=255, nullable=true)
* @Assert\NotBlank(groups={"admin", "configuration"})
*/
private $responsableEmail;
/**
* @var string
*
* @ORM\Column(name="club_responsable", type="string", length=255, nullable=true)
* @Assert\NotBlank(groups={"admin", "configuration"})
*/
private $clubResponsable;
/**
* @ORM\Column(name="is_online_subscribed", type="boolean", nullable=true)
*/
private bool $isOnlineSubscribed = false;
/**
* @ORM\Column(name="is_complete", type="boolean", nullable=true)
*/
private bool $isComplete = false;
/**
* @ORM\Column(name="theme_color", type="string", length=255, nullable=true)
*/
private string $themeColor = 'blue';
/**
* @ORM\Column(name="theme_site", type="string", length=255, nullable=true)
*/
private string $themeSite = '1';
/**
* @var string
*
* @Gedmo\Slug(fields={"clubName"}, updatable=false)
* @ORM\Column(type="string", length=255)
*/
private $slug;
/**
* @var string
*
* @ORM\Column(name="password", type="string", length=255)
* @Assert\NotBlank(groups={"creation"})
* @Assert\Length(min="6", minMessage="Le mot de passe doit faire au moins {{ limit }} caractères", groups={"creation"})
*/
private $password;
/**
* @var string
*
* @ORM\Column(name="email", type="string", length=255)
* @Assert\NotBlank(groups={"creation", "configuration"})
* @Assert\Email(groups={"creation", "configuration"})
*/
private $email;
/**
* @var string
*
* @ORM\Column(name="facebook_url", type="string", length=255, nullable=true)
*/
private $facebookUrl;
/**
* @var string
*
* @ORM\Column(name="twitter_url", type="string", length=255, nullable=true)
*/
private $twitterUrl;
/**
* @var string
*
* @ORM\Column(name="instagram_url", type="string", length=255, nullable=true)
*/
private $instagramUrl;
/**
* @var string
*
* @ORM\Column(name="youtube_url", type="string", length=255, nullable=true)
*/
private $youtubeUrl;
/**
* @ORM\Column(name="salt", type="string", length=255)
*/
private string $salt;
/**
* @var integer
*
* @ORM\Column(name="news_position", type="integer", nullable=true, options= {"default" : 1})
*/
private $newsPosition = 1;
/**
* @var bool
*
* @ORM\Column(name="news_visible", type="boolean", options= {"default" : 1})
*/
private $newsVisible = true;
/**
* @var integer
*
* @ORM\Column(name="event_position", type="integer", nullable=true, options= {"default" : 2})
*/
private $eventPosition = 2;
/**
* @var bool
*
* @ORM\Column(name="event_visible", type="boolean", options= {"default" : 1})
*/
private $eventVisible = true;
/**
* @var integer
*
* @ORM\Column(name="gallery_position", type="integer", nullable=true, options= {"default" : 3})
*/
private $galleryPosition = 3;
/**
* @var bool
*
* @ORM\Column(name="gallery_visible", type="boolean", options= {"default" : 1})
*/
private $galleryVisible = true;
/**
* @var datetime $cgu_at
*
* @ORM\Column(name="cgu_at", type="datetime")
*/
private \Datetime $cguAt;
/**
* @var string $authenticationToken
*
* @ORM\Column(name="authentication_token", type="string", length=255, nullable=true)
*/
private $authenticationToken;
/**
* @ORM\OneToMany(targetEntity="Partner", mappedBy="website", cascade={"persist", "remove"})
*/
protected $partners;
/**
* @ORM\OneToMany(targetEntity="News", mappedBy="website", cascade={"persist", "remove"})
*/
protected $news;
/**
* @ORM\OneToMany(targetEntity="Event", mappedBy="website", cascade={"persist", "remove"})
*/
protected $events;
/**
* @ORM\OneToMany(targetEntity="Gallery", mappedBy="website", cascade={"persist", "remove"})
* @ORM\OrderBy({"displayDate" = "DESC"})
*/
protected $galleries;
/**
* @ORM\OneToMany(targetEntity="Page", mappedBy="website", cascade={"persist", "remove"})
*/
protected $pages;
/**
* @ORM\ManyToOne(targetEntity="Contract", inversedBy="websites")
* @ORM\JoinColumn(name="contract_id", referencedColumnName="id", nullable=true, onDelete="cascade")
*/
protected $contract;
/**
* @Assert\Image(
* maxSize="8M",
* minWidth="500",
* minHeight="333",
* groups={"creation", "configuration"},
* mimeTypes={"image/png", "image/jpeg"}
* )
* @Vich\UploadableField(mapping="default_picture", fileNameProperty="pictureName")
*
* @var File $picture
*/
protected $picture;
/**
* @ORM\Column(name="picture_name", type="string", length=255, nullable=true)
*
* @var string $pictureName
*/
protected $pictureName;
public function __construct()
{
$this->salt = base_convert(sha1(uniqid(random_int(0, mt_getrandmax()), true)), 16, 36);
$this->partners = new ArrayCollection();
$this->news = new ArrayCollection();
$this->events = new ArrayCollection();
$this->galleries = new ArrayCollection();
$this->pages = new ArrayCollection();
$this->cguAt = new \Datetime();
}
public function __toString()
{
if($this->clubName) return $this->clubName;
return "new";
}
public function serialize()
{
return serialize([$this->id, $this->email, $this->password, $this->salt]);
}
/** @see \Serializable::unserialize() */
public function unserialize($serialized)
{
[$this->id, $this->email, $this->password, $this->salt] = unserialize($serialized);
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
* @return Product
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Get username
*
* @return string
*/
public function getUsername()
{
return $this->email;
}
/**
* Set password
*
* @param string $password
*
* @return User
*/
public function setPassword($password)
{
$this->password = $password;
return $this;
}
/**
* Get password
*
* @return string
*/
public function getPassword(): ?string
{
return $this->password;
}
/**
* Set email
*
* @param string $email
*
* @return User
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
public function getSalt()
{
return $this->salt;
}
public function getSlug()
{
return $this->slug;
}
public function getRoles()
{
return ['ROLE_WEBMASTER'];
}
public function eraseCredentials()
{
}
/**
* Set clubName
*
* @param string $clubName
*
* @return Website
*/
public function setClubName($clubName)
{
$this->clubName = $clubName;
return $this;
}
/**
* Get clubName
*
* @return string
*/
public function getClubName()
{
return $this->clubName;
}
/**
* Set clubNumber
*
* @param string $clubNumber
*
* @return Website
*/
public function setClubNumber($clubNumber)
{
$this->clubNumber = $clubNumber;
return $this;
}
/**
* Get clubNumber
*
* @return string
*/
public function getClubNumber()
{
return $this->clubNumber;
}
/**
* Set address
*
* @param string $address
*
* @return Website
*/
public function setAddress($address)
{
$this->address = $address;
return $this;
}
/**
* Get address
*
* @return string
*/
public function getAddress()
{
return $this->address;
}
/**
* Set zipcode
*
* @param string $zipcode
*
* @return Website
*/
public function setZipcode($zipcode)
{
$this->zipcode = $zipcode;
return $this;
}
/**
* Get zipcode
*
* @return string
*/
public function getZipcode()
{
return $this->zipcode;
}
/**
* Set city
*
* @param string $city
*
* @return Website
*/
public function setCity($city)
{
$this->city = $city;
return $this;
}
/**
* Get city
*
* @return string
*/
public function getCity()
{
return $this->city;
}
/**
* Set latitude
*
* @param float $latitude
*
* @return Website
*/
public function setLatitude($latitude)
{
$this->latitude = $latitude;
return $this;
}
/**
* Get latitude
*
* @return float
*/
public function getLatitude()
{
return $this->latitude;
}
/**
* Set longitude
*
* @param float $longitude
*
* @return Website
*/
public function setLongitude($longitude)
{
$this->longitude = $longitude;
return $this;
}
/**
* Get longitude
*
* @return float
*/
public function getLongitude()
{
return $this->longitude;
}
/**
* Set phone
*
* @param string $phone
*
* @return Website
*/
public function setPhone($phone)
{
$this->phone = $phone;
return $this;
}
/**
* Get phone
*
* @return string
*/
public function getPhone()
{
return $this->phone;
}
/**
* Set contactEmail
*
* @param string $contactEmail
*
* @return Website
*/
public function setContactEmail($contactEmail)
{
$this->contactEmail = $contactEmail;
return $this;
}
/**
* Get contactEmail
*
* @return string
*/
public function getContactEmail()
{
return $this->contactEmail;
}
/**
* Set contactName
*
* @param string $contactName
*
* @return Website
*/
public function setContactName($contactName)
{
$this->contactName = $contactName;
return $this;
}
/**
* Get contactName
*
* @return string
*/
public function getContactName()
{
return $this->contactName;
}
/**
* Set isOnlineSubscribed
*
* @param boolean $isOnlineSubscribed
*
* @return Website
*/
public function setIsOnlineSubscribed($isOnlineSubscribed)
{
$this->isOnlineSubscribed = $isOnlineSubscribed;
return $this;
}
/**
* Get isOnlineSubscribed
*
* @return boolean
*/
public function getIsOnlineSubscribed()
{
return $this->isOnlineSubscribed;
}
/**
* Set themeColor
*
* @param string $themeColor
*
* @return Website
*/
public function setThemeColor($themeColor)
{
$this->themeColor = $themeColor;
return $this;
}
/**
* Get themeColor
*
* @return string
*/
public function getThemeColor()
{
return $this->themeColor;
}
/**
* Set themeSite
*
* @param string $themeSite
*
* @return Website
*/
public function setThemeSite($themeSite)
{
$this->themeSite = $themeSite;
return $this;
}
/**
* Get themeSite
*
* @return string
*/
public function getThemeSite()
{
return $this->themeSite;
}
/**
* Set url
*
* @param string $url
*
* @return Website
*/
public function setUrl($url)
{
$this->url = $url;
return $this;
}
/**
* Get url
*
* @return string
*/
public function getUrl()
{
if(strstr($this->url, 'https') !== false) {
return $this->url;
}
else {
return 'https://'.$this->url;
}
}
/**
* Set salt
*
* @param string $salt
*
* @return Website
*/
public function setSalt($salt)
{
$this->salt = $salt;
return $this;
}
/**
* Add partner
*
* @param Partner $partner
*
* @return Website
*/
public function addPartner(Partner $partner)
{
$partner->setWebsite($this);
$this->partners[] = $partner;
return $this;
}
/**
* Remove partner
*
* @param Partner $partner
*/
public function removePartner(Partner $partner)
{
$this->partners->removeElement($partner);
}
/**
* Get partners
*
* @return Collection
*/
public function getPartners()
{
return $this->partners;
}
/**
* Add news
*
* @param News $news
*
* @return Website
*/
public function addNews(News $news)
{
$news->setWebsite($this);
$this->news[] = $news;
return $this;
}
/**
* Remove news
*
* @param News $news
*/
public function removeNews(News $news)
{
$this->news->removeElement($news);
}
/**
* Get news
*
* @return Collection
*/
public function getNews()
{
return $this->news;
}
/**
* Add event
*
* @param Event $event
*
* @return Website
*/
public function addEvent(Event $event)
{
$event->setWebsite($this);
$this->events[] = $event;
return $this;
}
/**
* Remove event
*
* @param Event $event
*/
public function removeEvent(Event $event)
{
$this->events->removeElement($event);
}
/**
* Get events
*
* @return Collection
*/
public function getEvents()
{
return $this->events;
}
/**
* Add gallery
*
* @param Gallery $gallery
*
* @return Website
*/
public function addGallery(Gallery $gallery)
{
$gallery->setWebsite($this);
$this->galleries[] = $gallery;
return $this;
}
/**
* Remove gallery
*
* @param Gallery $gallery
*/
public function removeGallery(Gallery $gallery)
{
$this->galleries->removeElement($gallery);
}
/**
* Get galleries
*
* @return Collection
*/
public function getGalleries()
{
return $this->galleries;
}
/**
* Add page
*
* @param Page $page
*
* @return Website
*/
public function addPage(Page $page)
{
$page->setWebsite($this);
$this->pages[] = $page;
return $this;
}
/**
* Remove page
*
* @param Page $page
*/
public function removePage(Page $page)
{
$this->pages->removeElement($page);
}
/**
* Get pages
*
* @return Collection
*/
public function getPages()
{
return $this->pages;
}
/**
* Set facebookUrl
*
* @param string $facebookUrl
*
* @return Website
*/
public function setFacebookUrl($facebookUrl)
{
$this->facebookUrl = $facebookUrl;
return $this;
}
/**
* Get facebookUrl
*
* @return string
*/
public function getFacebookUrl()
{
return $this->facebookUrl;
}
/**
* Set twitterUrl
*
* @param string $twitterUrl
*
* @return Website
*/
public function setTwitterUrl($twitterUrl)
{
$this->twitterUrl = $twitterUrl;
return $this;
}
/**
* Get twitterUrl
*
* @return string
*/
public function getTwitterUrl()
{
return $this->twitterUrl;
}
/**
* Set instagramUrl
*
* @param string $instagramUrl
*
* @return Website
*/
public function setInstagramUrl($instagramUrl)
{
$this->instagramUrl = $instagramUrl;
return $this;
}
/**
* Get instagramUrl
*
* @return string
*/
public function getInstagramUrl()
{
return $this->instagramUrl;
}
/**
* Set youtubeUrl
*
* @param string $youtubeUrl
*
* @return Website
*/
public function setYoutubeUrl($youtubeUrl)
{
$this->youtubeUrl = $youtubeUrl;
return $this;
}
/**
* Get youtubeUrl
*
* @return string
*/
public function getYoutubeUrl()
{
return $this->youtubeUrl;
}
/**
* Set usageContract
*
* @param UsageContract $usageContract
*
* @return Website
*/
public function setContract(Contract $contract = null)
{
$this->contract = $contract;
return $this;
}
/**
* Get usageContract
*
* @return UsageContract
*/
public function getContract()
{
return $this->contract;
}
/**
* Set isComplete
*
* @param boolean $isComplete
*
* @return Website
*/
public function setIsComplete($isComplete)
{
$this->isComplete = $isComplete;
return $this;
}
/**
* Get isComplete
*
* @return boolean
*/
public function getIsComplete()
{
return $this->isComplete;
}
/**
* Set cguAt
*
* @param datetime $cguAt
*/
public function setCguAt($cguAt)
{
$this->cguAt = $cguAt;
return $this;
}
/**
* Get cguAt
*
* @return string
*/
public function getCguAt()
{
return $this->cguAt;
}
public function hasSocialNetworks()
{
if($this->facebookUrl != "" || $this->instagramUrl != "" || $this->twitterUrl != ""
|| $this->youtubeUrl != "") {
return true;
}
return false;
}
public function getPageAdhesion()
{
foreach($this->pages as $page) {
if($page->getIsAdhesion() === true) {
return $page;
}
}
}
public function setAuthenticationToken($token)
{
$this->authenticationToken = $token;
}
public function getAuthenticationToken()
{
return $this->authenticationToken;
}
public function generateAndSetAuthenticationToken()
{
$this->authenticationToken = sha1(uniqid().random_int(10000,90000).$this->email.time());
}
public function getResponsableLastname(): ?string
{
return $this->responsableLastname;
}
public function setResponsableLastname(?string $responsableLastname): self
{
$this->responsableLastname = $responsableLastname;
return $this;
}
public function getResponsableFirstname(): ?string
{
return $this->responsableFirstname;
}
public function setResponsableFirstname(?string $responsableFirstname): self
{
$this->responsableFirstname = $responsableFirstname;
return $this;
}
public function getResponsableEmail(): ?string
{
return $this->responsableEmail;
}
public function setResponsableEmail(?string $responsableEmail): self
{
$this->responsableEmail = $responsableEmail;
return $this;
}
public function getClubResponsable(): ?string
{
return $this->clubResponsable;
}
public function setClubResponsable(?string $clubResponsable): self
{
$this->clubResponsable = $clubResponsable;
return $this;
}
public function getNewsPosition(): ?int
{
return $this->newsPosition;
}
public function setNewsPosition(?int $newsPosition): self
{
$this->newsPosition = $newsPosition;
return $this;
}
public function isNewsVisible(): ?bool
{
return $this->newsVisible;
}
public function setNewsVisible(bool $newsVisible): self
{
$this->newsVisible = $newsVisible;
return $this;
}
public function getEventPosition(): ?int
{
return $this->eventPosition;
}
public function setEventPosition(?int $eventPosition): self
{
$this->eventPosition = $eventPosition;
return $this;
}
public function isEventVisible(): ?bool
{
return $this->eventVisible;
}
public function setEventVisible(bool $eventVisible): self
{
$this->eventVisible = $eventVisible;
return $this;
}
public function getGalleryPosition(): ?int
{
return $this->galleryPosition;
}
public function setGalleryPosition(?int $galleryPosition): self
{
$this->galleryPosition = $galleryPosition;
return $this;
}
public function isGalleryVisible(): ?bool
{
return $this->galleryVisible;
}
public function setGalleryVisible(bool $galleryVisible): self
{
$this->galleryVisible = $galleryVisible;
return $this;
}
public function getFixedMenuWithPositions(): array
{
$positions = [];
if ($this->isNewsVisible()) {
$positions[$this->getNewsPosition()] = ['title' => 'actualités', 'route' => 'news'];
}
if ($this->isEventVisible()) {
$positions[$this->getEventPosition()] = ['title' => 'événements', 'route' => 'events'];
}
if ($this->isGalleryVisible()) {
$positions[$this->getGalleryPosition()] = ['title' => 'galeries', 'route' => 'galleries'];
}
ksort($positions);
return $positions;
}
/**
* @param File $picture
*/
public function setPicture($picture)
{
$this->picture = $picture;
if ($picture instanceof File) {
$this->updatedAt = new \DateTime('now');
}
}
/**
* @return File
*/
public function getPicture()
{
return $this->picture;
}
/**
* @param string $pictureName
*/
public function setPictureName($pictureName)
{
$this->pictureName = $pictureName;
}
/**
* @return string
*/
public function getPictureName()
{
return $this->pictureName;
}
}