<?php
namespace App\V4\Model\Section;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Model\IriNormalizableInterface;
use App\Model\NormalizeAsIRITrait;
use App\Model\Traits\ImportableObjectTrait;
use App\V4\Entity\SavedRequest;
use App\V4\Model\Customer\Customer;
use App\V4\Model\Security\UserInfo;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ApiResource(
* shortName="V4/Section",
* attributes={
* "api_allow_update": true
* },
* collectionOperations={
* "get": {
* "path": "/V4/sections",
* "normalization_context": {
* "groups": {"section:list"}
* },
* "security": "is_granted(constant('App\\V4\\Voters\\SectionVoter::SECTION_SHOW_LIST'), 'App\V4\Voters\SectionVoter')"
* },
* "post_section": {
* "method": "POST",
* "deserialize": false,
* "write": false,
* "controller": "App\V4\Controller\Section\SectionDataPersisterAction",
* "path": "/V4/sections",
* "input_formats": {
* "multipart": {"multipart/form-data"}
* },
* "normalization_context": {
* "groups": {"section:read"}
* },
* "denormalization_context": {
* "groups": {}
* }
* },
* "get_form": {
* "method": "GET",
* "path": "/V4/sections/form",
* "controller": App\V4\Controller\Section\GetSectionFormAction::class
* },
* },
* itemOperations={
* "get": {
* "path": "/V4/sections/{id}",
* },
* "get_form": {
* "method": "GET",
* "path": "/V4/sections/{id}/form",
* "controller": App\V4\Controller\Section\GetSectionFormAction::class
* },
* "put_section": {
* "method": "POST",
* "deserialize": false,
* "write": false,
* "controller": "App\V4\Controller\Section\SectionDataPersisterAction",
* "path": "/V4/sections/{id}",
* "input_formats": {
* "multipart": {"multipart/form-data"}
* },
* "normalization_context": {
* "groups": {"section:read"}
* },
* "denormalization_context": {
* "groups": {}
* }
* },
* "delete_section": {
* "method": "DELETE",
* "deserialize": false,
* "write": false,
* "controller": "App\V4\Controller\Section\SectionDataPersisterAction",
* "path": "/V4/sections/{id}"
* }
* }
* )
*/
class Section implements IriNormalizableInterface
{
use ImportableObjectTrait;
use NormalizeAsIRITrait;
/**
* @ApiProperty(identifier=true)
*
* @var string|null
* @Groups({
* "prospect:list", "prospect:read", "prospect:write", "prospect:update",
* "section:list", "section:read", "section:write", "section:update",
* "list", "read"
* })
*/
private $id;
/**
* @var Customer|null
* @Groups({
* "prospect:list", "prospect:read", "prospect:write", "prospect:update",
* "section:list", "section:read", "section:write",
* "list", "read"
* })
*/
private $customer;
/**
* @var string|null
* @Groups({
* "prospect:list", "prospect:read",
* "section:list", "section:read", "section:write", "section:update",
* "list", "read"
* })
*/
private $code;
/**
* @var Section|null
* @Groups({
* "prospect:list", "prospect:read",
* "section:list", "section:read", "section:write", "section:update",
* "list", "read"
* })
*/
private $parent;
/**
* @var Section[]|Collection
* @Groups({
* "prospect:list", "prospect:read",
* "section:list", "section:read",
* "list", "read"
* })
*/
private $sections;
/**
* @var bool
* @Groups({
* "section:list", "section:read", "section:write", "section:update",
* "list", "read"
* })
*/
private $isVisible = false;
/**
* @var UserInfo[]|Collection
* @Groups({
* "prospect:list", "prospect:read",
* "section:list", "section:read", "section:write", "section:update",
* "list", "read"
* })
*/
private $leaders;
/**
* @var UserInfo[]|Collection
* @Groups({
* "prospect:list", "prospect:read",
* "section:list", "section:read", "section:write", "section:update",
* "list", "read"
* })
*/
private $members;
/**
* @var SavedRequest[]|Collection
*/
private $sectionSavedRequests;
public function __construct()
{
$this->sections = new ArrayCollection();
$this->leaders = new ArrayCollection();
$this->members = new ArrayCollection();
$this->sectionSavedRequests = new ArrayCollection();
}
public function __toString()
{
return $this->code;
}
/**
* @return UserInfo[]
*/
public function getUsersInSectionOrChildSection(): array
{
$users = [];
foreach ($this->getLeaders() as $leader) {
$users[] = $leader;
}
foreach ($this->getMembers() as $member) {
$users[] = $member;
}
foreach ($this->getSections() as $section) {
$users = array_merge($users, $section->getUsersInSectionOrChildSection());
}
return array_unique($users, SORT_REGULAR);
}
/**
* @return string|null
*/
public function getId(): ?string
{
return $this->id;
}
/**
* @param string|null $id
*
* @return Section
*/
public function setId(?string $id): self
{
$this->id = $id;
return $this;
}
/**
* @return Customer|null
*/
public function getCustomer(): ?Customer
{
return $this->customer;
}
/**
* @param Customer|null $customer
*
* @return Section
*/
public function setCustomer(?Customer $customer): self
{
$this->customer = $customer;
return $this;
}
/**
* @return string|null
*/
public function getCode(): ?string
{
return $this->code;
}
/**
* @param string|null $code
*
* @return Section
*/
public function setCode(?string $code): self
{
$this->code = $code;
return $this;
}
/**
* @return Section|null
*/
public function getParent(): ?Section
{
return $this->parent;
}
/**
* @param Section|null $parent
*
* @return Section
*/
public function setParent(?Section $parent): self
{
$this->parent = $parent;
return $this;
}
/**
* @return Section[]|Collection
*/
public function getSections(): Collection
{
return $this->sections;
}
/**
* @param ArrayCollection<Section> $sections
*
* @return Section
*/
public function setSections(ArrayCollection $sections): self
{
$this->sections = $sections;
return $this;
}
/**
* @param Section $section
*
* @return Section
*/
public function addSection(Section $section): self
{
if (!$this->sections->contains($section)) {
$this->sections->add($section);
}
return $this;
}
/**
* @param Section $section
*
* @return Section
*/
public function removeSection(Section $section): self
{
if ($this->sections->contains($section)) {
$this->sections->removeElement($section);
}
return $this;
}
/**
* @return UserInfo[]|Collection
*/
public function getLeaders(): Collection
{
return $this->leaders;
}
/**
* @param UserInfo[]|Collection|null $leaders
*/
public function setLeaders(?Collection $leaders): self
{
$this->leaders = $leaders;
return $this;
}
/**
* @param UserInfo $leader
*
* @return Section
*/
public function addLeader(UserInfo $leader): self
{
if (!$this->leaders->contains($leader)) {
$this->leaders->add($leader);
}
return $this;
}
/**
* @param UserInfo $leader
*
* @return Section
*/
public function removeLeader(UserInfo $leader): self
{
if ($this->leaders->contains($leader)) {
$this->leaders->removeElement($leader);
}
return $this;
}
/**
* @return UserInfo[]|Collection
*/
public function getMembers(): Collection
{
return $this->members;
}
/**
* @param UserInfo[]|Collection|null $members
*
* @return Section
*/
public function setMembers(?Collection $members): self
{
$this->members = $members;
return $this;
}
/**
* @param UserInfo $member
*
* @return Section
*/
public function addMember(UserInfo $member): self
{
if (!$this->members->contains($member)) {
$this->members->add($member);
}
return $this;
}
/**
* @param UserInfo $member
*
* @return Section
*/
public function removeMember(UserInfo $member): self
{
if ($this->members->contains($member)) {
$this->members->removeElement($member);
}
return $this;
}
/**
* @return bool
*/
public function isVisible(): bool
{
return $this->isVisible;
}
/**
* @param bool $isVisible
*
* @return Section
*/
public function setIsVisible(bool $isVisible): self
{
$this->isVisible = $isVisible;
return $this;
}
/**
* @return SavedRequest[]|Collection
*/
public function getSectionSavedRequests()
{
return $this->sectionSavedRequests;
}
/**
* @param SavedRequest[]|Collection $sectionSavedRequests
*/
public function setSectionSavedRequests($sectionSavedRequests): void
{
$this->sectionSavedRequests = $sectionSavedRequests;
}
/**
* @param SavedRequest $sectionSavedRequest
*
* @return $this
*/
public function addSectionSavedRequest(SavedRequest $sectionSavedRequest): self
{
if (!$this->sectionSavedRequests->contains($sectionSavedRequest)) {
$this->sectionSavedRequests->add($sectionSavedRequest);
}
return $this;
}
/**
* @param SavedRequest $sectionSavedRequest
*
* @return $this
*/
public function removeSectionSavedRequest(SavedRequest $sectionSavedRequest): self
{
if ($this->sectionSavedRequests->contains($sectionSavedRequest)) {
$this->sectionSavedRequests->removeElement($sectionSavedRequest);
}
return $this;
}
}