src/Entity/Company.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Symfony\Component\Serializer\Annotation\Groups;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClass'App\Repository\CompanyRepository')]
  8. class Company
  9. {
  10.     #[ORM\Id]
  11.     #[ORM\GeneratedValue]
  12.     #[ORM\Column(type'integer')]
  13.     private $id;
  14.     #[Groups(['LogService''APIJob'])]
  15.     #[ORM\Column(type'string'length64nullabletrue)]
  16.     private $fullName;
  17.     #[ORM\OneToMany(targetEntity'App\Entity\Invitation'mappedBy'company'orphanRemovaltrue)]
  18.     private $invitations;
  19.     #[ORM\ManyToOne(targetEntity'App\Entity\User'inversedBy'company')]
  20.     #[ORM\JoinColumn(name'user_id'referencedColumnName'id'onDelete'CASCADE'nullablefalse)]
  21.     private $user;
  22.     #[Groups(['LogService''APIJob'])]
  23.     #[ORM\OneToMany(targetEntity'App\Entity\Office'mappedBy'company'orphanRemovaltrue)]
  24.     private $offices;
  25.     #[ORM\OneToMany(targetEntity'App\Entity\Document'mappedBy'company')]
  26.     private $documents;
  27.     #[Groups(['LogService'])]
  28.     #[ORM\Column(type'text'nullabletrue)]
  29.     private $logo;
  30.     #[ORM\OneToMany(targetEntity'App\Entity\Department'mappedBy'company')]
  31.     private $departments;
  32.     #[ORM\OneToMany(targetEntity'App\Entity\AppraisalForm'mappedBy'company'orphanRemovaltrue)]
  33.     private $appraisalForms;
  34.     #[ORM\OneToMany(targetEntityLog::class, mappedBy'company')]
  35.     private $logs;
  36.     #[Groups(['LogService'])]
  37.     #[ORM\Column(type'text'nullabletrue)]
  38.     private $introduction;
  39.     #[ORM\Column(type'text'nullabletrue)]
  40.     private $starterGuide;
  41.     #[ORM\OneToMany(targetEntityQnA::class, mappedBy'company'orphanRemovaltrue)]
  42.     private $QnAs;
  43.     #[ORM\OneToMany(targetEntityTraining::class, mappedBy'company'orphanRemovaltrue)]
  44.     private $trainings;
  45.     #[ORM\OneToMany(targetEntityAnnouncement::class, mappedBy'company'orphanRemovaltrue)]
  46.     private $announcements;
  47.     #[ORM\OneToOne(targetEntitySocialMedia::class, mappedBy'company'cascade: ['persist''remove'])]
  48.     private $socialMedia;
  49.     #[ORM\OneToMany(targetEntityJob::class, mappedBy'company')]
  50.     private $jobs;
  51.     #[ORM\Column(type'array'nullabletrue)]
  52.     private $reminder = [];
  53.     #[ORM\Column(type'json'nullabletrue)]
  54.     private $attributes = [];
  55.     #[ORM\OneToMany(mappedBy'company'targetEntityAppraisalCategory::class, orphanRemovaltrue)]
  56.     private Collection $appraisalCategories;
  57.     #[ORM\OneToMany(mappedBy'company'targetEntityChatbotCompanyPrompt::class, orphanRemovaltrue)]
  58.     private Collection $chatbotCompanyPrompts;
  59.     public function __construct()
  60.     {
  61.         $this->invitations = new ArrayCollection();
  62.         $this->offices = new ArrayCollection();
  63.         $this->documents = new ArrayCollection();
  64.         $this->departments = new ArrayCollection();
  65.         $this->appraisalForms = new ArrayCollection();
  66.         $this->logs = new ArrayCollection();
  67.         $this->QnAs = new ArrayCollection();
  68.         $this->trainings = new ArrayCollection();
  69.         $this->announcements = new ArrayCollection();
  70.         $this->jobs = new ArrayCollection();
  71.         $this->appraisalCategories = new ArrayCollection();
  72.         $this->chatbotCompanyPrompts = new ArrayCollection();
  73.     }
  74.     public function getId(): ?int
  75.     {
  76.         return $this->id;
  77.     }
  78.     public function getFullName(): ?string
  79.     {
  80.         return $this->fullName;
  81.     }
  82.     public function setFullName(?string $fullName): self
  83.     {
  84.         $this->fullName $fullName;
  85.         return $this;
  86.     }
  87.     /**
  88.      * @return Collection|Invitation[]
  89.      */
  90.     public function getInvitations(): Collection
  91.     {
  92.         return $this->invitations;
  93.     }
  94.     public function addInvitation(Invitation $invitation): self
  95.     {
  96.         if (!$this->invitations->contains($invitation)) {
  97.             $this->invitations[] = $invitation;
  98.             $invitation->setCompany($this);
  99.         }
  100.         return $this;
  101.     }
  102.     public function removeInvitation(Invitation $invitation): self
  103.     {
  104.         if ($this->invitations->contains($invitation)) {
  105.             $this->invitations->removeElement($invitation);
  106.             // set the owning side to null (unless already changed)
  107.             if ($invitation->getCompany() === $this) {
  108.                 $invitation->setCompany(null);
  109.             }
  110.         }
  111.         return $this;
  112.     }
  113.     public function getUser(): ?User
  114.     {
  115.         return $this->user;
  116.     }
  117.     public function setUser(?User $user): self
  118.     {
  119.         $this->user $user;
  120.         return $this;
  121.     }
  122.     /**
  123.      * @return Collection|Office[]
  124.      */
  125.     public function getOffices(): Collection
  126.     {
  127.         return $this->offices;
  128.     }
  129.     public function addOffice(Office $office): self
  130.     {
  131.         if (!$this->offices->contains($office)) {
  132.             $this->offices[] = $office;
  133.             $office->setCompany($this);
  134.         }
  135.         return $this;
  136.     }
  137.     public function removeOffice(Office $office): self
  138.     {
  139.         if ($this->offices->contains($office)) {
  140.             $this->offices->removeElement($office);
  141.             // set the owning side to null (unless already changed)
  142.             if ($office->getCompany() === $this) {
  143.                 $office->setCompany(null);
  144.             }
  145.         }
  146.         return $this;
  147.     }
  148.     /**
  149.      * @return Collection|Document[]
  150.      */
  151.     public function getDocuments(): Collection
  152.     {
  153.         return $this->documents;
  154.     }
  155.     public function addDocument(Document $document): self
  156.     {
  157.         if (!$this->documents->contains($document)) {
  158.             $this->documents[] = $document;
  159.             $document->setCompany($this);
  160.         }
  161.         return $this;
  162.     }
  163.     public function removeDocument(Document $document): self
  164.     {
  165.         if ($this->documents->contains($document)) {
  166.             $this->documents->removeElement($document);
  167.             // set the owning side to null (unless already changed)
  168.             if ($document->getCompany() === $this) {
  169.                 $document->setCompany(null);
  170.             }
  171.         }
  172.         return $this;
  173.     }
  174.     public function getLogo(): ?string
  175.     {
  176.         return $this->logo;
  177.     }
  178.     public function setLogo(?string $logo): self
  179.     {
  180.         $this->logo $logo;
  181.         return $this;
  182.     }
  183.     /**
  184.      * @return Collection|Department[]
  185.      */
  186.     public function getDepartments(): Collection
  187.     {
  188.         return $this->departments;
  189.     }
  190.     public function addDepartment(Department $department): self
  191.     {
  192.         if (!$this->departments->contains($department)) {
  193.             $this->departments[] = $department;
  194.             $department->setCompany($this);
  195.         }
  196.         return $this;
  197.     }
  198.     public function removeDepartment(Department $department): self
  199.     {
  200.         if ($this->departments->contains($department)) {
  201.             $this->departments->removeElement($department);
  202.             // set the owning side to null (unless already changed)
  203.             if ($department->getCompany() === $this) {
  204.                 $department->setCompany(null);
  205.             }
  206.         }
  207.         return $this;
  208.     }
  209.     public function getAllUser()
  210.     {
  211.         $users = [];
  212.         foreach ($this->getOffices() as $office) {
  213.             foreach ($office->getUsers() as $user) {
  214.                 if ($user->getIsActive() == true)
  215.                     array_push($users$user);
  216.             }
  217.             ;
  218.         }
  219.         return $users;
  220.     }
  221.     public function getAllUsers()
  222.     {
  223.         $users = [];
  224.         foreach ($this->getOffices() as $office) {
  225.             foreach ($office->getUsers() as $user) {
  226.                 // if ($user->getIsActive() == true)
  227.                     array_push($users$user);
  228.             }
  229.             ;
  230.         }
  231.         return $users;
  232.     }
  233.     public function getAllUserSameOffice($user)
  234.     {
  235.         $office $user->getOffice();
  236.         $users = [];
  237.         foreach ($office->getUsers() as $user) {
  238.             if ($user->getIsActive() == true)
  239.                 array_push($users$user);
  240.         }
  241.         ;
  242.         return $users;
  243.     }
  244.     public function getAllDeactivatedUser()
  245.     {
  246.         $users = [];
  247.         foreach ($this->getOffices() as $office) {
  248.             foreach ($office->getUsers() as $user) {
  249.                 if ($user->getIsActive() == false)
  250.                     array_push($users$user);
  251.             }
  252.             ;
  253.         }
  254.         return $users;
  255.     }
  256.     public function countStatus()
  257.     {
  258.         $status = [];
  259.         // need to register all status here
  260.         $status['status.new'] = 0;
  261.         $status['status.off'] = 0;
  262.         $status['status.working'] = 0;
  263.         $status['status.working_home'] = 0;
  264.         $status['status.working_abroad'] = 0;
  265.         //$status['status.break'] = 0;
  266.         $status['status.sick'] = 0;
  267.         $status['status.leave'] = 0;
  268.         foreach ($this->getOffices() as $office) {
  269.             foreach ($office->getUsers() as $user) {
  270.                 if ($user->getIsActive() == true && $user->getStatus() != null)
  271.                     $status[$user->getStatus()]++;
  272.             }
  273.             ;
  274.         }
  275.         return $status;
  276.     }
  277.     /**
  278.      * @return Collection|AppraisalForm[]
  279.      */
  280.     public function getAppraisalForms(): Collection
  281.     {
  282.         return $this->appraisalForms;
  283.     }
  284.     public function addAppraisalForm(AppraisalForm $appraisalForm): self
  285.     {
  286.         if (!$this->appraisalForms->contains($appraisalForm)) {
  287.             $this->appraisalForms[] = $appraisalForm;
  288.             $appraisalForm->setCompany($this);
  289.         }
  290.         return $this;
  291.     }
  292.     public function removeAppraisalForm(AppraisalForm $appraisalForm): self
  293.     {
  294.         if ($this->appraisalForms->contains($appraisalForm)) {
  295.             $this->appraisalForms->removeElement($appraisalForm);
  296.             // set the owning side to null (unless already changed)
  297.             if ($appraisalForm->getCompany() === $this) {
  298.                 $appraisalForm->setCompany(null);
  299.             }
  300.         }
  301.         return $this;
  302.     }
  303.     /**
  304.      * @return Collection|Log[]
  305.      */
  306.     public function getLogs(): Collection
  307.     {
  308.         return $this->logs;
  309.     }
  310.     public function addLog(Log $log): self
  311.     {
  312.         if (!$this->logs->contains($log)) {
  313.             $this->logs[] = $log;
  314.             $log->setCompany($this);
  315.         }
  316.         return $this;
  317.     }
  318.     public function removeLog(Log $log): self
  319.     {
  320.         if ($this->logs->contains($log)) {
  321.             $this->logs->removeElement($log);
  322.             // set the owning side to null (unless already changed)
  323.             if ($log->getCompany() === $this) {
  324.                 $log->setCompany(null);
  325.             }
  326.         }
  327.         return $this;
  328.     }
  329.     public function getIntroduction(): ?string
  330.     {
  331.         return $this->introduction;
  332.     }
  333.     public function setIntroduction(?string $introduction): self
  334.     {
  335.         $this->introduction $introduction;
  336.         return $this;
  337.     }
  338.     public function getStarterGuide(): ?string
  339.     {
  340.         return $this->starterGuide;
  341.     }
  342.     public function setStarterGuide(?string $starterGuide): self
  343.     {
  344.         $this->starterGuide $starterGuide;
  345.         return $this;
  346.     }
  347.     /**
  348.      * @return Collection|QnA[]
  349.      */
  350.     public function getQnAs(): Collection
  351.     {
  352.         return $this->QnAs;
  353.     }
  354.     public function addQnA(QnA $qnA): self
  355.     {
  356.         if (!$this->QnAs->contains($qnA)) {
  357.             $this->QnAs[] = $qnA;
  358.             $qnA->setCompany($this);
  359.         }
  360.         return $this;
  361.     }
  362.     public function removeQnA(QnA $qnA): self
  363.     {
  364.         if ($this->QnAs->contains($qnA)) {
  365.             $this->QnAs->removeElement($qnA);
  366.             // set the owning side to null (unless already changed)
  367.             if ($qnA->getCompany() === $this) {
  368.                 $qnA->setCompany(null);
  369.             }
  370.         }
  371.         return $this;
  372.     }
  373.     /**
  374.      * @return Collection|Training[]
  375.      */
  376.     public function getTrainings(): Collection
  377.     {
  378.         return $this->trainings;
  379.     }
  380.     public function addTraining(Training $training): self
  381.     {
  382.         if (!$this->trainings->contains($training)) {
  383.             $this->trainings[] = $training;
  384.             $training->setCompany($this);
  385.         }
  386.         return $this;
  387.     }
  388.     public function removeTraining(Training $training): self
  389.     {
  390.         if ($this->trainings->contains($training)) {
  391.             $this->trainings->removeElement($training);
  392.             // set the owning side to null (unless already changed)
  393.             if ($training->getCompany() === $this) {
  394.                 $training->setCompany(null);
  395.             }
  396.         }
  397.         return $this;
  398.     }
  399.     public function companyCompletion()
  400.     {
  401.         $cc['data'] = [];
  402.         $cc['completed'] = 0;
  403.         if ($this->getFullName() == null) {
  404.             array_push($cc['data'], ['message.company.name' => false]);
  405.         } else {
  406.             array_push($cc['data'], ['message.company.name' => true]);
  407.             $cc['completed']++;
  408.         }
  409.         if (count($this->offices) == 0) {
  410.             array_push($cc['data'], ['message.company.office' => false]);
  411.         } else {
  412.             array_push($cc['data'], ['message.company.office' => true]);
  413.             $cc['completed']++;
  414.         }
  415.         $cc['total'] = ($cc['completed'] / count($cc['data'])) * 100;
  416.         return $cc;
  417.     }
  418.     /**
  419.      * @return Collection|Announcement[]
  420.      */
  421.     public function getAnnouncements(): Collection
  422.     {
  423.         return $this->announcements;
  424.     }
  425.     public function addAnnouncement(Announcement $announcement): self
  426.     {
  427.         if (!$this->announcements->contains($announcement)) {
  428.             $this->announcements[] = $announcement;
  429.             $announcement->setCompany($this);
  430.         }
  431.         return $this;
  432.     }
  433.     public function removeAnnouncement(Announcement $announcement): self
  434.     {
  435.         if ($this->announcements->contains($announcement)) {
  436.             $this->announcements->removeElement($announcement);
  437.             // set the owning side to null (unless already changed)
  438.             if ($announcement->getCompany() === $this) {
  439.                 $announcement->setCompany(null);
  440.             }
  441.         }
  442.         return $this;
  443.     }
  444.     public function getSocialMedia(): ?SocialMedia
  445.     {
  446.         return $this->socialMedia;
  447.     }
  448.     public function setSocialMedia(?SocialMedia $socialMedia): self
  449.     {
  450.         $this->socialMedia $socialMedia;
  451.         // set (or unset) the owning side of the relation if necessary
  452.         $newCompany null === $socialMedia null $this;
  453.         if ($socialMedia->getCompany() !== $newCompany) {
  454.             $socialMedia->setCompany($newCompany);
  455.         }
  456.         return $this;
  457.     }
  458.     public function superAdmins($userException null)
  459.     {
  460.         $users = [];
  461.         foreach ($this->getOffices() as $office) {
  462.             foreach ($office->getUsers() as $user) {
  463.                 if ($user != $userException && $user->getIsActive() == true && in_array('ROLE_MANAGEMENT'$user->getRoles()))
  464.                     array_push($users$user);
  465.             }
  466.             ;
  467.         }
  468.         return $users;
  469.     }
  470.     /**
  471.      * @return Collection|Job[]
  472.      */
  473.     public function getJobs(): Collection
  474.     {
  475.         return $this->jobs;
  476.     }
  477.     public function addJob(Job $job): self
  478.     {
  479.         if (!$this->jobs->contains($job)) {
  480.             $this->jobs[] = $job;
  481.             $job->setCompany($this);
  482.         }
  483.         return $this;
  484.     }
  485.     public function removeJob(Job $job): self
  486.     {
  487.         if ($this->jobs->removeElement($job)) {
  488.             // set the owning side to null (unless already changed)
  489.             if ($job->getCompany() === $this) {
  490.                 $job->setCompany(null);
  491.             }
  492.         }
  493.         return $this;
  494.     }
  495.     public function getReminder(): ?array
  496.     {
  497.         return $this->reminder;
  498.     }
  499.     public function setReminder(?array $reminder): self
  500.     {
  501.         $this->reminder $reminder;
  502.         return $this;
  503.     }
  504.     public function getAllManager($sort true$includeSub false)
  505.     {
  506.         $managers = [];
  507.         foreach ($this->offices as $office) {
  508.             $officeManagers $office->getAllManager(false$includeSub);
  509.             array_push($managers$officeManagers);
  510.         }
  511.         $managers call_user_func_array('array_merge'$managers);
  512.         if ($sort) {
  513.             usort($managers, function ($a$b) {
  514.                 return strcmp($a->getPersonalInfo()->getFirstName(), $b->getPersonalInfo()->getFirstName());
  515.             });
  516.         }
  517.         ;
  518.         return $managers;
  519.     }
  520.     public function getAllSubManager($sort true)
  521.     {
  522.         $managers = [];
  523.         foreach ($this->offices as $office) {
  524.             $officeManagers $office->getAllSubManager(false);
  525.             array_push($managers, ...$officeManagers);
  526.         }
  527.         $managers array_filter($managers, function ($manager) {
  528.             return is_object($manager);
  529.         });
  530.         if ($sort) {
  531.             usort($managers, function ($a$b) {
  532.                 return strcmp($a->getPersonalInfo()->getFirstName(), $b->getPersonalInfo()->getFirstName());
  533.             });
  534.         }
  535.         ;
  536.         return $managers;
  537.     }
  538.     public function getAttributes(): ?array
  539.     {
  540.         return $this->attributes;
  541.     }
  542.     public function setAttributes(?array $attributes): self
  543.     {
  544.         $this->attributes $attributes;
  545.         return $this;
  546.     }
  547.     public function appraisalStatusOverview($type null$manager null)
  548.     {
  549.         if ($manager) {
  550.             $users $manager->getSubordinates();
  551.         } else {
  552.             $users $this->getAllUser();
  553.         }
  554.         $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];
  555.         foreach ($users as $user) {
  556.             if ($type) {
  557.                 if ($user->latestAppraisal() == null)
  558.                     continue;
  559.                 if ($type == 'permanent' && $user->latestAppraisal()->getProbation() == true)
  560.                     continue;
  561.                 if ($user->getPersonalInfo()->getJobStatus() != 'form.job_status.' $type)
  562.                     continue;
  563.             }
  564.             ;
  565.             $appraisalType $user->latestAppraisal()->getProbation() == true 'probation' 'yearly';
  566.             $appraisalStatus $user->getAppraisalStatus();
  567.             $objectiveStatus $user->getObjectiveStatus();
  568.             switch ($appraisalStatus['step']) {
  569.                 case 1:
  570.                     if ($appraisalStatus['missed'] == false) {
  571.                         $overview['user']++;
  572.                         $overview['total']++;
  573.                         if ($appraisalType == 'yearly')
  574.                             $overview['yearly']['user']++;
  575.                     }
  576.                     ;
  577.                     if ($appraisalStatus['draft'] == true) {
  578.                         $overview['user-draft']++;
  579.                         $overview['total']++;
  580.                         if ($appraisalType == 'yearly')
  581.                             $overview['yearly']['user-draft']++;
  582.                     }
  583.                     ;
  584.                     break;
  585.                 case 2:
  586.                     if ($appraisalStatus['missed'] == false) {
  587.                         $overview['manager']++;
  588.                         $overview['total']++;
  589.                         if ($appraisalType == 'yearly')
  590.                             $overview['yearly']['manager']++;
  591.                     }
  592.                     ;
  593.                     if ($appraisalStatus['draft'] == true) {
  594.                         $overview['manager-draft']++;
  595.                         $overview['total']++;
  596.                         if ($appraisalType == 'yearly')
  597.                             $overview['yearly']['manager-draft']++;
  598.                     }
  599.                     ;
  600.                     break;
  601.                 case 3:
  602.                     if ($appraisalStatus['missed'] == true) {
  603.                         $overview['meeting']++;
  604.                         $overview['total']++;
  605.                         if ($appraisalType == 'yearly')
  606.                             $overview['yearly']['meeting']++;
  607.                     }
  608.                     ;
  609.                     break;
  610.                 case 5:
  611.                     $overview['summary']++;
  612.                     $overview['total']++;
  613.                     if ($appraisalType == 'yearly')
  614.                         $overview['yearly']['summary']++;
  615.                     break;
  616.             }
  617.             if (isset($objectiveStatus['expired']) && $objectiveStatus['expired'] == true) {
  618.                 $overview['total']++;
  619.                 $overview['objective']++;
  620.                 if ($appraisalType == 'yearly')
  621.                     $overview['yearly']['objective']++;
  622.             }
  623.             ;
  624.         }
  625.         return $overview;
  626.     }
  627.     /**
  628.      * @return Collection<int, AppraisalCategory>
  629.      */
  630.     public function getAppraisalCategories(): Collection
  631.     {
  632.         return $this->appraisalCategories;
  633.     }
  634.     public function addAppraisalCategory(AppraisalCategory $appraisalCategory): self
  635.     {
  636.         if (!$this->appraisalCategories->contains($appraisalCategory)) {
  637.             $this->appraisalCategories->add($appraisalCategory);
  638.             $appraisalCategory->setCompany($this);
  639.         }
  640.         return $this;
  641.     }
  642.     public function removeAppraisalCategory(AppraisalCategory $appraisalCategory): self
  643.     {
  644.         if ($this->appraisalCategories->removeElement($appraisalCategory)) {
  645.             // set the owning side to null (unless already changed)
  646.             if ($appraisalCategory->getCompany() === $this) {
  647.                 $appraisalCategory->setCompany(null);
  648.             }
  649.         }
  650.         return $this;
  651.     }
  652.     /**
  653.      * @return Collection<int, ChatbotCompanyPrompt>
  654.      */
  655.     public function getChatbotCompanyPrompts(): Collection
  656.     {
  657.         return $this->chatbotCompanyPrompts;
  658.     }
  659.     public function addChatbotCompanyPrompt(ChatbotCompanyPrompt $chatbotCompanyPrompt): self
  660.     {
  661.         if (!$this->chatbotCompanyPrompts->contains($chatbotCompanyPrompt)) {
  662.             $this->chatbotCompanyPrompts->add($chatbotCompanyPrompt);
  663.             $chatbotCompanyPrompt->setCompany($this);
  664.         }
  665.         return $this;
  666.     }
  667.     public function removeChatbotCompanyPrompt(ChatbotCompanyPrompt $chatbotCompanyPrompt): self
  668.     {
  669.         if ($this->chatbotCompanyPrompts->removeElement($chatbotCompanyPrompt)) {
  670.             // set the owning side to null (unless already changed)
  671.             if ($chatbotCompanyPrompt->getCompany() === $this) {
  672.                 $chatbotCompanyPrompt->setCompany(null);
  673.             }
  674.         }
  675.         return $this;
  676.     }
  677. }