<?php
namespace App\Entity;
use App\Entity\Traits\DefaultTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Persistence\Event\LifecycleEventArgs;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\String\ByteString;
/**
* @ORM\HasLifecycleCallbacks()
* @ORM\Entity(repositoryClass="App\Repository\HeadquarterRepository")
*/
class Headquarter
{
use DefaultTrait;
public const STATUS_UNPUBLISHED = 0;
public const STATUS_PUBLISHED = 1;
public const STATUS = [
'UNPUBLISHED' => self::STATUS_UNPUBLISHED,
'PUBLISHED' => self::STATUS_PUBLISHED
];
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private int $id;
/**
* @var HeadquarterConfig
*
* @ORM\OneToOne(targetEntity="App\Entity\HeadquarterConfig", cascade={"persist", "remove"})
*/
private $config;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Language")
* @ORM\JoinColumn(nullable=false)
*/
private Language $preferred_language;
/**
* @ORM\Column(type="string", length=128, unique=true)
*/
private string $alias;
/**
* @ORM\Column(type="string", length=50, unique=true)
*/
private string $api_key;
/**
* @ORM\Column(type="string", length=128)
*/
private string $name;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $cif = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $logo = null;
/**
* @ORM\Column(type="string", length=128, nullable=true)
*/
private ?string $email = null;
/**
* @ORM\Column(type="string", length=128, nullable=true)
*/
private ?string $phone = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $address = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $city = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $postal = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $region = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $country = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $config_mailer_transport = null;
/**
* @ORM\Column(type="boolean")
*/
private bool $is_generic = false;
/**
* @var ArrayCollection|Role[]
*
* @ORM\OneToMany(targetEntity="App\Entity\Role", mappedBy="headquarter")
*/
private $roles;
/**
* @var ArrayCollection|Permission[]
*
* @ORM\ManyToMany(targetEntity="App\Entity\Permission", inversedBy="headquarters")
* @ORM\JoinTable(name="headquarter_permission")
* @ORM\OrderBy({"alias" = "ASC"})
*/
private $permissions;
/**
* @var ArrayCollection|Admin[]
*
* @ORM\OneToMany(targetEntity="App\Entity\Admin", mappedBy="headquarter")
*/
private $admins;
/**
* @var ArrayCollection|Audience[]
*
* @ORM\OneToMany(targetEntity="App\Entity\Audience", mappedBy="headquarter")
*/
private $audiences;
/**
* @var ArrayCollection|Article[]
*
* @ORM\OneToMany(targetEntity="App\Entity\Article", mappedBy="headquarter")
*/
private $articles;
/**
* @var ArrayCollection|Email[]
*
* @ORM\OneToMany(targetEntity="App\Entity\Email", mappedBy="headquarter")
*/
private $emails;
/**
* @var ArrayCollection|Notification[]
*
* @ORM\OneToMany(targetEntity="App\Entity\Notification", mappedBy="headquarter")
*/
private $notifications;
/**
* @var ArrayCollection|Reservation[]
*
* @ORM\OneToMany(targetEntity="App\Entity\Reservation", mappedBy="headquarter")
*/
private $reservations;
/**
* @var ArrayCollection|Survey[]
*
* @ORM\OneToMany(targetEntity="App\Entity\Survey", mappedBy="headquarter")
*/
private $surveys;
/**
* @var ArrayCollection|Workgroup[]
*
* @ORM\OneToMany(targetEntity="App\Entity\Workgroup", mappedBy="headquarter")
*/
private $workgroups;
/**
* @var ArrayCollection|Category[]
*
* @ORM\OneToMany(targetEntity="App\Entity\Category", mappedBy="headquarter")
* @ORM\OrderBy({"lft" = "ASC"})
*/
private $categories;
/**
* @var ArrayCollection|Tag[]
*
* @ORM\OneToMany(targetEntity="App\Entity\Tag", mappedBy="headquarter")
*/
private $tags;
/**
* @ORM\OneToMany(targetEntity="App\Entity\HeadquarterHomeRow", mappedBy="headquarter")
*/
private $headquarterHomeRows;
/**
* @ORM\OneToMany(targetEntity="App\Entity\HeadquarterHomeWidget", mappedBy="headquarter")
*/
private $headquarterHomeWidgets;
/**
* @var ArrayCollection|TagGroup[]
*
* @ORM\OneToMany(targetEntity="App\Entity\TagGroup", mappedBy="headquarter")
*/
private $tag_groups;
/**
* @var ArrayCollection|User[]
*
* @ORM\OneToMany(targetEntity="App\Entity\User", mappedBy="headquarter")
* @ORM\OrderBy({"cdate" = "DESC"})
*/
private $users;
/**
* @var ArrayCollection|Language[]
*
* @ORM\ManyToMany(targetEntity="App\Entity\Language", inversedBy="headquarters")
* @ORM\JoinTable(name="headquarter_language")
*/
private $languages;
/**
* @var ArrayCollection|Workplace[]
*
* @ORM\OneToMany(targetEntity=Workplace::class, mappedBy="headquarter")
*/
private $workplaces;
/**
* @var array
* @ORM\Column(type="json")
*/
private $app_config = [
'hasQrCode' => true,
'slotQuizz' => 1,// week
'adminTimesheetShowAll' => false
];
/**
* @var ArrayCollection|Link[]
*
* @ORM\OneToMany(targetEntity="App\Entity\Link", mappedBy="headquarter")
*/
private $links;
/**
* @ORM\Column(type="boolean")
*/
private bool $is_enabled_holiday_remember = true;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private string $web_domain;
/**
* @var array
* @ORM\Column(type="json")
*/
private $web_config = [
'logo' => null,
'authenticatedLogo' => null,
'color' => null,
'backgroundImage' => null,
'favicon' => null,
'fingerprintEnabled' => false
];
/**
* @ORM\Column(type="text", nullable=true)
*/
private $android_url;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $ios_url;
/**
* @ORM\Column(type="string", length=512, unique=true, nullable=true)
*/
private $external_api_key;
/**
* @ORM\Column(type="json", nullable=true)
*/
private $external_api_config = [];
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $config_mailer_from;
/**
* @ORM\JoinColumn(onDelete="SET NULL")
* @ORM\ManyToOne(targetEntity=User::class)
*/
private $holidays_bcc_user;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $firebase_name_database;
/**
* @ORM\Column(type="json")
*/
private $firebase_service_account = [];
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $register_available;
public function __construct()
{
$this->roles = new ArrayCollection();
$this->permissions = new ArrayCollection();
$this->admins = new ArrayCollection();
$this->audiences = new ArrayCollection();
$this->articles = new ArrayCollection();
$this->emails = new ArrayCollection();
$this->notifications = new ArrayCollection();
$this->surveys = new ArrayCollection();
$this->workgroups = new ArrayCollection();
$this->categories = new ArrayCollection();
$this->tags = new ArrayCollection();
$this->tag_groups = new ArrayCollection();
$this->users = new ArrayCollection();
$this->languages = new ArrayCollection();
$this->reservations = new ArrayCollection();
$this->workplaces = new ArrayCollection();
$this->links = new ArrayCollection();
}
/**
* @internal Added function
*/
public function getLanguagesAlternates(): Collection
{
$preferred = $this->preferred_language;
return $this->languages->filter(function ($el) use ($preferred) {
return $el !== $preferred;
});
}
/**
* @internal Added function
*/
public function getPermissionsToArray(): array
{
return $this->permissions->map(function ($el) {
return $el->getAlias();
})->toArray();
}
public function getId(): ?int
{
return $this->id;
}
public function getConfig(): HeadquarterConfig
{
return $this->config;
}
public function setConfig(?HeadquarterConfig $config): self
{
$this->config = $config;
return $this;
}
public function getAlias(): ?string
{
return $this->alias;
}
public function setAlias(string $alias): self
{
$this->alias = $alias;
return $this;
}
public function getApiKey(): ?string
{
return $this->api_key;
}
public function setApiKey(string $api_key): self
{
$this->api_key = $api_key;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getCif(): ?string
{
return $this->cif;
}
public function setCif(?string $cif): self
{
$this->cif = $cif;
return $this;
}
public function getLogo(): ?string
{
return $this->logo;
}
public function setLogo(?string $logo): self
{
$this->logo = $logo;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): self
{
$this->email = $email;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getAddress(): ?string
{
return $this->address;
}
public function setAddress(?string $address): self
{
$this->address = $address;
return $this;
}
public function getCity(): ?string
{
return $this->city;
}
public function setCity(?string $city): self
{
$this->city = $city;
return $this;
}
public function getPostal(): ?string
{
return $this->postal;
}
public function setPostal(?string $postal): self
{
$this->postal = $postal;
return $this;
}
public function getRegion(): ?string
{
return $this->region;
}
public function setRegion(?string $region): self
{
$this->region = $region;
return $this;
}
public function getCountry(): ?string
{
return $this->country;
}
public function setCountry(?string $country): self
{
$this->country = $country;
return $this;
}
public function getConfigMailerTransport(): ?string
{
return $this->config_mailer_transport;
}
public function setConfigMailerTransport(?string $config_mailer_transport): self
{
$this->config_mailer_transport = $config_mailer_transport;
return $this;
}
public function getPreferredLanguage(): ?Language
{
return $this->preferred_language;
}
public function setPreferredLanguage(?Language $preferred_language): self
{
$this->preferred_language = $preferred_language;
return $this;
}
/**
* @return Collection|Role[]
*/
public function getRoles(): Collection
{
return $this->roles;
}
public function addRole(Role $role): self
{
if (!$this->roles->contains($role)) {
$this->roles[] = $role;
$role->setHeadquarter($this);
}
return $this;
}
public function removeRole(Role $role): self
{
if ($this->roles->removeElement($role)) {
// set the owning side to null (unless already changed)
if ($role->getHeadquarter() === $this) {
$role->setHeadquarter(null);
}
}
return $this;
}
/**
* @return Collection|Permission[]
*/
public function getPermissions(): Collection
{
return $this->permissions;
}
public function addPermission(Permission $permission): self
{
if (!$this->permissions->contains($permission)) {
$this->permissions[] = $permission;
}
return $this;
}
public function removePermission(Permission $permission): self
{
$this->permissions->removeElement($permission);
return $this;
}
/**
* @return Collection|Admin[]
*/
public function getAdmins(): Collection
{
return $this->admins;
}
public function addAdmin(Admin $admin): self
{
if (!$this->admins->contains($admin)) {
$this->admins[] = $admin;
$admin->setHeadquarter($this);
}
return $this;
}
public function removeAdmin(Admin $admin): self
{
if ($this->admins->removeElement($admin)) {
// set the owning side to null (unless already changed)
if ($admin->getHeadquarter() === $this) {
$admin->setHeadquarter(null);
}
}
return $this;
}
/**
* @return Collection|Audience[]
*/
public function getAudiences(): Collection
{
return $this->audiences;
}
public function addAudience(Audience $audience): self
{
if (!$this->audiences->contains($audience)) {
$this->audiences[] = $audience;
$audience->setHeadquarter($this);
}
return $this;
}
public function removeAudience(Audience $audience): self
{
if ($this->audiences->removeElement($audience)) {
// set the owning side to null (unless already changed)
if ($audience->getHeadquarter() === $this) {
$audience->setHeadquarter(null);
}
}
return $this;
}
/**
* @return Collection|Article[]
*/
public function getArticles(): Collection
{
return $this->articles;
}
public function addArticle(Article $article): self
{
if (!$this->articles->contains($article)) {
$this->articles[] = $article;
$article->setHeadquarter($this);
}
return $this;
}
public function removeArticle(Article $article): self
{
if ($this->articles->removeElement($article)) {
// set the owning side to null (unless already changed)
if ($article->getHeadquarter() === $this) {
$article->setHeadquarter(null);
}
}
return $this;
}
/**
* @return Collection|Email[]
*/
public function getEmails(): Collection
{
return $this->emails;
}
public function addEmail(Email $email): self
{
if (!$this->emails->contains($email)) {
$this->emails[] = $email;
$email->setHeadquarter($this);
}
return $this;
}
public function removeEmail(Email $email): self
{
if ($this->emails->removeElement($email)) {
// set the owning side to null (unless already changed)
if ($email->getHeadquarter() === $this) {
$email->setHeadquarter(null);
}
}
return $this;
}
/**
* @return Collection|Notification[]
*/
public function getNotifications(): Collection
{
return $this->notifications;
}
public function addNotification(Notification $notification): self
{
if (!$this->notifications->contains($notification)) {
$this->notifications[] = $notification;
$notification->setHeadquarter($this);
}
return $this;
}
public function removeNotification(Notification $notification): self
{
if ($this->notifications->removeElement($notification)) {
// set the owning side to null (unless already changed)
if ($notification->getHeadquarter() === $this) {
$notification->setHeadquarter(null);
}
}
return $this;
}
/**
* @return Collection|Reservation[]
*/
public function getReservations(): Collection
{
return $this->reservations;
}
public function addReservation(Reservation $reservation): self
{
if (!$this->reservations->contains($reservation)) {
$this->reservations[] = $reservation;
$reservation->setHeadquarter($this);
}
return $this;
}
public function removeReservation(Reservation $reservation): self
{
if ($this->reservations->removeElement($reservation)) {
// set the owning side to null (unless already changed)
if ($reservation->getHeadquarter() === $this) {
$reservation->setHeadquarter(null);
}
}
return $this;
}
/**
* @return Collection|Survey[]
*/
public function getSurveys(): Collection
{
return $this->surveys;
}
public function addSurvey(Survey $survey): self
{
if (!$this->surveys->contains($survey)) {
$this->surveys[] = $survey;
$survey->setHeadquarter($this);
}
return $this;
}
public function removeSurvey(Survey $survey): self
{
if ($this->surveys->removeElement($survey)) {
// set the owning side to null (unless already changed)
if ($survey->getHeadquarter() === $this) {
$survey->setHeadquarter(null);
}
}
return $this;
}
/**
* @return Collection|Workgroup[]
*/
public function getWorkgroups(): Collection
{
return $this->workgroups;
}
public function addWorkgroup(Workgroup $workgroup): self
{
if (!$this->workgroups->contains($workgroup)) {
$this->workgroups[] = $workgroup;
$workgroup->setHeadquarter($this);
}
return $this;
}
public function removeWorkgroup(Workgroup $workgroup): self
{
if ($this->workgroups->removeElement($workgroup)) {
// set the owning side to null (unless already changed)
if ($workgroup->getHeadquarter() === $this) {
$workgroup->setHeadquarter(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->setHeadquarter($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->getHeadquarter() === $this) {
$category->setHeadquarter(null);
}
}
return $this;
}
/**
* @return Collection|Tag[]
*/
public function getTags(): Collection
{
return $this->tags;
}
public function addTag(Tag $tag): self
{
if (!$this->tags->contains($tag)) {
$this->tags[] = $tag;
$tag->setHeadquarter($this);
}
return $this;
}
public function removeTag(Tag $tag): self
{
if ($this->tags->removeElement($tag)) {
// set the owning side to null (unless already changed)
if ($tag->getHeadquarter() === $this) {
$tag->setHeadquarter(null);
}
}
return $this;
}
/**
* @return Collection|TagGroup[]
*/
public function getTagGroups(): Collection
{
return $this->tag_groups;
}
public function addTagGroup(TagGroup $tagGroup): self
{
if (!$this->tag_groups->contains($tagGroup)) {
$this->tag_groups[] = $tagGroup;
$tagGroup->setHeadquarter($this);
}
return $this;
}
public function removeTagGroup(TagGroup $tagGroup): self
{
if ($this->tag_groups->removeElement($tagGroup)) {
// set the owning side to null (unless already changed)
if ($tagGroup->getHeadquarter() === $this) {
$tagGroup->setHeadquarter(null);
}
}
return $this;
}
/**
* @return Collection|User[]
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(User $user): self
{
if (!$this->users->contains($user)) {
$this->users[] = $user;
$user->setHeadquarter($this);
}
return $this;
}
public function removeUser(User $user): self
{
if ($this->users->removeElement($user)) {
// set the owning side to null (unless already changed)
if ($user->getHeadquarter() === $this) {
$user->setHeadquarter(null);
}
}
return $this;
}
public function clearLanguages(): void
{
$this->languages->clear();
}
public function clearPermissions(): void
{
$this->permissions->clear();
}
/**
* @return Collection|Language[]
*/
public function getLanguages(): Collection
{
return $this->languages;
}
public function addLanguage(Language $language): self
{
if (!$this->languages->contains($language)) {
$this->languages[] = $language;
}
return $this;
}
public function removeLanguage(Language $language): self
{
$this->languages->removeElement($language);
return $this;
}
/**
* @return Collection|Workplace[]
*/
public function getWorkplaces(): Collection
{
return $this->workplaces;
}
public function addWorkplace(Workplace $workplace): self
{
if (!$this->workplaces->contains($workplace)) {
$this->workplaces[] = $workplace;
$workplace->setHeadquarter($this);
}
return $this;
}
public function removeWorkplace(Workplace $workplace): self
{
if ($this->workplaces->removeElement($workplace)) {
// set the owning side to null (unless already changed)
if ($workplace->getHeadquarter() === $this) {
$workplace->setHeadquarter(null);
}
}
return $this;
}
public function getAppConfig(): ?array
{
return $this->app_config;
}
public function setAppConfig(array $app_config): self
{
$this->app_config = $app_config;
return $this;
}
/**
* @return Collection|Link[]
*/
public function getLinks(): Collection
{
return $this->links;
}
public function addLink(Link $link): self
{
if (!$this->links->contains($link)) {
$this->links[] = $link;
$link->setHeadquarter($this);
}
return $this;
}
public function removeLink(Link $link): self
{
if ($this->links->removeElement($link)) {
// set the owning side to null (unless already changed)
if ($link->getHeadquarter() === $this) {
$link->setHeadquarter(null);
}
}
return $this;
}
public function getIsGeneric(): ?bool
{
return $this->is_generic;
}
public function setIsGeneric(bool $is_generic): self
{
$this->is_generic = $is_generic;
return $this;
}
public function getIsEnabledHolidayRemember(): ?bool
{
return $this->is_enabled_holiday_remember;
}
public function setIsEnabledHolidayRemember(bool $is_enabled_holiday_remember): self
{
$this->is_enabled_holiday_remember = $is_enabled_holiday_remember;
return $this;
}
public function getWebDomain(): ?string
{
return $this->web_domain;
}
public function setWebDomain(?string $web_domain): self
{
$this->web_domain = $web_domain;
return $this;
}
public function getWebConfig(): ?array
{
return $this->web_config;
}
public function setWebConfig(array $web_config): self
{
$this->web_config = $web_config;
return $this;
}
public function getAndroidUrl(): ?string
{
return $this->android_url;
}
public function setAndroidUrl(?string $android_url): self
{
$this->android_url = $android_url;
return $this;
}
public function getIosUrl(): ?string
{
return $this->ios_url;
}
public function setIosUrl(?string $ios_url): self
{
$this->ios_url = $ios_url;
return $this;
}
public function getExternalApiKey(): ?string
{
return $this->external_api_key;
}
public function getExternalApiConfig(): ?array
{
return $this->external_api_config;
}
public function setExternalApiConfig(?array $external_api_config): self
{
$this->external_api_config = $external_api_config;
return $this;
}
public function getHomeRows(): ?Collection
{
return $this->headquarterHomeRows;
}
public function getHomeWidgets(): ?Collection
{
return $this->headquarterHomeWidgets;
}
public function getConfigMailerFrom(): ?string
{
return $this->config_mailer_from;
}
public function setConfigMailerFrom(?string $config_mailer_from): self
{
$this->config_mailer_from = $config_mailer_from;
return $this;
}
public function getHolidaysBccUser(): ?User
{
return $this->holidays_bcc_user;
}
public function setHolidaysBccUser(?User $holidays_bcc_user): self
{
$this->holidays_bcc_user = $holidays_bcc_user;
return $this;
}
public function getFirebaseNameDatabase(): ?string
{
return $this->firebase_name_database;
}
public function setFirebaseNameDatabase(?string $firebase_name_database): self
{
$this->firebase_name_database = $firebase_name_database;
return $this;
}
public function getFirebaseServiceAccount(): ?array
{
return $this->firebase_service_account;
}
public function setFirebaseServiceAccount(array $firebase_service_account): self
{
$this->firebase_service_account = $firebase_service_account;
return $this;
}
public function getRegisterAvailable(): ?bool
{
return $this->register_available;
}
public function setRegisterAvailable(?bool $register_available): self
{
$this->register_available = $register_available;
return $this;
}
}