src/Aqarmap/Bundle/ListingBundle/Entity/Location.php line 50

Open in your IDE?
  1. <?php
  2. namespace Aqarmap\Bundle\ListingBundle\Entity;
  3. use Aqarmap\Bundle\DiscussionBundle\Entity\Discussion;
  4. use Aqarmap\Bundle\ExchangeBundle\Entity\ExchangeRequest;
  5. use Aqarmap\Bundle\ListingBundle\Constant\PhotoTypes;
  6. use Aqarmap\Bundle\NeighborhoodBundle\Entity\LocationCompound;
  7. use Aqarmap\Bundle\NeighborhoodBundle\Entity\LocationStatistics;
  8. use Aqarmap\Bundle\NotifierBundle\Entity\Notifier;
  9. use Aqarmap\Bundle\UserBundle\Constant\UserInterestStatus;
  10. use Aqarmap\Bundle\UserBundle\Entity\UserInterest;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\Common\Collections\Collection;
  13. use Doctrine\Common\Collections\Criteria;
  14. use Doctrine\ORM\Mapping as ORM;
  15. use Gedmo\Mapping\Annotation as Gedmo;
  16. use Gedmo\Translatable\Translatable;
  17. use JMS\Serializer\Annotation as Serializer;
  18. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  19. /**
  20.  * Location.
  21.  *
  22.  * @ORM\Table(name="locations", indexes={
  23.  *
  24.  *    @ORM\Index(columns={"disabled"}),
  25.  *    @ORM\Index(columns={"listings_counter"}),
  26.  *    @ORM\Index(columns={"searchable"}),
  27.  *    @ORM\Index(columns={"synced"}),
  28.  *    @ORM\Index(columns={"lat"}),
  29.  *    @ORM\Index(columns={"lon"}),
  30.  *    @ORM\Index(columns={"root"}),
  31.  *    @ORM\Index(columns={"root", "_left", "_right"}),
  32.  *    @ORM\Index(columns={"home_filter", "is_compound_location", "listing_id"}),
  33.  * })
  34.  *
  35.  * @ORM\Entity(repositoryClass="Aqarmap\Bundle\ListingBundle\Repository\LocationRepository")
  36.  *
  37.  * @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="write_rare")
  38.  *
  39.  * @Gedmo\TranslationEntity(class="Aqarmap\Bundle\ListingBundle\Entity\LocationTranslation")
  40.  *
  41.  * @Gedmo\Tree(type="nested")
  42.  *
  43.  * @Serializer\ExclusionPolicy("all")
  44.  *
  45.  * @UniqueEntity("slug")
  46.  */
  47. class Location implements Translatable
  48. {
  49.     /**
  50.      * @var int
  51.      *
  52.      * @ORM\Column(name="id", type="integer")
  53.      *
  54.      * @ORM\Id
  55.      *
  56.      * @ORM\GeneratedValue(strategy="AUTO")
  57.      *
  58.      * @Serializer\Groups({
  59.      *     "Default", "listingDetails", "List", "MiniList", "Data", "Autocomplete", "Details", "Neighborhood",
  60.      *     "NeighborhoodStatistics", "Discussion", "Exchange", "LocationFlat", "Search", "AutocompleteV3", "DefaultV4",
  61.      *     "SearchV4", "ProjectDetailsV4", "Translation", "SlugResolver", "RelatedListingsV2", "locationListingV2",
  62.      * })
  63.      *
  64.      * @Serializer\Expose
  65.      */
  66.     private $id;
  67.     /**
  68.      * @var string
  69.      *
  70.      * @ORM\Column(name="title", type="string", length=50)
  71.      *
  72.      * @Gedmo\Translatable
  73.      *
  74.      * @Serializer\Groups({
  75.      *     "Default", "listingDetails", "List", "MiniList", "Data", "Details", "Neighborhood", "NeighborhoodStatistics",
  76.      *     "Discussion", "Exchange", "LocationFlat", "Search", "Translation", "SlugResolver", "Autocomplete", "MyLeads",
  77.      * })
  78.      *
  79.      * @Serializer\Expose
  80.      */
  81.     private $title;
  82.     /**
  83.      * @var string
  84.      *
  85.      * @ORM\Column(name="alias", type="string", length=512, nullable=true)
  86.      *
  87.      * @Gedmo\Translatable
  88.      *
  89.      * @Serializer\Groups({"SlugResolver"})
  90.      *
  91.      * @Serializer\Expose
  92.      */
  93.     private $alias;
  94.     /**
  95.      * @var string
  96.      *
  97.      * @ORM\Column(name="description", type="text", length=512, nullable=true)
  98.      *
  99.      * @Gedmo\Translatable
  100.      *
  101.      * @Serializer\Groups({"Neighborhood"})
  102.      *
  103.      * @Serializer\Expose
  104.      */
  105.     private $description;
  106.     /**
  107.      * @Gedmo\Slug(handlers={
  108.      *
  109.      *      @Gedmo\SlugHandler(class="Gedmo\Sluggable\Handler\TreeSlugHandler", options={
  110.      *
  111.      *          @Gedmo\SlugHandlerOption(name="parentRelationField", value="parent"),
  112.      *          @Gedmo\SlugHandlerOption(name="separator", value="/")
  113.      *      })
  114.      * }, fields={"title"})
  115.      *
  116.      * @ORM\Column(length=128, unique=true)
  117.      *
  118.      * @Serializer\Groups({"Default", "listingDetails", "List", "MiniList", "Data", "Details", "Neighborhood", "LocationFlat", "Autocomplete", "AutocompleteV3", "DefaultV4", "SearchV4", "SlugResolver", "RelatedListingsV2"})
  119.      *
  120.      * @Serializer\Expose
  121.      */
  122.     private $slug;
  123.     /**
  124.      * @var float
  125.      *
  126.      * @ORM\Column(name="lat", type="float", nullable=true)
  127.      *
  128.      * @Serializer\Groups({"DataJS"})
  129.      *
  130.      * @Serializer\Since("v2.14")
  131.      *
  132.      * @Serializer\Expose
  133.      */
  134.     private $lat;
  135.     /**
  136.      * @var float
  137.      *
  138.      * @ORM\Column(name="lon", type="float", nullable=true)
  139.      *
  140.      * @Serializer\Groups({"DataJS"})
  141.      *
  142.      * @Serializer\Since("v2.14")
  143.      *
  144.      * @Serializer\Expose
  145.      */
  146.     private $lon;
  147.     /**
  148.      * @var int
  149.      *
  150.      * @ORM\Column(name="zoom", type="smallint", nullable=true)
  151.      *
  152.      * @Serializer\Groups({"DataJS"})
  153.      *
  154.      * @Serializer\Since("v2.14")
  155.      *
  156.      * @Serializer\Expose
  157.      */
  158.     private $zoom;
  159.     /**
  160.      * @var array
  161.      *
  162.      * @ORM\Column(name="coordinates", type="array", nullable=true)
  163.      */
  164.     private $coordinates;
  165.     /**
  166.      * @ORM\Column(type="boolean")
  167.      *
  168.      * @Serializer\Expose
  169.      *
  170.      * @Serializer\Groups({"List", "Data", "Details", "LocationFlat"})
  171.      */
  172.     private $searchable;
  173.     /**
  174.      * @Serializer\Expose
  175.      *
  176.      * @Serializer\Groups({"Neighborhood"})
  177.      *
  178.      * @ORM\Column(name="home_filter", type="boolean")
  179.      */
  180.     private $homeFilter false;
  181.     /**
  182.      * @Serializer\Expose
  183.      *
  184.      * @Serializer\Groups({"Neighborhood"})
  185.      *
  186.      * @ORM\Column(name="statistics_filter", type="boolean")
  187.      */
  188.     private $statisticsFilter false;
  189.     /**
  190.      * @Serializer\Expose
  191.      *
  192.      * @Serializer\Groups({"Neighborhood"})
  193.      *
  194.      * @ORM\Column(name="neighborhood_filter", type="boolean")
  195.      */
  196.     private $neighborhoodFilter false;
  197.     /**
  198.      * @ORM\Column(name="compound_filter", type="boolean")
  199.      */
  200.     private $compoundFilter false;
  201.     /**
  202.      * @ORM\Column(type="boolean")
  203.      *
  204.      * @Serializer\Expose
  205.      *
  206.      * @Serializer\Groups({"List", "Data", "Details", "LocationFlat"})
  207.      */
  208.     private $estimate false;
  209.     /**
  210.      * @ORM\Column(type="boolean")
  211.      *
  212.      * @Serializer\Expose
  213.      *
  214.      * @Serializer\Groups({"DefaultV4"})
  215.      */
  216.     private $disabled false;
  217.     /**
  218.      * @ORM\Column(name="synced", type="boolean")
  219.      */
  220.     private $synced false;
  221.     /**
  222.      * @Gedmo\TreeLevel
  223.      *
  224.      * @ORM\Column(name="level", type="integer")
  225.      *
  226.      * @Serializer\Expose
  227.      *
  228.      * @Serializer\Groups({"List", "Data", "LocationFlat", "DefaultV4", "SlugResolver"})
  229.      */
  230.     private $level;
  231.     /**
  232.      * @Gedmo\TreeLeft
  233.      *
  234.      * @ORM\Column(name="_left", type="integer")
  235.      */
  236.     private $left;
  237.     /**
  238.      * @Gedmo\TreeRight
  239.      *
  240.      * @ORM\Column(name="_right", type="integer")
  241.      */
  242.     private $right;
  243.     /**
  244.      * @Gedmo\TreeRoot
  245.      *
  246.      * @ORM\Column(name="root", type="integer", nullable=true)
  247.      */
  248.     private $root;
  249.     /**
  250.      * @Gedmo\TreeParent
  251.      *
  252.      * @ORM\ManyToOne(targetEntity="Location", inversedBy="children")
  253.      *
  254.      * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE")
  255.      *
  256.      * @Serializer\Expose
  257.      *
  258.      * @Serializer\Groups({"DefaultV4", "SearchV4", "SlugResolver", "RelatedListingsV2", "listingDetails"})
  259.      *
  260.      * @Serializer\MaxDepth(1)
  261.      */
  262.     private $parent;
  263.     /**
  264.      * @ORM\OneToMany(targetEntity="Location", mappedBy="parent")
  265.      *
  266.      * @ORM\OrderBy({"left" = "ASC"})
  267.      *
  268.      * @Serializer\Expose
  269.      *
  270.      * @Serializer\Groups({"List"})
  271.      *
  272.      * @Serializer\MaxDepth(2)
  273.      *
  274.      * @Serializer\Accessor(getter="getChildren")
  275.      */
  276.     private $children;
  277.     /**
  278.      * @ORM\ManyToMany(targetEntity="Location", cascade={"persist"})
  279.      *
  280.      * @ORM\JoinTable(
  281.      *      name="locations_nearestby",
  282.      *      joinColumns={@ORM\JoinColumn(name="nearest_location_id", referencedColumnName="id")},
  283.      *      inverseJoinColumns={@ORM\JoinColumn(name="location_id", referencedColumnName="id")}
  284.      * )
  285.      */
  286.     protected $nearestLocations;
  287.     /**
  288.      * @ORM\OneToMany(
  289.      *   targetEntity="LocationTranslation",
  290.      *   mappedBy="object",
  291.      *   cascade={"persist", "remove"},
  292.      * )
  293.      */
  294.     private $translations;
  295.     /**
  296.      * @ORM\OneToMany(targetEntity="Listing", mappedBy="location")
  297.      */
  298.     protected $listings;
  299.     /**
  300.      * @ORM\ManyToMany(targetEntity="PropertyType")
  301.      */
  302.     protected $propertyTypes;
  303.     /**
  304.      * @ORM\OneToMany(targetEntity="Aqarmap\Bundle\CRMBundle\Entity\Company", mappedBy="location")
  305.      */
  306.     protected $companies;
  307.     /**
  308.      * @ORM\OneToMany(targetEntity="LocationSupplyDemand", mappedBy="location")
  309.      */
  310.     protected $locationSupplyDemand;
  311.     /**
  312.      * @ORM\OneToMany(targetEntity="Aqarmap\Bundle\NotifierBundle\Entity\Notifier", mappedBy="location")
  313.      */
  314.     protected $notifiers;
  315.     /**
  316.      * @ORM\OneToMany(targetEntity="Aqarmap\Bundle\UserBundle\Entity\UserInterest", mappedBy="location",fetch="EXTRA_LAZY")
  317.      */
  318.     protected $interests;
  319.     /**
  320.      * @ORM\OneToMany(targetEntity="Rule", mappedBy="location")
  321.      */
  322.     protected $rules;
  323.     /**
  324.      * @Serializer\Expose
  325.      *
  326.      * @Serializer\Groups({"Neighborhood"})
  327.      *
  328.      * @ORM\OneToMany(targetEntity="LocationPhoto", mappedBy="location", cascade={"persist", "remove"})
  329.      **/
  330.     protected $photos;
  331.     /**
  332.      * @Serializer\Expose
  333.      *
  334.      * @Serializer\Groups({"Neighborhood"})
  335.      *
  336.      * @ORM\OneToMany(targetEntity="\Aqarmap\Bundle\NeighborhoodBundle\Entity\LocationStatistics",
  337.      * mappedBy="location", fetch="EXTRA_LAZY")
  338.      */
  339.     protected $locationStatistics;
  340.     /**
  341.      * @ORM\OneToOne(targetEntity="\Aqarmap\Bundle\NeighborhoodBundle\Entity\LocationCompound",
  342.      * cascade={"persist", "remove"}, mappedBy="location")
  343.      *
  344.      * @ORM\JoinColumn(name="location_compound_id", referencedColumnName="id")
  345.      */
  346.     protected $locationCompound;
  347.     /**
  348.      * @ORM\OneToMany(targetEntity="\Aqarmap\Bundle\DiscussionBundle\Entity\Discussion",
  349.      * mappedBy="location", fetch="EXTRA_LAZY")
  350.      */
  351.     protected $discussions;
  352.     /**
  353.      * @ORM\OneToMany(targetEntity="\Aqarmap\Bundle\ExchangeBundle\Entity\ExchangeRequest",
  354.      * mappedBy="location", fetch="EXTRA_LAZY")
  355.      */
  356.     protected $exchangeRequests;
  357.     /**
  358.      * @Serializer\Expose
  359.      *
  360.      * @Serializer\Groups({"Neighborhood"})
  361.      *
  362.      * @ORM\OneToOne(targetEntity="LocationRating", cascade={"persist", "remove"})
  363.      * */
  364.     protected $rating;
  365.     /**
  366.      * @ORM\ManyToOne(targetEntity="Listing", cascade={"persist", "remove"})
  367.      *
  368.      * @ORM\JoinColumn(name="listing_id", referencedColumnName="id", nullable=true)
  369.      *
  370.      * @Serializer\Expose
  371.      *
  372.      * @Serializer\Groups({"Autocomplete"})
  373.      *
  374.      * */
  375.     protected $listing;
  376.     /**
  377.      * @ORM\OneToMany(targetEntity="SearchTerm", mappedBy="location")
  378.      */
  379.     protected $searchTerms;
  380.     /**
  381.      * @Gedmo\Locale
  382.      * Used locale to override Translation listener`s locale
  383.      * this is not a mapped field of entity metadata, just a simple property
  384.      */
  385.     private $locale;
  386.     /**
  387.      * @var int
  388.      *          Count number of leads for live listings
  389.      *
  390.      * @ORM\Column(name="leads_counter", type="integer", options={"default" = 0})
  391.      *
  392.      * @Serializer\Groups({"Api"})
  393.      *
  394.      * @Serializer\Expose
  395.      */
  396.     private $leadsCounter 0;
  397.     /**
  398.      * @var int
  399.      *          Count number of live listings
  400.      *
  401.      * @ORM\Column(name="listings_counter", type="integer", options={"default" = 0})
  402.      *
  403.      * @Serializer\Groups({"Api", "RelatedResults", "MiniList"})
  404.      *
  405.      * @Serializer\Expose
  406.      */
  407.     private $listingsCounter 0;
  408.     /**
  409.      * Project File.
  410.      */
  411.     protected $file;
  412.     /**
  413.      * @ORM\Column(name="keyword", type="text", nullable=true)
  414.      */
  415.     private $keyword;
  416.     private $location;
  417.     /**
  418.      * @ORM\OneToMany(targetEntity="Aqarmap\Bundle\ValueEngineBundle\Entity\ListingInsight", mappedBy="location")
  419.      */
  420.     protected $listingInsights;
  421.     /**
  422.      * @ORM\Column(name="full_path", type="text", nullable=true)
  423.      *
  424.      * @var string
  425.      */
  426.     private $fullPath;
  427.     /**
  428.      * @ORM\Column(name="reference_id", type="integer", nullable=true)
  429.      */
  430.     private $referenceId;
  431.     /**
  432.      * @var array
  433.      */
  434.     private $locationTranslations = [];
  435.     /**
  436.      * @var array
  437.      */
  438.     private $v4Translations = [];
  439.     /**
  440.      * @ORM\Column(name="eligible_for_mortgage", type="boolean")
  441.      */
  442.     protected $eligibleForMortgage false;
  443.     /**
  444.      * @ORM\Column(name="is_compound_location", type="boolean")
  445.      *
  446.      * @Serializer\Expose
  447.      *
  448.      * @Serializer\Groups({"Autocomplete","List", "Data", "Details", "LocationFlat", "AutocompleteV3", "Compound", "SlugResolver"})
  449.      */
  450.     private $isCompoundLocation false;
  451.     /**
  452.      * @ORM\OneToMany(targetEntity="Location", mappedBy="parent")
  453.      *
  454.      * @ORM\OrderBy({"id" = "ASC"})
  455.      *
  456.      * @Serializer\Expose
  457.      *
  458.      * @Serializer\Groups({"Data"})
  459.      *
  460.      * @Serializer\MaxDepth(2)
  461.      *
  462.      * @Serializer\Accessor(getter="getChildrenSortedById")
  463.      *
  464.      * @Serializer\SerializedName("children")
  465.      */
  466.     private $childrenSortedById;
  467.     /**
  468.      * @Serializer\VirtualProperty
  469.      */
  470.     public function getLocation()
  471.     {
  472.         return $this->location;
  473.     }
  474.     public function getKeyword()
  475.     {
  476.         return $this->keyword;
  477.     }
  478.     /**
  479.      * @param mixed $keyword
  480.      */
  481.     public function setKeyword(string $keyword): self
  482.     {
  483.         $this->keyword $this->getKeyword() ? $this->getKeyword().','.$keyword $keyword;
  484.         return $this;
  485.     }
  486.     public function removeKeyword(string $keyword): self
  487.     {
  488.         $newKeyword array_diff(explode(','$this->getKeyword()), [$keyword]);
  489.         $this->keyword implode(','$newKeyword) ?? null;
  490.         return $this;
  491.     }
  492.     public function getFile()
  493.     {
  494.         return $this->file;
  495.     }
  496.     public function setFile($file): void
  497.     {
  498.         $this->file $file;
  499.     }
  500.     /**
  501.      * Constructor.
  502.      */
  503.     public function __construct()
  504.     {
  505.         $this->children = new ArrayCollection();
  506.         $this->translations = new ArrayCollection();
  507.         $this->listings = new ArrayCollection();
  508.         $this->notifiers = new ArrayCollection();
  509.         $this->rules = new ArrayCollection();
  510.         $this->locationStatistics = new ArrayCollection();
  511.         $this->photos = new ArrayCollection();
  512.         $this->discussions = new ArrayCollection();
  513.         $this->propertyTypes = new ArrayCollection();
  514.         $this->nearestLocations = new ArrayCollection();
  515.         $this->interests = new ArrayCollection();
  516.         $this->exchangeRequests = new ArrayCollection();
  517.     }
  518.     // ---------------------------------------------------------------------
  519.     /**
  520.      * Get id.
  521.      *
  522.      * @return int
  523.      */
  524.     public function getId()
  525.     {
  526.         return $this->id;
  527.     }
  528.     // ---------------------------------------------------------------------
  529.     /**
  530.      * Set title.
  531.      *
  532.      * @param string $title
  533.      *
  534.      * @return Location
  535.      */
  536.     public function setTitle($title)
  537.     {
  538.         $this->title $title;
  539.         return $this;
  540.     }
  541.     /**
  542.      * Get title.
  543.      *
  544.      * @return string
  545.      */
  546.     public function getTitle()
  547.     {
  548.         return $this->title;
  549.     }
  550.     /**
  551.      * @return string
  552.      */
  553.     public function getIndentedTitle()
  554.     {
  555.         return str_repeat('--'$this->getLevel()).' '.$this->getTitle();
  556.     }
  557.     // ---------------------------------------------------------------------
  558.     /**
  559.      * Set description.
  560.      *
  561.      * @param string $description
  562.      *
  563.      * @return Location
  564.      */
  565.     public function setDescription($description)
  566.     {
  567.         $this->description $description;
  568.         return $this;
  569.     }
  570.     /**
  571.      * Get description.
  572.      *
  573.      * @return string
  574.      */
  575.     public function getDescription()
  576.     {
  577.         return $this->description;
  578.     }
  579.     // ---------------------------------------------------------------------
  580.     /**
  581.      * Set slug.
  582.      *
  583.      * @param string $slug
  584.      *
  585.      * @return Location
  586.      */
  587.     public function setSlug($slug)
  588.     {
  589.         $this->slug $slug;
  590.         return $this;
  591.     }
  592.     /**
  593.      * Get slug.
  594.      *
  595.      * @return string
  596.      */
  597.     public function getSlug()
  598.     {
  599.         return $this->slug;
  600.     }
  601.     // ---------------------------------------------------------------------
  602.     /**
  603.      * Set centerLat.
  604.      *
  605.      * @param float $centerLat
  606.      *
  607.      * @return Location
  608.      */
  609.     public function setCenterLat($centerLat)
  610.     {
  611.         return $this->setLat($centerLat);
  612.     }
  613.     /**
  614.      * @Serializer\VirtualProperty()
  615.      *
  616.      * @Serializer\Groups({"Map", "Details", "Neighborhood", "LocationFlat", "Autocomplete"})
  617.      *
  618.      * @Serializer\SerializedName("center_lat")
  619.      *
  620.      * @Serializer\Until("v2.13")
  621.      *
  622.      * @Serializer\Expose
  623.      *
  624.      * @return float
  625.      */
  626.     public function getCenterLat()
  627.     {
  628.         return $this->getLat(2);
  629.     }
  630.     /**
  631.      * @param float $latitude
  632.      *
  633.      * @return Location
  634.      */
  635.     public function setLat($latitude)
  636.     {
  637.         $this->lat $latitude;
  638.         return $this;
  639.     }
  640.     /**
  641.      * @return float|null
  642.      */
  643.     public function getLat()
  644.     {
  645.         if (!$this->lat) {
  646.             return null;
  647.         }
  648.         return (float) $this->lat;
  649.     }
  650.     // ---------------------------------------------------------------------
  651.     /**
  652.      * Set lon.
  653.      *
  654.      * @deprecated
  655.      *
  656.      * @param float $lon
  657.      *
  658.      * @return Location
  659.      */
  660.     public function setCenterLng($lon)
  661.     {
  662.         return $this->setLon($lon);
  663.     }
  664.     /**
  665.      * @Serializer\VirtualProperty()
  666.      *
  667.      * @Serializer\Groups({"Map", "Details", "Neighborhood", "LocationFlat", "Autocomplete"})
  668.      *
  669.      * @Serializer\SerializedName("center_lng")
  670.      *
  671.      * @Serializer\Until("v2.13")
  672.      *
  673.      * @Serializer\Expose
  674.      *
  675.      * @deprecated
  676.      *
  677.      * @return float|null
  678.      */
  679.     public function getCenterLng()
  680.     {
  681.         return $this->getLon(2);
  682.     }
  683.     /**
  684.      * @param float $longitude
  685.      *
  686.      * @return Location
  687.      */
  688.     public function setLon($longitude)
  689.     {
  690.         $this->lon $longitude;
  691.         return $this;
  692.     }
  693.     /**
  694.      * @return float|null
  695.      */
  696.     public function getLon()
  697.     {
  698.         if (!$this->lon) {
  699.             return null;
  700.         }
  701.         return (float) $this->lon;
  702.     }
  703.     // ---------------------------------------------------------------------
  704.     /**
  705.      * Set zoom.
  706.      *
  707.      * @deprecated
  708.      *
  709.      * @param int $zoom
  710.      *
  711.      * @return Location
  712.      */
  713.     public function setZoomLevel($zoom)
  714.     {
  715.         return $this->setZoom($zoom);
  716.     }
  717.     /**
  718.      * @Serializer\VirtualProperty()
  719.      *
  720.      * @Serializer\Groups({"Map", "Details", "Neighborhood", "LocationFlat", "Autocomplete", "AutocompleteV3", "DefaultV4"})
  721.      *
  722.      * @Serializer\SerializedName("zoom_level")
  723.      *
  724.      * @Serializer\Until("v2.13")
  725.      *
  726.      * @Serializer\Expose
  727.      *
  728.      * @deprecated
  729.      *
  730.      * @return int
  731.      */
  732.     public function getZoomLevel()
  733.     {
  734.         return $this->getZoom();
  735.     }
  736.     public function setZoom(?int $level): self
  737.     {
  738.         $this->zoom $level;
  739.         return $this;
  740.     }
  741.     /**
  742.      * @Serializer\VirtualProperty()
  743.      *
  744.      * @Serializer\SerializedName("zoom")
  745.      *
  746.      * @Serializer\Groups({"DataJS"})
  747.      *
  748.      * @return int|null
  749.      */
  750.     public function getZoom()
  751.     {
  752.         return $this->zoom;
  753.     }
  754.     // ---------------------------------------------------------------------
  755.     /**
  756.      * Set coordinates.
  757.      *
  758.      * @param array $coordinates
  759.      *
  760.      * @return Location
  761.      */
  762.     public function setCoordinates($coordinates)
  763.     {
  764.         $this->coordinates $coordinates;
  765.         return $this;
  766.     }
  767.     /**
  768.      * Get coordinates.
  769.      *
  770.      * @return array
  771.      */
  772.     public function getCoordinates()
  773.     {
  774.         return $this->coordinates;
  775.     }
  776.     // ---------------------------------------------------------------------
  777.     /**
  778.      * Set searchable.
  779.      *
  780.      * @param bool $searchable
  781.      *
  782.      * @return Location
  783.      */
  784.     public function setSearchable($searchable)
  785.     {
  786.         $this->searchable $searchable;
  787.         return $this;
  788.     }
  789.     /**
  790.      * Get searchable.
  791.      *
  792.      * @return bool
  793.      */
  794.     public function getSearchable()
  795.     {
  796.         return $this->searchable;
  797.     }
  798.     // ---------------------------------------------------------------------
  799.     /**
  800.      * Set homeFilter.
  801.      *
  802.      * @param bool $homeFilter
  803.      *
  804.      * @return Location
  805.      */
  806.     public function setHomeFilter($homeFilter)
  807.     {
  808.         $this->homeFilter $homeFilter;
  809.         return $this;
  810.     }
  811.     /**
  812.      * Get homeFilter.
  813.      *
  814.      * @return bool
  815.      */
  816.     public function getHomeFilter()
  817.     {
  818.         return $this->homeFilter;
  819.     }
  820.     // ---------------------------------------------------------------------
  821.     /**
  822.      * Set estimate.
  823.      *
  824.      * @param bool $estimate
  825.      *
  826.      * @return Location
  827.      */
  828.     public function setEstimate($estimate)
  829.     {
  830.         $this->estimate $estimate;
  831.         return $this;
  832.     }
  833.     /**
  834.      * Get estimate.
  835.      *
  836.      * @return bool
  837.      */
  838.     public function getEstimate()
  839.     {
  840.         return $this->estimate;
  841.     }
  842.     // ---------------------------------------------------------------------
  843.     /**
  844.      * Set disabled.
  845.      *
  846.      * @param bool $disabled
  847.      *
  848.      * @return Location
  849.      */
  850.     public function setDisabled($disabled)
  851.     {
  852.         $this->disabled $disabled;
  853.         return $this;
  854.     }
  855.     /**
  856.      * Get disabled.
  857.      *
  858.      * @return bool
  859.      */
  860.     public function getDisabled()
  861.     {
  862.         return $this->disabled;
  863.     }
  864.     // ---------------------------------------------------------------------
  865.     /**
  866.      * Set parent.
  867.      *
  868.      * @return Location
  869.      */
  870.     public function setParent(?self $parent null)
  871.     {
  872.         $this->parent $parent;
  873.         return $this;
  874.     }
  875.     /**
  876.      * Get parent.
  877.      *
  878.      * @return Location
  879.      */
  880.     public function getParent()
  881.     {
  882.         return $this->parent;
  883.     }
  884.     // ---------------------------------------------------------------------
  885.     /**
  886.      * Add children.
  887.      *
  888.      * @return Location
  889.      */
  890.     public function addChild(self $children)
  891.     {
  892.         $this->children[] = $children;
  893.         return $this;
  894.     }
  895.     /**
  896.      * Remove children.
  897.      */
  898.     public function removeChild(self $children): void
  899.     {
  900.         $this->children->removeElement($children);
  901.     }
  902.     /**
  903.      * Get children.
  904.      *
  905.      * @return Collection
  906.      */
  907.     public function getChildren()
  908.     {
  909.         $criteria Criteria::create()
  910.             ->where(Criteria::expr()->eq('disabled'false));
  911.         return $this->children->matching($criteria);
  912.     }
  913.     /**
  914.      * Get children sorted by id.
  915.      *
  916.      * @return Collection
  917.      */
  918.     public function getChildrenSortedById($filters = [])
  919.     {
  920.         $criteria Criteria::create()
  921.             ->where(Criteria::expr()->eq('disabled'false));
  922.         if (isset($filters['neighborhoodFilter'])) {
  923.             $criteria->andWhere(Criteria::expr()->eq('neighborhoodFilter'$filters['neighborhoodFilter']));
  924.         }
  925.         return $this->childrenSortedById->matching($criteria);
  926.     }
  927.     /**
  928.      * Get children.
  929.      *
  930.      * @return Collection
  931.      */
  932.     public function getChildrenArray()
  933.     {
  934.         $criteria Criteria::create()
  935.             ->where(Criteria::expr()->eq('disabled'false));
  936.         return $this->children->matching($criteria)->toArray();
  937.     }
  938.     /**
  939.      * Get neighborhoodchildren.
  940.      *
  941.      * @return Collection
  942.      */
  943.     public function getNeighborhoodChildren()
  944.     {
  945.         $criteria Criteria::create()
  946.             ->andWhere(Criteria::expr()->eq('disabled'false))
  947.             ->andWhere(Criteria::expr()->eq('neighborhoodFilter'true));
  948.         return $this->children->matching($criteria);
  949.     }
  950.     /**
  951.      * Get leveled children.
  952.      *
  953.      * @return Collection
  954.      */
  955.     public function getLeveledChildren()
  956.     {
  957.         $criteria Criteria::create()
  958.             ->where(Criteria::expr()->eq('disabled'false))
  959.             ->where(Criteria::expr()->lte('level'2));
  960.         return $this->children->matching($criteria);
  961.     }
  962.     // ---------------------------------------------------------------------
  963.     /**
  964.      * Get translations.
  965.      *
  966.      * @return ArrayCollection
  967.      */
  968.     public function getTranslations()
  969.     {
  970.         return $this->translations;
  971.     }
  972.     /**
  973.      * Add translation.
  974.      *
  975.      * @return Location
  976.      */
  977.     public function addTranslation(LocationTranslation $translation)
  978.     {
  979.         if (!$this->translations->contains($translation)) {
  980.             $this->translations->add($translation);
  981.             $translation->setObject($this);
  982.         }
  983.         return $this;
  984.     }
  985.     /**
  986.      * Remove translation.
  987.      *
  988.      * @return Location
  989.      */
  990.     public function removeTranslation(LocationTranslation $translation)
  991.     {
  992.         if ($this->translations->contains($translation)) {
  993.             $this->translations->removeElement($translation);
  994.         }
  995.         return $this;
  996.     }
  997.     // ---------------------------------------------------------------------
  998.     /**
  999.      * Add listings.
  1000.      *
  1001.      * @return Location
  1002.      */
  1003.     public function addListing(Listing $listings)
  1004.     {
  1005.         $this->listings[] = $listings;
  1006.         return $this;
  1007.     }
  1008.     /**
  1009.      * Remove listings.
  1010.      */
  1011.     public function removeListing(Listing $listings): void
  1012.     {
  1013.         $this->listings->removeElement($listings);
  1014.     }
  1015.     /**
  1016.      * Get listings.
  1017.      *
  1018.      * @return Collection
  1019.      */
  1020.     public function getListings()
  1021.     {
  1022.         return $this->listings;
  1023.     }
  1024.     // ---------------------------------------------------------------------
  1025.     /**
  1026.      * Add notifiers.
  1027.      *
  1028.      * @return Location
  1029.      */
  1030.     public function addNotifier(Notifier $notifiers)
  1031.     {
  1032.         $this->notifiers[] = $notifiers;
  1033.         return $this;
  1034.     }
  1035.     /**
  1036.      * Remove notifiers.
  1037.      */
  1038.     public function removeNotifier(Notifier $notifiers): void
  1039.     {
  1040.         $this->notifiers->removeElement($notifiers);
  1041.     }
  1042.     /**
  1043.      * Get notifiers.
  1044.      *
  1045.      * @return Collection
  1046.      */
  1047.     public function getNotifiers()
  1048.     {
  1049.         return $this->notifiers;
  1050.     }
  1051.     // ---------------------------------------------------------------------
  1052.     /**
  1053.      * Add rules.
  1054.      *
  1055.      * @return Location
  1056.      */
  1057.     public function addRule(Rule $rules)
  1058.     {
  1059.         $this->rules[] = $rules;
  1060.         return $this;
  1061.     }
  1062.     /**
  1063.      * Remove rules.
  1064.      */
  1065.     public function removeRule(Rule $rules): void
  1066.     {
  1067.         $this->rules->removeElement($rules);
  1068.     }
  1069.     /**
  1070.      * Get rules.
  1071.      *
  1072.      * @return Collection
  1073.      */
  1074.     public function getRules()
  1075.     {
  1076.         return $this->rules;
  1077.     }
  1078.     // ---------------------------------------------------------------------
  1079.     /**
  1080.      * Get Nearest Searchable Location.
  1081.      */
  1082.     public function getNearestSearchable()
  1083.     {
  1084.         $location $this;
  1085.         while ($location && !$location->getSearchable()) {
  1086.             $location $location->getParent();
  1087.         }
  1088.         if (!$location) {
  1089.             return $this;
  1090.         }
  1091.         return $location;
  1092.     }
  1093.     // -----------------------------------------------------------------------------
  1094.     /**
  1095.      * Get Nearest Neighborhood Parent.
  1096.      */
  1097.     public function getNearestNeighborhood()
  1098.     {
  1099.         $location $this;
  1100.         while (
  1101.             !$location->getNeighborhoodFilter()
  1102.             && $location->getParent()
  1103.             && != $location->getParent()->getLevel()
  1104.         ) {
  1105.             $location $location->getParent();
  1106.         }
  1107.         if (!$location->getNeighborhoodFilter() || == $location->getLevel()) {
  1108.             return;
  1109.         }
  1110.         return $location;
  1111.     }
  1112.     /**
  1113.      * Get Nearest Location Custom Level .
  1114.      *
  1115.      * @param int $level
  1116.      *
  1117.      * @return Location
  1118.      */
  1119.     public function getNearestLeveledLocation($level 1)
  1120.     {
  1121.         $location $this;
  1122.         if (\in_array($location->getLevel(), [0$level])) {
  1123.             return $location;
  1124.         }
  1125.         while ($location->getParent() && != $location->getParent()->getLevel()) {
  1126.             $location $location->getParent();
  1127.         }
  1128.         return $location;
  1129.     }
  1130.     /**
  1131.      * @Serializer\VirtualProperty
  1132.      *
  1133.      * @Serializer\SerializedName("parent")
  1134.      *
  1135.      * @Serializer\Expose
  1136.      *
  1137.      * @Serializer\Groups({"LocationFlat"})
  1138.      */
  1139.     public function getVirtualParent()
  1140.     {
  1141.         $parent $this->getParent();
  1142.         if ($parent) {
  1143.             return [
  1144.                 'id' => $parent->getId(),
  1145.                 'title' => $parent->getTitle(),
  1146.             ];
  1147.         }
  1148.         return null;
  1149.     }
  1150.     /**
  1151.      * Gets parent by level.
  1152.      *
  1153.      * @param int $level
  1154.      *
  1155.      * @return Location|null
  1156.      */
  1157.     public function getLeveledParent($level 1)
  1158.     {
  1159.         $location $this;
  1160.         while ($location $location->getParent()) {
  1161.             if ($location->getLevel() == $level) {
  1162.                 return $location;
  1163.             }
  1164.         }
  1165.         return null;
  1166.     }
  1167.     /**
  1168.      * Get Nearest Location Custom Level .
  1169.      *
  1170.      * @return Location
  1171.      */
  1172.     public function getFirstParent()
  1173.     {
  1174.         $location $this;
  1175.         if (== $location->getLevel()) {
  1176.             return $location;
  1177.         }
  1178.         while ($location $location->getParent()) {
  1179.             if (== $location->getLevel()) {
  1180.                 return $location;
  1181.             }
  1182.         }
  1183.         return $location;
  1184.     }
  1185.     /**
  1186.      * Set level.
  1187.      *
  1188.      * @param int $level
  1189.      *
  1190.      * @return Location
  1191.      */
  1192.     public function setLevel($level)
  1193.     {
  1194.         $this->level $level;
  1195.         return $this;
  1196.     }
  1197.     /**
  1198.      * Get level.
  1199.      *
  1200.      * @return int
  1201.      */
  1202.     public function getLevel()
  1203.     {
  1204.         return $this->level;
  1205.     }
  1206.     /**
  1207.      * Set left.
  1208.      *
  1209.      * @param int $left
  1210.      *
  1211.      * @return Location
  1212.      */
  1213.     public function setLeft($left)
  1214.     {
  1215.         $this->left $left;
  1216.         return $this;
  1217.     }
  1218.     /**
  1219.      * Get left.
  1220.      *
  1221.      * @return int
  1222.      */
  1223.     public function getLeft()
  1224.     {
  1225.         return $this->left;
  1226.     }
  1227.     /**
  1228.      * Set right.
  1229.      *
  1230.      * @param int $right
  1231.      *
  1232.      * @return Location
  1233.      */
  1234.     public function setRight($right)
  1235.     {
  1236.         $this->right $right;
  1237.         return $this;
  1238.     }
  1239.     /**
  1240.      * Get right.
  1241.      *
  1242.      * @return int
  1243.      */
  1244.     public function getRight()
  1245.     {
  1246.         return $this->right;
  1247.     }
  1248.     /**
  1249.      * Set root.
  1250.      *
  1251.      * @param int $root
  1252.      *
  1253.      * @return Location
  1254.      */
  1255.     public function setRoot($root)
  1256.     {
  1257.         $this->root $root;
  1258.         return $this;
  1259.     }
  1260.     /**
  1261.      * Get root.
  1262.      *
  1263.      * @return int
  1264.      */
  1265.     public function getRoot()
  1266.     {
  1267.         return $this->root;
  1268.     }
  1269.     /**
  1270.      * Add locationSupplyDemand.
  1271.      *
  1272.      * @return Location
  1273.      */
  1274.     public function addLocationSupplyDemand(LocationSupplyDemand $locationSupplyDemand)
  1275.     {
  1276.         $this->locationSupplyDemand[] = $locationSupplyDemand;
  1277.         return $this;
  1278.     }
  1279.     /**
  1280.      * Remove locationSupplyDemand.
  1281.      */
  1282.     public function removeLocationSupplyDemand(LocationSupplyDemand $locationSupplyDemand): void
  1283.     {
  1284.         $this->locationSupplyDemand->removeElement($locationSupplyDemand);
  1285.     }
  1286.     /**
  1287.      * Get locationSupplyDemand.
  1288.      *
  1289.      * @return Collection
  1290.      */
  1291.     public function getLocationSupplyDemand()
  1292.     {
  1293.         return $this->locationSupplyDemand;
  1294.     }
  1295.     // ---------------------------------------------------------------------
  1296.     /**
  1297.      * Add photos.
  1298.      *
  1299.      * @return Location
  1300.      */
  1301.     public function addPhoto(LocationPhoto $photo)
  1302.     {
  1303.         $photo->setLocation($this);
  1304.         $this->photos[] = $photo;
  1305.         return $this;
  1306.     }
  1307.     /**
  1308.      * Set photos.
  1309.      *
  1310.      * @return Location
  1311.      */
  1312.     public function setPhotos($photos)
  1313.     {
  1314.         foreach ($photos as $photo) {
  1315.             $this->addPhoto($photo);
  1316.         }
  1317.         return $this;
  1318.     }
  1319.     /**
  1320.      * Remove photos.
  1321.      */
  1322.     public function removePhoto(LocationPhoto $photo): void
  1323.     {
  1324.         $this->photos->removeElement($photo);
  1325.     }
  1326.     /**
  1327.      * @return ArrayCollection
  1328.      */
  1329.     public function getPhotos()
  1330.     {
  1331.         return $this->photos;
  1332.     }
  1333.     /**
  1334.      * @return mixed|null
  1335.      *
  1336.      * @Serializer\VirtualProperty
  1337.      *
  1338.      * @Serializer\Groups({"Default", "LocationFlat"})
  1339.      */
  1340.     public function getMainPhoto()
  1341.     {
  1342.         // Important for API
  1343.         if ($this->getPhotos()->count() <= 0) {
  1344.             return;
  1345.         }
  1346.         /* @var Photo $photo */
  1347.         $mainPhoto $this->photos->filter(fn ($photo) => PhotoTypes::MAIN_PHOTO == $photo->getType());
  1348.         return $mainPhoto->first() ?: $this->getPhotos()->first();
  1349.     }
  1350.     // ---------------------------------------------------------------------
  1351.     public function __clone()
  1352.     {
  1353.         $this->id null;
  1354.     }
  1355.     public function __toString()
  1356.     {
  1357.         return $this->title;
  1358.     }
  1359.     /**
  1360.      * Set rating.
  1361.      *
  1362.      * @return Location
  1363.      */
  1364.     public function setRating(?LocationRating $rating null)
  1365.     {
  1366.         $this->rating $rating;
  1367.         $this->rating->setLocation($this);
  1368.         return $this;
  1369.     }
  1370.     /**
  1371.      * Get rating.
  1372.      *
  1373.      * @return LocationRating
  1374.      */
  1375.     public function getRating()
  1376.     {
  1377.         return $this->rating;
  1378.     }
  1379.     /**
  1380.      * Set neighborhoodFilter.
  1381.      *
  1382.      * @param bool $neighborhoodFilter
  1383.      *
  1384.      * @return Location
  1385.      */
  1386.     public function setNeighborhoodFilter($neighborhoodFilter)
  1387.     {
  1388.         $this->neighborhoodFilter $neighborhoodFilter;
  1389.         return $this;
  1390.     }
  1391.     /**
  1392.      * Get neighborhoodFilter.
  1393.      *
  1394.      * @return bool
  1395.      */
  1396.     public function getNeighborhoodFilter()
  1397.     {
  1398.         return $this->neighborhoodFilter;
  1399.     }
  1400.     /**
  1401.      * Add locationStatistic.
  1402.      *
  1403.      * @return Location
  1404.      */
  1405.     public function addLocationStatistic(LocationStatistics $locationStatistic)
  1406.     {
  1407.         $this->locationStatistics[] = $locationStatistic;
  1408.         return $this;
  1409.     }
  1410.     /**
  1411.      * Remove locationStatistic.
  1412.      */
  1413.     public function removeLocationStatistic(LocationStatistics $locationStatistic): void
  1414.     {
  1415.         $this->locationStatistics->removeElement($locationStatistic);
  1416.     }
  1417.     /**
  1418.      * Get locationStatistics.
  1419.      *
  1420.      * @return Collection
  1421.      */
  1422.     public function getLocationStatistics()
  1423.     {
  1424.         return $this->locationStatistics;
  1425.     }
  1426.     /**
  1427.      * Get lowest Average Price.
  1428.      *
  1429.      * @return LocationStatistics $locationStatistic
  1430.      */
  1431.     public function getSingleStatistics(?PropertyType $propertyType null)
  1432.     {
  1433.         $criteria Criteria::create()
  1434.             ->andWhere(Criteria::expr()->neq('avgPrice'null))
  1435.             ->andWhere(Criteria::expr()->gt('avgPrice'0))
  1436.             ->orderBy(['avgPrice' => Criteria::ASC]);
  1437.         if ($propertyType) {
  1438.             $criteria
  1439.                 ->andWhere(Criteria::expr()->eq('propertyType'$propertyType));
  1440.         }
  1441.         return $this->locationStatistics->matching($criteria)->first();
  1442.     }
  1443.     /**
  1444.      * Set statisticsFilter.
  1445.      *
  1446.      * @param bool $statisticsFilter
  1447.      *
  1448.      * @return Location
  1449.      */
  1450.     public function setStatisticsFilter($statisticsFilter)
  1451.     {
  1452.         $this->statisticsFilter $statisticsFilter;
  1453.         return $this;
  1454.     }
  1455.     /**
  1456.      * Get statisticsFilter.
  1457.      *
  1458.      * @return bool
  1459.      */
  1460.     public function getStatisticsFilter()
  1461.     {
  1462.         return $this->statisticsFilter;
  1463.     }
  1464.     /**
  1465.      * Add company.
  1466.      *
  1467.      * @return Location
  1468.      */
  1469.     public function addCompany(\Aqarmap\Bundle\CRMBundle\Entity\Company $company)
  1470.     {
  1471.         $this->companies[] = $company;
  1472.         return $this;
  1473.     }
  1474.     /**
  1475.      * Remove company.
  1476.      */
  1477.     public function removeCompany(\Aqarmap\Bundle\CRMBundle\Entity\Company $company): void
  1478.     {
  1479.         $this->companies->removeElement($company);
  1480.     }
  1481.     /**
  1482.      * Get companies.
  1483.      *
  1484.      * @return Collection
  1485.      */
  1486.     public function getCompanies()
  1487.     {
  1488.         return $this->companies;
  1489.     }
  1490.     /**
  1491.      * Add discussion.
  1492.      *
  1493.      * @return Location
  1494.      */
  1495.     public function addDiscussion(Discussion $discussion)
  1496.     {
  1497.         $this->discussions[] = $discussion;
  1498.         return $this;
  1499.     }
  1500.     /**
  1501.      * Remove discussion.
  1502.      */
  1503.     public function removeDiscussion(Discussion $discussion): void
  1504.     {
  1505.         $this->discussions->removeElement($discussion);
  1506.     }
  1507.     /**
  1508.      * Get discussions.
  1509.      *
  1510.      * @return Collection
  1511.      */
  1512.     public function getDiscussions()
  1513.     {
  1514.         return $this->discussions;
  1515.     }
  1516.     /**
  1517.      * Set compoundFilter.
  1518.      *
  1519.      * @param bool $compoundFilter
  1520.      *
  1521.      * @return Location
  1522.      */
  1523.     public function setCompoundFilter($compoundFilter)
  1524.     {
  1525.         $this->compoundFilter $compoundFilter;
  1526.         return $this;
  1527.     }
  1528.     /**
  1529.      * Get compoundFilter.
  1530.      *
  1531.      * @return bool
  1532.      */
  1533.     public function getCompoundFilter()
  1534.     {
  1535.         return $this->compoundFilter;
  1536.     }
  1537.     /**
  1538.      * Add propertyType.
  1539.      *
  1540.      * @return Location
  1541.      */
  1542.     public function addPropertyType(PropertyType $propertyType)
  1543.     {
  1544.         $this->propertyTypes[] = $propertyType;
  1545.         return $this;
  1546.     }
  1547.     /**
  1548.      * Remove propertyType.
  1549.      */
  1550.     public function removePropertyType(PropertyType $propertyType): void
  1551.     {
  1552.         $this->propertyTypes->removeElement($propertyType);
  1553.     }
  1554.     /**
  1555.      * Get propertyTypes.
  1556.      *
  1557.      * @return Collection
  1558.      */
  1559.     public function getPropertyTypes()
  1560.     {
  1561.         return $this->propertyTypes;
  1562.     }
  1563.     /**
  1564.      * Set listing.
  1565.      *
  1566.      * @return Location
  1567.      */
  1568.     public function setListing(?Listing $listing null)
  1569.     {
  1570.         $this->listing $listing;
  1571.         return $this;
  1572.     }
  1573.     /**
  1574.      * Set listing.
  1575.      *
  1576.      * @return Location
  1577.      */
  1578.     public function setListings(array $listings = [])
  1579.     {
  1580.         $this->listings $listings;
  1581.         return $this;
  1582.     }
  1583.     /**
  1584.      * Get listing.
  1585.      *
  1586.      * @return Listing
  1587.      */
  1588.     public function getListing()
  1589.     {
  1590.         return $this->listing;
  1591.     }
  1592.     /**
  1593.      * Set locationCompound.
  1594.      *
  1595.      * @return Location
  1596.      */
  1597.     public function setLocationCompound(?LocationCompound $locationCompound null)
  1598.     {
  1599.         $this->locationCompound $locationCompound;
  1600.         $this->locationCompound->setLocation($this);
  1601.         return $this;
  1602.     }
  1603.     /**
  1604.      * Get locationCompound.
  1605.      *
  1606.      * @return LocationCompound
  1607.      */
  1608.     public function getLocationCompound()
  1609.     {
  1610.         return $this->locationCompound;
  1611.     }
  1612.     /**
  1613.      * Add nearestLocation.
  1614.      *
  1615.      * @return Location
  1616.      */
  1617.     public function addNearestLocation(self $nearestLocation)
  1618.     {
  1619.         if (!$this->nearestLocations->contains($nearestLocation)) {
  1620.             $this->nearestLocations->add($nearestLocation);
  1621.         }
  1622.         return $this;
  1623.     }
  1624.     /**
  1625.      * Remove nearestLocation.
  1626.      *
  1627.      * @return Location
  1628.      */
  1629.     public function removeNearestLocation(self $nearestLocation)
  1630.     {
  1631.         if ($this->nearestLocations->contains($nearestLocation)) {
  1632.             $this->nearestLocations->removeElement($nearestLocation);
  1633.         }
  1634.         return $this;
  1635.     }
  1636.     /**
  1637.      * Get nearestLocations.
  1638.      *
  1639.      * @return Collection
  1640.      */
  1641.     public function getNearestLocations()
  1642.     {
  1643.         return $this->nearestLocations;
  1644.     }
  1645.     /**
  1646.      * Add interest.
  1647.      *
  1648.      * @return Location
  1649.      */
  1650.     public function addInterest(UserInterest $interest)
  1651.     {
  1652.         $this->interests[] = $interest;
  1653.         return $this;
  1654.     }
  1655.     /**
  1656.      * Remove interest.
  1657.      */
  1658.     public function removeInterest(UserInterest $interest): void
  1659.     {
  1660.         $this->interests->removeElement($interest);
  1661.     }
  1662.     /**
  1663.      * Get interests.
  1664.      *
  1665.      * @return Collection
  1666.      */
  1667.     public function getInterests()
  1668.     {
  1669.         return $this->interests;
  1670.     }
  1671.     /**
  1672.      * Get interests.
  1673.      *
  1674.      * @return UserInterest
  1675.      */
  1676.     public function getLiveInterests()
  1677.     {
  1678.         $criteria Criteria::create()
  1679.             ->andwhere(Criteria::expr()->eq('status'UserInterestStatus::LIVE));
  1680.         return $this->interests->matching($criteria);
  1681.     }
  1682.     public function setTranslatableLocale($locale): void
  1683.     {
  1684.         $this->locale $locale;
  1685.     }
  1686.     /**
  1687.      * Add exchangeRequest.
  1688.      *
  1689.      * @return Location
  1690.      */
  1691.     public function addExchangeRequest(ExchangeRequest $exchangeRequest)
  1692.     {
  1693.         $this->exchangeRequests[] = $exchangeRequest;
  1694.         return $this;
  1695.     }
  1696.     /**
  1697.      * Remove exchangeRequest.
  1698.      */
  1699.     public function removeExchangeRequest(ExchangeRequest $exchangeRequest): void
  1700.     {
  1701.         $this->exchangeRequests->removeElement($exchangeRequest);
  1702.     }
  1703.     /**
  1704.      * Get exchangeRequests.
  1705.      *
  1706.      * @return Collection
  1707.      */
  1708.     public function getExchangeRequests()
  1709.     {
  1710.         return $this->exchangeRequests;
  1711.     }
  1712.     public function setSearchTerms($searchTerms): void
  1713.     {
  1714.         $this->searchTerms $searchTerms;
  1715.     }
  1716.     public function getSearchTerms()
  1717.     {
  1718.         return $this->searchTerms;
  1719.     }
  1720.     /**
  1721.      * @return int
  1722.      */
  1723.     public function getLeadsCounter()
  1724.     {
  1725.         return $this->leadsCounter;
  1726.     }
  1727.     /**
  1728.      * @param int $leadsCounter
  1729.      */
  1730.     public function setLeadsCounter($leadsCounter): void
  1731.     {
  1732.         $this->leadsCounter $leadsCounter;
  1733.     }
  1734.     /**
  1735.      * @return int
  1736.      */
  1737.     public function getListingsCounter()
  1738.     {
  1739.         return $this->listingsCounter;
  1740.     }
  1741.     /**
  1742.      * @param int $listingsCounter
  1743.      *
  1744.      * @return Location
  1745.      */
  1746.     public function setListingsCounter($listingsCounter)
  1747.     {
  1748.         $this->listingsCounter $listingsCounter;
  1749.         return $this;
  1750.     }
  1751.     /**
  1752.      * @return int
  1753.      */
  1754.     public function getLocationParentLabel()
  1755.     {
  1756.         $parent $this->getParent() ? $this->getParent()->getTitle().' / ' null;
  1757.         return $parent.$this->getTitle();
  1758.     }
  1759.     /**
  1760.      * @return int
  1761.      */
  1762.     public function getLastSlug()
  1763.     {
  1764.         $segments explode('/'$this->slug);
  1765.         return end($segments);
  1766.     }
  1767.     /**
  1768.      * @return bool
  1769.      *
  1770.      * @Serializer\VirtualProperty()
  1771.      *
  1772.      * @Serializer\SerializedName("has_children")
  1773.      *
  1774.      * @Serializer\Expose()
  1775.      *
  1776.      * @Serializer\Groups({"LocationFlat", "AutocompleteV3", "DefaultV4"})
  1777.      */
  1778.     public function getHasChildren()
  1779.     {
  1780.         return $this->getChildren()->isEmpty() ? false true;
  1781.     }
  1782.     /**
  1783.      * @Serializer\VirtualProperty()
  1784.      *
  1785.      * @Serializer\SerializedName("text")
  1786.      *
  1787.      * @Serializer\Groups({"Autocomplete"})
  1788.      *
  1789.      * @Serializer\Expose
  1790.      *
  1791.      * @return string
  1792.      */
  1793.     public function getText()
  1794.     {
  1795.         return $this->getTitle();
  1796.     }
  1797.     /**
  1798.      * Get Title FullPath
  1799.      * e.g. takes 90th street and returns Greater Cairo / New Cairo / 90th Street.
  1800.      *
  1801.      * @Serializer\VirtualProperty()
  1802.      *
  1803.      * @Serializer\SerializedName("title_full_path")
  1804.      *
  1805.      * @Serializer\Groups({"Autocomplete", "AutocompleteV3", "DefaultV4", "SearchV4", "ProjectDetailsV4", "SlugResolver", "RelatedListingsV2"})
  1806.      *
  1807.      * @Serializer\Expose
  1808.      */
  1809.     public function getTitleFullPath(): string
  1810.     {
  1811.         $location $this;
  1812.         $titlesFullPath[] = $this->getTitle();
  1813.         while ($location $location->getParent()) {
  1814.             $titlesFullPath[] = $location->getTitle();
  1815.         }
  1816.         return implode(' / 'array_reverse($titlesFullPath ?? []));
  1817.     }
  1818.     /**
  1819.      * Get searchable title keywords
  1820.      * e.g. takes 90th street and returns Greater Cairo / New Cairo / 90th Street.
  1821.      */
  1822.     public function getSearchableTitle(): string
  1823.     {
  1824.         $location $this;
  1825.         $titlesFullPath = [];
  1826.         $this->handleTitle($location$titlesFullPath);
  1827.         while ($location $location->getParent()) {
  1828.             $this->handleTitle($location$titlesFullPath);
  1829.         }
  1830.         return implode(' / 'array_reverse($titlesFullPath ?? []));
  1831.     }
  1832.     /**
  1833.      * Get Title FullPath started from children
  1834.      * e.g. takes 90th street and returns Greater 90th Street - New Cairo - Cairo.
  1835.      */
  1836.     public function getTitleFullPathStartedFromChildren(): string
  1837.     {
  1838.         $location $this;
  1839.         $titlesFullPath[] = $this->getTitle();
  1840.         while ($location $location->getParent()) {
  1841.             $titlesFullPath[] = $location->getTitle();
  1842.         }
  1843.         return implode(' - '$titlesFullPath);
  1844.     }
  1845.     /**
  1846.      * @return Location
  1847.      */
  1848.     public function setSynced($synced)
  1849.     {
  1850.         $this->synced $synced;
  1851.         return $this;
  1852.     }
  1853.     public function getSynced()
  1854.     {
  1855.         return $this->synced;
  1856.     }
  1857.     /**
  1858.      * @Serializer\VirtualProperty()
  1859.      *
  1860.      * @Serializer\Groups({"Autocomplete"})
  1861.      *
  1862.      * @Serializer\Expose
  1863.      */
  1864.     public function getTranslation(): array
  1865.     {
  1866.         $translations = [];
  1867.         foreach ($this->getTranslations()->toArray() as $trans) {
  1868.             $translations[$trans->getLocale()] = $trans->getContent();
  1869.         }
  1870.         return $translations;
  1871.     }
  1872.     /**
  1873.      * @return string|null
  1874.      */
  1875.     public function getFullPath()
  1876.     {
  1877.         return $this->fullPath;
  1878.     }
  1879.     public function setFullPath(?string $fullPath null): self
  1880.     {
  1881.         $this->fullPath $fullPath;
  1882.         return $this;
  1883.     }
  1884.     /**
  1885.      * @Serializer\VirtualProperty()
  1886.      *
  1887.      * @Serializer\SerializedName("name")
  1888.      *
  1889.      * @Serializer\Groups({"AutocompleteV3", "DefaultV4", "SearchV4"})
  1890.      *
  1891.      * @Serializer\Expose
  1892.      *
  1893.      * @return string
  1894.      */
  1895.     public function getName()
  1896.     {
  1897.         return $this->getTitle();
  1898.     }
  1899.     /**
  1900.      * @Serializer\VirtualProperty()
  1901.      *
  1902.      * @Serializer\SerializedName("latitude")
  1903.      *
  1904.      * @Serializer\Groups({"AutocompleteV3", "DefaultV4", "ProjectDetailsV4"})
  1905.      *
  1906.      * @Serializer\Expose
  1907.      *
  1908.      * @return string
  1909.      */
  1910.     public function getLatitude()
  1911.     {
  1912.         return $this->getLat();
  1913.     }
  1914.     /**
  1915.      * @Serializer\VirtualProperty()
  1916.      *
  1917.      * @Serializer\SerializedName("longitude")
  1918.      *
  1919.      * @Serializer\Groups({"AutocompleteV3", "DefaultV4", "ProjectDetailsV4"})
  1920.      *
  1921.      * @Serializer\Expose
  1922.      *
  1923.      * @return string
  1924.      */
  1925.     public function getLongitude()
  1926.     {
  1927.         return $this->getLon();
  1928.     }
  1929.     /**
  1930.      * @Serializer\VirtualProperty()
  1931.      *
  1932.      * @Serializer\Groups({"AutocompleteV3"})
  1933.      *
  1934.      * @Serializer\SerializedName("translations")
  1935.      *
  1936.      * @Serializer\Expose
  1937.      */
  1938.     public function getLocationTranslations(): array
  1939.     {
  1940.         return $this->locationTranslations;
  1941.     }
  1942.     public function setLocationTranslations(array $translation): self
  1943.     {
  1944.         $this->locationTranslations $translation;
  1945.         return $this;
  1946.     }
  1947.     /**
  1948.      * @return int|null
  1949.      */
  1950.     public function getReferenceId()
  1951.     {
  1952.         return $this->id;
  1953.     }
  1954.     /**
  1955.      * @return self
  1956.      */
  1957.     public function setReferenceId(?int $referenceId)
  1958.     {
  1959.         $this->referenceId $referenceId;
  1960.         return $this;
  1961.     }
  1962.     /**
  1963.      * @Serializer\VirtualProperty()
  1964.      *
  1965.      * @Serializer\Groups({"DefaultV4"})
  1966.      *
  1967.      * @Serializer\SerializedName("listingsCount")
  1968.      *
  1969.      * @Serializer\Expose
  1970.      *
  1971.      * @return int
  1972.      */
  1973.     public function getListingsCount()
  1974.     {
  1975.         return $this->listingsCounter;
  1976.     }
  1977.     /**
  1978.      * @return $this
  1979.      */
  1980.     public function setListingsCount(int $listingsCount): self
  1981.     {
  1982.         $this->listingsCounter $listingsCount;
  1983.         return $this;
  1984.     }
  1985.     /**
  1986.      * @Serializer\VirtualProperty
  1987.      *
  1988.      * @Serializer\SerializedName("referenceId")
  1989.      *
  1990.      * @Serializer\Expose()
  1991.      *
  1992.      * @Serializer\Groups({"DefaultV4", "AutocompleteV3", "SearchV4"})
  1993.      */
  1994.     public function getReferencedV4Id()
  1995.     {
  1996.         return $this->getId();
  1997.     }
  1998.     /**
  1999.      * @param array $translations
  2000.      *
  2001.      * @return self
  2002.      */
  2003.     public function setV4Translations($translations = [])
  2004.     {
  2005.         $this->v4Translations $translations;
  2006.         return $this;
  2007.     }
  2008.     /**
  2009.      * Get translations.
  2010.      *
  2011.      * @Serializer\VirtualProperty
  2012.      *
  2013.      * @Serializer\Groups({"DefaultV4", "MyListing", "SearchV4"})
  2014.      *
  2015.      * @Serializer\SerializedName("translations")
  2016.      *
  2017.      * @Serializer\Expose
  2018.      *
  2019.      * @return array
  2020.      */
  2021.     public function getV4Translations()
  2022.     {
  2023.         return $this->v4Translations;
  2024.     }
  2025.     /**
  2026.      * @return Location
  2027.      */
  2028.     public function setEligibleForMortgage(bool $eligibleForMortgage)
  2029.     {
  2030.         $this->eligibleForMortgage $eligibleForMortgage;
  2031.         return $this;
  2032.     }
  2033.     /**
  2034.      * Get Eligible For Mortgage.
  2035.      *
  2036.      * @return bool
  2037.      */
  2038.     public function getEligibleForMortgage()
  2039.     {
  2040.         return $this->eligibleForMortgage;
  2041.     }
  2042.     /**
  2043.      * Set isCompoundLocation.
  2044.      *
  2045.      * @param bool $isCompoundLocation
  2046.      *
  2047.      * @return Location
  2048.      */
  2049.     public function setIsCompoundLocation($isCompoundLocation)
  2050.     {
  2051.         $this->isCompoundLocation $isCompoundLocation;
  2052.         return $this;
  2053.     }
  2054.     /**
  2055.      * Get isCompoundLocation.
  2056.      *
  2057.      * @return bool
  2058.      */
  2059.     public function getIsCompoundLocation()
  2060.     {
  2061.         return $this->isCompoundLocation;
  2062.     }
  2063.     /**
  2064.      * @param self $location
  2065.      * @param array &$titlesFullPath
  2066.      */
  2067.     private function handleTitle($location, &$titlesFullPath): void
  2068.     {
  2069.         $translations $location->getTranslations() ? $location->getTranslations()->toArray() : [];
  2070.         foreach ($translations as $trans) {
  2071.             if ('en' == $trans->getLocale() && 'title' == $trans->getField()) {
  2072.                 $titlesFullPath[] = ucfirst($trans->getContent());
  2073.             }
  2074.         }
  2075.         $titlesFullPath[] = $location->getTitle();
  2076.     }
  2077.     private $listingOrNull;
  2078.     /**
  2079.      * @Serializer\VirtualProperty()
  2080.      *
  2081.      * @Serializer\Groups({"SlugResolver", "Compound", "locationListingV2", "homeCompoundV2", "listingDetailsWithLocationCompound"})
  2082.      *
  2083.      * @Serializer\SerializedName("compound_listing")
  2084.      *
  2085.      * @Serializer\Expose
  2086.      */
  2087.     public function getListingOrNull(): ?Listing
  2088.     {
  2089.         return $this->listingOrNull;
  2090.     }
  2091.     public function setListingOrNull(?Listing $listingOrNull): void
  2092.     {
  2093.         $this->listingOrNull $listingOrNull;
  2094.     }
  2095.     public function getAlias(): string
  2096.     {
  2097.         return $this->alias;
  2098.     }
  2099.     public function setAlias(string $alias): void
  2100.     {
  2101.         $this->alias $alias;
  2102.     }
  2103. }