<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Controller\Api\Activity\GetActivitiesController;
use App\Repository\ActivityRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\Entity(repositoryClass: ActivityRepository::class)]
#[ApiResource(
collectionOperations: [
"get_activities" => [
'controller' => GetActivitiesController::class,
'method' => 'POST',
'path' => '/activities-list'
],
],
normalizationContext: [
'groups' => 'read:activity:collection'
]
)]
class Activity
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups([
'read:activity:collection',
'read:club:collection:getCompanies',
'read:company:collection:get',
'read:user:item:me',
])]
private ?int $id = null;
#[ORM\Column(length: 255)]
#[Groups([
'read:activity:collection',
'read:club:collection:getCompanies',
'read:company:collection:get',
'read:user:item:me',
'read:user:item:user:companies:management'
])]
private ?string $name = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $ape = null;
#[ORM\OneToMany(mappedBy: 'activity', targetEntity: Company::class)]
private Collection $companies;
#[ORM\Column(length: 255, nullable: true)]
private ?string $slug = null;
#[ORM\Column(type: Types::ARRAY, nullable: true)]
private array $apes = [];
public function __toString(): string
{
return $this->name;
}
public function __construct()
{
$this->companies = new ArrayCollection();
}
public function getFullName(): string
{
$name = $this->name;
if (sizeof($this->apes) > 0) {
$name .= '(';
}
foreach($this->apes as $i => $ape) {
$name .= $ape;
if ($i < sizeof($this->apes)-1) {
$name .= ',';
}
}
if (sizeof($this->apes) > 0) {
$name .= ')';
}
return $name;
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getApe(): ?string
{
return $this->ape;
}
public function setApe(?string $ape): self
{
$this->ape = $ape;
return $this;
}
/**
* @return Collection<int, Company>
*/
public function getCompanies(): Collection
{
return $this->companies;
}
public function addCompany(Company $company): self
{
if (!$this->companies->contains($company)) {
$this->companies->add($company);
$company->setActivity($this);
}
return $this;
}
public function removeCompany(Company $company): self
{
if ($this->companies->removeElement($company)) {
// set the owning side to null (unless already changed)
if ($company->getActivity() === $this) {
$company->setActivity(null);
}
}
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(?string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getApes(): array
{
return $this->apes;
}
public function setApes(?array $apes): self
{
$this->apes = $apes;
return $this;
}
}