src/Entity/Company.php line 42
<?php
namespace App\Entity;
use DateTime;
use App\Entity\User;
use App\Entity\Season;
use App\Entity\Expense;
use App\Entity\Location;
use App\Entity\Classroom;
use App\Entity\enums\CompanyCategory;
use Symfony\Component\Uid\Ulid;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\CompanyRepository;
use App\Controller\MyCompanyController;
use Doctrine\Common\Collections\Collection;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
use Gedmo\Mapping\Annotation as Gedmo;
#[ORM\Entity(repositoryClass: CompanyRepository::class)]
#[Gedmo\SoftDeleteable(fieldName: 'deletedAt', timeAware: false, hardDelete: true)]
#[ORM\HasLifecycleCallbacks()]
#[ApiResource(
normalizationContext: [
'groups' => ['read:company']
],
itemOperations: [
'mycompany' => [
'pagination_enabled' => false,
'path' => '/mycompany',
'method' => 'get',
'requirements' => [],
'controller' => MyCompanyController::class,
'read' => false,
]
],
collectionOperations: [],
)]
class Company
{
use Timestamps;
const TYPES = [
'Crèche',
'Jardin d\'enfants',
'Établissement « multi-accueil ».'
];
#[ORM\Id]
#[ORM\Column(type: 'ulid', unique: true)]
#[ORM\GeneratedValue(strategy: "CUSTOM")]
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
#[Groups(['read:company'])]
private ?Ulid $id = null;
#[ORM\Column(type: 'string', length: 255)]
#[Groups(['read:company'])]
private $name;
#[ORM\Column(type: 'string', length: 255, enumType: CompanyCategory::class)]
#[Groups(['read:company'])]
private $type;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(['read:company'])]
private $size;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(['read:company'])]
private $logo;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(['read:company'])]
private $email;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(['read:company'])]
private $phone;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(['read:company'])]
private $mobile;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(['read:company'])]
private $fax;
#[ORM\Column(type: 'text', nullable: true)]
#[Groups(['read:company'])]
private $description;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(['read:company'])]
private $website;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(['read:company'])]
private $facebook;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(['read:company'])]
private $twitter;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(['read:company'])]
private $instagram;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(['read:company'])]
private $youtube;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(['read:company'])]
private $tiktok;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(['read:company'])]
private $rc;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(['read:company'])]
private $nif;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(['read:company'])]
private $nis;
#[ORM\Column(type: 'boolean', nullable: true)]
private $is_active;
#[ORM\OneToMany(mappedBy: 'company', targetEntity: User::class)]
private $users;
#[ORM\OneToOne(targetEntity: Location::class, cascade: ['persist', 'remove'])]
#[Groups(['read:company'])]
private $address;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $date_format;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $languege;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $currencie;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $time_zone;
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: Expense::class, orphanRemoval: true)]
private $expenses;
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: ExpenseCategory::class, orphanRemoval: true)]
private $expenseCategories;
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: Season::class, orphanRemoval: true)]
private $seasons;
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: Service::class, orphanRemoval: true)]
private $services;
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: Section::class, orphanRemoval: true)]
private $sections;
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: FamilyMember::class, orphanRemoval: true)]
private $familyMembers;
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: Child::class, orphanRemoval: true)]
private $children;
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: Employee::class, orphanRemoval: true)]
private $employees;
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: Subscription::class, orphanRemoval: true)]
private $subscriptions;
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: Payment::class, orphanRemoval: true)]
private $payments;
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: Classroom::class, orphanRemoval: true)]
private $classrooms;
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: Evenement::class, orphanRemoval: true)]
private $evenements;
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: Task::class, orphanRemoval: true)]
private $tasks;
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: AbsenceEmployee::class, orphanRemoval: true)]
private $absenceEmployees;
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: Post::class, orphanRemoval: true)]
private $posts;
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: Colleague::class, orphanRemoval: true)]
private $colleagues;
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: Abonnement::class, orphanRemoval: true)]
private $abonnements;
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: Order::class, orphanRemoval: true)]
private $orders;
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: Prechild::class, orphanRemoval: true)]
private $prechildren;
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: Pointing::class, orphanRemoval: true)]
private $pointings;
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: Activity::class)]
private Collection $activities;
public function __construct()
{
$this->cars = new ArrayCollection();
$this->users = new ArrayCollection();
$this->type = CompanyCategory::creche;
$this->expenses = new ArrayCollection();
$this->expenseCategories = new ArrayCollection();
$this->seasons = new ArrayCollection();
$this->services = new ArrayCollection();
$this->sections = new ArrayCollection();
$this->familyMembers = new ArrayCollection();
$this->children = new ArrayCollection();
$this->employees = new ArrayCollection();
$this->subscriptions = new ArrayCollection();
$this->payments = new ArrayCollection();
$this->classrooms = new ArrayCollection();
$this->evenements = new ArrayCollection();
$this->tasks = new ArrayCollection();
$this->absenceChildren = new ArrayCollection();
$this->absenceEmployees = new ArrayCollection();
$this->posts = new ArrayCollection();
$this->colleagues = new ArrayCollection();
$this->abonnements = new ArrayCollection();
$this->orders = new ArrayCollection();
$this->prechildren = new ArrayCollection();
$this->currencie = 'DZD';
$this->pointings = new ArrayCollection();
$this->activities = new ArrayCollection();
}
public function __toString()
{
return $this->name;
}
public function isTrial()
{
$now = new DateTime();
$interval = $now->diff($this->getCreatedAt(), true);
if (intval($interval->format('%a')) < 30) {
return true;
}
return false;
}
public function hasActivePlan()
{
$abonnements = $this->getAbonnements();
if (count($abonnements) > 0) {
return true;
}
return false;
}
public function getId(): ?Ulid
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
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 getMobile(): ?string
{
return $this->mobile;
}
public function setMobile(?string $mobile): self
{
$this->mobile = $mobile;
return $this;
}
public function getFax(): ?string
{
return $this->fax;
}
public function setFax(?string $fax): self
{
$this->fax = $fax;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getWebsite(): ?string
{
return $this->website;
}
public function setWebsite(?string $website): self
{
$this->website = $website;
return $this;
}
public function getFacebook(): ?string
{
return $this->facebook;
}
public function setFacebook(?string $facebook): self
{
$this->facebook = $facebook;
return $this;
}
public function getTwitter(): ?string
{
return $this->twitter;
}
public function setTwitter(?string $twitter): self
{
$this->twitter = $twitter;
return $this;
}
public function getInstagram(): ?string
{
return $this->instagram;
}
public function setInstagram(?string $instagram): self
{
$this->instagram = $instagram;
return $this;
}
public function getYoutube(): ?string
{
return $this->youtube;
}
public function setYoutube(?string $youtube): self
{
$this->youtube = $youtube;
return $this;
}
public function getTiktok(): ?string
{
return $this->tiktok;
}
public function setTiktok(?string $tiktok): self
{
$this->tiktok = $tiktok;
return $this;
}
public function getRc(): ?string
{
return $this->rc;
}
public function setRc(?string $rc): self
{
$this->rc = $rc;
return $this;
}
public function getNif(): ?string
{
return $this->nif;
}
public function setNif(?string $nif): self
{
$this->nif = $nif;
return $this;
}
public function getNis(): ?string
{
return $this->nis;
}
public function setNis(?string $nis): self
{
$this->nis = $nis;
return $this;
}
public function getIsActive(): ?bool
{
return $this->is_active;
}
public function setIsActive(bool $is_active): self
{
$this->is_active = $is_active;
return $this;
}
public function getType(): ?CompanyCategory
{
return $this->type;
}
public function setType(?CompanyCategory $type): self
{
$this->type = $type;
return $this;
}
/**
* @return Collection<int, User>
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(User $user): self
{
if (!$this->users->contains($user)) {
$this->users[] = $user;
$user->setCompany($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->getCompany() === $this) {
$user->setCompany(null);
}
}
return $this;
}
public function getSize(): ?string
{
return $this->size;
}
public function setSize(?string $size): self
{
$this->size = $size;
return $this;
}
public function getAddress(): ?Location
{
return $this->address;
}
public function setAddress(?Location $address): self
{
$this->address = $address;
return $this;
}
public function getDateFormat(): ?string
{
return $this->date_format;
}
public function setDateFormat(?string $date_format): self
{
$this->date_format = $date_format;
return $this;
}
public function getLanguege(): ?string
{
return $this->languege;
}
public function setLanguege(?string $languege): self
{
$this->languege = $languege;
return $this;
}
public function getCurrencie(): ?string
{
return $this->currencie;
}
public function setCurrencie(?string $currencie): self
{
$this->currencie = $currencie;
return $this;
}
public function getTimeZone(): ?string
{
return $this->time_zone;
}
public function setTimeZone(?string $time_zone): self
{
$this->time_zone = $time_zone;
return $this;
}
/**
* @return Collection<int, Expense>
*/
public function getExpenses(): Collection
{
return $this->expenses;
}
public function addExpense(Expense $expense): self
{
if (!$this->expenses->contains($expense)) {
$this->expenses[] = $expense;
$expense->setOwner($this);
}
return $this;
}
public function removeExpense(Expense $expense): self
{
if ($this->expenses->removeElement($expense)) {
// set the owning side to null (unless already changed)
if ($expense->getOwner() === $this) {
$expense->setOwner(null);
}
}
return $this;
}
/**
* @return Collection<int, ExpenseCategory>
*/
public function getExpenseCategories(): Collection
{
return $this->expenseCategories;
}
public function addExpenseCategory(ExpenseCategory $expenseCategory): self
{
if (!$this->expenseCategories->contains($expenseCategory)) {
$this->expenseCategories[] = $expenseCategory;
$expenseCategory->setOwner($this);
}
return $this;
}
public function removeExpenseCategory(ExpenseCategory $expenseCategory): self
{
if ($this->expenseCategories->removeElement($expenseCategory)) {
// set the owning side to null (unless already changed)
if ($expenseCategory->getOwner() === $this) {
$expenseCategory->setOwner(null);
}
}
return $this;
}
/**
* @return Collection<int, Season>
*/
public function getSeasons(): Collection
{
return $this->seasons;
}
public function addSeason(Season $season): self
{
if (!$this->seasons->contains($season)) {
$this->seasons[] = $season;
$season->setOwner($this);
}
return $this;
}
public function getActiveSeason(): Season|null
{
$seasons = $this->getSeasons();
foreach ($seasons as $season) {
if ($season->isIsActive()) {
return $season;
}
}
return null;
}
public function removeSeason(Season $season): self
{
if ($this->seasons->removeElement($season)) {
// set the owning side to null (unless already changed)
if ($season->getOwner() === $this) {
$season->setOwner(null);
}
}
return $this;
}
/**
* @return Collection<int, Service>
*/
public function getServices(): Collection
{
return $this->services;
}
public function addService(Service $service): self
{
if (!$this->services->contains($service)) {
$this->services[] = $service;
$service->setOwner($this);
}
return $this;
}
public function removeService(Service $service): self
{
if ($this->services->removeElement($service)) {
// set the owning side to null (unless already changed)
if ($service->getOwner() === $this) {
$service->setOwner(null);
}
}
return $this;
}
/**
* @return Collection<int, Section>
*/
public function getSections(): Collection
{
return $this->sections;
}
public function addSection(Section $section): self
{
if (!$this->sections->contains($section)) {
$this->sections[] = $section;
$section->setOwner($this);
}
return $this;
}
public function removeSection(Section $section): self
{
if ($this->sections->removeElement($section)) {
// set the owning side to null (unless already changed)
if ($section->getOwner() === $this) {
$section->setOwner(null);
}
}
return $this;
}
/**
* @return Collection<int, FamilyMember>
*/
public function getFamilyMembers(): Collection
{
return $this->familyMembers;
}
public function addFamilyMember(FamilyMember $familyMember): self
{
if (!$this->familyMembers->contains($familyMember)) {
$this->familyMembers[] = $familyMember;
$familyMember->setOwner($this);
}
return $this;
}
public function removeFamilyMember(FamilyMember $familyMember): self
{
if ($this->familyMembers->removeElement($familyMember)) {
// set the owning side to null (unless already changed)
if ($familyMember->getOwner() === $this) {
$familyMember->setOwner(null);
}
}
return $this;
}
/**
* @return Collection<int, Child>
*/
public function getChildren(): Collection
{
return $this->children;
}
public function addChild(Child $child): self
{
if (!$this->children->contains($child)) {
$this->children[] = $child;
$child->setOwner($this);
}
return $this;
}
public function removeChild(Child $child): self
{
if ($this->children->removeElement($child)) {
// set the owning side to null (unless already changed)
if ($child->getOwner() === $this) {
$child->setOwner(null);
}
}
return $this;
}
/**
* @return Collection<int, Employee>
*/
public function getEmployees(): Collection
{
return $this->employees;
}
public function addEmployee(Employee $employee): self
{
if (!$this->employees->contains($employee)) {
$this->employees[] = $employee;
$employee->setOwner($this);
}
return $this;
}
public function removeEmployee(Employee $employee): self
{
if ($this->employees->removeElement($employee)) {
// set the owning side to null (unless already changed)
if ($employee->getOwner() === $this) {
$employee->setOwner(null);
}
}
return $this;
}
/**
* @return Collection<int, Subscription>
*/
public function getSubscriptions(): Collection
{
return $this->subscriptions;
}
public function addSubscription(Subscription $subscription): self
{
if (!$this->subscriptions->contains($subscription)) {
$this->subscriptions[] = $subscription;
$subscription->setOwner($this);
}
return $this;
}
public function removeSubscription(Subscription $subscription): self
{
if ($this->subscriptions->removeElement($subscription)) {
// set the owning side to null (unless already changed)
if ($subscription->getOwner() === $this) {
$subscription->setOwner(null);
}
}
return $this;
}
/**
* @return Collection<int, Payment>
*/
public function getPayments(): Collection
{
return $this->payments;
}
public function addPayment(Payment $payment): self
{
if (!$this->payments->contains($payment)) {
$this->payments[] = $payment;
$payment->setOwner($this);
}
return $this;
}
public function removePayment(Payment $payment): self
{
if ($this->payments->removeElement($payment)) {
// set the owning side to null (unless already changed)
if ($payment->getOwner() === $this) {
$payment->setOwner(null);
}
}
return $this;
}
/**
* @return Collection<int, Classroom>
*/
public function getClassrooms(): Collection
{
return $this->classrooms;
}
public function addClassroom(Classroom $classroom): self
{
if (!$this->classrooms->contains($classroom)) {
$this->classrooms[] = $classroom;
$classroom->setOwner($this);
}
return $this;
}
public function removeClassroom(Classroom $classroom): self
{
if ($this->classrooms->removeElement($classroom)) {
// set the owning side to null (unless already changed)
if ($classroom->getOwner() === $this) {
$classroom->setOwner(null);
}
}
return $this;
}
/**
* @return Collection<int, Evenement>
*/
public function getEvenements(): Collection
{
return $this->evenements;
}
public function addEvenement(Evenement $evenement): self
{
if (!$this->evenements->contains($evenement)) {
$this->evenements[] = $evenement;
$evenement->setOwner($this);
}
return $this;
}
public function removeEvenement(Evenement $evenement): self
{
if ($this->evenements->removeElement($evenement)) {
// set the owning side to null (unless already changed)
if ($evenement->getOwner() === $this) {
$evenement->setOwner(null);
}
}
return $this;
}
/**
* @return Collection<int, Task>
*/
public function getTasks(): Collection
{
return $this->tasks;
}
public function addTask(Task $task): self
{
if (!$this->tasks->contains($task)) {
$this->tasks[] = $task;
$task->setOwner($this);
}
return $this;
}
public function removeTask(Task $task): self
{
if ($this->tasks->removeElement($task)) {
// set the owning side to null (unless already changed)
if ($task->getOwner() === $this) {
$task->setOwner(null);
}
}
return $this;
}
/**
* @return Collection<int, AbsenceEmployee>
*/
public function getAbsenceEmployees(): Collection
{
return $this->absenceEmployees;
}
public function addAbsenceEmployee(AbsenceEmployee $absenceEmployee): self
{
if (!$this->absenceEmployees->contains($absenceEmployee)) {
$this->absenceEmployees[] = $absenceEmployee;
$absenceEmployee->setOwner($this);
}
return $this;
}
public function removeAbsenceEmployee(AbsenceEmployee $absenceEmployee): self
{
if ($this->absenceEmployees->removeElement($absenceEmployee)) {
// set the owning side to null (unless already changed)
if ($absenceEmployee->getOwner() === $this) {
$absenceEmployee->setOwner(null);
}
}
return $this;
}
/**
* @return Collection<int, Post>
*/
public function getPosts(): Collection
{
return $this->posts;
}
public function addPost(Post $post): self
{
if (!$this->posts->contains($post)) {
$this->posts[] = $post;
$post->setOwner($this);
}
return $this;
}
public function removePost(Post $post): self
{
if ($this->posts->removeElement($post)) {
// set the owning side to null (unless already changed)
if ($post->getOwner() === $this) {
$post->setOwner(null);
}
}
return $this;
}
/**
* @return Collection<int, Colleague>
*/
public function getColleagues(): Collection
{
return $this->colleagues;
}
public function addColleague(Colleague $colleague): self
{
if (!$this->colleagues->contains($colleague)) {
$this->colleagues[] = $colleague;
$colleague->setOwner($this);
}
return $this;
}
public function removeColleague(Colleague $colleague): self
{
if ($this->colleagues->removeElement($colleague)) {
// set the owning side to null (unless already changed)
if ($colleague->getOwner() === $this) {
$colleague->setOwner(null);
}
}
return $this;
}
/**
* @return Collection<int, Abonnement>
*/
public function getAbonnements(): Collection
{
foreach ($this->abonnements as $key => $value) {
if ($value->getExpireDate() < new DateTime()) {
$this->abonnements->remove($key);
}
}
return $this->abonnements;
}
public function addAbonnement(Abonnement $abonnement): self
{
if (!$this->abonnements->contains($abonnement)) {
$this->abonnements[] = $abonnement;
$abonnement->setOwner($this);
}
return $this;
}
public function removeAbonnement(Abonnement $abonnement): self
{
if ($this->abonnements->removeElement($abonnement)) {
// set the owning side to null (unless already changed)
if ($abonnement->getOwner() === $this) {
$abonnement->setOwner(null);
}
}
return $this;
}
/**
* @return Collection<int, Order>
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function addOrder(Order $order): self
{
if (!$this->orders->contains($order)) {
$this->orders[] = $order;
$order->setOwner($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->getOwner() === $this) {
$order->setOwner(null);
}
}
return $this;
}
/**
* @return Collection<int, Prechild>
*/
public function getPrechildren(): Collection
{
return $this->prechildren;
}
public function addPrechild(Prechild $prechild): self
{
if (!$this->prechildren->contains($prechild)) {
$this->prechildren[] = $prechild;
$prechild->setOwner($this);
}
return $this;
}
public function removePrechild(Prechild $prechild): self
{
if ($this->prechildren->removeElement($prechild)) {
// set the owning side to null (unless already changed)
if ($prechild->getOwner() === $this) {
$prechild->setOwner(null);
}
}
return $this;
}
/**
* @return Collection<int, Pointing>
*/
public function getPointings(): Collection
{
return $this->pointings;
}
public function addPointing(Pointing $pointing): self
{
if (!$this->pointings->contains($pointing)) {
$this->pointings[] = $pointing;
$pointing->setOwner($this);
}
return $this;
}
public function removePointing(Pointing $pointing): self
{
if ($this->pointings->removeElement($pointing)) {
// set the owning side to null (unless already changed)
if ($pointing->getOwner() === $this) {
$pointing->setOwner(null);
}
}
return $this;
}
public function isIsActive(): ?bool
{
return $this->is_active;
}
/**
* @return Collection<int, Activity>
*/
public function getActivities(): Collection
{
return $this->activities;
}
public function addActivity(Activity $activity): static
{
if (!$this->activities->contains($activity)) {
$this->activities->add($activity);
$activity->setOwner($this);
}
return $this;
}
public function removeActivity(Activity $activity): static
{
if ($this->activities->removeElement($activity)) {
// set the owning side to null (unless already changed)
if ($activity->getOwner() === $this) {
$activity->setOwner(null);
}
}
return $this;
}
public function getOwner(): User|null
{
foreach ($this->users as $user) {
if (in_array('ROLE_OWNER', $user->getRoles())) {
return $user;
}
}
return null;
}
}