<?php
namespace App\Entity;
use Symfony\Component\Serializer\Annotation\Groups;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: 'App\Repository\CompanyRepository')]
class Company
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[Groups(['LogService', 'APIJob'])]
#[ORM\Column(type: 'string', length: 64, nullable: true)]
private $fullName;
#[ORM\OneToMany(targetEntity: 'App\Entity\Invitation', mappedBy: 'company', orphanRemoval: true)]
private $invitations;
#[ORM\ManyToOne(targetEntity: 'App\Entity\User', inversedBy: 'company')]
#[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', onDelete: 'CASCADE', nullable: false)]
private $user;
#[Groups(['LogService', 'APIJob'])]
#[ORM\OneToMany(targetEntity: 'App\Entity\Office', mappedBy: 'company', orphanRemoval: true)]
private $offices;
#[ORM\OneToMany(targetEntity: 'App\Entity\Document', mappedBy: 'company')]
private $documents;
#[Groups(['LogService'])]
#[ORM\Column(type: 'text', nullable: true)]
private $logo;
#[ORM\OneToMany(targetEntity: 'App\Entity\Department', mappedBy: 'company')]
private $departments;
#[ORM\OneToMany(targetEntity: 'App\Entity\AppraisalForm', mappedBy: 'company', orphanRemoval: true)]
private $appraisalForms;
#[ORM\OneToMany(targetEntity: Log::class, mappedBy: 'company')]
private $logs;
#[Groups(['LogService'])]
#[ORM\Column(type: 'text', nullable: true)]
private $introduction;
#[ORM\Column(type: 'text', nullable: true)]
private $starterGuide;
#[ORM\OneToMany(targetEntity: QnA::class, mappedBy: 'company', orphanRemoval: true)]
private $QnAs;
#[ORM\OneToMany(targetEntity: Training::class, mappedBy: 'company', orphanRemoval: true)]
private $trainings;
#[ORM\OneToMany(targetEntity: Announcement::class, mappedBy: 'company', orphanRemoval: true)]
private $announcements;
#[ORM\OneToOne(targetEntity: SocialMedia::class, mappedBy: 'company', cascade: ['persist', 'remove'])]
private $socialMedia;
#[ORM\OneToMany(targetEntity: Job::class, mappedBy: 'company')]
private $jobs;
#[ORM\Column(type: 'array', nullable: true)]
private $reminder = [];
#[ORM\Column(type: 'json', nullable: true)]
private $attributes = [];
#[ORM\OneToMany(mappedBy: 'company', targetEntity: AppraisalCategory::class, orphanRemoval: true)]
private Collection $appraisalCategories;
#[ORM\OneToMany(mappedBy: 'company', targetEntity: ChatbotCompanyPrompt::class, orphanRemoval: true)]
private Collection $chatbotCompanyPrompts;
public function __construct()
{
$this->invitations = new ArrayCollection();
$this->offices = new ArrayCollection();
$this->documents = new ArrayCollection();
$this->departments = new ArrayCollection();
$this->appraisalForms = new ArrayCollection();
$this->logs = new ArrayCollection();
$this->QnAs = new ArrayCollection();
$this->trainings = new ArrayCollection();
$this->announcements = new ArrayCollection();
$this->jobs = new ArrayCollection();
$this->appraisalCategories = new ArrayCollection();
$this->chatbotCompanyPrompts = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getFullName(): ?string
{
return $this->fullName;
}
public function setFullName(?string $fullName): self
{
$this->fullName = $fullName;
return $this;
}
/**
* @return Collection|Invitation[]
*/
public function getInvitations(): Collection
{
return $this->invitations;
}
public function addInvitation(Invitation $invitation): self
{
if (!$this->invitations->contains($invitation)) {
$this->invitations[] = $invitation;
$invitation->setCompany($this);
}
return $this;
}
public function removeInvitation(Invitation $invitation): self
{
if ($this->invitations->contains($invitation)) {
$this->invitations->removeElement($invitation);
// set the owning side to null (unless already changed)
if ($invitation->getCompany() === $this) {
$invitation->setCompany(null);
}
}
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
/**
* @return Collection|Office[]
*/
public function getOffices(): Collection
{
return $this->offices;
}
public function addOffice(Office $office): self
{
if (!$this->offices->contains($office)) {
$this->offices[] = $office;
$office->setCompany($this);
}
return $this;
}
public function removeOffice(Office $office): self
{
if ($this->offices->contains($office)) {
$this->offices->removeElement($office);
// set the owning side to null (unless already changed)
if ($office->getCompany() === $this) {
$office->setCompany(null);
}
}
return $this;
}
/**
* @return Collection|Document[]
*/
public function getDocuments(): Collection
{
return $this->documents;
}
public function addDocument(Document $document): self
{
if (!$this->documents->contains($document)) {
$this->documents[] = $document;
$document->setCompany($this);
}
return $this;
}
public function removeDocument(Document $document): self
{
if ($this->documents->contains($document)) {
$this->documents->removeElement($document);
// set the owning side to null (unless already changed)
if ($document->getCompany() === $this) {
$document->setCompany(null);
}
}
return $this;
}
public function getLogo(): ?string
{
return $this->logo;
}
public function setLogo(?string $logo): self
{
$this->logo = $logo;
return $this;
}
/**
* @return Collection|Department[]
*/
public function getDepartments(): Collection
{
return $this->departments;
}
public function addDepartment(Department $department): self
{
if (!$this->departments->contains($department)) {
$this->departments[] = $department;
$department->setCompany($this);
}
return $this;
}
public function removeDepartment(Department $department): self
{
if ($this->departments->contains($department)) {
$this->departments->removeElement($department);
// set the owning side to null (unless already changed)
if ($department->getCompany() === $this) {
$department->setCompany(null);
}
}
return $this;
}
public function getAllUser()
{
$users = [];
foreach ($this->getOffices() as $office) {
foreach ($office->getUsers() as $user) {
if ($user->getIsActive() == true)
array_push($users, $user);
}
;
}
return $users;
}
public function getAllUsers()
{
$users = [];
foreach ($this->getOffices() as $office) {
foreach ($office->getUsers() as $user) {
// if ($user->getIsActive() == true)
array_push($users, $user);
}
;
}
return $users;
}
public function getAllUserSameOffice($user)
{
$office = $user->getOffice();
$users = [];
foreach ($office->getUsers() as $user) {
if ($user->getIsActive() == true)
array_push($users, $user);
}
;
return $users;
}
public function getAllDeactivatedUser()
{
$users = [];
foreach ($this->getOffices() as $office) {
foreach ($office->getUsers() as $user) {
if ($user->getIsActive() == false)
array_push($users, $user);
}
;
}
return $users;
}
public function countStatus()
{
$status = [];
// need to register all status here
$status['status.new'] = 0;
$status['status.off'] = 0;
$status['status.working'] = 0;
$status['status.working_home'] = 0;
$status['status.working_abroad'] = 0;
//$status['status.break'] = 0;
$status['status.sick'] = 0;
$status['status.leave'] = 0;
foreach ($this->getOffices() as $office) {
foreach ($office->getUsers() as $user) {
if ($user->getIsActive() == true && $user->getStatus() != null)
$status[$user->getStatus()]++;
}
;
}
return $status;
}
/**
* @return Collection|AppraisalForm[]
*/
public function getAppraisalForms(): Collection
{
return $this->appraisalForms;
}
public function addAppraisalForm(AppraisalForm $appraisalForm): self
{
if (!$this->appraisalForms->contains($appraisalForm)) {
$this->appraisalForms[] = $appraisalForm;
$appraisalForm->setCompany($this);
}
return $this;
}
public function removeAppraisalForm(AppraisalForm $appraisalForm): self
{
if ($this->appraisalForms->contains($appraisalForm)) {
$this->appraisalForms->removeElement($appraisalForm);
// set the owning side to null (unless already changed)
if ($appraisalForm->getCompany() === $this) {
$appraisalForm->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->contains($log)) {
$this->logs->removeElement($log);
// set the owning side to null (unless already changed)
if ($log->getCompany() === $this) {
$log->setCompany(null);
}
}
return $this;
}
public function getIntroduction(): ?string
{
return $this->introduction;
}
public function setIntroduction(?string $introduction): self
{
$this->introduction = $introduction;
return $this;
}
public function getStarterGuide(): ?string
{
return $this->starterGuide;
}
public function setStarterGuide(?string $starterGuide): self
{
$this->starterGuide = $starterGuide;
return $this;
}
/**
* @return Collection|QnA[]
*/
public function getQnAs(): Collection
{
return $this->QnAs;
}
public function addQnA(QnA $qnA): self
{
if (!$this->QnAs->contains($qnA)) {
$this->QnAs[] = $qnA;
$qnA->setCompany($this);
}
return $this;
}
public function removeQnA(QnA $qnA): self
{
if ($this->QnAs->contains($qnA)) {
$this->QnAs->removeElement($qnA);
// set the owning side to null (unless already changed)
if ($qnA->getCompany() === $this) {
$qnA->setCompany(null);
}
}
return $this;
}
/**
* @return Collection|Training[]
*/
public function getTrainings(): Collection
{
return $this->trainings;
}
public function addTraining(Training $training): self
{
if (!$this->trainings->contains($training)) {
$this->trainings[] = $training;
$training->setCompany($this);
}
return $this;
}
public function removeTraining(Training $training): self
{
if ($this->trainings->contains($training)) {
$this->trainings->removeElement($training);
// set the owning side to null (unless already changed)
if ($training->getCompany() === $this) {
$training->setCompany(null);
}
}
return $this;
}
public function companyCompletion()
{
$cc['data'] = [];
$cc['completed'] = 0;
if ($this->getFullName() == null) {
array_push($cc['data'], ['message.company.name' => false]);
} else {
array_push($cc['data'], ['message.company.name' => true]);
$cc['completed']++;
}
if (count($this->offices) == 0) {
array_push($cc['data'], ['message.company.office' => false]);
} else {
array_push($cc['data'], ['message.company.office' => true]);
$cc['completed']++;
}
$cc['total'] = ($cc['completed'] / count($cc['data'])) * 100;
return $cc;
}
/**
* @return Collection|Announcement[]
*/
public function getAnnouncements(): Collection
{
return $this->announcements;
}
public function addAnnouncement(Announcement $announcement): self
{
if (!$this->announcements->contains($announcement)) {
$this->announcements[] = $announcement;
$announcement->setCompany($this);
}
return $this;
}
public function removeAnnouncement(Announcement $announcement): self
{
if ($this->announcements->contains($announcement)) {
$this->announcements->removeElement($announcement);
// set the owning side to null (unless already changed)
if ($announcement->getCompany() === $this) {
$announcement->setCompany(null);
}
}
return $this;
}
public function getSocialMedia(): ?SocialMedia
{
return $this->socialMedia;
}
public function setSocialMedia(?SocialMedia $socialMedia): self
{
$this->socialMedia = $socialMedia;
// set (or unset) the owning side of the relation if necessary
$newCompany = null === $socialMedia ? null : $this;
if ($socialMedia->getCompany() !== $newCompany) {
$socialMedia->setCompany($newCompany);
}
return $this;
}
public function superAdmins($userException = null)
{
$users = [];
foreach ($this->getOffices() as $office) {
foreach ($office->getUsers() as $user) {
if ($user != $userException && $user->getIsActive() == true && in_array('ROLE_MANAGEMENT', $user->getRoles()))
array_push($users, $user);
}
;
}
return $users;
}
/**
* @return Collection|Job[]
*/
public function getJobs(): Collection
{
return $this->jobs;
}
public function addJob(Job $job): self
{
if (!$this->jobs->contains($job)) {
$this->jobs[] = $job;
$job->setCompany($this);
}
return $this;
}
public function removeJob(Job $job): self
{
if ($this->jobs->removeElement($job)) {
// set the owning side to null (unless already changed)
if ($job->getCompany() === $this) {
$job->setCompany(null);
}
}
return $this;
}
public function getReminder(): ?array
{
return $this->reminder;
}
public function setReminder(?array $reminder): self
{
$this->reminder = $reminder;
return $this;
}
public function getAllManager($sort = true, $includeSub = false)
{
$managers = [];
foreach ($this->offices as $office) {
$officeManagers = $office->getAllManager(false, $includeSub);
array_push($managers, $officeManagers);
}
$managers = call_user_func_array('array_merge', $managers);
if ($sort) {
usort($managers, function ($a, $b) {
return strcmp($a->getPersonalInfo()->getFirstName(), $b->getPersonalInfo()->getFirstName());
});
}
;
return $managers;
}
public function getAllSubManager($sort = true)
{
$managers = [];
foreach ($this->offices as $office) {
$officeManagers = $office->getAllSubManager(false);
array_push($managers, ...$officeManagers);
}
$managers = array_filter($managers, function ($manager) {
return is_object($manager);
});
if ($sort) {
usort($managers, function ($a, $b) {
return strcmp($a->getPersonalInfo()->getFirstName(), $b->getPersonalInfo()->getFirstName());
});
}
;
return $managers;
}
public function getAttributes(): ?array
{
return $this->attributes;
}
public function setAttributes(?array $attributes): self
{
$this->attributes = $attributes;
return $this;
}
public function appraisalStatusOverview($type = null, $manager = null)
{
if ($manager) {
$users = $manager->getSubordinates();
} else {
$users = $this->getAllUser();
}
$overview = ['user' => 0, 'user-draft' => 0, 'manager' => 0, 'manager-draft' => 0, 'meeting' => 0, 'summary' => 0, 'objective' => 0, 'yearly' => ['user' => 0, 'user-draft' => 0, 'manager' => 0, 'manager-draft' => 0, 'meeting' => 0, 'summary' => 0, 'objective' => 0], 'total' => 0];
foreach ($users as $user) {
if ($type) {
if ($user->latestAppraisal() == null)
continue;
if ($type == 'permanent' && $user->latestAppraisal()->getProbation() == true)
continue;
if ($user->getPersonalInfo()->getJobStatus() != 'form.job_status.' . $type)
continue;
}
;
$appraisalType = $user->latestAppraisal()->getProbation() == true ? 'probation' : 'yearly';
$appraisalStatus = $user->getAppraisalStatus();
$objectiveStatus = $user->getObjectiveStatus();
switch ($appraisalStatus['step']) {
case 1:
if ($appraisalStatus['missed'] == false) {
$overview['user']++;
$overview['total']++;
if ($appraisalType == 'yearly')
$overview['yearly']['user']++;
}
;
if ($appraisalStatus['draft'] == true) {
$overview['user-draft']++;
$overview['total']++;
if ($appraisalType == 'yearly')
$overview['yearly']['user-draft']++;
}
;
break;
case 2:
if ($appraisalStatus['missed'] == false) {
$overview['manager']++;
$overview['total']++;
if ($appraisalType == 'yearly')
$overview['yearly']['manager']++;
}
;
if ($appraisalStatus['draft'] == true) {
$overview['manager-draft']++;
$overview['total']++;
if ($appraisalType == 'yearly')
$overview['yearly']['manager-draft']++;
}
;
break;
case 3:
if ($appraisalStatus['missed'] == true) {
$overview['meeting']++;
$overview['total']++;
if ($appraisalType == 'yearly')
$overview['yearly']['meeting']++;
}
;
break;
case 5:
$overview['summary']++;
$overview['total']++;
if ($appraisalType == 'yearly')
$overview['yearly']['summary']++;
break;
}
if (isset($objectiveStatus['expired']) && $objectiveStatus['expired'] == true) {
$overview['total']++;
$overview['objective']++;
if ($appraisalType == 'yearly')
$overview['yearly']['objective']++;
}
;
}
return $overview;
}
/**
* @return Collection<int, AppraisalCategory>
*/
public function getAppraisalCategories(): Collection
{
return $this->appraisalCategories;
}
public function addAppraisalCategory(AppraisalCategory $appraisalCategory): self
{
if (!$this->appraisalCategories->contains($appraisalCategory)) {
$this->appraisalCategories->add($appraisalCategory);
$appraisalCategory->setCompany($this);
}
return $this;
}
public function removeAppraisalCategory(AppraisalCategory $appraisalCategory): self
{
if ($this->appraisalCategories->removeElement($appraisalCategory)) {
// set the owning side to null (unless already changed)
if ($appraisalCategory->getCompany() === $this) {
$appraisalCategory->setCompany(null);
}
}
return $this;
}
/**
* @return Collection<int, ChatbotCompanyPrompt>
*/
public function getChatbotCompanyPrompts(): Collection
{
return $this->chatbotCompanyPrompts;
}
public function addChatbotCompanyPrompt(ChatbotCompanyPrompt $chatbotCompanyPrompt): self
{
if (!$this->chatbotCompanyPrompts->contains($chatbotCompanyPrompt)) {
$this->chatbotCompanyPrompts->add($chatbotCompanyPrompt);
$chatbotCompanyPrompt->setCompany($this);
}
return $this;
}
public function removeChatbotCompanyPrompt(ChatbotCompanyPrompt $chatbotCompanyPrompt): self
{
if ($this->chatbotCompanyPrompts->removeElement($chatbotCompanyPrompt)) {
// set the owning side to null (unless already changed)
if ($chatbotCompanyPrompt->getCompany() === $this) {
$chatbotCompanyPrompt->setCompany(null);
}
}
return $this;
}
}