src/Entity/Reference/ReferencePropertyLandType.php line 38

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Reference;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Repository\Reference\ReferencePropertyLandTypeRepository;
  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-land-type:read"}, "swagger_definition_name"="Read"},
  14.  *     denormalizationContext={"groups"={"reference-land-type:write"}, "swagger_definition_name"="Write"},
  15.  *     itemOperations={
  16.  *          "get"
  17.  *     },
  18.  *     collectionOperations={
  19.  *           "get",
  20.  *           "milkiya_reference_property_land_types"={
  21.  *              "security"="is_granted('PUBLIC_ACCESS')",
  22.  *              "normalization_context"={"groups"={"milkiya:read"}},
  23.  *              "method"="GET",
  24.  *              "path"="/internal/reference_property_land_types",
  25.  *              "pagination_enabled" = false
  26.  *          },
  27.  *     },
  28.  *     attributes={
  29.  *          "pagination_items_per_page"=10,
  30.  *          "formats"={"jsonld", "json", "html", "jsonhal", "csv"={"text/csv"} }
  31.  *     }
  32.  * )
  33.  * @ORM\Entity(repositoryClass=ReferencePropertyLandTypeRepository::class)
  34.  */
  35. class ReferencePropertyLandType
  36. {
  37.     public const TRANSLATION_DOMAIN 'reference_property';
  38.     public const REFERENCE_PROPERTY_TYPE_FARM 'reference.property.type.FARM';
  39.     public const REFERENCE_PROPERTY_TYPE_BARE_LAND 'reference.property.type.BARE_LAND';
  40.     public const REFERENCE_PROPERTY_TYPE_AGRICULTURAL_LAND 'reference.property.type.AGRICULTURAL_LAND';
  41.     public const CODE_REFERENCE_PROPERTY_TYPE_AGRICULTURAL_LAND 0;
  42.     public const CODE_REFERENCE_PROPERTY_TYPE_BARE_LAND 1;
  43.     public const CODE_REFERENCE_PROPERTY_TYPE_FARM 2;
  44.     public const ALL_REFERENCE_PROPERTY_LAND_TYPE = [
  45.         self::REFERENCE_PROPERTY_TYPE_AGRICULTURAL_LAND,
  46.         self::REFERENCE_PROPERTY_TYPE_BARE_LAND,
  47.         self::REFERENCE_PROPERTY_TYPE_FARM,
  48.     ];
  49.     public const ALL_REFERENCE_CODE_PROPERTY_LAND_TYPE = [
  50.         self::CODE_REFERENCE_PROPERTY_TYPE_AGRICULTURAL_LAND,
  51.         self::CODE_REFERENCE_PROPERTY_TYPE_BARE_LAND,
  52.         self::CODE_REFERENCE_PROPERTY_TYPE_FARM,
  53.     ];
  54.     /**
  55.      * @ORM\Id
  56.      * @ORM\GeneratedValue
  57.      * @ORM\Column(type="integer")
  58.      *
  59.      * @Groups({
  60.      *   "property:read",
  61.      *   "mandate:read",
  62.      *   "transaction-item:read",
  63.      *   "reference-land-type:read",
  64.      *   "milkiya:read",
  65.      *   "property-visit:read",
  66.      * })
  67.      */
  68.     private $id;
  69.     /**
  70.      * @ORM\Column(type="string", length=100)
  71.      *
  72.      * @Groups({
  73.      *   "property:read",
  74.      *   "mandate:read",
  75.      *   "transaction-item:read",
  76.      *   "reference-land-type:read",
  77.      *   "milkiya:read",
  78.      *   "property-visit:read",
  79.      * })
  80.      */
  81.     private ?string $name;
  82.     /**
  83.      * @ORM\Column(type="integer")
  84.      *
  85.      * @Groups({
  86.      *   "property:read",
  87.      *   "mandate:read",
  88.      *   "transaction-item:read",
  89.      *   "reference-land-type:read",
  90.      *   "milkiya:read",
  91.      *   "property-visit:read",
  92.      * })
  93.      *
  94.      */
  95.     private ?int $code;
  96.     /**
  97.      * @ORM\OneToMany(targetEntity=Property::class, mappedBy="referencePropertyLandType")
  98.      */
  99.     private $properties;
  100.     public function __construct()
  101.     {
  102.         $this->properties = new ArrayCollection();
  103.     }
  104.     public function getId(): ?int
  105.     {
  106.         return $this->id;
  107.     }
  108.     public function getName(): ?string
  109.     {
  110.         return $this->name;
  111.     }
  112.     public function setName(string $name): self
  113.     {
  114.         $this->name $name;
  115.         return $this;
  116.     }
  117.     public function getCode(): ?int
  118.     {
  119.         return $this->code;
  120.     }
  121.     public function setCode(int $code): self
  122.     {
  123.         $this->code $code;
  124.         return $this;
  125.     }
  126.     /**
  127.      * @return Collection<int, Property>
  128.      */
  129.     public function getProperties(): Collection
  130.     {
  131.         return $this->properties;
  132.     }
  133.     public function addProperty(Property $property): self
  134.     {
  135.         if (!$this->properties->contains($property)) {
  136.             $this->properties[] = $property;
  137.             $property->setReferencePropertyLandType($this);
  138.         }
  139.         return $this;
  140.     }
  141.     public function removeProperty(Property $property): self
  142.     {
  143.         if ($this->properties->removeElement($property)) {
  144.             // set the owning side to null (unless already changed)
  145.             if ($property->getReferencePropertyLandType() === $this) {
  146.                 $property->setReferencePropertyLandType(null);
  147.             }
  148.         }
  149.         return $this;
  150.     }
  151.     public function isFarm(): bool
  152.     {
  153.         if (null === $this) {
  154.             return false;
  155.         }
  156.         return $this->code === self::CODE_REFERENCE_PROPERTY_TYPE_FARM;
  157.     }
  158.     public function isBare(): bool
  159.     {
  160.         if (null === $this) {
  161.             return false;
  162.         }
  163.         return $this->code === self::CODE_REFERENCE_PROPERTY_TYPE_BARE_LAND;
  164.     }
  165.     public function isAgricultural(): bool
  166.     {
  167.         if (null === $this) {
  168.             return false;
  169.         }
  170.         return $this->code === self::CODE_REFERENCE_PROPERTY_TYPE_AGRICULTURAL_LAND;
  171.     }
  172. }