src/Entity/Building.php line 34

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use DateTime;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. use Doctrine\Common\Annotations\Annotation\IgnoreAnnotation;
  10. use Symfony\Component\Serializer\Annotation\Ignore;
  11. /**
  12.  * Building
  13.  *
  14.  * @ORM\Table(
  15.  *     name="building",
  16.  *     uniqueConstraints={@ORM\UniqueConstraint(name="uniq_user_id_building_code", columns={"user_id","code"})},
  17.  *     indexes={@ORM\Index(columns={"address"})}
  18.  * )
  19.  *
  20.  * @ORM\Entity(repositoryClass="App\Repository\BuildingRepository")
  21.  *
  22.  * @UniqueEntity(
  23.  *     fields={"code", "user"},
  24.  *     errorPath="code",
  25.  *     message="Ovaj kod zgrade je već u upotrebi."
  26.  * )
  27.  *
  28.  * @IgnoreAnnotation("Serializer\ExclusionPolicy")
  29.  *
  30.  */
  31. class Building
  32. {
  33.     public const PROFESSIONAL_MANAGEMENT 0;
  34.     public const COMPULSORY_MANAGEMENT 1;
  35.     public const TENANT_MANAGEMENT 2;
  36.     /**
  37.      * @var array<string>
  38.      */
  39.     #[Ignore]
  40.     public static array $DATATABLE_ORDER = [
  41.         'code',
  42.         'address',
  43.         'type',
  44.         'flats',
  45.         'buildingSize',
  46.         'population',
  47.         'constructionYear',
  48.         'comment',
  49.         'management',
  50.         'elevator'
  51.     ];
  52.     /**
  53.      * @ORM\Column(name="id", type="integer")
  54.      * @ORM\Id
  55.      * @ORM\GeneratedValue(strategy="AUTO")
  56.      */
  57.     private int $id;
  58.     /**
  59.      * @ORM\Column(name="comment", type="string", length=512, nullable=true)
  60.      */
  61.     private string|null $comment;
  62.     /**
  63.      * @ORM\Column(name="created_at", type="datetime", nullable=true)
  64.      */
  65.     private DateTime|null $createdAt;
  66.     /**
  67.      * @ORM\Column(name="updated_at", type="datetime", nullable=true)
  68.      */
  69.     private DateTime|null $updatedAt;
  70.     /**
  71.      * @Assert\Length(
  72.      *      min = 2,
  73.      *      max = 7,
  74.      *      minMessage = "Kod zgrade treba da ima minimum {{ limit }} karaktera.",
  75.      *      maxMessage = "Kod zgrade treba da ima maksimalno {{ limit }} karaktera."
  76.      * )
  77.      * @Assert\NotBlank()
  78.      *
  79.      * @ORM\Column(name="code", type="string", length=64, nullable=true)
  80.      */
  81.     private string|null $code;
  82.     /**
  83.      * @ORM\Column(name="address", type="string", length=255, nullable=true)
  84.      */
  85.     private string|null $address;
  86.     /**
  87.      * @ORM\Column(name="mat_id", type="string", length=64, nullable=true)
  88.      */
  89.     private string|null $matId;
  90.     /**
  91.      * @ORM\Column(name="pib", type="string", length=64, nullable=true)
  92.      */
  93.     private string|null $pib;
  94.     /**
  95.      * @ORM\Column(name="startingMoney", type="float", options={"default" : 0.0}, nullable=true)
  96.      */
  97.     private float|null $startingMoney;
  98.     /**
  99.      * @ORM\Column(name="bank_account", type="string", length=128, nullable=true)
  100.      * @Assert\NotBlank()
  101.      */
  102.     private string|null $bankAccount;
  103.     /**
  104.      * @ORM\Column(name="flats", type="integer", options={"default" : 0}, nullable=true)
  105.      */
  106.     private int|null $flats;
  107.     /**
  108.      * @ORM\Column(name="building_size", type="float", options={"default" : 0.0}, nullable=true)
  109.      */
  110.     private float|null $buildingSize;
  111.     /**
  112.      * @ORM\Column(name="population", type="integer", options={"default" : 0}, nullable=true)
  113.      */
  114.     private int|null $population;
  115.     /**
  116.      *
  117.      * @ORM\ManyToOne(targetEntity="App\Entity\User", cascade={"persist"})
  118.      * @ORM\JoinColumns({
  119.      *   @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
  120.      * })
  121.      */
  122.     #[Ignore]
  123.     private User $user;
  124.     /**
  125.      * @Assert\NotBlank()
  126.      *
  127.      * @ORM\Column(name="post_code", type="string", length=64, nullable=true)
  128.      */
  129.     #[Ignore]
  130.     private string|null $postCode '';
  131.     /**
  132.      * @Assert\NotBlank()
  133.      *
  134.      * @ORM\Column(name="city", type="string", length=64, nullable=true)
  135.      */
  136.     private string|null $city '';
  137.     /**
  138.      * @Assert\NotBlank()
  139.      *
  140.      * @ORM\Column(name="municipality", type="string", length=64, nullable=true)
  141.      */
  142.     private string|null $municipality '';
  143.     /**
  144.      * @ORM\Column(name="type", type="integer", nullable=true, options={"default" : 1})
  145.      */
  146.     private int|null $type;
  147.     /**
  148.      * @var Collection<int, Equipment>
  149.      * @ORM\OneToMany(targetEntity="Equipment", mappedBy="building")
  150.      */
  151.     #[Ignore]
  152.     private Collection $equipment;
  153.     /**
  154.      * @var Collection<int, BuildingDictionary>
  155.      * @ORM\OneToMany(targetEntity="BuildingDictionary", mappedBy="building", cascade={"remove"})
  156.      */
  157.     #[Ignore]
  158.     private Collection $buildingDictionaries;
  159.     /**
  160.      * @ORM\ManyToOne(targetEntity="App\Entity\Building", cascade={"persist"})
  161.      * @ORM\JoinColumns({
  162.      *   @ORM\JoinColumn(name="building_id_bs", referencedColumnName="id", nullable=true, onDelete="CASCADE")
  163.      * })
  164.      */
  165.     #[Ignore]
  166.     private Building|null $buildingIdBs;
  167.     /**
  168.      * @Assert\Email(message = "The email '{{ value }}' is not a valid email.")
  169.      *
  170.      * @ORM\Column(name="email", type="string", nullable=true)
  171.      */
  172.     private string|null $email null;
  173.     /**
  174.      *
  175.      * @ORM\OneToOne(targetEntity="Flat")
  176.      * @ORM\JoinColumns({
  177.      * @ORM\JoinColumn(name="main_flat_id", referencedColumnName="id", nullable=true)
  178.      * })
  179.      */
  180.     #[Ignore]
  181.     private Flat|null $mainFlat;
  182.     /**
  183.      * @ORM\Column(name="construction_year", type="string", length=64, nullable=true)
  184.      */
  185.     private string|null $constructionYear;
  186.     /**
  187.      * @ORM\Column(name="active_status", type="integer", nullable=false, options={"default" : 1})
  188.      */
  189.     private int $activeStatus;
  190.     /**
  191.      * @ORM\Column(name="createdBy", type="string", nullable=true)
  192.      */
  193.     private string|null $createdBy;
  194.     /**
  195.      * @ORM\Column(name="enableFlatUserCreate", type="boolean",  options={"default" : false})
  196.      */
  197.     private bool $enableFlatUserCreate false;
  198.     /**
  199.      * @ORM\Column(name="elevator", type="integer", nullable=true, options={"default" : null})
  200.      */
  201.     private int|null $elevator;
  202.     /**
  203.      * @ORM\Column(name="building_servicing", type="string", length=64, nullable=true, options={"default" : null})
  204.      */
  205.     private string|null $buildingServicing;
  206.     /**
  207.      * @ORM\Column (name="management", type="integer", nullable=true)
  208.      */
  209.     private int|null $management;
  210.     /**
  211.      * @return string
  212.      */
  213.     public function getCreatedBy(): string
  214.     {
  215.         return $this->createdBy;
  216.     }
  217.     public function __construct()
  218.     {
  219.         $this->equipment = new ArrayCollection();
  220.         $this->buildingDictionaries = new ArrayCollection();
  221.     }
  222.     /**
  223.      * @return bool
  224.      */
  225.     public function isEnableFlatUserCreate(): bool
  226.     {
  227.         return $this->enableFlatUserCreate;
  228.     }
  229.     /**
  230.      * @param bool $enableFlatUserCreate
  231.      */
  232.     public function setEnableFlatUserCreate(bool $enableFlatUserCreate): void
  233.     {
  234.         $this->enableFlatUserCreate $enableFlatUserCreate;
  235.     }
  236.     /**
  237.      * @return Flat|null
  238.      */
  239.     public function getMainFlat(): ?Flat
  240.     {
  241.         return $this->mainFlat;
  242.     }
  243.     /**
  244.      * @param Flat|null $mainFlat
  245.      */
  246.     public function setMainFlat(?Flat $mainFlat): void
  247.     {
  248.         $this->mainFlat $mainFlat;
  249.     }
  250.     /**
  251.      * @return float|null
  252.      */
  253.     public function getStartingMoney(): ?float
  254.     {
  255.         return $this->startingMoney;
  256.     }
  257.     /**
  258.      * @param float|null $startingMoney
  259.      */
  260.     public function setStartingMoney(?float $startingMoney): void
  261.     {
  262.         $this->startingMoney $startingMoney;
  263.     }
  264.     /**
  265.      * @return Collection<int, Equipment>
  266.      */
  267.     public function getEquipment(): Collection
  268.     {
  269.         return $this->equipment;
  270.     }
  271.     /**
  272.      * @param Equipment $equip
  273.      * @return void
  274.      */
  275.     public function setEquipment(Equipment $equip): void
  276.     {
  277.         $this->equipment[] = $equip;
  278.     }
  279.     /**
  280.      * @return Collection<int, BuildingDictionary>
  281.      */
  282.     #[Ignore]
  283.     public function getBuildingDictionaries(): Collection
  284.     {
  285.         return $this->buildingDictionaries;
  286.     }
  287.     /**
  288.      * @param BuildingDictionary $buildingDictionary
  289.      * @return void
  290.      */
  291.     #[Ignore]
  292.     public function setBuildingDictionary(BuildingDictionary $buildingDictionary): void
  293.     {
  294.         $this->buildingDictionaries[] = $buildingDictionary;
  295.     }
  296.     /**
  297.      * Get id
  298.      *
  299.      * @return int
  300.      */
  301.     public function getId(): int
  302.     {
  303.         return $this->id;
  304.     }
  305.     /**
  306.      * @param string|null $comment
  307.      *
  308.      * @return $this
  309.      */
  310.     public function setComment(?string $comment): self
  311.     {
  312.         $this->comment $comment;
  313.         return $this;
  314.     }
  315.     /**
  316.      * Get comment
  317.      *
  318.      * @return string|null
  319.      */
  320.     public function getComment(): ?string
  321.     {
  322.         return $this->comment;
  323.     }
  324.     /**
  325.      * @return string|null
  326.      */
  327.     public function getPostCode(): ?string
  328.     {
  329.         return $this->postCode;
  330.     }
  331.     /**
  332.      * @param string|null $postCode
  333.      */
  334.     public function setPostCode(?string $postCode): void
  335.     {
  336.         $this->postCode $postCode;
  337.     }
  338.     /**
  339.      * @return string|null
  340.      */
  341.     public function getCity(): ?string
  342.     {
  343.         return $this->city;
  344.     }
  345.     /**
  346.      * @param string|null $city
  347.      */
  348.     public function setCity(?string $city): void
  349.     {
  350.         $this->city $city;
  351.     }
  352.     /**
  353.      * @return string|null
  354.      */
  355.     public function getMunicipality(): ?string
  356.     {
  357.         return $this->municipality;
  358.     }
  359.     /**
  360.      * @param string|null $municipality
  361.      */
  362.     public function setMunicipality(?string $municipality): void
  363.     {
  364.         $this->municipality $municipality;
  365.     }
  366.     /**
  367.      * Set address
  368.      *
  369.      * @param string|null $address
  370.      *
  371.      * @return Building
  372.      */
  373.     public function setAddress(?string $address): Building
  374.     {
  375.         $this->address $address;
  376.         return $this;
  377.     }
  378.     /**
  379.      * @return Building|null
  380.      */
  381.     public function getBuildingIdBs(): ?Building
  382.     {
  383.         return $this->buildingIdBs;
  384.     }
  385.     /**
  386.      * @param Building|null $buildingIdBs
  387.      */
  388.     public function setBuildingIdBs(?Building $buildingIdBs): void
  389.     {
  390.         $this->buildingIdBs $buildingIdBs;
  391.     }
  392.     /**
  393.      * Get address
  394.      *
  395.      * @return string|null
  396.      */
  397.     public function getAddress(): ?string
  398.     {
  399.         return $this->address;
  400.     }
  401.     /**
  402.      * Set flats
  403.      *
  404.      * @param int|null $flats
  405.      *
  406.      * @return Building
  407.      */
  408.     public function setFlats(?int $flats): Building
  409.     {
  410.         $this->flats $flats;
  411.         return $this;
  412.     }
  413.     /**
  414.      * Get flats
  415.      *
  416.      * @return int|null
  417.      */
  418.     public function getFlats(): ?int
  419.     {
  420.         return $this->flats;
  421.     }
  422.     /**
  423.      * @param float|null $buildingSize
  424.      *
  425.      * @return $this
  426.      */
  427.     public function setBuildingSize(?float $buildingSize): self
  428.     {
  429.         $this->buildingSize $buildingSize;
  430.         return $this;
  431.     }
  432.     /**
  433.      * Get population
  434.      *
  435.      * @return int|null
  436.      */
  437.     public function getPopulation(): ?int
  438.     {
  439.         return $this->population;
  440.     }
  441.     /**
  442.      * Set pupulation
  443.      *
  444.      * @param int|null $population
  445.      *
  446.      * @return Building
  447.      */
  448.     public function setPopulation(?int $population): Building
  449.     {
  450.         $this->population $population;
  451.         return $this;
  452.     }
  453.     /**
  454.      * Get buildingSize
  455.      *
  456.      * @return float|null
  457.      */
  458.     public function getBuildingSize(): ?float
  459.     {
  460.         return $this->buildingSize;
  461.     }
  462.     /**
  463.      * @return User
  464.      */
  465.     public function getUser(): User
  466.     {
  467.         return $this->user;
  468.     }
  469.     /**
  470.      * @param User $user
  471.      */
  472.     public function setUser(User $user): void
  473.     {
  474.         $this->user $user;
  475.         if (empty($this->createdBy)) {
  476.             $this->createdBy $user->getCreatedByValue();
  477.         }
  478.     }
  479.     /**
  480.      * @return int|null
  481.      */
  482.     public function getType(): ?int
  483.     {
  484.         return $this->type;
  485.     }
  486.     /**
  487.      * @param int|null $type
  488.      */
  489.     public function setType(?int $type): void
  490.     {
  491.         $this->type $type;
  492.     }
  493.     /**
  494.      * @param int $increment
  495.      */
  496.     public function incrementPopulation(int $increment): void
  497.     {
  498.         $this->population $this->population $increment;
  499.     }
  500.     /**
  501.      * @param int $decrement
  502.      */
  503.     public function decrementPopulation(int $decrement): void
  504.     {
  505.         $this->population $this->population $decrement;
  506.     }
  507.     /**
  508.      * @param int|float $decrement
  509.      */
  510.     public function decrementBuildingSize(int|float $decrement): void
  511.     {
  512.         $this->buildingSize -= $decrement;
  513.     }
  514.     /**
  515.      * @param int $changeSize
  516.      */
  517.     public function changeSumSize(int $changeSize): void
  518.     {
  519.         $this->buildingSize $this->buildingSize $changeSize;
  520.     }
  521.     /**
  522.      * Set code
  523.      *
  524.      * @param string|null $code
  525.      *
  526.      * @return Building
  527.      */
  528.     public function setCode(?string $code): self
  529.     {
  530.         $this->code $code;
  531.         return $this;
  532.     }
  533.     /**
  534.      * Get code
  535.      *
  536.      * @return string|null
  537.      */
  538.     public function getCode(): ?string
  539.     {
  540.         return $this->code;
  541.     }
  542.     /**
  543.      * Set pib
  544.      *
  545.      * @param string|null $pib
  546.      *
  547.      * @return Building
  548.      */
  549.     public function setPib(?string $pib): self
  550.     {
  551.         $this->pib $pib;
  552.         return $this;
  553.     }
  554.     /**
  555.      * Get code
  556.      *
  557.      * @return string|null
  558.      */
  559.     public function getPib(): ?string
  560.     {
  561.         return $this->pib;
  562.     }
  563.     /**
  564.      * Set matId
  565.      *
  566.      * @param string|null $matId
  567.      *
  568.      * @return Building
  569.      */
  570.     public function setMatId(?string $matId): Building
  571.     {
  572.         $this->matId $matId;
  573.         return $this;
  574.     }
  575.     /**
  576.      * Get matId
  577.      *
  578.      * @return string|null
  579.      */
  580.     public function getMatId(): ?string
  581.     {
  582.         return $this->matId;
  583.     }
  584.     /**
  585.      * @return string|null
  586.      */
  587.     public function getEmail(): ?string
  588.     {
  589.         return $this->email;
  590.     }
  591.     /**
  592.      * @param string|null $email
  593.      */
  594.     public function setEmail(?string $email): void
  595.     {
  596.         $this->email $email;
  597.     }
  598.     /**
  599.      * Set bankAccount
  600.      *
  601.      * @param string|null $bankAccount
  602.      *
  603.      * @return Building
  604.      */
  605.     public function setBankAccount(?string $bankAccount): Building
  606.     {
  607.         $this->bankAccount $bankAccount;
  608.         return $this;
  609.     }
  610.     /**
  611.      * Get bankAccount
  612.      *
  613.      * @return string|null
  614.      */
  615.     public function getBankAccount(): ?string
  616.     {
  617.         return $this->bankAccount;
  618.     }
  619.     /**
  620.      *
  621.      */
  622.     public function incrementFlatsNumber(): void
  623.     {
  624.         $this->flats++;
  625.     }
  626.     /**
  627.      *
  628.      */
  629.     public function decrementFlatsNumber(): void
  630.     {
  631.         $this->flats--;
  632.     }
  633.     public function secretBillNumber(): string
  634.     {
  635.         return sprintf("%s%s"mb_substr($this->getAddress(), 02), $this->getId());
  636.     }
  637.     /**
  638.      * @return DateTime|null
  639.      */
  640.     public function getCreatedAt(): ?DateTime
  641.     {
  642.         return $this->createdAt;
  643.     }
  644.     /**
  645.      * @param DateTime|null $createdAt
  646.      */
  647.     public function setCreatedAt(?DateTime $createdAt): void
  648.     {
  649.         $this->createdAt $createdAt;
  650.     }
  651.     /**
  652.      * @return DateTime|null
  653.      */
  654.     public function getUpdatedAt(): ?DateTime
  655.     {
  656.         return $this->updatedAt;
  657.     }
  658.     /**
  659.      * @param DateTime|null $updatedAt
  660.      */
  661.     public function setUpdatedAt(?DateTime $updatedAt): void
  662.     {
  663.         $this->updatedAt $updatedAt;
  664.     }
  665.     /**
  666.      * @return string|null
  667.      */
  668.     public function getConstructionYear(): ?string
  669.     {
  670.         return $this->constructionYear;
  671.     }
  672.     /**
  673.      * @param string|null $constructionYear
  674.      */
  675.     public function setConstructionYear(?string $constructionYear): void
  676.     {
  677.         $this->constructionYear $constructionYear;
  678.     }
  679.     /**
  680.      * @return int
  681.      */
  682.     public function getActiveStatus(): int
  683.     {
  684.         return $this->activeStatus;
  685.     }
  686.     /**
  687.      * @param int $activeStatus
  688.      */
  689.     public function setActiveStatus(int $activeStatus): void
  690.     {
  691.         $this->activeStatus $activeStatus;
  692.     }
  693.     /**
  694.      * @return int|null
  695.      */
  696.     public function getElevator(): ?int
  697.     {
  698.         return $this->elevator;
  699.     }
  700.     /**
  701.      * @param int|null $elevator
  702.      */
  703.     public function setElevator(?int $elevator): void
  704.     {
  705.         $this->elevator $elevator;
  706.     }
  707.     /**
  708.      * @return string|null
  709.      */
  710.     public function getBuildingServicing(): ?string
  711.     {
  712.         return $this->buildingServicing;
  713.     }
  714.     /**
  715.      * @param string|null $buildingServicing
  716.      */
  717.     public function setBuildingServicing(?string $buildingServicing): void
  718.     {
  719.         $this->buildingServicing $buildingServicing;
  720.     }
  721.     /**
  722.      * @return int|null
  723.      */
  724.     public function isManagement(): ?int
  725.     {
  726.         return $this->management;
  727.     }
  728.     /**
  729.      * @param int|null $management
  730.      */
  731.     public function setManagement(?int $management): void
  732.     {
  733.         $this->management $management;
  734.     }
  735.     public function __toString()
  736.     {
  737.         return (string) $this->getAddress();
  738.     }
  739. }