<?php
namespace App\Entity\ChannelUserData;
use App\Entity\Channel\ChannelUserRole;
use App\Entity\Channel\Company;
use App\Entity\Channel\CompanyChannelUserData;
use App\Entity\Channel\Organization;
use App\Entity\Channel\Place;
use App\Entity\Channel\Training;
use App\Entity\ChannelUserData\Activity\ActivityFeed;
use App\Entity\ChannelUserData\AdminChannelUserData\AdminChannelUserDataOrganization;
use App\Entity\ChannelUserData\AdminChannelUserData\AdminChannelUserDataPlace;
use App\Entity\ChannelUserData\AdminChannelUserData\AdminChannelUserDataPrice;
use App\Entity\ChannelUserData\AdminChannelUserData\AdminChannelUserDataSkill;
use App\Entity\ChannelUserData\AdminChannelUserData\Document\AdminChannelUserDataAgreement;
use App\Entity\ChannelUserData\AdminChannelUserData\Document\AdminChannelUserDataCertificate;
use App\Entity\ChannelUserData\AdminChannelUserData\Document\AdminChannelUserDataDocument;
use App\Entity\ChannelUserData\Cursus\Internship;
use App\Enum\ChannelUserData\Activity\AdminChannelUserDataActivityTagEnum;
use App\Enum\ChannelUserData\AdminChannelUserDataActivityStatusEnum;
use App\Enum\ChannelUserData\AdminChannelUserStatusEnum;
use App\Repository\ChannelUserData\ChannelUserDataRepository;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Drosalys\Bundle\ApiBundle\Serializer\Attributes\IdGroups;
use Nellapp\Bundle\SDKBundle\Channel\Entity\ChannelUserData\AdminChannelUserDataInterface;
use Nellapp\Bundle\SDKBundle\Channel\Entity\ChannelUserData\AdminChannelUserDataMethodTrait;
use Nellapp\Bundle\SDKBundle\Enum\ChannelUserData\AdminChannelUserTypeEnum;
use Nellapp\Bundle\SDKBundle\TrackData\Attribute\TrackEntity;
use Nellapp\Bundle\SDKBundle\TrackData\Attribute\TrackField;
use Symfony\Component\Serializer\Annotation as Serial;
use Symfony\Component\Validator\Constraints as Assert;
#[
ORM\Entity(repositoryClass: ChannelUserDataRepository::class),
ORM\Table(name: 'channel_user_data_admin'),
TrackEntity(
fieldGroups: [
'informations' => [
'tags' => [AdminChannelUserDataActivityTagEnum::INFORMATIONS],
],
'skills' => [
'tags' => [AdminChannelUserDataActivityTagEnum::SKILLS],
],
'files' => [
'tags' => [AdminChannelUserDataActivityTagEnum::FILES]
],
'prices' => [
'tags' => [AdminChannelUserDataActivityTagEnum::PRICES],
]
]
),
]
class AdminChannelUserData extends ChannelUserData implements AdminChannelUserDataInterface
{
use AdminChannelUserDataMethodTrait;
#[ORM\Column(type: 'date', nullable: true)]
#[Assert\GreaterThanOrEqual(
propertyPath: 'startAt',
groups: ['admin_channel_user_profile']
)]
#[Serial\Groups(['Sync'])]
private ?DateTimeInterface $expireAt = null;
#[ORM\Column(type: 'date', nullable: true)]
#[Assert\LessThanOrEqual(
propertyPath: 'expireAt',
groups: ['admin_channel_user_profile'])
]
#[Serial\Groups(['Sync'])]
private ?DateTimeInterface $startAt = null;
#[ORM\ManyToOne(targetEntity: ChannelUserRole::class)]
#[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
#[IdGroups(['Sync'])]
private ?ChannelUserRole $channelUserRole = null;
#[ORM\Column(type: 'string', nullable: true)]
#[Assert\Choice(
callback: [AdminChannelUserTypeEnum::class, 'getChoices'],
message: 'adminChannelUser.role.Choice.message',
)]
#[Serial\Groups(['Sync'])]
private ?string $adminChannelUserType = null;
#[ORM\Column(type: 'simple_array', nullable: true)]
#[Serial\Groups(['Sync'])]
private ?array $displayedMenu = null;
#[ORM\OneToMany(mappedBy: 'adminChannelUserData', targetEntity: CompanyChannelUserData::class, cascade: ['persist', 'remove'], fetch: 'LAZY', orphanRemoval: true)]
private Collection $companyChannelUserDatas;
#[ORM\OneToMany(mappedBy: 'tutor', targetEntity: Internship::class, fetch: 'LAZY')]
private Collection $internships;
#[ORM\OneToMany(mappedBy: 'channelUserData', targetEntity: AdminChannelUserDataOrganization::class, cascade: ['persist', 'remove'], fetch: 'LAZY', orphanRemoval: true)]
private Collection $adminChannelUserDataOrganizations;
#[ORM\OneToMany(mappedBy: 'channelUserData', targetEntity: AdminChannelUserDataPlace::class, cascade: ['persist', 'remove'], fetch: 'LAZY', orphanRemoval: true)]
private Collection $adminChannelUserDataPlaces;
#[ORM\Column(type: 'string', nullable: true)]
#[TrackFIeld(name: 'page.admin_channel_user_data.entity.status.label', fieldKey: 'informations', callable: 'getStatusKey', callableClass: AdminChannelUserStatusEnum::class)]
private ?string $status = null;
#[ORM\Column(type: 'string', nullable: true)]
#[TrackFIeld(name: 'page.admin_channel_user_data.entity.activity_status.label', fieldKey: 'informations', callable: 'getStatusKey', callableClass: AdminChannelUserDataActivityStatusEnum::class)]
private ?string $activityStatus = null;
#[ORM\OneToOne(targetEntity: ActivityFeed::class, cascade: ['remove', 'persist'], orphanRemoval: true)]
#[ORM\JoinColumn(nullable: false)]
private ?ActivityFeed $activityFeed = null;
#[ORM\OneToMany(mappedBy: 'channelUserData', targetEntity: AdminChannelUserDataPrice::class, cascade: ['persist', 'remove'], fetch: 'LAZY', orphanRemoval: true)]
#[ORM\OrderBy(['sortOrder' => 'ASC'])]
private Collection $adminChannelUserDataPrices;
#[ORM\OneToMany(mappedBy: 'channelUserData', targetEntity: AdminChannelUserDataSkill::class, cascade: ['persist', 'remove'], fetch: 'LAZY', orphanRemoval: true)]
private Collection $adminChannelUserDataSkills;
#[ORM\OneToMany(mappedBy: 'channelUserData', targetEntity: AdminChannelUserDataDocument::class, cascade: ['persist', 'remove'], fetch: 'LAZY', orphanRemoval: true)]
private Collection $documents;
public function __construct()
{
parent::__construct();
$this->companyChannelUserDatas = new ArrayCollection();
$this->internships = new ArrayCollection();
$this->adminChannelUserDataOrganizations = new ArrayCollection();
$this->adminChannelUserDataPlaces = new ArrayCollection();
}
public function getMainPrice(): ?AdminChannelUserDataPrice
{
$price = $this->getAdminChannelUserDataPrices()->first();
return $price !== false ? $price : null;
}
public function removeDisplayedMenuLinks(array $links): static
{
$this->displayedMenu = array_diff($this->displayedMenu, $links);
return $this;
}
public function addDisplayedMenuLinks(array $links): static
{
$this->displayedMenu = array_unique(array_merge($this->displayedMenu, $links));
return $this;
}
public function getCompanyChannelUserDataFor(?Company $company): ?CompanyChannelUserData
{
foreach ($this->getCompanyChannelUserDatas() as $companyChannelUserData) {
if ($companyChannelUserData->getCompany() === $company) {
return $companyChannelUserData;
}
}
return null;
}
/**
* @return Collection<int, CompanyChannelUserData>
*/
public function getCompanyChannelUserDatas(): Collection
{
return $this->companyChannelUserDatas;
}
public function addCompany(Company $company, ?string $job = null): self
{
if (!$companyChannelUserData = $this->getCompanyChannelUserDataFor($company)) {
$company->addChannelUserData($this, $job);
}
return $this;
}
public function removeCompany(Company $company): self
{
if (!$companyChannelUserData = $this->getCompanyChannelUserDataFor($company)) {
return $this;
}
$company->removeChannelUserData($this);
return $this;
}
public function getInternships(): Collection
{
return $this->internships;
}
public function getInternshipsCursuses(): Collection
{
return new ArrayCollection(array_unique($this->internships->map(function (Internship $internship) {
return $internship->getCursus();
})->toArray()));
}
public function getActiveInternships(Company $company): Collection
{
return $this->getInternships()->filter(function (Internship $internship) use ($company) {
return $internship->isActive() && (!$company || $internship->getCompany() === $company);
});
}
public function addInternship(Internship $internship): self
{
if (!$this->internships->contains($internship)) {
$internship->setTutor($this);
$this->internships->add($internship);
}
return $this;
}
public function removeInternship(Internship $internship): self
{
if ($this->internships->contains($internship)) {
$internship->setTutor(null);
$this->internships->removeElement($internship);
}
return $this;
}
public function getAdminChannelUserDataOrganizations(): Collection
{
return $this->adminChannelUserDataOrganizations;
}
public function addAdminChannelUserDataOrganization(AdminChannelUserDataOrganization $link): static
{
if (!$this->adminChannelUserDataOrganizations->contains($link)) {
$this->adminChannelUserDataOrganizations->add($link);
$link->setChannelUserData($this);
}
return $this;
}
public function removeAdminChannelUserDataOrganization(AdminChannelUserDataOrganization $link): static
{
$this->adminChannelUserDataOrganizations->removeElement($link);
return $this;
}
public function setAdminChannelUserDataOrganizations(Collection $links): static
{
foreach ($this->adminChannelUserDataOrganizations as $link) {
if (!$links->contains($link) && $link->getChannelUserData() === $this) {
$link->setChannelUserData(null);
}
}
$this->adminChannelUserDataOrganizations = $links;
foreach ($this->adminChannelUserDataOrganizations as $link) {
if ($link->getChannelUserData() !== $this) {
$link->setChannelUserData($this);
}
}
return $this;
}
public function getOrganizations(): array
{
return $this->adminChannelUserDataOrganizations
->map(fn(AdminChannelUserDataOrganization $link) => $link->getOrganization())
->filter(fn(?Organization $organization) => null !== $organization)
->toArray();
}
public function addOrganization(Organization $organization): static
{
foreach ($this->adminChannelUserDataOrganizations as $link) {
if ($link->getOrganization() === $organization) {
return $this;
}
}
$link = new AdminChannelUserDataOrganization();
$link->setChannelUserData($this);
$link->setOrganization($organization);
$this->adminChannelUserDataOrganizations->add($link);
return $this;
}
public function removeOrganization(Organization $organization): static
{
foreach ($this->adminChannelUserDataOrganizations as $link) {
if ($link->getOrganization() === $organization) {
$this->removeAdminChannelUserDataOrganization($link);
break;
}
}
return $this;
}
public function setOrganizations(Collection $organizations): static
{
foreach ($this->adminChannelUserDataOrganizations as $link) {
if (null !== $link->getOrganization() && !$organizations->contains($link->getOrganization())) {
$this->removeAdminChannelUserDataOrganization($link);
}
}
foreach ($organizations as $organization) {
$this->addOrganization($organization);
}
return $this;
}
public function getAdminChannelUserDataPlaces(): Collection
{
return $this->adminChannelUserDataPlaces;
}
public function addAdminChannelUserDataPlace(AdminChannelUserDataPlace $link): static
{
if (!$this->adminChannelUserDataPlaces->contains($link)) {
$this->adminChannelUserDataPlaces->add($link);
$link->setChannelUserData($this);
}
return $this;
}
public function removeAdminChannelUserDataPlace(AdminChannelUserDataPlace $link): static
{
$this->adminChannelUserDataPlaces->removeElement($link);
return $this;
}
public function setAdminChannelUserDataPlaces(Collection $links): static
{
foreach ($this->adminChannelUserDataPlaces as $link) {
if (!$links->contains($link) && $link->getChannelUserData() === $this) {
$link->setChannelUserData(null);
}
}
$this->adminChannelUserDataPlaces = $links;
foreach ($this->adminChannelUserDataPlaces as $link) {
if ($link->getChannelUserData() !== $this) {
$link->setChannelUserData($this);
}
}
return $this;
}
public function getPlaces(): array
{
return $this->adminChannelUserDataPlaces
->map(fn(AdminChannelUserDataPlace $link) => $link->getPlace())
->filter(fn(?Place $place) => null !== $place)
->toArray();
}
public function addPlace(Place $place): static
{
foreach ($this->adminChannelUserDataPlaces as $link) {
if ($link->getPlace() === $place) {
return $this;
}
}
$link = new AdminChannelUserDataPlace();
$link->setChannelUserData($this);
$link->setPlace($place);
$this->adminChannelUserDataPlaces->add($link);
return $this;
}
public function removePlace(Place $place): static
{
foreach ($this->adminChannelUserDataPlaces as $link) {
if ($link->getPlace() === $place) {
$this->removeAdminChannelUserDataPlace($link);
break;
}
}
return $this;
}
public function setPlaces(Collection $places): static
{
foreach ($this->adminChannelUserDataPlaces as $link) {
if (null !== $link->getPlace() && !$places->contains($link->getPlace())) {
$this->removeAdminChannelUserDataPlace($link);
}
}
foreach ($places as $place) {
$this->addPlace($place);
}
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(?string $status): AdminChannelUserData
{
$this->status = $status;
return $this;
}
public function getActivityFeed(): ?ActivityFeed
{
return $this->activityFeed;
}
public function setActivityFeed(?ActivityFeed $activityFeed): static
{
$this->activityFeed = $activityFeed;
return $this;
}
public function getAdminChannelUserDataPrices(): Collection
{
return $this->adminChannelUserDataPrices;
}
public function addAdminChannelUserDataPrice(AdminChannelUserDataPrice $price): static
{
if (!$this->adminChannelUserDataPrices->contains($price)) {
$this->adminChannelUserDataPrices->add($price);
}
return $this;
}
public function removeAdminChannelUserDataPrice(AdminChannelUserDataPrice $price): static
{
if ($this->adminChannelUserDataPrices->contains($price)) {
$this->adminChannelUserDataPrices->removeElement($price);
}
return $this;
}
public function setAdminChannelUserDataPrices(Collection $adminChannelUserDataPrices): AdminChannelUserData
{
$this->adminChannelUserDataPrices = $adminChannelUserDataPrices;
return $this;
}
public function getAdminChannelUserDataSkills(): Collection
{
return $this->adminChannelUserDataSkills;
}
public function addAdminChannelUserDataSkill(AdminChannelUserDataSkill $skill): static
{
if (!$this->adminChannelUserDataSkills->contains($skill)) {
$this->adminChannelUserDataSkills->add($skill);
}
return $this;
}
public function removeAdminChannelUserDataSkill(AdminChannelUserDataSkill $skill): static
{
if ($this->adminChannelUserDataSkills->contains($skill)) {
$this->adminChannelUserDataSkills->removeElement($skill);
}
return $this;
}
public function setAdminChannelUserDataSkills(Collection $adminChannelUserDataSkills): AdminChannelUserData
{
$this->adminChannelUserDataSkills = $adminChannelUserDataSkills;
return $this;
}
public function getTrainings(): array
{
return $this->adminChannelUserDataSkills
->map(fn(AdminChannelUserDataSkill $skill) => $skill->getTraining())
->toArray();
}
public function addTraining(Training $training): static
{
foreach ($this->adminChannelUserDataSkills as $skill) {
if ($skill->getTraining() === $training) {
return $this;
}
}
$link = (new AdminChannelUserDataSkill())
->setTraining($training)
->setChannelUserData($this);
$this->adminChannelUserDataSkills->add($link);
return $this;
}
public function removeTraining(Training $training): static
{
foreach ($this->adminChannelUserDataSkills as $skill) {
if ($skill->getTraining() === $training) {
$this->removeAdminChannelUserDataSkill($skill);
break;
}
}
return $this;
}
public function setTrainings(Collection $trainings): static
{
foreach ($this->adminChannelUserDataSkills as $skill) {
$this->removeAdminChannelUserDataSkill($skill);
}
foreach ($trainings as $training) {
$this->addTraining($training);
}
return $this;
}
public function getDocuments(): Collection
{
return $this->documents;
}
public function setDocuments(Collection $documents): AdminChannelUserData
{
$this->documents = $documents;
return $this;
}
public function getActivityStatus(): ?string
{
return $this->activityStatus;
}
public function setActivityStatus(?string $activityStatus): AdminChannelUserData
{
$this->activityStatus = $activityStatus;
return $this;
}
public function getCertificates(): Collection
{
return $this->documents->filter(
fn(AdminChannelUserDataDocument $document) => $document instanceof AdminChannelUserDataCertificate
);
}
public function getAgreement(): ?AdminChannelUserDataAgreement
{
foreach ($this->documents as $document) {
if ($document instanceof AdminChannelUserDataAgreement) {
return $document;
}
}
return null;
}
}