src/V4/Model/Section/Section.php line 88

Open in your IDE?
  1. <?php
  2. namespace App\V4\Model\Section;
  3. use ApiPlatform\Core\Annotation\ApiProperty;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use App\Model\IriNormalizableInterface;
  6. use App\Model\NormalizeAsIRITrait;
  7. use App\Model\Traits\ImportableObjectTrait;
  8. use App\V4\Entity\SavedRequest;
  9. use App\V4\Model\Customer\Customer;
  10. use App\V4\Model\Security\UserInfo;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\Common\Collections\Collection;
  13. use Symfony\Component\Serializer\Annotation\Groups;
  14. /**
  15.  * @ApiResource(
  16.  *     shortName="V4/Section",
  17.  *     attributes={
  18.  *         "api_allow_update": true
  19.  *     },
  20.  *     collectionOperations={
  21.  *        "get": {
  22.  *             "path": "/V4/sections",
  23.  *             "normalization_context": {
  24.  *                  "groups": {"section:list"}
  25.  *             },
  26.  *             "security": "is_granted(constant('App\\V4\\Voters\\SectionVoter::SECTION_SHOW_LIST'), 'App\V4\Voters\SectionVoter')"
  27.  *         },
  28.  *         "post_section": {
  29.  *             "method": "POST",
  30.  *             "deserialize": false,
  31.  *             "write": false,
  32.  *             "controller": "App\V4\Controller\Section\SectionDataPersisterAction",
  33.  *             "path": "/V4/sections",
  34.  *             "input_formats": {
  35.  *                 "multipart": {"multipart/form-data"}
  36.  *             },
  37.  *             "normalization_context": {
  38.  *                  "groups": {"section:read"}
  39.  *             },
  40.  *             "denormalization_context": {
  41.  *                  "groups": {}
  42.  *             }
  43.  *         },
  44.  *         "get_form": {
  45.  *             "method": "GET",
  46.  *             "path": "/V4/sections/form",
  47.  *             "controller": App\V4\Controller\Section\GetSectionFormAction::class
  48.  *         },
  49.  *     },
  50.  *     itemOperations={
  51.  *        "get": {
  52.  *             "path": "/V4/sections/{id}",
  53.  *         },
  54.  *         "get_form": {
  55.  *             "method": "GET",
  56.  *             "path": "/V4/sections/{id}/form",
  57.  *             "controller": App\V4\Controller\Section\GetSectionFormAction::class
  58.  *         },
  59.  *         "put_section": {
  60.  *             "method": "POST",
  61.  *             "deserialize": false,
  62.  *             "write": false,
  63.  *             "controller": "App\V4\Controller\Section\SectionDataPersisterAction",
  64.  *             "path": "/V4/sections/{id}",
  65.  *             "input_formats": {
  66.  *                 "multipart": {"multipart/form-data"}
  67.  *             },
  68.  *             "normalization_context": {
  69.  *                  "groups": {"section:read"}
  70.  *             },
  71.  *             "denormalization_context": {
  72.  *                  "groups": {}
  73.  *             }
  74.  *         },
  75.  *         "delete_section": {
  76.  *             "method": "DELETE",
  77.  *             "deserialize": false,
  78.  *             "write": false,
  79.  *             "controller": "App\V4\Controller\Section\SectionDataPersisterAction",
  80.  *             "path": "/V4/sections/{id}"
  81.  *         }
  82.  *     }
  83.  * )
  84.  */
  85. class Section implements IriNormalizableInterface
  86. {
  87.     use ImportableObjectTrait;
  88.     use NormalizeAsIRITrait;
  89.     /**
  90.      * @ApiProperty(identifier=true)
  91.      *
  92.      * @var string|null
  93.      * @Groups({
  94.      *     "prospect:list", "prospect:read", "prospect:write", "prospect:update",
  95.      *     "section:list", "section:read", "section:write", "section:update",
  96.      *     "list", "read"
  97.      * })
  98.      */
  99.     private $id;
  100.     /**
  101.      * @var Customer|null
  102.      * @Groups({
  103.      *     "prospect:list", "prospect:read", "prospect:write", "prospect:update",
  104.      *     "section:list", "section:read", "section:write",
  105.      *     "list", "read"
  106.      * })
  107.      */
  108.     private $customer;
  109.     /**
  110.      * @var string|null
  111.      * @Groups({
  112.      *     "prospect:list", "prospect:read",
  113.      *     "section:list", "section:read", "section:write", "section:update",
  114.      *     "list", "read"
  115.      * })
  116.      */
  117.     private $code;
  118.     /**
  119.      * @var Section|null
  120.      * @Groups({
  121.      *     "prospect:list", "prospect:read",
  122.      *     "section:list", "section:read", "section:write", "section:update",
  123.      *     "list", "read"
  124.      * })
  125.      */
  126.     private $parent;
  127.     /**
  128.      * @var Section[]|Collection
  129.      * @Groups({
  130.      *     "prospect:list", "prospect:read",
  131.      *     "section:list", "section:read",
  132.      *     "list", "read"
  133.      * })
  134.      */
  135.     private $sections;
  136.     /**
  137.      * @var bool
  138.      * @Groups({
  139.      *     "section:list", "section:read", "section:write", "section:update",
  140.      *     "list", "read"
  141.      * })
  142.      */
  143.     private $isVisible false;
  144.     /**
  145.      * @var UserInfo[]|Collection
  146.      * @Groups({
  147.      *     "prospect:list", "prospect:read",
  148.      *     "section:list", "section:read", "section:write", "section:update",
  149.      *     "list", "read"
  150.      * })
  151.      */
  152.     private $leaders;
  153.     /**
  154.      * @var UserInfo[]|Collection
  155.      * @Groups({
  156.      *     "prospect:list", "prospect:read",
  157.      *     "section:list", "section:read", "section:write", "section:update",
  158.      *     "list", "read"
  159.      * })
  160.      */
  161.     private $members;
  162.     /**
  163.      * @var SavedRequest[]|Collection
  164.      */
  165.     private $sectionSavedRequests;
  166.     public function __construct()
  167.     {
  168.         $this->sections = new ArrayCollection();
  169.         $this->leaders = new ArrayCollection();
  170.         $this->members = new ArrayCollection();
  171.         $this->sectionSavedRequests = new ArrayCollection();
  172.     }
  173.     public function __toString()
  174.     {
  175.         return $this->code;
  176.     }
  177.     /**
  178.      * @return UserInfo[]
  179.      */
  180.     public function getUsersInSectionOrChildSection(): array
  181.     {
  182.         $users = [];
  183.         foreach ($this->getLeaders() as $leader) {
  184.             $users[] = $leader;
  185.         }
  186.         foreach ($this->getMembers() as $member) {
  187.             $users[] = $member;
  188.         }
  189.         foreach ($this->getSections() as $section) {
  190.             $users array_merge($users$section->getUsersInSectionOrChildSection());
  191.         }
  192.         return array_unique($usersSORT_REGULAR);
  193.     }
  194.     /**
  195.      * @return string|null
  196.      */
  197.     public function getId(): ?string
  198.     {
  199.         return $this->id;
  200.     }
  201.     /**
  202.      * @param string|null $id
  203.      *
  204.      * @return Section
  205.      */
  206.     public function setId(?string $id): self
  207.     {
  208.         $this->id $id;
  209.         return $this;
  210.     }
  211.     /**
  212.      * @return Customer|null
  213.      */
  214.     public function getCustomer(): ?Customer
  215.     {
  216.         return $this->customer;
  217.     }
  218.     /**
  219.      * @param Customer|null $customer
  220.      *
  221.      * @return Section
  222.      */
  223.     public function setCustomer(?Customer $customer): self
  224.     {
  225.         $this->customer $customer;
  226.         return $this;
  227.     }
  228.     /**
  229.      * @return string|null
  230.      */
  231.     public function getCode(): ?string
  232.     {
  233.         return $this->code;
  234.     }
  235.     /**
  236.      * @param string|null $code
  237.      *
  238.      * @return Section
  239.      */
  240.     public function setCode(?string $code): self
  241.     {
  242.         $this->code $code;
  243.         return $this;
  244.     }
  245.     /**
  246.      * @return Section|null
  247.      */
  248.     public function getParent(): ?Section
  249.     {
  250.         return $this->parent;
  251.     }
  252.     /**
  253.      * @param Section|null $parent
  254.      *
  255.      * @return Section
  256.      */
  257.     public function setParent(?Section $parent): self
  258.     {
  259.         $this->parent $parent;
  260.         return $this;
  261.     }
  262.     /**
  263.      * @return Section[]|Collection
  264.      */
  265.     public function getSections(): Collection
  266.     {
  267.         return $this->sections;
  268.     }
  269.     /**
  270.      * @param ArrayCollection<Section> $sections
  271.      *
  272.      * @return Section
  273.      */
  274.     public function setSections(ArrayCollection $sections): self
  275.     {
  276.         $this->sections $sections;
  277.         return $this;
  278.     }
  279.     /**
  280.      * @param Section $section
  281.      *
  282.      * @return Section
  283.      */
  284.     public function addSection(Section $section): self
  285.     {
  286.         if (!$this->sections->contains($section)) {
  287.             $this->sections->add($section);
  288.         }
  289.         return $this;
  290.     }
  291.     /**
  292.      * @param Section $section
  293.      *
  294.      * @return Section
  295.      */
  296.     public function removeSection(Section $section): self
  297.     {
  298.         if ($this->sections->contains($section)) {
  299.             $this->sections->removeElement($section);
  300.         }
  301.         return $this;
  302.     }
  303.     /**
  304.      * @return UserInfo[]|Collection
  305.      */
  306.     public function getLeaders(): Collection
  307.     {
  308.         return $this->leaders;
  309.     }
  310.     /**
  311.      * @param UserInfo[]|Collection|null $leaders
  312.      */
  313.     public function setLeaders(?Collection $leaders): self
  314.     {
  315.         $this->leaders $leaders;
  316.         return $this;
  317.     }
  318.     /**
  319.      * @param UserInfo $leader
  320.      *
  321.      * @return Section
  322.      */
  323.     public function addLeader(UserInfo $leader): self
  324.     {
  325.         if (!$this->leaders->contains($leader)) {
  326.             $this->leaders->add($leader);
  327.         }
  328.         return $this;
  329.     }
  330.     /**
  331.      * @param UserInfo $leader
  332.      *
  333.      * @return Section
  334.      */
  335.     public function removeLeader(UserInfo $leader): self
  336.     {
  337.         if ($this->leaders->contains($leader)) {
  338.             $this->leaders->removeElement($leader);
  339.         }
  340.         return $this;
  341.     }
  342.     /**
  343.      * @return UserInfo[]|Collection
  344.      */
  345.     public function getMembers(): Collection
  346.     {
  347.         return $this->members;
  348.     }
  349.     /**
  350.      * @param UserInfo[]|Collection|null $members
  351.      *
  352.      * @return Section
  353.      */
  354.     public function setMembers(?Collection $members): self
  355.     {
  356.         $this->members $members;
  357.         return $this;
  358.     }
  359.     /**
  360.      * @param UserInfo $member
  361.      *
  362.      * @return Section
  363.      */
  364.     public function addMember(UserInfo $member): self
  365.     {
  366.         if (!$this->members->contains($member)) {
  367.             $this->members->add($member);
  368.         }
  369.         return $this;
  370.     }
  371.     /**
  372.      * @param UserInfo $member
  373.      *
  374.      * @return Section
  375.      */
  376.     public function removeMember(UserInfo $member): self
  377.     {
  378.         if ($this->members->contains($member)) {
  379.             $this->members->removeElement($member);
  380.         }
  381.         return $this;
  382.     }
  383.     /**
  384.      * @return bool
  385.      */
  386.     public function isVisible(): bool
  387.     {
  388.         return $this->isVisible;
  389.     }
  390.     /**
  391.      * @param bool $isVisible
  392.      *
  393.      * @return Section
  394.      */
  395.     public function setIsVisible(bool $isVisible): self
  396.     {
  397.         $this->isVisible $isVisible;
  398.         return $this;
  399.     }
  400.     /**
  401.      * @return SavedRequest[]|Collection
  402.      */
  403.     public function getSectionSavedRequests()
  404.     {
  405.         return $this->sectionSavedRequests;
  406.     }
  407.     /**
  408.      * @param SavedRequest[]|Collection $sectionSavedRequests
  409.      */
  410.     public function setSectionSavedRequests($sectionSavedRequests): void
  411.     {
  412.         $this->sectionSavedRequests $sectionSavedRequests;
  413.     }
  414.     /**
  415.      * @param SavedRequest $sectionSavedRequest
  416.      *
  417.      * @return $this
  418.      */
  419.     public function addSectionSavedRequest(SavedRequest $sectionSavedRequest): self
  420.     {
  421.         if (!$this->sectionSavedRequests->contains($sectionSavedRequest)) {
  422.             $this->sectionSavedRequests->add($sectionSavedRequest);
  423.         }
  424.         return $this;
  425.     }
  426.     /**
  427.      * @param SavedRequest $sectionSavedRequest
  428.      *
  429.      * @return $this
  430.      */
  431.     public function removeSectionSavedRequest(SavedRequest $sectionSavedRequest): self
  432.     {
  433.         if ($this->sectionSavedRequests->contains($sectionSavedRequest)) {
  434.             $this->sectionSavedRequests->removeElement($sectionSavedRequest);
  435.         }
  436.         return $this;
  437.     }
  438. }