<?php
namespace App\Entity;
use App\Config\AssetConfig;
use App\Repository\SpeakerRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity(repositoryClass=SpeakerRepository::class)
* @UniqueEntity("uri")
* @ORM\HasLifecycleCallbacks()
*/
class Speaker
{
use RemoveImageTrait;
const STATUS_NEW = 0;
const STATUS_APPROVE = 1;
const STATUS_REJECT = 2;
const TYPE_COMPANY = 1;
const TYPE_PERSON = 2;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @Gedmo\Slug(fields={"firstName", "lastName"})
* @ORM\Column(type="string", length=255, unique=true)
* @Assert\NotBlank()
* @Assert\Regex(pattern="/^[a-z\d\-]+$/", htmlPattern="^[a-zA-Z]+$")
*/
private $uri;
/**
* @ORM\Column(type="integer")
*/
private $type = self::TYPE_COMPANY;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $photo;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $photoWide;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $photoBackground;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $photoAvatar;
/**
* @ORM\Column(type="boolean")
*/
private $premium = false;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $font;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $shortDescription;
/**
* @ORM\Column(type="float")
*/
private $rating = 0;
/**
* @ORM\Column(type="integer")
*/
private $ratingVote = 0;
/**
* @ORM\Column(type="integer")
*/
private $position = 0;
/**
* @ORM\Column(type="boolean")
*/
private $inTopBanner = false;
/**
* @ORM\ManyToMany(targetEntity=Category::class, inversedBy="speakers")
*/
private $categories;
/**
* @ORM\ManyToMany(targetEntity=Badge::class, inversedBy="speakers")
*/
private $badges;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $created;
/**
* @ORM\Column(type="boolean")
*/
private $isNewFace = false;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $description;
/**
* @ORM\ManyToOne(targetEntity=MediaObject::class, cascade={"persist", "remove"})
*/
private $promoVideo;
/**
* @ORM\OneToMany(targetEntity=SpeakerLink::class, mappedBy="speaker", cascade={"persist", "remove"})
*/
private $speakerLinks;
/**
* @ORM\Column(type="boolean")
*/
private $enabled = false;
/**
* @ORM\ManyToMany(targetEntity=User::class, inversedBy="subscribedToSpeakers")
*/
private $subscribers;
/**
* @ORM\OneToMany(targetEntity=Review::class, mappedBy="speaker", orphanRemoval=true)
* @ORM\OrderBy({"date" = "DESC"})
*/
private $reviews;
/**
* @ORM\OneToMany(targetEntity=SpeakerCourse::class, mappedBy="speaker", orphanRemoval=true)
*/
private $courses;
/**
* @ORM\OneToMany(targetEntity=SpeakerConsultation::class, mappedBy="speaker", orphanRemoval=true)
*/
private $consultations;
/**
* @ORM\OneToOne(targetEntity=User::class, inversedBy="speaker", cascade={"persist"})
*/
private $user;
/**
* @ORM\OneToMany(targetEntity=PromoCode::class, mappedBy="speaker")
*/
private $promoCodes;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $keywords;
/**
* @ORM\OneToMany(targetEntity=SpeakerCharity::class, mappedBy="speaker", orphanRemoval=true, cascade={"persist", "remove"})
*/
private $charities;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $paymentReceiver;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $paymentIban;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $paymentIpn;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $paymentBank;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $paymentBic;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $paymentOkpo;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $personPaymentPhone;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $personPaymentCard;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $personPaymentBank;
/**
* @ORM\Column(type="json", nullable=true)
*/
private $premiumDetail = [];
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $topBannerExpired;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $premiumExpired;
/**
* @ORM\Column(type="string", length=255)
*/
private $tcLogin = '';
/**
* @ORM\Column(type="string", length=255)
*/
private $tcPass = '';
/**
* @ORM\Column(type="integer")
*/
private $status = self::STATUS_NEW;
private $nearestDate;
/**
* @ORM\PostRemove()
*/
public function postRemoveEvent()
{
$this->removeImage($this->getPhoto());
$this->removeImage($this->getPhotoWide());
$this->removeImage($this->getPhotoBackground());
$this->removeImage($this->getPhotoAvatar());
// Remove promo video
$this->removeImage($this->getPromoVideo(), AssetConfig::VIDEO_UPLOAD_DIR);
}
public function __construct()
{
$this->uri = uniqid();
$this->categories = new ArrayCollection();
$this->badges = new ArrayCollection();
$this->created = new \DateTime();
$this->speakerLinks = new ArrayCollection();
$this->subscribers = new ArrayCollection();
$this->reviews = new ArrayCollection();
$this->courses = new ArrayCollection();
$this->consultations = new ArrayCollection();
$this->promoCodes = new ArrayCollection();
$this->charities = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getUri(): ?string
{
return $this->uri;
}
public function setUri(?string $uri): self
{
$this->uri = (string)$uri;
return $this;
}
public function getType(): ?int
{
return $this->type;
}
public function setType(int $type): self
{
$this->type = $type;
return $this;
}
public function isCompany(): bool
{
return $this->type === self::TYPE_COMPANY;
}
public function isPerson(): bool
{
return $this->type === self::TYPE_PERSON;
}
public function getPhoto(): ?string
{
return $this->photo;
}
public function setPhoto(?string $photo): self
{
$this->photo = $photo;
return $this;
}
public function getPhotoWide(): ?string
{
return $this->photoWide;
}
public function setPhotoWide(?string $photoWide): self
{
$this->photoWide = $photoWide;
return $this;
}
public function getFirstName(): ?string
{
return $this->getUser() ? $this->getUser()->getFirstName() : null;
}
public function getLastName(): ?string
{
return $this->getUser() ? $this->getUser()->getLastName() : null;
}
public function getPremium(): ?bool
{
return $this->premium;
}
public function setPremium(bool $premium): self
{
$this->premium = $premium;
return $this;
}
public function getFont(): ?string
{
return $this->font;
}
public function setFont(?string $font): self
{
$this->font = $font;
return $this;
}
public function getShortDescription(): ?string
{
return $this->shortDescription;
}
public function setShortDescription(?string $shortDescription): self
{
$this->shortDescription = $shortDescription;
return $this;
}
public function getRating(): ?float
{
return $this->rating;
}
public function setRating(float $rating): self
{
$this->rating = $rating;
return $this;
}
public function getPosition(): ?int
{
return $this->position;
}
public function setPosition(int $position): self
{
$this->position = $position;
return $this;
}
public function getInTopBanner(): ?bool
{
return $this->inTopBanner;
}
public function setInTopBanner(bool $inTopBanner): self
{
$this->inTopBanner = $inTopBanner;
return $this;
}
/**
* @return Collection|Category[]
*/
public function getCategories(): Collection
{
$limit = $this->getPremiumDetail()->getCategoryLimit();
if ($this->categories->count() > $limit) {
return new ArrayCollection($this->categories->slice(0, $limit));
}
return $this->categories;
}
public function addCategory(Category $category): self
{
if (!$this->categories->contains($category)) {
$this->categories[] = $category;
}
return $this;
}
public function removeCategory(Category $category): self
{
$this->categories->removeElement($category);
return $this;
}
/**
* @return Collection|Badge[]
*/
public function getBadges(): Collection
{
return $this->badges;
}
public function addBadge(Badge $badge): self
{
if (!$this->badges->contains($badge)) {
$this->badges[] = $badge;
}
return $this;
}
public function removeBadge(Badge $badge): self
{
$this->badges->removeElement($badge);
return $this;
}
public function getRatingVote(): ?int
{
return $this->ratingVote;
}
public function setRatingVote(int $ratingVote): self
{
$this->ratingVote = $ratingVote;
return $this;
}
public function getCreated(): ?\DateTimeInterface
{
return $this->created;
}
public function setCreated(?\DateTimeInterface $created): self
{
$this->created = $created;
return $this;
}
public function getIsNewFace(): ?bool
{
return $this->isNewFace;
}
public function setIsNewFace(bool $isNewFace): self
{
$this->isNewFace = $isNewFace;
return $this;
}
public function getPhotoBackground(): ?string
{
return $this->photoBackground;
}
public function setPhotoBackground(?string $photoBackground): self
{
$this->photoBackground = $photoBackground;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getPromoVideo(): ?MediaObject
{
return $this->promoVideo;
}
public function setPromoVideo(?MediaObject $promoVideo): self
{
$this->promoVideo = $promoVideo;
return $this;
}
/**
* @return Collection|SpeakerLink[]
*/
public function getSpeakerLinks(): Collection
{
return $this->speakerLinks;
}
public function addSpeakerLink(SpeakerLink $speakerLink): self
{
$predicate = function ($key, $element) use ($speakerLink) {
return $element->getType() === $speakerLink->getType();
};
if (!$this->speakerLinks->exists($predicate)) {
$this->speakerLinks[] = $speakerLink;
$speakerLink->setSpeaker($this);
}
return $this;
}
public function removeSpeakerLink(SpeakerLink $speakerLink): self
{
if ($this->speakerLinks->removeElement($speakerLink)) {
// set the owning side to null (unless already changed)
if ($speakerLink->getSpeaker() === $this) {
$speakerLink->setSpeaker(null);
}
}
return $this;
}
public function getEnabled(): ?bool
{
return $this->enabled;
}
public function setEnabled(bool $enabled): self
{
$this->enabled = $enabled;
return $this;
}
public function __toString(): string
{
return $this->getFirstName() . ' ' . $this->getLastName();
}
/**
* @return Collection|User[]
*/
public function getSubscribers(): Collection
{
return $this->subscribers;
}
public function addSubscriber(User $subscriber): self
{
if (!$this->subscribers->contains($subscriber)) {
$this->subscribers[] = $subscriber;
}
return $this;
}
public function removeSubscriber(User $subscriber): self
{
$this->subscribers->removeElement($subscriber);
return $this;
}
/**
* @return Collection|Review[]
*/
public function getReviews(): Collection
{
return $this->reviews;
}
public function addReview(Review $review): self
{
if (!$this->reviews->contains($review)) {
$this->reviews[] = $review;
$review->setSpeaker($this);
}
return $this;
}
public function removeReview(Review $review): self
{
if ($this->reviews->removeElement($review)) {
// set the owning side to null (unless already changed)
if ($review->getSpeaker() === $this) {
$review->setSpeaker(null);
}
}
return $this;
}
public function updateRating()
{
$rating = 0;
$votes = 0;
if ($this->getReviews()->count() > 0) {
foreach ($this->getReviews() as $review) {
if ($review->isApproved()) {
$rating += $review->getRating();
$votes ++;
}
}
}
$this->setRating($votes > 0 ? ($rating / $votes) : 0)->setRatingVote($votes);
return $this;
}
/**
* @return Collection|SpeakerCourse[]
*/
public function getCourses(): Collection
{
return $this->courses;
}
public function addCourse(SpeakerCourse $course): self
{
if (!$this->courses->contains($course)) {
$this->courses[] = $course;
$course->setSpeaker($this);
}
return $this;
}
public function removeCourse(SpeakerCourse $course): self
{
if ($this->courses->removeElement($course)) {
// set the owning side to null (unless already changed)
if ($course->getSpeaker() === $this) {
$course->setSpeaker(null);
}
}
return $this;
}
/**
* @return Collection|SpeakerConsultation[]
*/
public function getConsultations(): Collection
{
return $this->consultations;
}
public function addConsultation(SpeakerConsultation $consultation): self
{
if (!$this->consultations->contains($consultation)) {
$consultation->setSpeaker($this);
$this->consultations[] = $consultation;
}
return $this;
}
public function removeConsultation(SpeakerConsultation $consultation): self
{
if ($this->consultations->removeElement($consultation)) {
// set the owning side to null (unless already changed)
if ($consultation->getSpeaker() === $this) {
$consultation->setSpeaker(null);
}
}
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
/**
* @return Collection|PromoCode[]
*/
public function getPromoCodes(): Collection
{
return $this->promoCodes;
}
public function addPromoCode(PromoCode $promoCode): self
{
if (!$this->promoCodes->contains($promoCode)) {
$this->promoCodes[] = $promoCode;
$promoCode->setSpeaker($this);
}
return $this;
}
public function removePromoCode(PromoCode $promoCode): self
{
if ($this->promoCodes->removeElement($promoCode)) {
// set the owning side to null (unless already changed)
if ($promoCode->getSpeaker() === $this) {
$promoCode->setSpeaker(null);
}
}
return $this;
}
public function getKeywords(): ?string
{
return $this->keywords;
}
public function setKeywords(?string $keywords): self
{
$this->keywords = $keywords;
return $this;
}
/**
* @return Collection|SpeakerCharity[]
*/
public function getCharities(): Collection
{
return $this->charities;
}
public function addCharity(SpeakerCharity $charity): self
{
$predicate = function ($key, $element) use ($charity) {
return $element->getCharity()->getId() == $charity->getCharity()->getId();
};
if (!$this->charities->exists($predicate)) {
$this->charities[] = $charity;
$charity->setSpeaker($this);
}
return $this;
}
public function removeCharity(SpeakerCharity $charity): self
{
if ($this->charities->removeElement($charity)) {
// set the owning side to null (unless already changed)
if ($charity->getSpeaker() === $this) {
$charity->setSpeaker(null);
}
}
return $this;
}
public function getPhotoAvatar(): ?string
{
return $this->photoAvatar;
}
public function setPhotoAvatar(?string $photoAvatar): self
{
$this->photoAvatar = $photoAvatar;
if ($this->getUser()->getAvatar() != $photoAvatar) {
$this->removeImage($this->getUser()->getAvatar());
$this->getUser()->setAvatar($photoAvatar);
}
return $this;
}
public function getPaymentReceiver(): ?string
{
return $this->paymentReceiver;
}
public function setPaymentReceiver(?string $paymentReceiver): self
{
$this->paymentReceiver = $paymentReceiver;
return $this;
}
public function getPaymentIban(): ?string
{
return $this->paymentIban;
}
public function setPaymentIban(?string $paymentIban): self
{
$this->paymentIban = $paymentIban;
return $this;
}
public function getPaymentIpn(): ?string
{
return $this->paymentIpn;
}
public function setPaymentIpn(?string $paymentIpn): self
{
$this->paymentIpn = $paymentIpn;
return $this;
}
public function getPaymentBank(): ?string
{
return $this->paymentBank;
}
public function setPaymentBank(?string $paymentBank): self
{
$this->paymentBank = $paymentBank;
return $this;
}
public function getPaymentBic(): ?string
{
return $this->paymentBic;
}
public function setPaymentBic(?string $paymentBic): self
{
$this->paymentBic = $paymentBic;
return $this;
}
public function getPaymentOkpo(): ?string
{
return $this->paymentOkpo;
}
public function setPaymentOkpo(?string $paymentOkpo): self
{
$this->paymentOkpo = $paymentOkpo;
return $this;
}
public function getPersonPaymentPhone(): ?string
{
return $this->personPaymentPhone;
}
public function setPersonPaymentPhone(?string $personPaymentPhone): self
{
$this->personPaymentPhone = $personPaymentPhone;
return $this;
}
public function getPersonPaymentCard(): ?string
{
return $this->personPaymentCard;
}
public function setPersonPaymentCard(?string $personPaymentCard): self
{
$this->personPaymentCard = $personPaymentCard;
return $this;
}
public function getPersonPaymentBank(): ?string
{
return $this->personPaymentBank;
}
public function setPersonPaymentBank(?string $personPaymentBank): self
{
$this->personPaymentBank = $personPaymentBank;
return $this;
}
public function getPremiumDetail(): ?SpeakerPremiumDetail
{
return new SpeakerPremiumDetail($this->premiumDetail);
}
public function setPremiumDetail(?SpeakerPremiumDetail $premiumDetail): self
{
$this->premiumDetail = is_null($premiumDetail) ? null : $premiumDetail->toArray();
return $this;
}
public function getTopBannerExpired(): ?\DateTimeInterface
{
return $this->topBannerExpired;
}
public function setTopBannerExpired(?\DateTimeInterface $topBannerExpired): self
{
$this->topBannerExpired = $topBannerExpired;
return $this;
}
public function getPremiumExpired(): ?\DateTimeInterface
{
return $this->premiumExpired;
}
public function setPremiumExpired(?\DateTimeInterface $premiumExpired): self
{
$this->premiumExpired = $premiumExpired;
return $this;
}
public function getTcLogin(): ?string
{
return $this->tcLogin;
}
public function setTcLogin(string $tcLogin): self
{
$this->tcLogin = $tcLogin;
return $this;
}
public function getTcPass(): ?string
{
return $this->tcPass;
}
public function setTcPass(string $tcPass): self
{
$this->tcPass = $tcPass;
return $this;
}
public function getStatus(): ?int
{
return $this->status;
}
public function setStatus(int $status): self
{
$this->status = $status;
return $this;
}
public function getNearestDate(): ?string
{
return $this->nearestDate;
}
public function setNearestDate(string $nearestDate): self
{
$this->nearestDate = $nearestDate;
return $this;
}
}