| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- declare(strict_types=1);
- namespace App\Entity\Organization;
- use ApiPlatform\Core\Annotation\ApiResource;
- use App\Annotation\OrganizationDefaultValue;
- use App\Entity\Core\AddressPostal;
- use App\Repository\Organization\OrganizationAddressPostalRepository;
- use Doctrine\ORM\Mapping as ORM;
- use Symfony\Component\Validator\Constraints as Assert;
- use Symfony\Component\Serializer\Annotation\Groups;
- #[ApiResource(
- collectionOperations: [
- "get" => ["security" => "is_granted('ROLE_ORGANIZATION_VIEW')"],
- "post"
- ],
- itemOperations: [
- "get" => ["security" => "is_granted('ROLE_ORGANIZATION_VIEW') and object.getOrganization().getId() == user.getOrganization().getId()"],
- "put" => ["security" => "object.getOrganization().getId() == user.getOrganization().getId()"],
- "delete" => ["security" => "object.getOrganization().getId() == user.getOrganization().getId()"],
- ],
- attributes: ["security" => "is_granted('ROLE_ORGANIZATION')"],
- denormalizationContext: [
- 'groups' => ['address'],
- ],
- normalizationContext: [
- 'groups' => ['address'],
- ],
- )]
- #[ORM\Entity(repositoryClass: OrganizationAddressPostalRepository::class)]
- #[OrganizationDefaultValue(fieldName: "organization")]
- class OrganizationAddressPostal
- {
- #[ORM\Id]
- #[ORM\Column]
- #[ORM\GeneratedValue]
- #[Groups("address")]
- private ?int $id = null;
- #[ORM\ManyToOne(inversedBy: 'organizationAddressPostals')]
- #[ORM\JoinColumn(nullable: false)]
- private Organization $organization;
- #[ORM\OneToOne(inversedBy: 'organizationAddressPostal', cascade: ['persist', 'remove'])]
- #[ORM\JoinColumn(nullable: false)]
- #[Groups("address")]
- private AddressPostal $addressPostal;
- #[ORM\Column(length: 255)]
- #[Assert\Choice(callback: ['\App\Enum\Organization\AddressPostalOrganizationTypeEnum', 'toArray'], message: 'invalid-address-postal-type')]
- #[Groups("address")]
- private string $type;
- public function getId(): ?int
- {
- return $this->id;
- }
- public function getOrganization(): ?Organization
- {
- return $this->organization;
- }
- public function setOrganization(Organization $organization): self
- {
- $this->organization = $organization;
- return $this;
- }
- public function getAddressPostal(): ?AddressPostal
- {
- return $this->addressPostal;
- }
- public function setAddressPostal(AddressPostal $addressPostal): self
- {
- $this->addressPostal = $addressPostal;
- return $this;
- }
- public function getType(): string
- {
- return $this->type;
- }
- public function setType(string $type): self
- {
- $this->type = $type;
- return $this;
- }
- }
|