src/Entity/Item.php line 92

  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\Item\ItemDeleteAction;
  7. use App\Controller\Api\Action\Item\ItemDuplicateAction;
  8. use App\Controller\Api\Action\Item\ItemToChildAction;
  9. use App\Controller\Api\Action\Item\ItemToParentAction;
  10. use App\Controller\Api\Action\Item\ItemChildrenBudgetAction;
  11. use App\Repository\ItemRepository;
  12. use App\Validator\Constraint as CustomValidator;
  13. use DateTime;
  14. use Doctrine\Common\Collections\ArrayCollection;
  15. use Doctrine\ORM\Mapping as ORM;
  16. use Symfony\Component\Validator\Constraints as Assert;
  17. #[ORM\Entity(
  18.     repositoryClassItemRepository::class
  19. )]
  20. #[ORM\Table(
  21.     name'item'
  22. )]
  23. #[ApiResource(
  24.     collectionOperations: [
  25.         'post' => [
  26.             'validation_groups' => [
  27.                 'create'
  28.             ]
  29.         ]
  30.     ],
  31.     itemOperations: [
  32.         'get',
  33.         'put' => [
  34.             'validation_groups' => [
  35.                 'create'
  36.             ]
  37.         ],
  38.         'delete' => [
  39.             'access_control' => 'is_granted("ROLE_USER")',
  40.             'controller' => ItemDeleteAction::class
  41.         ],
  42.         'duplicate' => [
  43.             'access_control' => 'is_granted("ROLE_USER")',
  44.             'controller' => ItemDuplicateAction::class,
  45.             'method' => 'POST',
  46.             'path' => '/items/duplicate/{id}'
  47.         ],
  48.         'to_child' => [
  49.             'access_control' => 'is_granted("ROLE_USER")',
  50.             'controller' => ItemToChildAction::class,
  51.             'method' => 'POST',
  52.             'path' => '/items/to-child/{id}'
  53.         ],
  54.         'to_parent' => [
  55.             'access_control' => 'is_granted("ROLE_USER")',
  56.             'controller' => ItemToParentAction::class,
  57.             'method' => 'PUT',
  58.             'path' => '/items/to-parent/{id}'
  59.         ],
  60.         'children_budget' => [
  61.             'access_control' => 'is_granted("ROLE_USER")',
  62.             'controller' => ItemChildrenBudgetAction::class,
  63.             'method' => 'GET',
  64.             'path' => '/items/budget/{id}'
  65.         ]
  66.     ]
  67. )]
  68. #[CustomValidator\ItemPlannedStartDate(
  69.     message'item.plannedStartDate',
  70.     fields: ['plannedStartDate'],
  71.     groups: ['create']
  72. )]
  73. #[CustomValidator\ItemPlannedEndDate(
  74.     message'item.plannedEndDate',
  75.     fields: ['plannedEndDate'],
  76.     groups: ['create']
  77. )]
  78. #[CustomValidator\ItemRealizedStartDate(
  79.     message'item.realizedStartDate',
  80.     fields: ['realizedStartDate'],
  81.     groups: ['create']
  82. )]
  83. #[CustomValidator\ItemRealizedEndDate(
  84.     message'item.realizedEndDate',
  85.     fields: ['realizedEndDate'],
  86.     groups: ['create']
  87. )]
  88. class Item implements CollectionItemInterface
  89. {
  90.     #[ORM\Id]
  91.     #[ORM\GeneratedValue]
  92.     #[ORM\Column(
  93.         type'integer'
  94.     )]
  95.     private ?int $id null;
  96.     #[ORM\Column(
  97.         name'date_created',
  98.         type'datetime',
  99.         nullabletrue
  100.     )]
  101.     private ?DateTime $dateCreated null;
  102.     #[ORM\Column(
  103.         name'date_changed',
  104.         type'datetime',
  105.         nullabletrue
  106.     )]
  107.     private ?DateTime $dateChanged 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'visible_in_the_calendar',
  132.         type'boolean',
  133.         options: ['default' => true]
  134.     )]
  135.     private bool $visibleInTheCalendar true;
  136.     #[ORM\Column(
  137.         name'name',
  138.         type'string',
  139.         length181,
  140.         nullabletrue
  141.     )]
  142.     #[Assert\NotBlank(
  143.         groups: ['create']
  144.     )]
  145.     private ?string $name null;
  146.     #[ORM\Column(
  147.         name'sequence',
  148.         type'integer',
  149.         nullabletrue
  150.     )]
  151.     private ?int $sequence null;
  152.     #[ORM\Column(
  153.         name'description',
  154.         type'text',
  155.         nullabletrue
  156.     )]
  157.     private ?string $description null;
  158.     #[ORM\Column(
  159.         name'planned_start_date',
  160.         type'datetime',
  161.         nullabletrue
  162.     )]
  163.     #[Assert\NotBlank(
  164.         groups: ['create']
  165.     )]
  166.     private ?DateTime $plannedStartDate null;
  167.     #[ORM\Column(
  168.         name'planned_end_date',
  169.         type'datetime',
  170.         nullabletrue
  171.     )]
  172.     #[Assert\NotBlank(
  173.         groups: ['create']
  174.     )]
  175.     #[Assert\GreaterThanOrEqual(
  176.         propertyPath'plannedStartDate',
  177.         message'item.plannedEndDateLessThanStartDate',
  178.         groups: ['create']
  179.     )]
  180.     private ?DateTime $plannedEndDate null;
  181.     #[ORM\Column(
  182.         name'realized_start_date',
  183.         type'datetime',
  184.         nullabletrue
  185.     )]
  186.     private ?DateTime $realizedStartDate null;
  187.     #[ORM\Column(
  188.         name'realized_end_date',
  189.         type'datetime',
  190.         nullabletrue
  191.     )]
  192.     #[Assert\GreaterThanOrEqual(
  193.         propertyPath'realizedStartDate',
  194.         message'item.realizedEndDateLessThanStartDate',
  195.         groups: ['create']
  196.     )]
  197.     private ?DateTime $realizedEndDate null;
  198.     #[ORM\Column(
  199.         name'budget',
  200.         type'decimal',
  201.         precision20,
  202.         scale2,
  203.         nullabletrue
  204.     )]
  205.     #[Assert\NotBlank(
  206.         groups: ['create']
  207.     )]
  208.     #[CustomValidator\PriceFormat(
  209.         groups: ['create'],
  210.         message'item.invalidFormat'
  211.     )]
  212.     private ?string $budget null;
  213.     #[ORM\Column(
  214.         name'external_budget',
  215.         type'decimal',
  216.         precision20,
  217.         scale2,
  218.         nullabletrue
  219.     )]
  220.     #[Assert\NotBlank(
  221.         groups: ['create']
  222.     )]
  223.     #[CustomValidator\PriceFormat(
  224.         groups: ['create'],
  225.         message'item.invalidFormat'
  226.     )]
  227.     private ?string $externalBudget null;
  228.     #[ORM\ManyToOne(
  229.         targetEntityProject::class,
  230.         cascade: ['persist'],
  231.         inversedBy'items'
  232.     )]
  233.     #[ORM\JoinColumn(
  234.         name'project',
  235.         nullabletrue,
  236.         onDelete'CASCADE'
  237.     )]
  238.     #[ApiSubresource]
  239.     private ?Project $project null;
  240.     #[ORM\ManyToOne(
  241.         targetEntityItem::class,
  242.         cascade: ['persist'],
  243.         inversedBy'children'
  244.     )]
  245.     #[ORM\JoinColumn(
  246.         name'parent',
  247.         nullabletrue,
  248.         onDelete'CASCADE'
  249.     )]
  250.     #[ApiSubresource]
  251.     private ?Item $parent null;
  252.     #[ORM\OneToMany(
  253.         mappedBy'item',
  254.         targetEntityItemUser::class,
  255.         cascade: ['persist''remove'],
  256.         fetch'EXTRA_LAZY',
  257.         orphanRemovaltrue
  258.     )]
  259.     private ?iterable $users;
  260.     #[ORM\OneToMany(
  261.         mappedBy'item',
  262.         targetEntityItemDocument::class,
  263.         cascade: ['persist''remove'],
  264.         fetch'EXTRA_LAZY',
  265.         orphanRemovaltrue
  266.     )]
  267.     private ?iterable $document;
  268.     #[ORM\OneToMany(
  269.         mappedBy'item',
  270.         targetEntityItemLabel::class,
  271.         cascade: ['persist''remove'],
  272.         fetch'EXTRA_LAZY',
  273.         orphanRemovaltrue
  274.     )]
  275.     private ?iterable $label;
  276.     #[ORM\OneToMany(
  277.         mappedBy'item',
  278.         targetEntityItemIndicator::class,
  279.         cascade: ['persist'],
  280.         fetch'EXTRA_LAZY',
  281.         orphanRemovaltrue
  282.     )]
  283.     private ?iterable $indicators;
  284.     #[ORM\OneToMany(
  285.         mappedBy'parent',
  286.         targetEntityItem::class,
  287.         cascade: ['persist''remove'],
  288.         fetch'EXTRA_LAZY',
  289.         orphanRemovaltrue
  290.     )]
  291.     private ?iterable $children;
  292.     public function __construct()
  293.     {
  294.         $this->users = new ArrayCollection();
  295.         $this->document = new ArrayCollection();
  296.         $this->label = new ArrayCollection();
  297.         $this->indicators = new ArrayCollection();
  298.         $this->children = new ArrayCollection();
  299.     }
  300.     public function getId(): ?int
  301.     {
  302.         return $this->id;
  303.     }
  304.     public function setId($id): self
  305.     {
  306.         $this->id $id;
  307.         return $this;
  308.     }
  309.     public function getDateCreated(): ?DateTime
  310.     {
  311.         return $this->dateCreated;
  312.     }
  313.     public function setDateCreated(?DateTime $dateCreated): self
  314.     {
  315.         $this->dateCreated $dateCreated;
  316.         return $this;
  317.     }
  318.     public function getDateChanged(): ?DateTime
  319.     {
  320.         return $this->dateChanged;
  321.     }
  322.     public function setDateChanged(?DateTime $dateChanged): self
  323.     {
  324.         $this->dateChanged $dateChanged;
  325.         return $this;
  326.     }
  327.     public function getUserCreated(): ?User
  328.     {
  329.         return $this->userCreated;
  330.     }
  331.     public function setUserCreated(?User $userCreated): self
  332.     {
  333.         $this->userCreated $userCreated;
  334.         return $this;
  335.     }
  336.     public function getUserChanged(): ?User
  337.     {
  338.         return $this->userChanged;
  339.     }
  340.     public function setUserChanged(?User $userChanged): self
  341.     {
  342.         $this->userChanged $userChanged;
  343.         return $this;
  344.     }
  345.     public function isActive(): bool
  346.     {
  347.         return $this->active;
  348.     }
  349.     public function setActive(bool $active): void
  350.     {
  351.         $this->active $active;
  352.     }
  353.     public function isVisibleInTheCalendar(): bool
  354.     {
  355.         return $this->visibleInTheCalendar;
  356.     }
  357.     public function setVisibleInTheCalendar(bool $visibleInTheCalendar): void
  358.     {
  359.         $this->visibleInTheCalendar $visibleInTheCalendar;
  360.     }
  361.     public function getName(): ?string
  362.     {
  363.         return $this->name;
  364.     }
  365.     public function setName(?string $name): self
  366.     {
  367.         $this->name $name;
  368.         return $this;
  369.     }
  370.     public function getSequence(): ?int
  371.     {
  372.         return $this->sequence;
  373.     }
  374.     public function setSequence(?int $sequence): self
  375.     {
  376.         $this->sequence $sequence;
  377.         return $this;
  378.     }
  379.     public function getDescription(): ?string
  380.     {
  381.         return $this->description;
  382.     }
  383.     public function setDescription(?string $description): self
  384.     {
  385.         $this->description $description;
  386.         return $this;
  387.     }
  388.     public function getPlannedStartDate(): ?DateTime
  389.     {
  390.         return $this->plannedStartDate;
  391.     }
  392.     public function setPlannedStartDate(?DateTime $plannedStartDate): self
  393.     {
  394.         $this->plannedStartDate $plannedStartDate;
  395.         return $this;
  396.     }
  397.     public function getPlannedEndDate(): ?DateTime
  398.     {
  399.         return $this->plannedEndDate;
  400.     }
  401.     public function setPlannedEndDate(?DateTime $plannedEndDate): self
  402.     {
  403.         $this->plannedEndDate $plannedEndDate;
  404.         return $this;
  405.     }
  406.     public function getRealizedStartDate(): ?DateTime
  407.     {
  408.         return $this->realizedStartDate;
  409.     }
  410.     public function setRealizedStartDate(?DateTime $realizedStartDate): self
  411.     {
  412.         $this->realizedStartDate $realizedStartDate;
  413.         return $this;
  414.     }
  415.     public function getRealizedEndDate(): ?DateTime
  416.     {
  417.         return $this->realizedEndDate;
  418.     }
  419.     public function setRealizedEndDate(?DateTime $realizedEndDate): self
  420.     {
  421.         $this->realizedEndDate $realizedEndDate;
  422.         return $this;
  423.     }
  424.     public function getBudget(): ?string
  425.     {
  426.         if (
  427.             $this->budget
  428.             &&
  429.             str_contains($this->budget',')
  430.         ) {
  431.             return $this->budget;
  432.         }
  433.         return $this->budget number_format((float) $this->budget2',''.') : null;
  434.     }
  435.     public function getRealBudget(): ?string
  436.     {
  437.         return $this->budget;
  438.     }
  439.     public function setBudget(?string $budget): self
  440.     {
  441.         $this->budget $budget;
  442.         return $this;
  443.     }
  444.     public function getExternalBudget(): ?string
  445.     {
  446.         if (
  447.             $this->externalBudget
  448.             &&
  449.             str_contains($this->externalBudget',')
  450.         ) {
  451.             return $this->externalBudget;
  452.         }
  453.         return $this->externalBudget number_format((float) $this->externalBudget2',''.') : null;
  454.     }
  455.     public function getRealExternalBudget(): ?string
  456.     {
  457.         return $this->externalBudget;
  458.     }
  459.     public function setExternalBudget(?string $externalBudget): self
  460.     {
  461.         $this->externalBudget $externalBudget;
  462.         return $this;
  463.     }
  464.     public function getProject(): ?Project
  465.     {
  466.         return $this->project;
  467.     }
  468.     public function setProject(?Project $project): self
  469.     {
  470.         $this->project $project;
  471.         return $this;
  472.     }
  473.     public function getParent(): ?Item
  474.     {
  475.         return $this->parent;
  476.     }
  477.     public function setParent(?Item $parent): self
  478.     {
  479.         $this->parent $parent;
  480.         return $this;
  481.     }
  482.     public function getChildren(): ?iterable
  483.     {
  484.         return $this->children;
  485.     }
  486.     public function getUsers(): iterable
  487.     {
  488.         return $this->users;
  489.     }
  490.     public function addUser(ItemUser $itemUser): void
  491.     {
  492.         if ($this->users->contains($itemUser)) {
  493.             return;
  494.         }
  495.         $this->users[] = $itemUser;
  496.         $itemUser->setItem($this);
  497.     }
  498.     public function cloneUser(ItemUser $itemUser): void
  499.     {
  500.         if ($this->users->contains($itemUser)) {
  501.             return;
  502.         }
  503.         $clonedUser = clone $itemUser;
  504.         $this->users[] = $clonedUser;
  505.         $clonedUser->setItem($this);
  506.     }
  507.     public function removeUser(ItemUser $itemUser): void
  508.     {
  509.         if (!$this->users->contains($itemUser)) {
  510.             return;
  511.         }
  512.         $this->users->removeElement($itemUser);
  513.         $itemUser->setItem(null);
  514.     }
  515.     public function getDocument(): iterable
  516.     {
  517.         return $this->document;
  518.     }
  519.     public function addDocument(ItemDocument $itemDocument): void
  520.     {
  521.         if ($this->document->contains($itemDocument)) {
  522.             return;
  523.         }
  524.         $this->document[] = $itemDocument;
  525.         $itemDocument->setItem($this);
  526.     }
  527.     public function cloneDocument(ItemDocument $itemDocument): void
  528.     {
  529.         if ($this->document->contains($itemDocument)) {
  530.             return;
  531.         }
  532.         $clonedDocument = clone $itemDocument;
  533.         $this->document[] = $clonedDocument;
  534.         $clonedDocument->setItem($this);
  535.     }
  536.     public function removeDocument(ItemDocument $itemDocument): void
  537.     {
  538.         if (!$this->document->contains($itemDocument)) {
  539.             return;
  540.         }
  541.         $this->document->removeElement($itemDocument);
  542.         $itemDocument->setItem(null);
  543.     }
  544.     public function getLabel(): iterable
  545.     {
  546.         return $this->label;
  547.     }
  548.     public function addLabel(ItemLabel $itemLabel): void
  549.     {
  550.         if ($this->label->contains($itemLabel)) {
  551.             return;
  552.         }
  553.         $this->label[] = $itemLabel;
  554.         $itemLabel->setItem($this);
  555.     }
  556.     public function cloneLabel(ItemLabel $itemLabel): void
  557.     {
  558.         if ($this->label->contains($itemLabel)) {
  559.             return;
  560.         }
  561.         $clonedLabel = clone $itemLabel;
  562.         $this->label[] = $clonedLabel;
  563.         $clonedLabel->setItem($this);
  564.     }
  565.     public function removeLabel(ItemLabel $itemLabel): void
  566.     {
  567.         if (!$this->label->contains($itemLabel)) {
  568.             return;
  569.         }
  570.         $this->label->removeElement($itemLabel);
  571.         $itemLabel->setItem(null);
  572.     }
  573.     public function getIndicators(): iterable
  574.     {
  575.         return $this->indicators;
  576.     }
  577.     public function addIndicator(ItemIndicator $itemIndicator): void
  578.     {
  579.         if ($this->indicators->contains($itemIndicator)) {
  580.             return;
  581.         }
  582.         $this->indicators[] = $itemIndicator;
  583.         $itemIndicator->setItem($this);
  584.     }
  585.     public function cloneIndicator(ItemIndicator $itemIndicator): void
  586.     {
  587.         if ($this->indicators->contains($itemIndicator)) {
  588.             return;
  589.         }
  590.         $clonedIndicator = clone $itemIndicator;
  591.         $this->indicators[] = $clonedIndicator;
  592.         $clonedIndicator->setItem($this);
  593.     }
  594.     public function removeIndicator(ItemIndicator $itemIndicator): void
  595.     {
  596.         if (!$this->indicators->contains($itemIndicator)) {
  597.             return;
  598.         }
  599.         $this->indicators->removeElement($itemIndicator);
  600.         $itemIndicator->setItem(null);
  601.     }
  602. }