src/Entity/LivingCostStatistics.php line 39
<?php
namespace App\Entity;
use App\Entity\City;
use ApiPlatform\Metadata\Get;
use Doctrine\ORM\Mapping as ORM;
use ApiPlatform\Metadata\ApiFilter;
use App\Entity\LivingCostSubmission;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\GetCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use App\Repository\LivingCostStatisticsRepository;
use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\Entity(repositoryClass: LivingCostStatisticsRepository::class)]
#[ApiResource(
operations:
[
new Get(
normalizationContext: [
'groups' => [self::SERIALIZATION_GROUP__FULL_DATA, City::SERIALIZATION_GROUP__FULL_DATA],
],
),
new GetCollection(
normalizationContext: [
'groups' => [self::SERIALIZATION_GROUP__FULL_DATA, City::SERIALIZATION_GROUP__FULL_DATA],
],
),
],
)]
#[ApiFilter(SearchFilter::class, properties: [self::CITY_PARAM_NAME => 'exact'])]
/**
* Contains model for LivingCostStatistics entity.
*/
class LivingCostStatistics
{
public const GET_RESOURCE_PATH = '_api_/living_cost_statistics/{id}{._format}_get';
//public const GET_COLLECTION_PATH = '/living_cost_statistics';
public const GET_COLLECTION_PATH = '_api_/living_cost_statistics{._format}_get_collection';
public const CITY_PARAM_NAME = 'city.name';
public const SERIALIZATION_GROUP__IRI_ONLY = 'lstat_iri_only';
public const SERIALIZATION_GROUP__FULL_DATA = 'lstat_full_data';
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
/** @var Collection<int, LivingCostSubmission> */
#[ORM\OneToMany(mappedBy: 'livingCostStatistics', targetEntity: LivingCostSubmission::class, cascade: ['persist'])]
private Collection $livingCostSubmissions;
#[ORM\Column]
#[Groups([self::SERIALIZATION_GROUP__FULL_DATA])]
private ?int $monthlyLivingCostAvg = null;
#[ORM\Column]
#[Groups([self::SERIALIZATION_GROUP__FULL_DATA])]
private ?int $monthlyAccommodationCostAvg = null;
#[ORM\OneToOne(mappedBy: 'livingCostStatistics', targetEntity: City::class, cascade: ['persist'])]
#[Groups([self::SERIALIZATION_GROUP__FULL_DATA])]
private ?City $city = null;
#[ORM\Column]
#[Groups([self::SERIALIZATION_GROUP__FULL_DATA])]
private ?int $stayDurationInMonthsAvg = null;
/**
* Constructor.
*/
public function __construct()
{
$this->livingCostSubmissions = new ArrayCollection();
}
/**
* @return integer|null
*/
public function getId(): ?int
{
return $this->id;
}
/**
* @return Collection<int, LivingCostSubmission>
*/
public function getLivingCostSubmissions(): Collection
{
return $this->livingCostSubmissions;
}
/**
* @param LivingCostSubmission $livingCostSubmission
*
* @return self
*/
public function addLivingCostSubmission(LivingCostSubmission $livingCostSubmission): self
{
if (!$this->livingCostSubmissions->contains($livingCostSubmission)) {
$this->livingCostSubmissions->add($livingCostSubmission);
$livingCostSubmission->setLivingCostStatistics($this);
}
return $this;
}
/**
* @param LivingCostSubmission $livingCostSubmission
*
* @return self
*/
public function removeLivingCostSubmission(LivingCostSubmission $livingCostSubmission): self
{
if ($this->livingCostSubmissions->removeElement($livingCostSubmission)) {
// set the owning side to null (unless already changed)
if ($livingCostSubmission->getLivingCostStatistics() === $this) {
$livingCostSubmission->setLivingCostStatistics(null);
}
}
return $this;
}
/**
* @return integer|null
*/
public function getMonthlyLivingCostAvg(): ?int
{
return $this->monthlyLivingCostAvg;
}
/**
* @param integer $monthlyLivingCostAvg
*
* @return self
*/
public function setMonthlyLivingCostAvg(int $monthlyLivingCostAvg): self
{
$this->monthlyLivingCostAvg = $monthlyLivingCostAvg;
return $this;
}
/**
* @return integer|null
*/
public function getMonthlyAccommodationCostAvg(): ?int
{
return $this->monthlyAccommodationCostAvg;
}
/**
* @param integer $monthlyAccommodationCostAvg
*
* @return self
*/
public function setMonthlyAccommodationCostAvg(int $monthlyAccommodationCostAvg): self
{
$this->monthlyAccommodationCostAvg = $monthlyAccommodationCostAvg;
return $this;
}
/**
* @return City|null
*/
public function getCity(): ?City
{
return $this->city;
}
/**
* @param City|null $city
*
* @return self
*/
public function setCity(?City $city): self
{
// unset the owning side of the relation if necessary
if (null === $city && null !== $this->city) {
$this->city->setLivingCostStatistics(null);
}
// set the owning side of the relation if necessary
if (null !== $city && $this !== $city->getLivingCostStatistics()) {
$city->setLivingCostStatistics($this);
}
$this->city = $city;
return $this;
}
/**
* @return integer|null
*/
public function getStayDurationInMonthsAvg(): ?int
{
return $this->stayDurationInMonthsAvg;
}
/**
* @param integer $stayDurationInMonthsAvg
*
* @return self
*/
public function setStayDurationInMonthsAvg(int $stayDurationInMonthsAvg): self
{
$this->stayDurationInMonthsAvg = $stayDurationInMonthsAvg;
return $this;
}
}