src/Entity/LivingCostStatistics.php line 39

  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\City;
  4. use ApiPlatform\Metadata\Get;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use ApiPlatform\Metadata\ApiFilter;
  7. use App\Entity\LivingCostSubmission;
  8. use ApiPlatform\Metadata\ApiResource;
  9. use ApiPlatform\Metadata\GetCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  13. use App\Repository\LivingCostStatisticsRepository;
  14. use Symfony\Component\Serializer\Annotation\Groups;
  15. #[ORM\Entity(repositoryClassLivingCostStatisticsRepository::class)]
  16. #[ApiResource(
  17.     operations:
  18.         [
  19.             new Get(
  20.                 normalizationContext: [
  21.                     'groups' => [self::SERIALIZATION_GROUP__FULL_DATACity::SERIALIZATION_GROUP__FULL_DATA],
  22.                 ],
  23.             ),
  24.             new GetCollection(
  25.                 normalizationContext: [
  26.                     'groups' => [self::SERIALIZATION_GROUP__FULL_DATACity::SERIALIZATION_GROUP__FULL_DATA],
  27.                 ],
  28.             ),
  29.         ],
  30. )]
  31. #[ApiFilter(SearchFilter::class, properties: [self::CITY_PARAM_NAME => 'exact'])]
  32. /**
  33.  * Contains model for LivingCostStatistics entity.
  34.  */
  35. class LivingCostStatistics
  36. {
  37.     public const GET_RESOURCE_PATH '_api_/living_cost_statistics/{id}{._format}_get';
  38.     //public const GET_COLLECTION_PATH = '/living_cost_statistics';
  39.     public const GET_COLLECTION_PATH '_api_/living_cost_statistics{._format}_get_collection';
  40.     public const CITY_PARAM_NAME 'city.name';
  41.     public const SERIALIZATION_GROUP__IRI_ONLY 'lstat_iri_only';
  42.     public const SERIALIZATION_GROUP__FULL_DATA 'lstat_full_data';
  43.     #[ORM\Id]
  44.     #[ORM\GeneratedValue]
  45.     #[ORM\Column]
  46.     private ?int $id null;
  47.     /** @var  Collection<int, LivingCostSubmission> */
  48.     #[ORM\OneToMany(mappedBy'livingCostStatistics'targetEntityLivingCostSubmission::class, cascade: ['persist'])]
  49.     private Collection $livingCostSubmissions;
  50.     #[ORM\Column]
  51.     #[Groups([self::SERIALIZATION_GROUP__FULL_DATA])]
  52.     private ?int $monthlyLivingCostAvg null;
  53.     #[ORM\Column]
  54.     #[Groups([self::SERIALIZATION_GROUP__FULL_DATA])]
  55.     private ?int $monthlyAccommodationCostAvg null;
  56.     #[ORM\OneToOne(mappedBy'livingCostStatistics'targetEntityCity::class, cascade: ['persist'])]
  57.     #[Groups([self::SERIALIZATION_GROUP__FULL_DATA])]
  58.     private ?City $city null;
  59.     #[ORM\Column]
  60.     #[Groups([self::SERIALIZATION_GROUP__FULL_DATA])]
  61.     private ?int $stayDurationInMonthsAvg null;
  62.     /**
  63.      * Constructor.
  64.      */
  65.     public function __construct()
  66.     {
  67.         $this->livingCostSubmissions = new ArrayCollection();
  68.     }
  69.     /**
  70.      * @return integer|null
  71.      */
  72.     public function getId(): ?int
  73.     {
  74.         return $this->id;
  75.     }
  76.     /**
  77.      * @return Collection<int, LivingCostSubmission>
  78.      */
  79.     public function getLivingCostSubmissions(): Collection
  80.     {
  81.         return $this->livingCostSubmissions;
  82.     }
  83.     /**
  84.      * @param LivingCostSubmission $livingCostSubmission
  85.      *
  86.      * @return self
  87.      */
  88.     public function addLivingCostSubmission(LivingCostSubmission $livingCostSubmission): self
  89.     {
  90.         if (!$this->livingCostSubmissions->contains($livingCostSubmission)) {
  91.             $this->livingCostSubmissions->add($livingCostSubmission);
  92.             $livingCostSubmission->setLivingCostStatistics($this);
  93.         }
  94.         return $this;
  95.     }
  96.     /**
  97.      * @param LivingCostSubmission $livingCostSubmission
  98.      *
  99.      * @return self
  100.      */
  101.     public function removeLivingCostSubmission(LivingCostSubmission $livingCostSubmission): self
  102.     {
  103.         if ($this->livingCostSubmissions->removeElement($livingCostSubmission)) {
  104.             // set the owning side to null (unless already changed)
  105.             if ($livingCostSubmission->getLivingCostStatistics() === $this) {
  106.                 $livingCostSubmission->setLivingCostStatistics(null);
  107.             }
  108.         }
  109.         return $this;
  110.     }
  111.     /**
  112.      * @return integer|null
  113.      */
  114.     public function getMonthlyLivingCostAvg(): ?int
  115.     {
  116.         return $this->monthlyLivingCostAvg;
  117.     }
  118.     /**
  119.      * @param integer $monthlyLivingCostAvg
  120.      *
  121.      * @return self
  122.      */
  123.     public function setMonthlyLivingCostAvg(int $monthlyLivingCostAvg): self
  124.     {
  125.         $this->monthlyLivingCostAvg $monthlyLivingCostAvg;
  126.         return $this;
  127.     }
  128.     /**
  129.      * @return integer|null
  130.      */
  131.     public function getMonthlyAccommodationCostAvg(): ?int
  132.     {
  133.         return $this->monthlyAccommodationCostAvg;
  134.     }
  135.     /**
  136.      * @param integer $monthlyAccommodationCostAvg
  137.      *
  138.      * @return self
  139.      */
  140.     public function setMonthlyAccommodationCostAvg(int $monthlyAccommodationCostAvg): self
  141.     {
  142.         $this->monthlyAccommodationCostAvg $monthlyAccommodationCostAvg;
  143.         return $this;
  144.     }
  145.     /**
  146.      * @return City|null
  147.      */
  148.     public function getCity(): ?City
  149.     {
  150.         return $this->city;
  151.     }
  152.     /**
  153.      * @param City|null $city
  154.      *
  155.      * @return self
  156.      */
  157.     public function setCity(?City $city): self
  158.     {
  159.         // unset the owning side of the relation if necessary
  160.         if (null === $city && null !== $this->city) {
  161.             $this->city->setLivingCostStatistics(null);
  162.         }
  163.         // set the owning side of the relation if necessary
  164.         if (null !== $city && $this !== $city->getLivingCostStatistics()) {
  165.             $city->setLivingCostStatistics($this);
  166.         }
  167.         $this->city $city;
  168.         return $this;
  169.     }
  170.     /**
  171.      * @return integer|null
  172.      */
  173.     public function getStayDurationInMonthsAvg(): ?int
  174.     {
  175.         return $this->stayDurationInMonthsAvg;
  176.     }
  177.     /**
  178.      * @param integer $stayDurationInMonthsAvg
  179.      *
  180.      * @return self
  181.      */
  182.     public function setStayDurationInMonthsAvg(int $stayDurationInMonthsAvg): self
  183.     {
  184.         $this->stayDurationInMonthsAvg $stayDurationInMonthsAvg;
  185.         return $this;
  186.     }
  187. }