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

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