<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use App\Entity\NetHunt\NetHuntOpportunityPlacementMapping;
use App\Entity\Placement\Pdf\PaymentPlan\PaymentPlan;
use App\Entity\Placement\Pdf\PaymentPlan\UnitInfo\SystemValueInfo;
use App\Repository\PlacementPropertyRepository;
use App\Validator\Constraint\JsonLanguageConstraint;
use App\Validator\Constraint\PlacementProperty\PlacementPropertyMainConstraint;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ApiResource(
* normalizationContext={"groups"={"placementProperty:read"}, "skip_null_values"=false, "enable_max_depth"=true},
* denormalizationContext={"groups"={"placementProperty:write"}, "enable_max_depth"=true}
* )
* @ORM\Entity(repositoryClass=PlacementPropertyRepository::class)
* @ORM\Table(
* indexes={
* @ORM\Index(
* columns={"system_name"}
* ),
* },
* uniqueConstraints={
* @ORM\UniqueConstraint(
* columns={"system_name", "complex_id"}
* )
* }
* )
*
* @ApiFilter(SearchFilter::class, properties={
* "complex": "exact",
* "systemName": "exact"
* })
*
* @PlacementPropertyMainConstraint
*/
class PlacementProperty
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({
* "placementProperty:read",
* "complex:read", "complex:write",
*
* "ppsPropertySetting:read",
* "ppsPropertySettingsGroup:read",
* "ppsDescriptionSection:read",
* "ppsHeaderSection:read",
* "placementPageSetup:read",
* "paymentPlan:read", "paymentPlan:post", "paymentPlan:put",
*
* "propertySetting:read", "propertySetting:post", "propertySetting:put",
* "subView:read", "subView:post", "subView:put",
* "view:read", "view:post", "view:put",
* "frontConfig:read", "frontConfig:post", "frontConfig:put",
* "frontType:read", "frontType:post", "frontType:put",
* "placementType:read", "placementType:write",
* "unitPageRedirect:read", "unitPageRedirect:post", "unitPageRedirect:put",
* })
*/
private ?int $id = null;
/**
* @ORM\ManyToOne(targetEntity=Complex::class, inversedBy="placementPropertiesApplyFilterSection")
* @ORM\JoinColumn(nullable=false)
* @Groups({
* "placementProperty:read",
* })
* @Assert\NotNull()
*/
private ?Complex $complex;
/**
* @ORM\Column(type="string", length=255)
* @Groups({
* "placementProperty:read",
* "complex:read",
*
* "ppsPropertySetting:read",
* "ppsPropertySettingsGroup:read",
* "ppsDescriptionSection:read",
* "ppsHeaderSection:read",
* "placementPageSetup:read",
* "paymentPlan:read",
*
* "propertySetting:read",
* "subView:read",
* "view:read",
* "frontConfig:read",
* "frontType:read",
* "placementType:read",
* "unitPageRedirect:read",
*
* })
*/
private string $systemName;
/**
* @ORM\Column(type="json", nullable=true)
* @Groups({
* "placementProperty:read",
* "complex:read",
*
* "ppsPropertySetting:read", "ppsPropertySetting:write",
* "ppsPropertySettingsGroup:read", "ppsPropertySettingsGroup:write",
* "ppsDescriptionSection:read", "ppsDescriptionSection:write",
* "ppsHeaderSection:read", "ppsHeaderSection:write",
* "placementPageSetup:read", "placementPageSetup:write", "placementPageSetup:post",
* "paymentPlan:read",
*
* "propertySetting:read",
* "subView:read",
* "view:read",
* "frontConfig:read",
* "frontType:read",
* "placementType:read",
* "unitPageRedirect:read",
* })
* @JsonLanguageConstraint()
*/
private ?array $translates = null;
/**
* @var Collection
* @ORM\OneToMany(targetEntity=SystemValueInfo::class, mappedBy="placementProperty", orphanRemoval=true, cascade={"remove"})
*/
private Collection $placementPdfPaymentPlanSystemValueInfos;
/**
* @var Collection
* @ORM\OneToMany(targetEntity=PaymentPlan::class, mappedBy="uniqueUnitName")
*/
private Collection $paymantPlans;
public static array $placementPropertiesList = [
'additionalAdvantage',
'additionalCondition',
'balconyArea',
'bathrooms',
'bedrooms',
'floors.numeration',
'house.numeration',
'livingArea',
'note',
'numeration',
'placementExplications.area',
'placementStatus.crosstableName',
'placementStatus.moduleName',
'placementStatus.name',
'placementType.title',
'planningType',
'pricePerSqM',
'pricePerSqMAlternative',
'rooms',
'row0',
'row1',
'row2',
'row3',
'row4',
'row5',
'row6',
'row7',
'row8',
'row9',
'section.numeration',
'tag',
'totalArea',
'totalPrice',
'totalPriceAlternative',
];
public static array $newNamesToOldNames = [
'house.numeration' =>'placement.house',
'section.numeration' =>'placement.section',
'floors.numeration' =>'placement.floor',
'numeration' =>'placement.numeration',
'totalArea' =>'placement.total_area',
'livingArea' =>'placement.living_area',
'balconyArea' =>'placement.balcony_area',
'rooms' =>'placement.rooms',
'bedrooms' =>'placement.bedrooms',
'bathrooms' =>'placement.bathrooms',
'totalPrice' =>'placement.total_price',
'pricePerSqM' =>'placement.price_per_sq_m',
'placementStatus.name' =>'placement.status',
'placementStatus.moduleName' =>'placement_status.module_name',
'placementStatus.crosstableName' =>'placement_status.crosstable_name',
'tag' =>'placement.tag',
'note' =>'placement.note',
'placementType.title' =>'placement.type',
'planningType' =>'placement.planning_type',
'additionalAdvantage' =>'placement.additional_advantage',
'pricePerSqMAlternative' =>'placement.price_per_sq_m_alternative',
'totalPriceAlternative' =>'placement.total_price_alternative',
'row0' =>'placement.row0',
'row1' =>'placement.row1',
'row2' =>'placement.row2',
'row3' =>'placement.row3',
'row4' =>'placement.row4',
'row5' =>'placement.row5',
'row6' =>'placement.row6',
'row7' =>'placement.row7',
'row8' =>'placement.row8',
'row9' =>'placement.row9',
'additionalCondition' =>'placement.additional_condition',
];
/**
* @ORM\OneToMany(targetEntity=PpsPropertySetting::class, mappedBy="placementProperty", orphanRemoval=true, cascade={"remove"})
*/
private $ppsPropertySettings;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({
* "placementProperty:read",
* "complex:read",
*
* "ppsPropertySetting:read",
* "ppsPropertySettingsGroup:read",
* "ppsDescriptionSection:read",
* "ppsHeaderSection:read",
* "placementPageSetup:read",
* "paymentPlan:read",
*
* "propertySetting:read",
* "subView:read",
* "view:read",
* "frontConfig:read",
* "frontType:read",
* "placementType:read",
* "unitPageRedirect:read",
*
* })
*/
private ?string $oldSystemName = null;
public function __construct()
{
$this->ppsPropertySettings = new ArrayCollection();
$this->placementPdfPaymentPlanSystemValueInfos = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getComplex(): ?Complex
{
return $this->complex;
}
public function setComplex(?Complex $complex): self
{
$this->complex = $complex;
return $this;
}
public function getSystemName(): ?string
{
return $this->systemName;
}
public function setSystemName(string $systemName): self
{
$this->systemName = $systemName;
return $this;
}
public function getTranslates(): ?array
{
return $this->translates;
}
public function setTranslates(?array $translates): self
{
$this->translates = $translates;
return $this;
}
/**
* @return Collection|PpsPropertySetting[]
*/
public function getPpsPropertySettings(): Collection
{
return $this->ppsPropertySettings;
}
public function addPpsPropertySetting(PpsPropertySetting $ppsPropertySetting): self
{
if (!$this->ppsPropertySettings->contains($ppsPropertySetting)) {
$this->ppsPropertySettings[] = $ppsPropertySetting;
$ppsPropertySetting->setPlacementProperty($this);
}
return $this;
}
public function removePpsPropertySetting(PpsPropertySetting $ppsPropertySetting): self
{
if ($this->ppsPropertySettings->removeElement($ppsPropertySetting)) {
// set the owning side to null (unless already changed)
if ($ppsPropertySetting->getPlacementProperty() === $this) {
$ppsPropertySetting->setPlacementProperty(null);
}
}
return $this;
}
public function getOldSystemName(): ?string
{
return $this->oldSystemName;
}
public function setOldSystemName(?string $oldSystemName): self
{
$this->oldSystemName = $oldSystemName;
return $this;
}
public static function createDefaultProperties(Complex $complex): ArrayCollection {
$placementPropertiesCollection = new ArrayCollection();
foreach (static::$placementPropertiesList as $placementPropertyName) {
$placementPropertyEntity = new PlacementProperty();
$placementPropertyEntity->setComplex($complex);
$placementPropertyEntity->setSystemName($placementPropertyName);
if (isset(self::$newNamesToOldNames[$placementPropertyName]))
$placementPropertyEntity->setOldSystemName(self::$newNamesToOldNames[$placementPropertyName]);
$placementPropertiesCollection[] = $placementPropertyEntity;
}
return $placementPropertiesCollection;
}
public function getPlacementPdfPaymentPlanSystemValueInfos(): Collection
{
return $this->placementPdfPaymentPlanSystemValueInfos;
}
public function addPlacementPdfPaymentPlanSystemValueInfo(SystemValueInfo $systemValueInfo): self
{
if (!$this->placementPdfPaymentPlanSystemValueInfos->contains($systemValueInfo)) {
$this->placementPdfPaymentPlanSystemValueInfos[] = $systemValueInfo;
$systemValueInfo->setPlacementProperty($this);
}
return $this;
}
public function removePlacementPdfPaymentPlanSystemValueInfo(SystemValueInfo $systemValueInfo): self
{
if ($this->placementPdfPaymentPlanSystemValueInfos->removeElement($systemValueInfo)) {
// set the owning side to null (unless already changed)
if ($systemValueInfo->getPlacementProperty() === $this) {
$systemValueInfo->setPlacementProperty(null);
}
}
return $this;
}
}