src/Entity/Activity.php line 30

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiProperty;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use App\Controller\Api\Activity\GetActivitiesController;
  6. use App\Repository\ActivityRepository;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\DBAL\Types\Types;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. #[ORM\Entity(repositoryClassActivityRepository::class)]
  13. #[ApiResource(
  14.     collectionOperations: [
  15.         "get_activities" => [
  16.             'controller' => GetActivitiesController::class,
  17.             'method' => 'POST',
  18.             'path' => '/activities-list'
  19.         ],
  20.     ],
  21.     normalizationContext: [
  22.     'groups' => 'read:activity:collection'
  23.     ]
  24. )]
  25. class Activity
  26. {
  27.     #[ORM\Id]
  28.     #[ORM\GeneratedValue]
  29.     #[ORM\Column]
  30.     #[Groups([
  31.         'read:activity:collection',
  32.         'read:club:collection:getCompanies',
  33.         'read:company:collection:get',
  34.         'read:user:item:me',
  35.     ])]
  36.     private ?int $id null;
  37.     #[ORM\Column(length255)]
  38.     #[Groups([
  39.         'read:activity:collection',
  40.         'read:club:collection:getCompanies',
  41.         'read:company:collection:get',
  42.         'read:user:item:me',
  43.         'read:user:item:user:companies:management'
  44.     ])]
  45.     private ?string $name null;
  46.     #[ORM\Column(length255nullabletrue)]
  47.     private ?string $ape null;
  48.     #[ORM\OneToMany(mappedBy'activity'targetEntityCompany::class)]
  49.     private Collection $companies;
  50.     #[ORM\Column(length255nullabletrue)]
  51.     private ?string $slug null;
  52.     #[ORM\Column(typeTypes::ARRAY, nullabletrue)]
  53.     private array $apes = [];
  54.     public function __toString(): string
  55.     {
  56.         return $this->name;
  57.     }
  58.     public function __construct()
  59.     {
  60.         $this->companies = new ArrayCollection();
  61.     }
  62.     public function getFullName(): string
  63.     {
  64.         $name $this->name;
  65.         if (sizeof($this->apes) > 0) {
  66.             $name .= '(';
  67.         }
  68.         foreach($this->apes as $i => $ape) {
  69.             $name .= $ape;
  70.             if ($i sizeof($this->apes)-1) {
  71.                 $name .= ',';
  72.             }
  73.         }
  74.         if (sizeof($this->apes) > 0) {
  75.             $name .= ')';
  76.         }
  77.         return $name;
  78.     }
  79.     public function getId(): ?int
  80.     {
  81.         return $this->id;
  82.     }
  83.     public function getName(): ?string
  84.     {
  85.         return $this->name;
  86.     }
  87.     public function setName(string $name): self
  88.     {
  89.         $this->name $name;
  90.         return $this;
  91.     }
  92.     public function getApe(): ?string
  93.     {
  94.         return $this->ape;
  95.     }
  96.     public function setApe(?string $ape): self
  97.     {
  98.         $this->ape $ape;
  99.         return $this;
  100.     }
  101.     /**
  102.      * @return Collection<int, Company>
  103.      */
  104.     public function getCompanies(): Collection
  105.     {
  106.         return $this->companies;
  107.     }
  108.     public function addCompany(Company $company): self
  109.     {
  110.         if (!$this->companies->contains($company)) {
  111.             $this->companies->add($company);
  112.             $company->setActivity($this);
  113.         }
  114.         return $this;
  115.     }
  116.     public function removeCompany(Company $company): self
  117.     {
  118.         if ($this->companies->removeElement($company)) {
  119.             // set the owning side to null (unless already changed)
  120.             if ($company->getActivity() === $this) {
  121.                 $company->setActivity(null);
  122.             }
  123.         }
  124.         return $this;
  125.     }
  126.     public function getSlug(): ?string
  127.     {
  128.         return $this->slug;
  129.     }
  130.     public function setSlug(?string $slug): self
  131.     {
  132.         $this->slug $slug;
  133.         return $this;
  134.     }
  135.     public function getApes(): array
  136.     {
  137.         return $this->apes;
  138.     }
  139.     public function setApes(?array $apes): self
  140.     {
  141.         $this->apes $apes;
  142.         return $this;
  143.     }
  144. }