src/Entity/Reference/ReferencePropertyDestination.php line 32

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