src/Entity/Reference/ReferencePropertyContractType.php line 39

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Reference;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Repository\Reference\ReferencePropertyContractTypeRepository;
  5. use App\Entity\Property;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. /**
  11.  * @ApiResource(
  12.  *     security= "is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
  13.  *     normalizationContext={"groups"={"reference-contract-type:read"}, "swagger_definition_name"="Read"},
  14.  *     denormalizationContext={"groups"={"reference-contract-type:write"}, "swagger_definition_name"="Write"},
  15.  *     itemOperations={
  16.  *          "get"
  17.  *     },
  18.  *     collectionOperations={
  19.  *           "get",
  20.  *           "milkiya_reference_property_contract_types"={
  21.  *              "security"="is_granted('PUBLIC_ACCESS')",
  22.  *              "normalization_context"={"groups"={"milkiya:read"}},
  23.  *              "method"="GET",
  24.  *              "path"="/internal/reference_property_contract_types",
  25.  *              "pagination_enabled" = false
  26.  *          },
  27.  *
  28.  *     },
  29.  *     attributes={
  30.  *          "pagination_items_per_page"=10,
  31.  *          "formats"={"jsonld", "json", "html", "jsonhal", "csv"={"text/csv"} }
  32.  *     }
  33.  * )
  34.  * @ORM\Entity(repositoryClass=ReferencePropertyContractTypeRepository::class)
  35.  */
  36. class ReferencePropertyContractType
  37. {
  38.     public const TRANSLATION_DOMAIN 'reference_property_contract_type';
  39.     public const REFERENCE_PROPERTY_CONTRACT_OFFICE 'reference.property.contract.OFFICE';
  40.     public const REFERENCE_PROPERTY_CONTRACT_WAREHOUSE 'reference.property.contract.WAREHOUSE';
  41.     public const REFERENCE_PROPERTY_CONTRACT_GOODWILL 'reference.property.contract.GOODWILL';
  42.     public const REFERENCE_PROPERTY_CONTRACT_WALLS 'reference.property.contract.WALLS';
  43.     public const CODE_REFERENCE_PROPERTY_CONTRACT_OFFICE 0;
  44.     public const CODE_REFERENCE_PROPERTY_CONTRACT_WAREHOUSE 1;
  45.     public const REFERENCE_CODE_PROPERTY_CONTRACT_GOODWILL 2;
  46.     public const REFERENCE_CODE_PROPERTY_CONTRACT_WALLS 3;
  47.     public const ALL_REFERENCE_PROPERTY_CONTRACT_TYPE = [
  48.         self::REFERENCE_PROPERTY_CONTRACT_OFFICE,
  49.         self::REFERENCE_PROPERTY_CONTRACT_WAREHOUSE,
  50.         self::REFERENCE_PROPERTY_CONTRACT_GOODWILL,
  51.         self::REFERENCE_PROPERTY_CONTRACT_WALLS,
  52.     ];
  53.     public const ALL_REFERENCE_CODE_PROPERTY_CONTRACT_TYPE = [
  54.         self::CODE_REFERENCE_PROPERTY_CONTRACT_OFFICE,
  55.         self::CODE_REFERENCE_PROPERTY_CONTRACT_WAREHOUSE,
  56.         self::REFERENCE_CODE_PROPERTY_CONTRACT_GOODWILL,
  57.         self::REFERENCE_CODE_PROPERTY_CONTRACT_WALLS,
  58.     ];
  59.     /**
  60.      * @ORM\Id
  61.      * @ORM\GeneratedValue
  62.      * @ORM\Column(type="integer")
  63.      *
  64.      * @Groups({
  65.      *   "property:read",
  66.      *   "mandate:read",
  67.      *   "transaction-item:read",
  68.      *   "reference-contract-type:read",
  69.      *   "milkiya:read",
  70.      *   "business-indication:item:read",
  71.      *   "property-visit:read",
  72.      * })
  73.      */
  74.     private $id;
  75.     /**
  76.      * @ORM\Column(type="string", length=100)
  77.      *
  78.      * @Groups({
  79.      *   "property:read",
  80.      *   "mandate:read",
  81.      *   "transaction-item:read",
  82.      *   "reference-contract-type:read",
  83.      *   "milkiya:read",
  84.      *   "business-indication:item:read",
  85.      *   "property-visit:read",
  86.      * })
  87.      */
  88.     private ?string $name;
  89.     /**
  90.      * @ORM\Column(type="integer")
  91.      *
  92.      * @Groups({
  93.      *   "property:read",
  94.      *   "mandate:read",
  95.      *   "transaction-item:read",
  96.      *   "reference-contract-type:read",
  97.      *   "milkiya:read",
  98.      *   "property-visit:read",
  99.      * })
  100.      *
  101.      */
  102.     private ?int $code;
  103.     /**
  104.      * @ORM\OneToMany(targetEntity=Property::class, mappedBy="referencePropertyContractType")
  105.      */
  106.     private $properties;
  107.     public function __construct()
  108.     {
  109.         $this->properties = new ArrayCollection();
  110.     }
  111.     public function getId(): ?int
  112.     {
  113.         return $this->id;
  114.     }
  115.     public function getName(): ?string
  116.     {
  117.         return $this->name;
  118.     }
  119.     public function setName(string $name): self
  120.     {
  121.         $this->name $name;
  122.         return $this;
  123.     }
  124.     public function getCode(): ?int
  125.     {
  126.         return $this->code;
  127.     }
  128.     public function setCode(int $code): self
  129.     {
  130.         $this->code $code;
  131.         return $this;
  132.     }
  133.     /**
  134.      * @return Collection<int, Property>
  135.      */
  136.     public function getProperties(): Collection
  137.     {
  138.         return $this->properties;
  139.     }
  140.     public function addProperty(Property $property): self
  141.     {
  142.         if (!$this->properties->contains($property)) {
  143.             $this->properties[] = $property;
  144.             $property->setReferencePropertyContractType($this);
  145.         }
  146.         return $this;
  147.     }
  148.     public function removeProperty(Property $property): self
  149.     {
  150.         if ($this->properties->removeElement($property)) {
  151.             // set the owning side to null (unless already changed)
  152.             if ($property->getReferencePropertyContractType() === $this) {
  153.                 $property->setReferencePropertyContractType(null);
  154.             }
  155.         }
  156.         return $this;
  157.     }
  158.     public function isOffice(): bool
  159.     {
  160.         if (null === $this) {
  161.             return false;
  162.         }
  163.         return $this->code === self::CODE_REFERENCE_PROPERTY_CONTRACT_OFFICE;
  164.     }
  165.     public function isWareHouse(): bool
  166.     {
  167.         if (null === $this) {
  168.             return false;
  169.         }
  170.         return $this->code === self::CODE_REFERENCE_PROPERTY_CONTRACT_WAREHOUSE;
  171.     }
  172.     public function isWalls(): bool
  173.     {
  174.         if (null === $this) {
  175.             return false;
  176.         }
  177.         return $this->code === self::REFERENCE_CODE_PROPERTY_CONTRACT_WALLS;
  178.     }
  179.     public function isGoodWill(): bool
  180.     {
  181.         if (null === $this) {
  182.             return false;
  183.         }
  184.         return $this->code === self::REFERENCE_CODE_PROPERTY_CONTRACT_GOODWILL;
  185.     }
  186. }