<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiSubresource;
use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Serializer\Filter\GroupFilter;
use App\Entity\Traits\Address;
use App\Repository\CompanyRepository;
use App\Security\UserChecker;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\Entity(repositoryClass=CompanyRepository::class)
* @ApiResource(
* normalizationContext={
* "groups"={"company:read"}
* },
* denormalizationContext={
* "groups"={"company:write"}
* },
* itemOperations={
* "get",
* "patch"={
* "security"="is_granted('ROLE_ADMIN') or is_granted('ROLE_COMPANY')"
* },
* "delete"={
* "security"="is_granted('ROLE_ADMIN')"
* }
* },
* collectionOperations={
* "get"={
* "security"="is_granted('ROLE_ADMIN')"
* },
* "post"={
* "security"="is_granted('ROLE_ADMIN')"
* },
* "export"={
* "method"="GET",
* "controller"="App\Controller\Api\CompanyController::extractCsv",
* "path"="/companies/export",
* "formats"={"csv"={"text/csv"}},
* "pagination_enabled"=false,
* "output"=Company::class,
* "normalization_context"={"groups"={"company:export_csv:read"}}
* },
* "post_update"={
* "security"="is_granted('ROLE_ADMIN')",
* "path"="/companies/{id}",
* "description"="Update a Company with method POST (using content-type: 'multipart')",
* "method"="POST",
* "controller"="App\Controller\Api\CompanyController::update"
* }
* }
* )
* @ApiFilter(SearchFilter::class,
* properties={
* "name":"partial"
* }
* )
* @ApiFilter(OrderFilter::class,
* properties={
* "id", "name", "user.lastName", "status", "subscriptionEnd", "subscriptionStart", "clientsCount"
* }
* )
* @ApiFilter(GroupFilter::class,
* arguments={
* "overrideDefaultGroups": true
* }
* )
* @ApiFilter(PropertyFilter::class,
* arguments={
* "parameterName"="fields",
* "overrideDefaultProperties"=true
* }
* )
* @ORM\HasLifecycleCallbacks
* @Vich\Uploadable
*/
class Company
{
const STATUS_ACTIVE = 'active';
const STATUS_EXPIRED = 'expired';
const STATUS_SUSPENDED = 'suspended';
const STATUS_INACTIVE = 'deactivated';
const MESSAGE_RESTRICTION = 'restricted_msg';
const MESSAGE_QUOTAS = 'restricted_msg';
const MESSAGE_DEFAULT = 'default';
const STATUSES = [
self::STATUS_INACTIVE,
self::STATUS_EXPIRED,
self::STATUS_SUSPENDED,
self::STATUS_ACTIVE,
];
use Address;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"company:read", "team:read", "company:read:id", "client:read", "company_form", "teamplay:read", "video:read", "exclusion_video:read", "exclusion_category:read", "category:read", "program:read", "message:read"})
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank
* @Groups({"company:read", "team:read", "company:read:name", "client:read", "company_form", "teamplay:read", "video:read", "exclusion_video:read", "exclusion_category:read", "category:read", "program:read", "message:read"})
*/
private $name;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"company:read:image", "client:read"})
*/
private $image;
/**
* @Groups({"company:read", "company:read:imageUrl", "client:read", "user:read"})
* @var ?string
*/
private $imageUrl = "https://placehold.co/600x300";
/**
* @ORM\Column(type="datetime", nullable=true)
* @Gedmo\Timestampable(on="update")
*/
private $updatedAt;
/**
* @ORM\OneToOne(targetEntity=User::class, inversedBy="company", cascade={"persist", "refresh", "remove"})
* @ORM\JoinColumn(nullable=false)
* @Assert\Valid()
* @Groups({"company:read", "company:read:user"})
*/
private $user;
/**
* @Vich\UploadableField(mapping="specialists_images", fileNameProperty="image")
* @Assert\File(
* mimeTypes={"image/jpeg", "image/gif", "image/png"},
* maxSize="700Ki",
* )
* @var File
*/
private $imageFile;
/**
* @ORM\OneToMany(targetEntity=Room::class, mappedBy="company", orphanRemoval=true, cascade={"persist", "refresh", "remove"})
* @Groups({"company:read", "company:read:rooms"})
*/
private $rooms;
/**
* @ORM\OneToMany(targetEntity=Workshop::class, mappedBy="company", cascade={"persist", "refresh", "remove"})
* @Groups({"company:read", "company:read:workshop"})
*/
private $workshops;
/**
* @ORM\OneToMany(targetEntity=Client::class, mappedBy="company", orphanRemoval=true, cascade={"persist", "refresh", "remove"})
* @Groups({"company:read", "company:read:clients"})
* @ApiSubresource(maxDepth=1)
*/
private $clients;
/**
* @ORM\OneToMany(targetEntity=Event::class, mappedBy="company", cascade={"persist", "refresh", "remove"})
* @Groups({"company:read", "company:read:events"})
*/
private $events;
/**
* @ORM\OneToMany(targetEntity=CompanyTag::class, mappedBy="company", orphanRemoval=true, cascade={"persist", "refresh", "remove"})
*/
private $companyTags;
/**
* @ORM\Column(type="text", nullable=true)
* @Groups({"company:read", "company:read:presentation"})
*/
private $presentation;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"company:read", "company:read:presentationTitle"})
*/
private $presentationTitle;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"company:read", "company:read:siret"})
*/
private $siret;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"company:read", "company:read:phone"})
*/
private $phone;
/**
* @ORM\Column(type="datetime", options={"default": "CURRENT_TIMESTAMP"})
* @Gedmo\Timestampable(on="create")
* @Groups({"company:read", "company:read:createdAt"})
*/
private $createdAt;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"company:read", "company:read:companyCode"})
*/
private $companyCode;
/**
* @ORM\OneToMany(targetEntity=VisioEventPromotion::class, mappedBy="company", cascade={"persist", "refresh", "remove"})
*/
private $visioEventPromotions;
/**
* @ORM\Column(type="boolean", options={"default": "1"})
* @Groups({"company:read", "company:read:visioAllowed"})
*/
private $visioAllowed = true;
/**
* @ORM\Column(type="boolean", options={"default": "1"})
* @Groups({"company:read", "company:read:visioPaymentAllowed"})
*/
private $visioPaymentAllowed = true;
/**
* @ORM\OneToMany(targetEntity=Specialist::class, mappedBy="affiliatedCompany", orphanRemoval=false)
*/
private $affiliatedSpecialists;
/**
* @ORM\ManyToMany(targetEntity=Specialist::class, mappedBy="companies")
* @Groups({"company:read", "company:read:specialists"})
*/
private $specialists;
/**
* @ORM\OneToMany(targetEntity=AffiliatedEventApplication::class, mappedBy="company", cascade={"persist", "refresh", "remove"})
*/
private $affiliatedEventApplications;
/**
* @ORM\OneToMany(targetEntity=Segmentation::class, mappedBy="company", cascade={"persist", "refresh", "remove"})
* @Groups({"company:read", "company:read:segmentations"})
* @ApiSubresource(maxDepth=1)
*/
private $segmentations;
/**
* @ORM\Column(type="boolean", options={"default": "0"})
* @Groups({"company:read", "client:read"})
*/
private $forceSegmentation = false;
/**
* @ORM\OneToMany(targetEntity=Configuration::class, mappedBy="company", cascade={"persist", "refresh", "remove"})
* @Groups({"company:read", "company:read:configurations"})
*/
private $configurations;
// TV FIELDS
/**
* @ORM\ManyToOne(targetEntity=MediaObject::class)
* @Groups({"company:read", "company:write", "company:read:logo", "client:read"})
*/
private $logo;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"company:read", "company:write", "company:read:siren"})
*/
private $siren;
/**
* @ORM\Column(type="string", length=255, options={"default": "active"})
* @Groups({"company:read", "company:write", "company:read:status"})
*/
private $status = self::STATUS_ACTIVE;
/**
* @ORM\Column(type="boolean", options={"default": "1"})
* @Groups({"company:read", "company:read:active"})
*/
private $active = true;
/**
* @ORM\Column(type="datetime", nullable=true)
* @Groups({"company:read", "company:write", "company:read:subscriptionStart"})
*/
private $subscriptionStart;
/**
* @ORM\Column(type="datetime", nullable=true)
* @Groups({"company:read", "company:write", "company:read:subscriptionEnd"})
*/
private $subscriptionEnd;
/**
* @ORM\Column(type="integer")
* @Groups({"company:read", "company:read:clientsCount"})
*/
private $clientsCount = 0;
/**
* Restriction messages if an User bypasses any restrictions
* A 'default' message key will be used if the message has not been customized
* @ORM\Column(type="array")
* @Groups({"company:read", "company:write"})
*/
private $messages = [self::MESSAGE_DEFAULT => UserChecker::QUOTAS_MESSAGE];
/**
* Maximum users allowed for the company
* @ORM\Column(type="integer", nullable=true)
* @Groups({"company:read", "company:write", "company:read:maxClients"})
*/
private $maxClients;
/**
* Forfait heure / forfait visionnage
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"company:read", "company:write"})
*/
private $plan;
/**
* Domain corresponding to this company ex:
* "orange.ulteam-tv.fr" will match company "Orange"
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"company:read", "company:write"})
*/
private $slug;
/**
* Restriction par IP
* @ORM\Column(type="array", nullable=true)
* @Groups({"company:read", "company:write"})
*/
private $ips = [];
/**
* Restriction par domaine mail
* @ORM\Column(type="array", nullable=true)
* @Groups({"company:read", "company:write"})
*/
private $domain = [];
/**
* Restriction heure de visionnage par utilisateur (5h)
* @ORM\Column(type="integer", nullable=true)
* @Groups({"company:read", "company:write"})
*/
private $hourlyRestriction;
/**
* @ORM\Column(type="boolean", options={"default": "0"})
*/
private $customizable = false;
/**
* @ORM\Column(type="text", nullable=true)
* @Groups({"company:read", "company:write", "company:read:cms"})
*/
private $cms;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"company:read", "company:write", "company:read:cmsTitle"})
*/
private $cmsTitle;
/**
* @ORM\ManyToOne(targetEntity=MediaObject::class)
* @Groups({"company:read", "company:write", "company:read:cmsImg"})
*/
private $cmsImg;
/**
* @ORM\Column(type="text", nullable=true)
* @Groups({"company:read", "company:write", "company:read:cmsText"})
*/
private $cmsText;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"company:read", "company:write", "company:read:cmsCtaText"})
*/
private $cmsCtaText;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"company:read", "company:write", "company:read:cmsCtaUrl"})
*/
private $cmsCtaUrl;
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"company:read", "company:write", "company:read:resaLinkActive"})
*/
private $resaLinkActive;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"company:read", "company:write", "company:read:email"})
*/
private $email;
/**
* @ORM\OneToMany(targetEntity=Restriction::class, mappedBy="company", orphanRemoval=true, cascade={"remove"})
* @Groups({"company:read"})
*/
private $restrictions;
/**
* @ORM\OneToMany(targetEntity=Order::class, mappedBy="company", cascade={"remove"})
* @Groups({"company:read"})
*/
private $orders;
/**
* @ORM\OneToMany(targetEntity=Category::class, mappedBy="company", cascade={"persist", "refresh", "remove"})
*/
private $categories;
/**
* @ORM\OneToMany(targetEntity=Channel::class, mappedBy="company", cascade={"persist", "refresh", "remove"})
*/
private $channels;
/**
* @ORM\OneToMany(targetEntity=ExclusionsChannel::class, mappedBy="company", orphanRemoval=true, cascade={"persist", "refresh", "remove"})
*/
private $exclusionsChannels;
/**
* @ORM\OneToMany(targetEntity=ExclusionsCategory::class, mappedBy="company", orphanRemoval=true, cascade={"persist", "refresh", "remove"})
*/
private $exclusionsCategories;
/**
* @ORM\OneToMany(targetEntity=ExclusionsVideo::class, mappedBy="company", orphanRemoval=true, cascade={"persist", "refresh", "remove"})
*/
private $exclusionsVideos;
/**
* @ORM\OneToMany(targetEntity=LogEmail::class, mappedBy="company", cascade={"persist", "refresh", "remove"})
*/
private $logEmails;
/**
* @ORM\ManyToMany(targetEntity=Association::class)
* @Groups({"company:read", "company:write"})
* @ApiSubresource(maxDepth=1)
*/
private $associations;
/**
* @ORM\OneToMany(targetEntity=Program::class, mappedBy="company", cascade={"persist", "refresh", "remove"})
*/
private $programs;
/**
* @ORM\OneToMany(targetEntity=Team::class, mappedBy="company", cascade={"persist", "refresh", "remove"})
* @Groups({"company:read"})
* @ApiSubresource(maxDepth=1)
*/
private $teams;
/**
* @ORM\OneToMany(targetEntity=Teamplay::class, mappedBy="company", cascade={"persist", "refresh", "remove"})
* @Groups({"company:read"})
*/
private $teamplays;
/**
* @ORM\OneToMany(targetEntity=TeamplayChallenge::class, mappedBy="company", cascade={"persist", "refresh", "remove"})
* @Groups({"company:read"})
*/
private $teamplayChallenges;
/**
* @ORM\OneToMany(targetEntity=TeamplayLog::class, mappedBy="company", cascade={"persist", "refresh", "remove"})
*/
private $teamplayLogs;
/**
* @ORM\OneToMany(targetEntity=PedometerLog::class, mappedBy="company", cascade={"persist", "refresh", "remove"})
*/
private $pedometerLogs;
/**
* @ORM\OneToMany(targetEntity=Log::class, mappedBy="company", cascade={"persist", "refresh", "remove"})
*/
private $logs;
/**
* @ORM\OneToMany(targetEntity=UserNotification::class, mappedBy="company", cascade={"persist", "refresh", "remove"})
*/
private $userNotifications;
/**
* @ORM\OneToMany(targetEntity=Slide::class, mappedBy="company", orphanRemoval=true, cascade={"persist", "refresh", "remove"})
* @Groups({"company:read"})
*/
private $slides;
/**
* @ORM\ManyToMany(targetEntity=Award::class, mappedBy="companies")
*/
private $awards;
/**
* @ORM\OneToMany(targetEntity=AwardConfig::class, mappedBy="company", orphanRemoval=true, cascade={"persist", "refresh", "remove"})
*/
private $awardConfigs;
/**
* @ORM\OneToOne(targetEntity=TvCompany::class, mappedBy="company", cascade={"persist", "refresh","remove"})
*/
private $tvCompany;
/**
* @ORM\Column(type="boolean", options={"default": "1"})
* @Groups({"company:write", "company:read", "company:read:live", "client:read"})
*/
private $live = true;
/**
* @ORM\Column(type="boolean", options={"default": "1"})
* @Groups({"company:write", "company:read", "company:read:tv", "client:read"})
*/
private $tv = true;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"company:read", "company:write", "company:read:consultLink", "client:read"})
*/
private $consultLink;
public function __construct()
{
$this->rooms = new ArrayCollection();
$this->workshops = new ArrayCollection();
$this->clients = new ArrayCollection();
$this->events = new ArrayCollection();
$this->companyTags = new ArrayCollection();
$this->createdAt = new \DateTime();
$this->visioEventPromotions = new ArrayCollection();
$this->affiliatedSpecialists = new ArrayCollection();
$this->specialists = new ArrayCollection();
$this->affiliatedEventApplications = new ArrayCollection();
$this->segmentations = new ArrayCollection();
$this->configurations = new ArrayCollection();
$this->restrictions = new ArrayCollection();
$this->orders = new ArrayCollection();
$this->categories = new ArrayCollection();
$this->channels = new ArrayCollection();
$this->exclusionsChannels = new ArrayCollection();
$this->exclusionsCategories = new ArrayCollection();
$this->exclusionsVideos = new ArrayCollection();
$this->logEmails = new ArrayCollection();
$this->associations = new ArrayCollection();
$this->programs = new ArrayCollection();
$this->teams = new ArrayCollection();
$this->teamplays = new ArrayCollection();
$this->teamplayChallenges = new ArrayCollection();
$this->teamplayLogs = new ArrayCollection();
$this->pedometerLogs = new ArrayCollection();
$this->logs = new ArrayCollection();
$this->userNotifications = new ArrayCollection();
$this->slides = new ArrayCollection();
$this->awards = new ArrayCollection();
$this->awardConfigs = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
if ($this->user instanceof User){
$this->user->setName($name);
}
return $this;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(?string $image): self
{
$this->image = $image;
return $this;
}
public function getUpdatedAt(): ?\DateTime
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTime $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
$this->setName($this->getName());
return $this;
}
/**
* @return File|null
*/
public function getImageFile(): ?File
{
return $this->imageFile;
}
/**
* @param File|null $imageFile
* @return Company
*/
public function setImageFile(?File $imageFile = null): self
{
$this->imageFile = $imageFile;
if ($imageFile) {
// if 'updatedAt' is not defined in your entity, use another property
$this->updatedAt = new \DateTime('now');
}
return $this;
}
/**
* @return Collection|Room[]
*/
public function getRooms(): Collection
{
return $this->rooms;
}
public function addRoom(Room $room): self
{
if (!$this->rooms->contains($room)) {
$this->rooms[] = $room;
$room->setCompany($this);
}
return $this;
}
public function removeRoom(Room $room): self
{
if ($this->rooms->removeElement($room)) {
// set the owning side to null (unless already changed)
if ($room->getCompany() === $this) {
$room->setCompany(null);
}
}
return $this;
}
/**
* @return Collection|Workshop[]
*/
public function getWorkshops(): Collection
{
return $this->workshops;
}
public function addWorkshop(Workshop $workshop): self
{
if (!$this->workshops->contains($workshop)) {
$this->workshops[] = $workshop;
$workshop->setCompany($this);
}
return $this;
}
public function removeWorkshop(Workshop $workshop): self
{
if ($this->workshops->removeElement($workshop)) {
// set the owning side to null (unless already changed)
if ($workshop->getCompany() === $this) {
$workshop->setCompany(null);
}
}
return $this;
}
/**
* @ORM\PrePersist()
*/
public function prePersist()
{
$this->user->setCategory(User::GROUP_COMPANY);
$this->user->addRole(User::ROLE_COMPANY);
}
public function __toString()
{
return $this->name??'';
}
/**
* @return Collection|Client[]
*/
public function getClients(): Collection
{
return $this->clients;
}
public function addClient(Client $client): self
{
if (!$this->clients->contains($client)) {
$this->clients[] = $client;
$client->setCompany($this);
}
return $this;
}
public function removeClient(Client $client): self
{
if ($this->clients->removeElement($client)) {
// set the owning side to null (unless already changed)
if ($client->getCompany() === $this) {
$client->setCompany(null);
}
}
return $this;
}
/**
* @return Collection|Event[]
*/
public function getEvents(): Collection
{
return $this->events;
}
public function addEvent(Event $event): self
{
if (!$this->events->contains($event)) {
$this->events[] = $event;
$event->setCompany($this);
}
return $this;
}
public function removeEvent(Event $event): self
{
if ($this->events->removeElement($event)) {
// set the owning side to null (unless already changed)
if ($event->getCompany() === $this) {
$event->setCompany(null);
}
}
return $this;
}
/**
* @return Collection|CompanyTag[]
*/
public function getCompanyTags(): Collection
{
return $this->companyTags;
}
public function setCompanyTags(array $companyTags): self
{
$this->companyTags = new ArrayCollection();
if (is_array($companyTags)){
$this->companyTags = new ArrayCollection($companyTags);
}
return $this;
}
public function addCompanyTag(CompanyTag $companyTag): self
{
if (!$this->companyTags->contains($companyTag)) {
$this->companyTags[] = $companyTag;
$companyTag->setCompany($this);
}
return $this;
}
public function removeCompanyTag(CompanyTag $companyTag): self
{
if ($this->companyTags->removeElement($companyTag)) {
// set the owning side to null (unless already changed)
if ($companyTag->getCompany() === $this) {
$companyTag->setCompany(null);
}
}
return $this;
}
public function getPresentation(): ?string
{
return $this->presentation;
}
public function setPresentation(?string $presentation): self
{
$this->presentation = $presentation;
return $this;
}
public function getPresentationTitle(): ?string
{
return $this->presentationTitle;
}
public function setPresentationTitle(?string $presentationTitle): self
{
$this->presentationTitle = $presentationTitle;
return $this;
}
public function getSiret(): ?string
{
return $this->siret;
}
public function setSiret(?string $siret): self
{
$this->siret = $siret;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getCreatedAt(): ?\DateTime
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getCompanyCode(): ?string
{
return $this->companyCode;
}
public function setCompanyCode(?string $companyCode): self
{
$this->companyCode = $companyCode;
return $this;
}
/**
* @return Collection<int, VisioEventPromotion>
*/
public function getVisioEventPromotions(): Collection
{
return $this->visioEventPromotions;
}
public function addVisioEventPromotion(VisioEventPromotion $visioEventPromotion): self
{
if (!$this->visioEventPromotions->contains($visioEventPromotion)) {
$this->visioEventPromotions[] = $visioEventPromotion;
$visioEventPromotion->setCompany($this);
}
return $this;
}
public function removeVisioEventPromotion(VisioEventPromotion $visioEventPromotion): self
{
if ($this->visioEventPromotions->removeElement($visioEventPromotion)) {
// set the owning side to null (unless already changed)
if ($visioEventPromotion->getCompany() === $this) {
$visioEventPromotion->setCompany(null);
}
}
return $this;
}
public function getVisioAllowed(): ?bool
{
return $this->visioAllowed;
}
public function setVisioAllowed(?bool $visioAllowed): self
{
$this->visioAllowed = $visioAllowed;
return $this;
}
public function getVisioPaymentAllowed(): ?bool
{
return $this->visioPaymentAllowed;
}
public function setVisioPaymentAllowed(bool $visioPaymentAllowed): self
{
$this->visioPaymentAllowed = $visioPaymentAllowed;
return $this;
}
/**
* @return Collection<int, Specialist>
*/
public function getAffiliatedSpecialists(): Collection
{
return $this->affiliatedSpecialists;
}
public function addAffiliatedSpecialist(Specialist $affiliatedSpecialist): self
{
if (!$this->affiliatedSpecialists->contains($affiliatedSpecialist)) {
$this->affiliatedSpecialists[] = $affiliatedSpecialist;
$affiliatedSpecialist->setAffiliatedCompany($this);
}
return $this;
}
public function removeAffiliatedSpecialist(Specialist $affiliatedSpecialist): self
{
if ($this->affiliatedSpecialists->removeElement($affiliatedSpecialist)) {
// set the owning side to null (unless already changed)
if ($affiliatedSpecialist->getAffiliatedCompany() === $this) {
$affiliatedSpecialist->setAffiliatedCompany(null);
}
}
return $this;
}
/**
* @return Collection<int, Specialist>
*/
public function getSpecialists(): Collection
{
return $this->specialists;
}
public function addSpecialist(Specialist $specialist): self
{
if (!$this->specialists->contains($specialist)) {
$this->specialists[] = $specialist;
$specialist->addCompany($this);
}
return $this;
}
public function removeSpecialist(Specialist $specialist): self
{
if ($this->specialists->removeElement($specialist)) {
$specialist->removeCompany($this);
}
return $this;
}
/**
* @return Collection<int, AffiliatedEventApplication>
*/
public function getAffiliatedEventApplications(): Collection
{
return $this->affiliatedEventApplications;
}
public function addAffiliatedEventApplication(AffiliatedEventApplication $affiliatedEventApplication): self
{
if (!$this->affiliatedEventApplications->contains($affiliatedEventApplication)) {
$this->affiliatedEventApplications[] = $affiliatedEventApplication;
$affiliatedEventApplication->setCompany($this);
}
return $this;
}
public function removeAffiliatedEventApplication(AffiliatedEventApplication $affiliatedEventApplication): self
{
if ($this->affiliatedEventApplications->removeElement($affiliatedEventApplication)) {
// set the owning side to null (unless already changed)
if ($affiliatedEventApplication->getCompany() === $this) {
$affiliatedEventApplication->setCompany(null);
}
}
return $this;
}
/**
* @return Collection<int, Segmentation>
*/
public function getSegmentations(): Collection
{
return $this->segmentations;
}
public function addSegmentation(Segmentation $segmentation): self
{
if (!$this->segmentations->contains($segmentation)) {
$this->segmentations[] = $segmentation;
$segmentation->setCompany($this);
}
return $this;
}
public function removeSegmentation(Segmentation $segmentation): self
{
if ($this->segmentations->removeElement($segmentation)) {
// set the owning side to null (unless already changed)
if ($segmentation->getCompany() === $this) {
$segmentation->setCompany(null);
}
}
return $this;
}
public function getForceSegmentation(): ?bool
{
return $this->forceSegmentation;
}
public function setForceSegmentation(?bool $forceSegmentation): self
{
$this->forceSegmentation = $forceSegmentation;
return $this;
}
/**
* @return Collection<int, Configuration>
*/
public function getConfigurations(): Collection
{
return $this->configurations;
}
public function addConfiguration(Configuration $configuration): self
{
if (!$this->configurations->contains($configuration)) {
$this->configurations[] = $configuration;
$configuration->setCompany($this);
}
return $this;
}
public function removeConfiguration(Configuration $configuration): self
{
if ($this->configurations->removeElement($configuration)) {
// set the owning side to null (unless already changed)
if ($configuration->getCompany() === $this) {
$configuration->setCompany(null);
}
}
return $this;
}
public function getLogo(): ?MediaObject
{
return $this->logo;
}
public function setLogo(?MediaObject $logo): self
{
$this->logo = $logo;
return $this;
}
/**
* @Groups({"company:write"})
*/
public function setLogoFile($file = null): self
{
if($file instanceof UploadedFile) {
$logo = empty($this->logo) ? new MediaObject : $this->logo;
$logo->setFile($file);
$this->setLogo($logo);
}
return $this;
}
public function getSiren(): ?string
{
return $this->siren;
}
public function setSiren(?string $siren): self
{
$this->siren = $siren;
return $this;
}
public function setStatus(?string $status): self
{
$this->status = $status;
if (in_array($this->status, [self::STATUS_SUSPENDED, self::STATUS_EXPIRED, self::STATUS_INACTIVE])) {
$this->active = false;
} else {
$this->active = true;
}
return $this;
}
/**
* @return string
*/
public function getStatus(): string
{
return $this->status;
}
public function getActive(): ?bool
{
return $this->active;
}
public function isActive(): ?bool
{
return $this->active;
}
public function setActive(?bool $active): self
{
$this->active = $active;
return $this;
}
public function getSubscriptionStart(): ?\DateTimeInterface
{
return $this->subscriptionStart;
}
public function setSubscriptionStart(?\DateTimeInterface $subscriptionStart): self
{
$this->subscriptionStart = $subscriptionStart;
return $this;
}
public function getSubscriptionEnd(): ?\DateTimeInterface
{
return $this->subscriptionEnd;
}
public function setSubscriptionEnd(?\DateTimeInterface $subscriptionEnd): self
{
$this->subscriptionEnd = $subscriptionEnd;
return $this;
}
/**
* Gets the active order no more than an order can be active at a time for a company
* @return Order|null
*/
public function getActiveOrder(): ?Order
{
foreach ($this->orders as $order) {
if ($order instanceof Order && $order->getActive()) {
return $order;
}
}
return null;
}
/**
* Updates the entity including users count, created at and updated at elements
* and the start and the end of the subscription
* @return company
* @ORM\PrePersist
*/
public function updateEntity(): self
{
$this->updateSubscription();
$this->updateStatus();
$this->updateClientsCount();
$this->updatedAt = new \DateTime();
return $this;
}
/**
* Updates the count of the company users
*/
private function updateClientsCount()
{
$this->clientsCount = $this->clients->count();
}
/**
* Updates subscription dates
*/
private function updateSubscription()
{
$order = $this->getActiveOrder();
if ($order instanceof Order) {
$this->subscriptionEnd = $order->getEnd();
$this->subscriptionStart = $order->getStart();
}
}
/**
* Updates the status of the company
*/
private function updateStatus()
{
$ret = self::STATUS_ACTIVE;
if ($this->subscriptionEnd < (new \DateTime())) {
$ret = self::STATUS_EXPIRED;
}
if (!$this->active) {
$ret = self::STATUS_SUSPENDED;
}
$this->status = $ret;
}
public function getMessages(): ?array
{
if (!is_array($this->messages)) {
$this->messages = [];
}
return $this->messages;
}
/**
* Gets a message if it exists
* @param string $key
* @return string|null
*/
public function getMessage(string $key): ?string
{
$_messages = $this->getMessages();
return (!empty($_messages[$key])) ? $_messages[$key] : null;
}
public function setMessages(?array $messages): self
{
$this->messages = $messages;
return $this;
}
public function getMaxClients(): ?int
{
return $this->maxClients;
}
public function setMaxClients(?int $maxClients): self
{
$this->maxClients = $maxClients;
return $this;
}
public function getPlan(): ?string
{
return $this->plan;
}
public function setPlan(?string $plan): self
{
$this->plan = $plan;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(?string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getIps(): ?array
{
return $this->ips;
}
public function setIps(?array $ips): self
{
$this->ips = $ips;
return $this;
}
public function getDomain(): ?array
{
return $this->domain;
}
public function setDomain(?array $domain): self
{
$this->domain = $domain;
return $this;
}
public function getHourlyRestriction(): ?int
{
return $this->hourlyRestriction;
}
public function setHourlyRestriction($hourlyRestriction): self
{
if (is_bool($hourlyRestriction)) {
if ($hourlyRestriction) {
$hourlyRestriction = 5;
} else {
$hourlyRestriction = 0;
}
}
$this->hourlyRestriction = $hourlyRestriction;
return $this;
}
public function getCustomizable(): ?bool
{
return $this->customizable;
}
public function isCustomizable(): bool
{
return boolval($this->customizable);
}
public function setCustomizable(bool $customizable): self
{
$this->customizable = $customizable;
return $this;
}
public function getCms(): ?string
{
return $this->cms;
}
public function setCms(?string $cms): self
{
$this->cms = $cms;
return $this;
}
public function getCmsTitle(): ?string
{
return $this->cmsTitle;
}
public function setCmsTitle(?string $cmsTitle): self
{
$this->cmsTitle = $cmsTitle;
return $this;
}
public function getCmsImg(): ?MediaObject
{
return $this->cmsImg;
}
public function setCmsImg(?MediaObject $cmsImg): self
{
$this->cmsImg = $cmsImg;
return $this;
}
/**
* @Groups({"company:write"})
*/
public function setCmsImgFile($file = null): self
{
if($file instanceof UploadedFile) {
$cmsImg = empty($this->cmsImg) ? new MediaObject : $this->cmsImg;
$cmsImg->setFile($file);
$this->setCmsImg($cmsImg);
}
return $this;
}
public function getCmsText(): ?string
{
return $this->cmsText;
}
public function setCmsText(?string $cmsText): self
{
$this->cmsText = $cmsText;
return $this;
}
public function getCmsCtaText(): ?string
{
return $this->cmsCtaText;
}
public function setCmsCtaText(?string $cmsCtaText): self
{
$this->cmsCtaText = $cmsCtaText;
return $this;
}
public function getCmsCtaUrl(): ?string
{
return $this->cmsCtaUrl;
}
public function setCmsCtaUrl(?string $cmsCtaUrl): self
{
$this->cmsCtaUrl = $cmsCtaUrl;
return $this;
}
public function getResaLinkActive(): ?bool
{
return $this->resaLinkActive;
}
public function setResaLinkActive(?bool $resaLinkActive): self
{
$this->resaLinkActive = $resaLinkActive;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): self
{
$this->email = $email;
return $this;
}
/**
* @return Collection|Restriction[]
*/
public function getRestrictions(): Collection
{
return $this->restrictions;
}
public function addRestriction(Restriction $restriction): self
{
if (!$this->restrictions->contains($restriction)) {
$this->restrictions[] = $restriction;
$restriction->setCompany($this);
}
return $this;
}
public function removeRestriction(Restriction $restriction): self
{
if ($this->restrictions->removeElement($restriction)) {
// set the owning side to null (unless already changed)
if ($restriction->getCompany() === $this) {
$restriction->setCompany(null);
}
}
return $this;
}
/**
* @return Collection|Order[]
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function addOrder(Order $order): self
{
if (!$this->orders->contains($order)) {
$this->orders[] = $order;
$order->setCompany($this);
}
return $this;
}
public function removeOrder(Order $order): self
{
if ($this->orders->removeElement($order)) {
// set the owning side to null (unless already changed)
if ($order->getCompany() === $this) {
$order->setCompany(null);
}
}
return $this;
}
/**
* @return Collection|Category[]
*/
public function getCategories(): Collection
{
return $this->categories;
}
public function addCategory(Category $category): self
{
if (!$this->categories->contains($category)) {
$this->categories[] = $category;
$category->setCompany($this);
}
return $this;
}
public function removeCategory(Category $category): self
{
if ($this->categories->removeElement($category)) {
// set the owning side to null (unless already changed)
if ($category->getCompany() === $this) {
$category->setCompany(null);
}
}
return $this;
}
/**
* @return Collection|Channel[]
*/
public function getChannels(): Collection
{
return $this->channels;
}
public function addChannel(Channel $channel): self
{
if (!$this->channels->contains($channel)) {
$this->channels[] = $channel;
$channel->setCompany($this);
}
return $this;
}
public function removeChannel(Channel $channel): self
{
if ($this->channels->removeElement($channel)) {
// set the owning side to null (unless already changed)
if ($channel->getCompany() === $this) {
$channel->setCompany(null);
}
}
return $this;
}
/**
* @return Collection|ExclusionsChannel[]
*/
public function getExclusionsChannels(): Collection
{
return $this->exclusionsChannels;
}
public function addExclusionsChannel(ExclusionsChannel $exclusionsChannel): self
{
if (!$this->exclusionsChannels->contains($exclusionsChannel)) {
$this->exclusionsChannels[] = $exclusionsChannel;
$exclusionsChannel->setCompany($this);
}
return $this;
}
public function removeExclusionsChannel(ExclusionsChannel $exclusionsChannel): self
{
if ($this->exclusionsChannels->removeElement($exclusionsChannel)) {
// set the owning side to null (unless already changed)
if ($exclusionsChannel->getCompany() === $this) {
$exclusionsChannel->setCompany(null);
}
}
return $this;
}
/**
* @return Collection|ExclusionsCategory[]
*/
public function getExclusionsCategories(): Collection
{
return $this->exclusionsCategories;
}
public function addExclusionsCategory(ExclusionsCategory $exclusionsCategory): self
{
if (!$this->exclusionsCategories->contains($exclusionsCategory)) {
$this->exclusionsCategories[] = $exclusionsCategory;
$exclusionsCategory->setCompany($this);
}
return $this;
}
public function removeExclusionsCategory(ExclusionsCategory $exclusionsCategory): self
{
if ($this->exclusionsCategories->removeElement($exclusionsCategory)) {
// set the owning side to null (unless already changed)
if ($exclusionsCategory->getCompany() === $this) {
$exclusionsCategory->setCompany(null);
}
}
return $this;
}
/**
* @return Collection|ExclusionsVideo[]
*/
public function getExclusionsVideos(): Collection
{
return $this->exclusionsVideos;
}
public function addExclusionsVideo(ExclusionsVideo $exclusionsVideo): self
{
if (!$this->exclusionsVideos->contains($exclusionsVideo)) {
$this->exclusionsVideos[] = $exclusionsVideo;
$exclusionsVideo->setCompany($this);
}
return $this;
}
public function removeExclusionsVideo(ExclusionsVideo $exclusionsVideo): self
{
if ($this->exclusionsVideos->removeElement($exclusionsVideo)) {
// set the owning side to null (unless already changed)
if ($exclusionsVideo->getCompany() === $this) {
$exclusionsVideo->setCompany(null);
}
}
return $this;
}
/**
* Permet de savoir si l'abonnement est actif ou non.
* @return bool
*/
public function hasCurrentSubscription(): bool
{
$hasCurrentSubscription = false;
if($this->checkSubscriptionsDates(new \DateTime("now"))) {
$hasCurrentSubscription = true;
}
return $hasCurrentSubscription;
}
public function checkSubscriptionsDates(\DateTime $today)
{
return $today >= $this->subscriptionStart && $today <= $this->subscriptionEnd;
}
/**
* @return Collection|LogEmail[]
*/
public function getLogEmails(): Collection
{
return $this->logEmails;
}
public function addLogEmail(LogEmail $logEmail): self
{
if (!$this->logEmails->contains($logEmail)) {
$this->logEmails[] = $logEmail;
$logEmail->setCompany($this);
}
return $this;
}
public function removeLogEmail(LogEmail $logEmail): self
{
if ($this->logEmails->removeElement($logEmail)) {
// set the owning side to null (unless already changed)
if ($logEmail->getCompany() === $this) {
$logEmail->setCompany(null);
}
}
return $this;
}
/**
* @return Collection|Association[]
*/
public function getAssociations(): Collection
{
return $this->associations;
}
public function addAssociation(Association $association): self
{
if (!$this->associations->contains($association)) {
$this->associations[] = $association;
}
return $this;
}
public function removeAssociation(Association $association): self
{
$this->associations->removeElement($association);
return $this;
}
/**
* @return Collection|Program[]
*/
public function getPrograms(): Collection
{
return $this->programs;
}
public function addProgram(Program $program): self
{
if (!$this->programs->contains($program)) {
$this->programs[] = $program;
$program->setCompany($this);
}
return $this;
}
public function removeProgram(Program $program): self
{
if ($this->programs->removeElement($program)) {
// set the owning side to null (unless already changed)
if ($program->getCompany() === $this) {
$program->setCompany(null);
}
}
return $this;
}
/**
* @return Collection|Team[]
*/
public function getTeams(): Collection
{
return $this->teams;
}
public function addTeam(Team $team): self
{
if (!$this->teams->contains($team)) {
$this->teams[] = $team;
$team->setCompany($this);
}
return $this;
}
public function removeTeam(Team $team): self
{
if ($this->teams->removeElement($team)) {
// set the owning side to null (unless already changed)
if ($team->getCompany() === $this) {
$team->setCompany(null);
}
}
return $this;
}
/**
* Récupère un array de team de type = "teamplay"
* @return Team[]|null
*/
public function getTeamplayTeams(): ?array
{
$teamplayTeams = null;
if (!empty($this->teams->toArray())) {
$teamplayTeams = [];
foreach ($this->teams->toArray() as $team) {
if ($team->isTeamplay()) $teamplayTeams[] = $team;
}
}
return $teamplayTeams;
}
/**
* @return Collection|Teamplay[]
*/
public function getTeamplays(): Collection
{
return $this->teamplays;
}
public function addTeamplay(Teamplay $teamplay): self
{
if (!$this->teamplays->contains($teamplay)) {
$this->teamplays[] = $teamplay;
$teamplay->setCompany($this);
}
return $this;
}
public function removeTeamplay(Teamplay $teamplay): self
{
if ($this->teamplays->removeElement($teamplay)) {
// set the owning side to null (unless already changed)
if ($teamplay->getCompany() === $this) {
$teamplay->setCompany(null);
}
}
return $this;
}
/**
* @return Collection|TeamplayChallenge[]
*/
public function getTeamplayChallenges(): Collection
{
return $this->teamplayChallenges;
}
public function addTeamplayChallenge(TeamplayChallenge $teamplayChallenge): self
{
if (!$this->teamplayChallenges->contains($teamplayChallenge)) {
$this->teamplayChallenges[] = $teamplayChallenge;
$teamplayChallenge->setCompany($this);
}
return $this;
}
public function removeTeamplayChallenge(TeamplayChallenge $teamplayChallenge): self
{
if ($this->teamplayChallenges->removeElement($teamplayChallenge)) {
// set the owning side to null (unless already changed)
if ($teamplayChallenge->getCompany() === $this) {
$teamplayChallenge->setCompany(null);
}
}
return $this;
}
/**
* @return Collection|TeamplayLog[]
*/
public function getTeamplayLogs(): Collection
{
return $this->teamplayLogs;
}
public function addTeamplayLog(TeamplayLog $teamplayLog): self
{
if (!$this->teamplayLogs->contains($teamplayLog)) {
$this->teamplayLogs[] = $teamplayLog;
$teamplayLog->setCompany($this);
}
return $this;
}
public function removeTeamplayLog(TeamplayLog $teamplayLog): self
{
if ($this->teamplayLogs->removeElement($teamplayLog)) {
// set the owning side to null (unless already changed)
if ($teamplayLog->getCompany() === $this) {
$teamplayLog->setCompany(null);
}
}
return $this;
}
/**
* @return Collection|PedometerLog[]
*/
public function getPedometerLogs(): Collection
{
return $this->pedometerLogs;
}
public function addPedometerLog(PedometerLog $pedometerLog): self
{
if (!$this->pedometerLogs->contains($pedometerLog)) {
$this->pedometerLogs[] = $pedometerLog;
$pedometerLog->setCompany($this);
}
return $this;
}
public function removePedometerLog(PedometerLog $pedometerLog): self
{
if ($this->pedometerLogs->removeElement($pedometerLog)) {
// set the owning side to null (unless already changed)
if ($pedometerLog->getCompany() === $this) {
$pedometerLog->setCompany(null);
}
}
return $this;
}
/**
* @return Collection|Log[]
*/
public function getLogs(): Collection
{
return $this->logs;
}
public function addLog(Log $log): self
{
if (!$this->logs->contains($log)) {
$this->logs[] = $log;
$log->setCompany($this);
}
return $this;
}
public function removeLog(Log $log): self
{
if ($this->logs->removeElement($log)) {
// set the owning side to null (unless already changed)
if ($log->getCompany() === $this) {
$log->setCompany(null);
}
}
return $this;
}
/**
* @return Collection<int, UserNotification>
*/
public function getUserNotifications(): Collection
{
return $this->userNotifications;
}
public function addUserNotification(UserNotification $userNotification): self
{
if (!$this->userNotifications->contains($userNotification)) {
$this->userNotifications[] = $userNotification;
$userNotification->setCompany($this);
}
return $this;
}
public function removeUserNotification(UserNotification $userNotification): self
{
if ($this->userNotifications->removeElement($userNotification)) {
// set the owning side to null (unless already changed)
if ($userNotification->getCompany() === $this) {
$userNotification->setCompany(null);
}
}
return $this;
}
/**
* @return Collection<int, Slide>
*/
public function getSlides(): Collection
{
return $this->slides;
}
public function addSlide(Slide $slide): self
{
if (!$this->slides->contains($slide)) {
$this->slides[] = $slide;
$slide->setCompany($this);
}
return $this;
}
public function removeSlide(Slide $slide): self
{
if ($this->slides->removeElement($slide)) {
// set the owning side to null (unless already changed)
if ($slide->getCompany() === $this) {
$slide->setCompany(null);
}
}
return $this;
}
/**
* @return Collection|Award[]
*/
public function getAwards(): Collection
{
return $this->awards;
}
public function addAward(Award $award): self
{
if (!$this->awards->contains($award)) {
$this->awards[] = $award;
$award->addCompany($this);
}
return $this;
}
public function removeAward(Award $award): self
{
if ($this->awards->removeElement($award)) {
$award->removeCompany($this);
}
return $this;
}
/**
* @Groups({"company:read", "compny:read:activeAward"})
*/
public function getActiveAward()
{
$award = null;
$today = (new \DateTime("now"))->setTime(0, 0, 0);
foreach ($this->awards->toArray() as $value) {
if ($value->getActive() && $value->getDateStart() <= $today && $value->getDateEnd() >= $today) {
$award = $value;
}
}
return $award;
}
/**
* @return Collection<int, AwardConfig>
*/
public function getAwardConfigs(): Collection
{
return $this->awardConfigs;
}
public function addAwardConfig(AwardConfig $awardConfig): self
{
if (!$this->awardConfigs->contains($awardConfig)) {
$this->awardConfigs[] = $awardConfig;
$awardConfig->setCompany($this);
}
return $this;
}
public function removeAwardConfig(AwardConfig $awardConfig): self
{
if ($this->awardConfigs->removeElement($awardConfig)) {
// set the owning side to null (unless already changed)
if ($awardConfig->getCompany() === $this) {
$awardConfig->setCompany(null);
}
}
return $this;
}
public function getClientsCount(): ?int
{
return $this->clientsCount;
}
public function setClientsCount(int $clientsCount): self
{
$this->clientsCount = $clientsCount;
return $this;
}
public function getTvCompany(): ?TvCompany
{
return $this->tvCompany;
}
public function setTvCompany(?TvCompany $tvCompany): self
{
$this->tvCompany = $tvCompany;
return $this;
}
public function isLive(): ?bool
{
return $this->live;
}
public function setLive(bool $isLive): self
{
$this->live = $isLive;
$this->getUser()->setLive($isLive);
$this->getUser()->setUpdatedAt(new \DateTime("now"));
// if(!$this->getClients()->isEmpty()) {
// foreach($this->getClients()->toArray() as $client) {
// if($client instanceof Client && $client->getUser() instanceof User) {
// $user = $client->getUser();
// $user->setLive($isLive);
// $user->setUpdatedAt(new \DateTime("now"));
// }
// }
// }
return $this;
}
public function isTv(): ?bool
{
return $this->tv;
}
public function setTv(bool $isTv): self
{
$this->tv = $isTv;
$this->getUser()->setTv($isTv);
$this->getUser()->setUpdatedAt(new \DateTime("now"));
// if(!$this->getClients()->isEmpty()) {
// foreach($this->getClients()->toArray() as $client) {
// if($client instanceof Client && $client->getUser() instanceof User) {
// $user = $client->getUser();
// $user->setTv($isTv);
// $user->setUpdatedAt(new \DateTime("now"));
// }
// }
// }
return $this;
}
/**
* Vérifie si les associations sont actives
*/
public function isActiveAssociation(): bool
{
$isActiveAssociation = false;
if(!empty($this->getAssociations()->toArray())) {
foreach ($this->getAssociations()->toArray() as $association) {
if($association->getActive() == 1) {
$isActiveAssociation = true;
break;
}
}
}
return $isActiveAssociation;
}
/**
* Indicates if a user is restricted according to general company restrictions
*
* @param \DateTime $time
* @return bool
*/
public function isRestricted(\DateTime $time): bool
{
foreach ($this->restrictions as $restriction) {
if ($restriction instanceof Restriction && $restriction->isRestricted($time)) {
return true;
}
}
return false;
}
/**
* Gets the start of the next restriction on a given interval
* @param \DateTime $start
* @param \DateTime $end
* @return \DateTime|null
*/
public function getNextRestriction(\DateTime $start, \DateTime $end): ?\DateTime
{
foreach ($this->restrictions as $restriction) {
if ($restriction instanceof Restriction) {
$startRestriction = $restriction->getStart($start);
if ($startRestriction <= $end) {
return $startRestriction;
}
}
}
return null;
}
/**
* Gets the end of a restriction
* @return string
*/
public function getEndRestriction(\DateTime $day): string
{
foreach ($this->restrictions as $restriction) {
if (
$restriction instanceof Restriction && $restriction->isRestricted($day)
&& $restriction->getCode() == Restriction::WEEKLY
) {
return $restriction->getEnd($day)->format('H:i');
}
}
return '';
}
/**
* Gets the end of a restriction
* @return string
*/
public function getStartRestriction(\DateTime $day): string
{
foreach ($this->restrictions as $restriction) {
if (
$restriction instanceof Restriction && $restriction->isRestricted($day)
&& $restriction->getCode() == Restriction::WEEKLY
) {
return $restriction->getStart($day)->format('H:i');
}
}
return '';
}
public function getImageUrl(): ?string
{
return $this->imageUrl;
}
public function setImageUrl(string $imageUrl): self
{
$this->imageUrl = $imageUrl;
return $this;
}
public function getConsultLink(): ?string
{
return $this->consultLink;
}
public function setConsultLink(?string $consultLink): self
{
$this->consultLink = $consultLink;
return $this;
}
}