src/Entity/Label.php line 78

  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Annotation\ApiSubresource;
  6. use App\Controller\Api\Action\Label\LabelDeleteAction;
  7. use App\Controller\Api\Action\Label\LabelDuplicateAction;
  8. use App\Controller\Api\Action\Label\LabelToChildAction;
  9. use App\Controller\Api\Action\Label\LabelCollectionGetAction;
  10. use App\Controller\Api\Action\Label\LabelOnProjectAction;
  11. use App\Controller\Api\Action\Label\LabelOnItemAction;
  12. use App\Controller\Api\Action\Label\LabelToParentAction;
  13. use App\Repository\LabelRepository;
  14. use DateTime;
  15. use Doctrine\Common\Collections\ArrayCollection;
  16. use Doctrine\ORM\Mapping as ORM;
  17. use Symfony\Component\Validator\Constraints as Assert;
  18. #[ORM\Entity(
  19.     repositoryClassLabelRepository::class
  20. )]
  21. #[ORM\Table(
  22.     name'label'
  23. )]
  24. #[ApiResource(
  25.     collectionOperations: [
  26.         'post' => [
  27.             'validation_groups' => [
  28.                 'create'
  29.             ]
  30.         ],
  31.         'get' => [
  32.             'controller' => LabelCollectionGetAction::class
  33.         ]
  34.     ],
  35.     itemOperations: [
  36.         'get',
  37.         'put',
  38.         'delete' => [
  39.             'access_control' => 'is_granted("ROLE_USER")',
  40.             'controller' => LabelDeleteAction::class
  41.         ],
  42.         'duplicate' => [
  43.             'access_control' => 'is_granted("ROLE_USER")',
  44.             'controller' => LabelDuplicateAction::class,
  45.             'method' => 'POST',
  46.             'path' => '/labels/duplicate/{id}'
  47.         ],
  48.         'to_child' => [
  49.             'access_control' => 'is_granted("ROLE_USER")',
  50.             'controller' => LabelToChildAction::class,
  51.             'method' => 'POST',
  52.             'path' => '/labels/to-child/{id}'
  53.         ],
  54.         'on_projects' => [
  55.             'access_control' => 'is_granted("ROLE_USER")',
  56.             'controller' => LabelOnProjectAction::class,
  57.             'method' => 'GET',
  58.             'path' => '/labels/{id}/on-projects'
  59.         ],
  60.         'on_items' => [
  61.             'access_control' => 'is_granted("ROLE_USER")',
  62.             'controller' => LabelOnItemAction::class,
  63.             'method' => 'GET',
  64.             'path' => '/labels/{id}/on-project/{project}'
  65.         ],
  66.         'to_parent' => [
  67.             'access_control' => 'is_granted("ROLE_USER")',
  68.             'controller' => LabelToParentAction::class,
  69.             'method' => 'PUT',
  70.             'path' => '/labels/to-parent/{id}'
  71.         ]
  72.     ]
  73. )]
  74. class Label implements CollectionItemInterface
  75. {
  76.     #[ORM\Id]
  77.     #[ORM\GeneratedValue]
  78.     #[ORM\Column(
  79.         type'integer'
  80.     )]
  81.     private ?int $id null;
  82.     #[ORM\Column(
  83.         name'date_created',
  84.         type'datetime',
  85.         nullabletrue
  86.     )]
  87.     private ?DateTime $dateCreated null;
  88.     #[ORM\Column(
  89.         name'date_changed',
  90.         type'datetime',
  91.         nullabletrue
  92.     )]
  93.     private ?DateTime $dateChanged null;
  94.     #[ORM\Column(
  95.         name'color',
  96.         type'string',
  97.         length191,
  98.         nullabletrue
  99.     )]
  100.     #[Assert\NotBlank(
  101.         groups: ['action']
  102.     )]
  103.     #[Assert\Length(
  104.         max100,
  105.         groups: ['action']
  106.     )]
  107.     private ?string $color null;
  108.     #[ORM\ManyToOne(
  109.         targetEntityUser::class,
  110.         cascade: ['persist']
  111.     )]
  112.     #[ORM\JoinColumn(
  113.         name'user_created'
  114.     )]
  115.     private ?User $userCreated null;
  116.     #[ORM\ManyToOne(
  117.         targetEntityUser::class,
  118.         cascade: ['persist']
  119.     )]
  120.     #[ORM\JoinColumn(
  121.         name'user_changed'
  122.     )]
  123.     private ?User $userChanged null;
  124.     #[ORM\Column(
  125.         name'active',
  126.         type'boolean',
  127.         options: ['default' => true]
  128.     )]
  129.     private bool $active true;
  130.     #[ORM\Column(
  131.         name'name',
  132.         type'string',
  133.         length181,
  134.         nullabletrue
  135.     )]
  136.     #[Assert\NotBlank(
  137.         groups: ['create']
  138.     )]
  139.     private ?string $name null;
  140.     #[ORM\Column(
  141.         name'sequence',
  142.         type'integer',
  143.         nullabletrue
  144.     )]
  145.     private ?int $sequence null;
  146.     #[ORM\Column(
  147.         name'description',
  148.         type'text',
  149.         nullabletrue
  150.     )]
  151.     private ?string $description null;
  152.     #[ORM\ManyToOne(
  153.         targetEntityInstitution::class,
  154.         cascade: ['persist']
  155.     )]
  156.     #[ORM\JoinColumn(
  157.         name'institution'
  158.     )]
  159.     #[ApiSubresource]
  160.     private ?Institution $institution null;
  161.     #[ORM\ManyToOne(
  162.         targetEntityLabel::class,
  163.         cascade: ['persist'],
  164.         inversedBy'children'
  165.     )]
  166.     #[ORM\JoinColumn(
  167.         name'parent',
  168.         nullabletrue,
  169.         onDelete'CASCADE'
  170.     )]
  171.     #[ApiSubresource]
  172.     private ?Label $parent null;
  173.     #[ORM\OneToMany(
  174.         mappedBy'label',
  175.         targetEntityItemLabel::class,
  176.         cascade: ['persist'],
  177.         fetch'EXTRA_LAZY',
  178.         orphanRemovaltrue
  179.     )]
  180.     private iterable $itemLabel;
  181.     #[ORM\OneToMany(
  182.         mappedBy'parent',
  183.         targetEntityLabel::class,
  184.         cascade: ['persist''remove'],
  185.         fetch'EXTRA_LAZY',
  186.         orphanRemovaltrue
  187.     )]
  188.     private ?iterable $children;
  189.     public function __construct()
  190.     {
  191.         $this->itemLabel = new ArrayCollection();
  192.         $this->children = new ArrayCollection();
  193.     }
  194.     public function getId(): ?int
  195.     {
  196.         return $this->id;
  197.     }
  198.     public function setId(?int $id): self
  199.     {
  200.         $this->id $id;
  201.         return $this;
  202.     }
  203.     public function getDateCreated(): ?DateTime
  204.     {
  205.         return $this->dateCreated;
  206.     }
  207.     public function setDateCreated(?DateTime $dateCreated): self
  208.     {
  209.         $this->dateCreated $dateCreated;
  210.         return $this;
  211.     }
  212.     public function getDateChanged(): ?DateTime
  213.     {
  214.         return $this->dateChanged;
  215.     }
  216.     public function setDateChanged(?DateTime $dateChanged): self
  217.     {
  218.         $this->dateChanged $dateChanged;
  219.         return $this;
  220.     }
  221.     public function getUserCreated(): ?User
  222.     {
  223.         return $this->userCreated;
  224.     }
  225.     public function setUserCreated(?User $userCreated): self
  226.     {
  227.         $this->userCreated $userCreated;
  228.         return $this;
  229.     }
  230.     public function getUserChanged(): ?User
  231.     {
  232.         return $this->userChanged;
  233.     }
  234.     public function setUserChanged(?User $userChanged): self
  235.     {
  236.         $this->userChanged $userChanged;
  237.         return $this;
  238.     }
  239.     public function isActive(): bool
  240.     {
  241.         return $this->active;
  242.     }
  243.     public function setActive(bool $active): self
  244.     {
  245.         $this->active $active;
  246.         return $this;
  247.     }
  248.     public function getName(): ?string
  249.     {
  250.         return $this->name;
  251.     }
  252.     public function setName(?string $name): self
  253.     {
  254.         $this->name $name;
  255.         return $this;
  256.     }
  257.     public function getSequence(): ?int
  258.     {
  259.         return $this->sequence;
  260.     }
  261.     public function setSequence(?int $sequence): self
  262.     {
  263.         $this->sequence $sequence;
  264.         return $this;
  265.     }
  266.     public function getDescription(): ?string
  267.     {
  268.         return $this->description;
  269.     }
  270.     public function setDescription(?string $description): self
  271.     {
  272.         $this->description $description;
  273.         return $this;
  274.     }
  275.     public function getColor(): ?string
  276.     {
  277.         return $this->color;
  278.     }
  279.     public function setColor(?string $color): self
  280.     {
  281.         $this->color $color;
  282.         return $this;
  283.     }
  284.     public function getInstitution(): ?Institution
  285.     {
  286.         return $this->institution;
  287.     }
  288.     public function setInstitution(?Institution $institution): self
  289.     {
  290.         $this->institution $institution;
  291.         return $this;
  292.     }
  293.     public function getItemLabel(): iterable
  294.     {
  295.         return $this->itemLabel;
  296.     }
  297.     public function setItemLabel($itemLabel): self
  298.     {
  299.         $this->itemLabel $itemLabel;
  300.         return $this;
  301.     }
  302.     public function getParent(): ?Label
  303.     {
  304.         return $this->parent;
  305.     }
  306.     public function setParent(?Label $parent): self
  307.     {
  308.         $this->parent $parent;
  309.         return $this;
  310.     }
  311.     public function getChildren(): ?iterable
  312.     {
  313.         return $this->children;
  314.     }
  315. }