src/Entity/PlacementProperty.php line 46

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  6. use App\Entity\NetHunt\NetHuntOpportunityPlacementMapping;
  7. use App\Entity\Placement\Pdf\PaymentPlan\PaymentPlan;
  8. use App\Entity\Placement\Pdf\PaymentPlan\UnitInfo\SystemValueInfo;
  9. use App\Repository\PlacementPropertyRepository;
  10. use App\Validator\Constraint\JsonLanguageConstraint;
  11. use App\Validator\Constraint\PlacementProperty\PlacementPropertyMainConstraint;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Doctrine\Common\Collections\Collection;
  14. use Doctrine\ORM\Mapping as ORM;
  15. use Symfony\Component\Serializer\Annotation\Groups;
  16. use Symfony\Component\Validator\Constraints as Assert;
  17. /**
  18.  * @ApiResource(
  19.  *     normalizationContext={"groups"={"placementProperty:read"}, "skip_null_values"=false, "enable_max_depth"=true},
  20.  *     denormalizationContext={"groups"={"placementProperty:write"}, "enable_max_depth"=true}
  21.  * )
  22.  * @ORM\Entity(repositoryClass=PlacementPropertyRepository::class)
  23.  * @ORM\Table(
  24.  *      indexes={
  25.  *          @ORM\Index(
  26.  *              columns={"system_name"}
  27.  *          ),
  28.  *      },
  29.  *      uniqueConstraints={
  30.  *          @ORM\UniqueConstraint(
  31.  *              columns={"system_name", "complex_id"}
  32.  *          )
  33.  *      }
  34.  * )
  35.  *
  36.  * @ApiFilter(SearchFilter::class, properties={
  37.  *      "complex": "exact",
  38.  *      "systemName": "exact"
  39.  * })
  40.  *
  41.  * @PlacementPropertyMainConstraint
  42.  */
  43. class PlacementProperty
  44. {
  45.     /**
  46.      * @ORM\Id
  47.      * @ORM\GeneratedValue
  48.      * @ORM\Column(type="integer")
  49.      * @Groups({
  50.      *     "placementProperty:read",
  51.      *     "complex:read", "complex:write",
  52.      *
  53.      *     "ppsPropertySetting:read",
  54.      *     "ppsPropertySettingsGroup:read",
  55.      *     "ppsDescriptionSection:read",
  56.      *     "ppsHeaderSection:read",
  57.      *     "placementPageSetup:read",
  58.      *     "paymentPlan:read", "paymentPlan:post", "paymentPlan:put",
  59.      *
  60.      *     "propertySetting:read", "propertySetting:post", "propertySetting:put",
  61.      *     "subView:read", "subView:post", "subView:put",
  62.      *     "view:read", "view:post", "view:put",
  63.      *     "frontConfig:read", "frontConfig:post", "frontConfig:put",
  64.      *     "frontType:read", "frontType:post", "frontType:put",
  65.      *     "placementType:read", "placementType:write",
  66.      *     "unitPageRedirect:read", "unitPageRedirect:post", "unitPageRedirect:put",
  67.      * })
  68.      */
  69.     private ?int $id null;
  70.     /**
  71.      * @ORM\ManyToOne(targetEntity=Complex::class, inversedBy="placementPropertiesApplyFilterSection")
  72.      * @ORM\JoinColumn(nullable=false)
  73.      * @Groups({
  74.      *     "placementProperty:read",
  75.      * })
  76.      * @Assert\NotNull()
  77.      */
  78.     private ?Complex $complex;
  79.     /**
  80.      * @ORM\Column(type="string", length=255)
  81.      * @Groups({
  82.      *     "placementProperty:read",
  83.      *     "complex:read",
  84.      *
  85.      *     "ppsPropertySetting:read",
  86.      *     "ppsPropertySettingsGroup:read",
  87.      *     "ppsDescriptionSection:read",
  88.      *     "ppsHeaderSection:read",
  89.      *     "placementPageSetup:read",
  90.      *     "paymentPlan:read",
  91.      *
  92.      *     "propertySetting:read",
  93.      *     "subView:read",
  94.      *     "view:read",
  95.      *     "frontConfig:read",
  96.      *     "frontType:read",
  97.      *     "placementType:read",
  98.      *     "unitPageRedirect:read",
  99.      *
  100.      * })
  101.      */
  102.     private string $systemName;
  103.     /**
  104.      * @ORM\Column(type="json", nullable=true)
  105.      * @Groups({
  106.      *     "placementProperty:read",
  107.      *     "complex:read",
  108.      *
  109.      *     "ppsPropertySetting:read", "ppsPropertySetting:write",
  110.      *     "ppsPropertySettingsGroup:read", "ppsPropertySettingsGroup:write",
  111.      *     "ppsDescriptionSection:read", "ppsDescriptionSection:write",
  112.      *     "ppsHeaderSection:read", "ppsHeaderSection:write",
  113.      *     "placementPageSetup:read", "placementPageSetup:write", "placementPageSetup:post",
  114.      *     "paymentPlan:read",
  115.      *
  116.      *     "propertySetting:read",
  117.      *     "subView:read",
  118.      *     "view:read",
  119.      *     "frontConfig:read",
  120.      *     "frontType:read",
  121.      *     "placementType:read",
  122.      *     "unitPageRedirect:read",
  123.      * })
  124.      * @JsonLanguageConstraint()
  125.      */
  126.     private ?array $translates null;
  127.     /**
  128.      * @var Collection
  129.      * @ORM\OneToMany(targetEntity=SystemValueInfo::class, mappedBy="placementProperty", orphanRemoval=true, cascade={"remove"})
  130.      */
  131.     private Collection $placementPdfPaymentPlanSystemValueInfos;
  132.     /**
  133.      * @var Collection
  134.      * @ORM\OneToMany(targetEntity=PaymentPlan::class, mappedBy="uniqueUnitName")
  135.      */
  136.     private Collection $paymantPlans;
  137.     public static array $placementPropertiesList = [
  138.         'additionalAdvantage',
  139.         'additionalCondition',
  140.         'balconyArea',
  141.         'bathrooms',
  142.         'bedrooms',
  143.         'floors.numeration',
  144.         'house.numeration',
  145.         'livingArea',
  146.         'note',
  147.         'numeration',
  148.         'placementExplications.area',
  149.         'placementStatus.crosstableName',
  150.         'placementStatus.moduleName',
  151.         'placementStatus.name',
  152.         'placementType.title',
  153.         'planningType',
  154.         'pricePerSqM',
  155.         'pricePerSqMAlternative',
  156.         'rooms',
  157.         'row0',
  158.         'row1',
  159.         'row2',
  160.         'row3',
  161.         'row4',
  162.         'row5',
  163.         'row6',
  164.         'row7',
  165.         'row8',
  166.         'row9',
  167.         'section.numeration',
  168.         'tag',
  169.         'totalArea',
  170.         'totalPrice',
  171.         'totalPriceAlternative',
  172.     ];
  173.     public static array $newNamesToOldNames = [
  174.         'house.numeration' =>'placement.house',
  175.         'section.numeration' =>'placement.section',
  176.         'floors.numeration' =>'placement.floor',
  177.         'numeration' =>'placement.numeration',
  178.         'totalArea' =>'placement.total_area',
  179.         'livingArea' =>'placement.living_area',
  180.         'balconyArea' =>'placement.balcony_area',
  181.         'rooms' =>'placement.rooms',
  182.         'bedrooms' =>'placement.bedrooms',
  183.         'bathrooms' =>'placement.bathrooms',
  184.         'totalPrice' =>'placement.total_price',
  185.         'pricePerSqM' =>'placement.price_per_sq_m',
  186.         'placementStatus.name' =>'placement.status',
  187.         'placementStatus.moduleName' =>'placement_status.module_name',
  188.         'placementStatus.crosstableName' =>'placement_status.crosstable_name',
  189.         'tag' =>'placement.tag',
  190.         'note' =>'placement.note',
  191.         'placementType.title' =>'placement.type',
  192.         'planningType' =>'placement.planning_type',
  193.         'additionalAdvantage' =>'placement.additional_advantage',
  194.         'pricePerSqMAlternative' =>'placement.price_per_sq_m_alternative',
  195.         'totalPriceAlternative' =>'placement.total_price_alternative',
  196.         'row0' =>'placement.row0',
  197.         'row1' =>'placement.row1',
  198.         'row2' =>'placement.row2',
  199.         'row3' =>'placement.row3',
  200.         'row4' =>'placement.row4',
  201.         'row5' =>'placement.row5',
  202.         'row6' =>'placement.row6',
  203.         'row7' =>'placement.row7',
  204.         'row8' =>'placement.row8',
  205.         'row9' =>'placement.row9',
  206.         'additionalCondition' =>'placement.additional_condition',
  207.     ];
  208.     /**
  209.      * @ORM\OneToMany(targetEntity=PpsPropertySetting::class, mappedBy="placementProperty", orphanRemoval=true, cascade={"remove"})
  210.      */
  211.     private $ppsPropertySettings;
  212.     /**
  213.      * @ORM\Column(type="string", length=255, nullable=true)
  214.      * @Groups({
  215.      *     "placementProperty:read",
  216.      *     "complex:read",
  217.      *
  218.      *     "ppsPropertySetting:read",
  219.      *     "ppsPropertySettingsGroup:read",
  220.      *     "ppsDescriptionSection:read",
  221.      *     "ppsHeaderSection:read",
  222.      *     "placementPageSetup:read",
  223.      *     "paymentPlan:read",
  224.      *
  225.      *     "propertySetting:read",
  226.      *     "subView:read",
  227.      *     "view:read",
  228.      *     "frontConfig:read",
  229.      *     "frontType:read",
  230.      *     "placementType:read",
  231.      *     "unitPageRedirect:read",
  232.      *
  233.      * })
  234.      */
  235.     private ?string $oldSystemName null;
  236.     public function __construct()
  237.     {
  238.         $this->ppsPropertySettings = new ArrayCollection();
  239.         $this->placementPdfPaymentPlanSystemValueInfos = new ArrayCollection();
  240.     }
  241.     public function getId(): ?int
  242.     {
  243.         return $this->id;
  244.     }
  245.     public function getComplex(): ?Complex
  246.     {
  247.         return $this->complex;
  248.     }
  249.     public function setComplex(?Complex $complex): self
  250.     {
  251.         $this->complex $complex;
  252.         return $this;
  253.     }
  254.     public function getSystemName(): ?string
  255.     {
  256.         return $this->systemName;
  257.     }
  258.     public function setSystemName(string $systemName): self
  259.     {
  260.         $this->systemName $systemName;
  261.         return $this;
  262.     }
  263.     public function getTranslates(): ?array
  264.     {
  265.         return $this->translates;
  266.     }
  267.     public function setTranslates(?array $translates): self
  268.     {
  269.         $this->translates $translates;
  270.         return $this;
  271.     }
  272.     /**
  273.      * @return Collection|PpsPropertySetting[]
  274.      */
  275.     public function getPpsPropertySettings(): Collection
  276.     {
  277.         return $this->ppsPropertySettings;
  278.     }
  279.     public function addPpsPropertySetting(PpsPropertySetting $ppsPropertySetting): self
  280.     {
  281.         if (!$this->ppsPropertySettings->contains($ppsPropertySetting)) {
  282.             $this->ppsPropertySettings[] = $ppsPropertySetting;
  283.             $ppsPropertySetting->setPlacementProperty($this);
  284.         }
  285.         return $this;
  286.     }
  287.     public function removePpsPropertySetting(PpsPropertySetting $ppsPropertySetting): self
  288.     {
  289.         if ($this->ppsPropertySettings->removeElement($ppsPropertySetting)) {
  290.             // set the owning side to null (unless already changed)
  291.             if ($ppsPropertySetting->getPlacementProperty() === $this) {
  292.                 $ppsPropertySetting->setPlacementProperty(null);
  293.             }
  294.         }
  295.         return $this;
  296.     }
  297.     public function getOldSystemName(): ?string
  298.     {
  299.         return $this->oldSystemName;
  300.     }
  301.     public function setOldSystemName(?string $oldSystemName): self
  302.     {
  303.         $this->oldSystemName $oldSystemName;
  304.         return $this;
  305.     }
  306.     public static function createDefaultProperties(Complex $complex): ArrayCollection {
  307.         $placementPropertiesCollection = new ArrayCollection();
  308.         foreach (static::$placementPropertiesList as $placementPropertyName) {
  309.             $placementPropertyEntity = new PlacementProperty();
  310.             $placementPropertyEntity->setComplex($complex);
  311.             $placementPropertyEntity->setSystemName($placementPropertyName);
  312.             if (isset(self::$newNamesToOldNames[$placementPropertyName]))
  313.                 $placementPropertyEntity->setOldSystemName(self::$newNamesToOldNames[$placementPropertyName]);
  314.             $placementPropertiesCollection[] = $placementPropertyEntity;
  315.         }
  316.         return $placementPropertiesCollection;
  317.     }
  318.     public function getPlacementPdfPaymentPlanSystemValueInfos(): Collection
  319.     {
  320.         return $this->placementPdfPaymentPlanSystemValueInfos;
  321.     }
  322.     public function addPlacementPdfPaymentPlanSystemValueInfo(SystemValueInfo $systemValueInfo): self
  323.     {
  324.         if (!$this->placementPdfPaymentPlanSystemValueInfos->contains($systemValueInfo)) {
  325.             $this->placementPdfPaymentPlanSystemValueInfos[] = $systemValueInfo;
  326.             $systemValueInfo->setPlacementProperty($this);
  327.         }
  328.         return $this;
  329.     }
  330.     public function removePlacementPdfPaymentPlanSystemValueInfo(SystemValueInfo $systemValueInfo): self
  331.     {
  332.         if ($this->placementPdfPaymentPlanSystemValueInfos->removeElement($systemValueInfo)) {
  333.             // set the owning side to null (unless already changed)
  334.             if ($systemValueInfo->getPlacementProperty() === $this) {
  335.                 $systemValueInfo->setPlacementProperty(null);
  336.             }
  337.         }
  338.         return $this;
  339.     }
  340. }