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", "leadsBank"
  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", "leadsBank"
  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 string
  433.      *
  434.      * @Serializer\Groups({"listingDetails", "listingDetailsWithLocationCompound"})
  435.      *
  436.      * @Serializer\Expose
  437.      *
  438.      * @ORM\Column(name="type", type="string", length=50)
  439.      */
  440.     private $type;
  441.     /**
  442.      * @var array
  443.      */
  444.     private $locationTranslations = [];
  445.     /**
  446.      * @var array
  447.      */
  448.     private $v4Translations = [];
  449.     /**
  450.      * @ORM\Column(name="eligible_for_mortgage", type="boolean")
  451.      */
  452.     protected $eligibleForMortgage false;
  453.     /**
  454.      * @ORM\Column(name="is_compound_location", type="boolean")
  455.      *
  456.      * @Serializer\Expose
  457.      *
  458.      * @Serializer\Groups({"Autocomplete","List", "Data", "Details", "LocationFlat", "AutocompleteV3", "Compound", "SlugResolver"})
  459.      */
  460.     private $isCompoundLocation false;
  461.     /**
  462.      * @ORM\OneToMany(targetEntity="Location", mappedBy="parent")
  463.      *
  464.      * @ORM\OrderBy({"id" = "ASC"})
  465.      *
  466.      * @Serializer\Expose
  467.      *
  468.      * @Serializer\Groups({"Data"})
  469.      *
  470.      * @Serializer\MaxDepth(2)
  471.      *
  472.      * @Serializer\Accessor(getter="getChildrenSortedById")
  473.      *
  474.      * @Serializer\SerializedName("children")
  475.      */
  476.     private $childrenSortedById;
  477.     /**
  478.      * @Serializer\VirtualProperty
  479.      */
  480.     public function getLocation()
  481.     {
  482.         return $this->location;
  483.     }
  484.     public function getKeyword()
  485.     {
  486.         return $this->keyword;
  487.     }
  488.     /**
  489.      * @param mixed $keyword
  490.      */
  491.     public function setKeyword(string $keyword): self
  492.     {
  493.         $this->keyword $this->getKeyword() ? $this->getKeyword().','.$keyword $keyword;
  494.         return $this;
  495.     }
  496.     public function removeKeyword(string $keyword): self
  497.     {
  498.         $newKeyword array_diff(explode(','$this->getKeyword()), [$keyword]);
  499.         $this->keyword implode(','$newKeyword) ?? null;
  500.         return $this;
  501.     }
  502.     public function getFile()
  503.     {
  504.         return $this->file;
  505.     }
  506.     public function setFile($file): void
  507.     {
  508.         $this->file $file;
  509.     }
  510.     /**
  511.      * Constructor.
  512.      */
  513.     public function __construct()
  514.     {
  515.         $this->children = new ArrayCollection();
  516.         $this->translations = new ArrayCollection();
  517.         $this->listings = new ArrayCollection();
  518.         $this->notifiers = new ArrayCollection();
  519.         $this->rules = new ArrayCollection();
  520.         $this->locationStatistics = new ArrayCollection();
  521.         $this->photos = new ArrayCollection();
  522.         $this->discussions = new ArrayCollection();
  523.         $this->propertyTypes = new ArrayCollection();
  524.         $this->nearestLocations = new ArrayCollection();
  525.         $this->interests = new ArrayCollection();
  526.         $this->exchangeRequests = new ArrayCollection();
  527.     }
  528.     // ---------------------------------------------------------------------
  529.     /**
  530.      * Get id.
  531.      *
  532.      * @return int
  533.      */
  534.     public function getId()
  535.     {
  536.         return $this->id;
  537.     }
  538.     // ---------------------------------------------------------------------
  539.     /**
  540.      * Set title.
  541.      *
  542.      * @param string $title
  543.      *
  544.      * @return Location
  545.      */
  546.     public function setTitle($title)
  547.     {
  548.         $this->title $title;
  549.         return $this;
  550.     }
  551.     /**
  552.      * Get title.
  553.      *
  554.      * @return string
  555.      */
  556.     public function getTitle()
  557.     {
  558.         return $this->title;
  559.     }
  560.     /**
  561.      * @return string
  562.      */
  563.     public function getIndentedTitle()
  564.     {
  565.         return str_repeat('--'$this->getLevel()).' '.$this->getTitle();
  566.     }
  567.     // ---------------------------------------------------------------------
  568.     /**
  569.      * Set description.
  570.      *
  571.      * @param string $description
  572.      *
  573.      * @return Location
  574.      */
  575.     public function setDescription($description)
  576.     {
  577.         $this->description $description;
  578.         return $this;
  579.     }
  580.     /**
  581.      * Get description.
  582.      *
  583.      * @return string
  584.      */
  585.     public function getDescription()
  586.     {
  587.         return $this->description;
  588.     }
  589.     // ---------------------------------------------------------------------
  590.     /**
  591.      * Set slug.
  592.      *
  593.      * @param string $slug
  594.      *
  595.      * @return Location
  596.      */
  597.     public function setSlug($slug)
  598.     {
  599.         $this->slug $slug;
  600.         return $this;
  601.     }
  602.     /**
  603.      * Get slug.
  604.      *
  605.      * @return string
  606.      */
  607.     public function getSlug()
  608.     {
  609.         return $this->slug;
  610.     }
  611.     // ---------------------------------------------------------------------
  612.     /**
  613.      * Set centerLat.
  614.      *
  615.      * @param float $centerLat
  616.      *
  617.      * @return Location
  618.      */
  619.     public function setCenterLat($centerLat)
  620.     {
  621.         return $this->setLat($centerLat);
  622.     }
  623.     /**
  624.      * @Serializer\VirtualProperty()
  625.      *
  626.      * @Serializer\Groups({"Map", "Details", "Neighborhood", "LocationFlat", "Autocomplete"})
  627.      *
  628.      * @Serializer\SerializedName("center_lat")
  629.      *
  630.      * @Serializer\Until("v2.13")
  631.      *
  632.      * @Serializer\Expose
  633.      *
  634.      * @return float
  635.      */
  636.     public function getCenterLat()
  637.     {
  638.         return $this->getLat(2);
  639.     }
  640.     /**
  641.      * @param float $latitude
  642.      *
  643.      * @return Location
  644.      */
  645.     public function setLat($latitude)
  646.     {
  647.         $this->lat $latitude;
  648.         return $this;
  649.     }
  650.     /**
  651.      * @return float|null
  652.      */
  653.     public function getLat()
  654.     {
  655.         if (!$this->lat) {
  656.             return null;
  657.         }
  658.         return (float) $this->lat;
  659.     }
  660.     // ---------------------------------------------------------------------
  661.     /**
  662.      * Set lon.
  663.      *
  664.      * @deprecated
  665.      *
  666.      * @param float $lon
  667.      *
  668.      * @return Location
  669.      */
  670.     public function setCenterLng($lon)
  671.     {
  672.         return $this->setLon($lon);
  673.     }
  674.     /**
  675.      * @Serializer\VirtualProperty()
  676.      *
  677.      * @Serializer\Groups({"Map", "Details", "Neighborhood", "LocationFlat", "Autocomplete"})
  678.      *
  679.      * @Serializer\SerializedName("center_lng")
  680.      *
  681.      * @Serializer\Until("v2.13")
  682.      *
  683.      * @Serializer\Expose
  684.      *
  685.      * @deprecated
  686.      *
  687.      * @return float|null
  688.      */
  689.     public function getCenterLng()
  690.     {
  691.         return $this->getLon(2);
  692.     }
  693.     /**
  694.      * @param float $longitude
  695.      *
  696.      * @return Location
  697.      */
  698.     public function setLon($longitude)
  699.     {
  700.         $this->lon $longitude;
  701.         return $this;
  702.     }
  703.     /**
  704.      * @return float|null
  705.      */
  706.     public function getLon()
  707.     {
  708.         if (!$this->lon) {
  709.             return null;
  710.         }
  711.         return (float) $this->lon;
  712.     }
  713.     // ---------------------------------------------------------------------
  714.     /**
  715.      * Set zoom.
  716.      *
  717.      * @deprecated
  718.      *
  719.      * @param int $zoom
  720.      *
  721.      * @return Location
  722.      */
  723.     public function setZoomLevel($zoom)
  724.     {
  725.         return $this->setZoom($zoom);
  726.     }
  727.     /**
  728.      * @Serializer\VirtualProperty()
  729.      *
  730.      * @Serializer\Groups({"Map", "Details", "Neighborhood", "LocationFlat", "Autocomplete", "AutocompleteV3", "DefaultV4"})
  731.      *
  732.      * @Serializer\SerializedName("zoom_level")
  733.      *
  734.      * @Serializer\Until("v2.13")
  735.      *
  736.      * @Serializer\Expose
  737.      *
  738.      * @deprecated
  739.      *
  740.      * @return int
  741.      */
  742.     public function getZoomLevel()
  743.     {
  744.         return $this->getZoom();
  745.     }
  746.     public function setZoom(?int $level): self
  747.     {
  748.         $this->zoom $level;
  749.         return $this;
  750.     }
  751.     /**
  752.      * @Serializer\VirtualProperty()
  753.      *
  754.      * @Serializer\SerializedName("zoom")
  755.      *
  756.      * @Serializer\Groups({"DataJS"})
  757.      *
  758.      * @return int|null
  759.      */
  760.     public function getZoom()
  761.     {
  762.         return $this->zoom;
  763.     }
  764.     // ---------------------------------------------------------------------
  765.     /**
  766.      * Set coordinates.
  767.      *
  768.      * @param array $coordinates
  769.      *
  770.      * @return Location
  771.      */
  772.     public function setCoordinates($coordinates)
  773.     {
  774.         $this->coordinates $coordinates;
  775.         return $this;
  776.     }
  777.     /**
  778.      * Get coordinates.
  779.      *
  780.      * @return array
  781.      */
  782.     public function getCoordinates()
  783.     {
  784.         return $this->coordinates;
  785.     }
  786.     // ---------------------------------------------------------------------
  787.     /**
  788.      * Set searchable.
  789.      *
  790.      * @param bool $searchable
  791.      *
  792.      * @return Location
  793.      */
  794.     public function setSearchable($searchable)
  795.     {
  796.         $this->searchable $searchable;
  797.         return $this;
  798.     }
  799.     /**
  800.      * Get searchable.
  801.      *
  802.      * @return bool
  803.      */
  804.     public function getSearchable()
  805.     {
  806.         return $this->searchable;
  807.     }
  808.     // ---------------------------------------------------------------------
  809.     /**
  810.      * Set homeFilter.
  811.      *
  812.      * @param bool $homeFilter
  813.      *
  814.      * @return Location
  815.      */
  816.     public function setHomeFilter($homeFilter)
  817.     {
  818.         $this->homeFilter $homeFilter;
  819.         return $this;
  820.     }
  821.     /**
  822.      * Get homeFilter.
  823.      *
  824.      * @return bool
  825.      */
  826.     public function getHomeFilter()
  827.     {
  828.         return $this->homeFilter;
  829.     }
  830.     // ---------------------------------------------------------------------
  831.     /**
  832.      * Set estimate.
  833.      *
  834.      * @param bool $estimate
  835.      *
  836.      * @return Location
  837.      */
  838.     public function setEstimate($estimate)
  839.     {
  840.         $this->estimate $estimate;
  841.         return $this;
  842.     }
  843.     /**
  844.      * Get estimate.
  845.      *
  846.      * @return bool
  847.      */
  848.     public function getEstimate()
  849.     {
  850.         return $this->estimate;
  851.     }
  852.     // ---------------------------------------------------------------------
  853.     /**
  854.      * Set disabled.
  855.      *
  856.      * @param bool $disabled
  857.      *
  858.      * @return Location
  859.      */
  860.     public function setDisabled($disabled)
  861.     {
  862.         $this->disabled $disabled;
  863.         return $this;
  864.     }
  865.     /**
  866.      * Get disabled.
  867.      *
  868.      * @return bool
  869.      */
  870.     public function getDisabled()
  871.     {
  872.         return $this->disabled;
  873.     }
  874.     // ---------------------------------------------------------------------
  875.     /**
  876.      * Set parent.
  877.      *
  878.      * @return Location
  879.      */
  880.     public function setParent(?self $parent null)
  881.     {
  882.         $this->parent $parent;
  883.         return $this;
  884.     }
  885.     /**
  886.      * Get parent.
  887.      *
  888.      * @return Location
  889.      */
  890.     public function getParent()
  891.     {
  892.         return $this->parent;
  893.     }
  894.     // ---------------------------------------------------------------------
  895.     /**
  896.      * Add children.
  897.      *
  898.      * @return Location
  899.      */
  900.     public function addChild(self $children)
  901.     {
  902.         $this->children[] = $children;
  903.         return $this;
  904.     }
  905.     /**
  906.      * Remove children.
  907.      */
  908.     public function removeChild(self $children): void
  909.     {
  910.         $this->children->removeElement($children);
  911.     }
  912.     /**
  913.      * Get children.
  914.      *
  915.      * @return Collection
  916.      */
  917.     public function getChildren()
  918.     {
  919.         $criteria Criteria::create()
  920.             ->where(Criteria::expr()->eq('disabled'false));
  921.         return $this->children->matching($criteria);
  922.     }
  923.     /**
  924.      * Get children sorted by id.
  925.      *
  926.      * @return Collection
  927.      */
  928.     public function getChildrenSortedById($filters = [])
  929.     {
  930.         $criteria Criteria::create()
  931.             ->where(Criteria::expr()->eq('disabled'false));
  932.         if (isset($filters['neighborhoodFilter'])) {
  933.             $criteria->andWhere(Criteria::expr()->eq('neighborhoodFilter'$filters['neighborhoodFilter']));
  934.         }
  935.         return $this->childrenSortedById->matching($criteria);
  936.     }
  937.     /**
  938.      * Get children.
  939.      *
  940.      * @return Collection
  941.      */
  942.     public function getChildrenArray()
  943.     {
  944.         $criteria Criteria::create()
  945.             ->where(Criteria::expr()->eq('disabled'false));
  946.         return $this->children->matching($criteria)->toArray();
  947.     }
  948.     /**
  949.      * Get neighborhoodchildren.
  950.      *
  951.      * @return Collection
  952.      */
  953.     public function getNeighborhoodChildren()
  954.     {
  955.         $criteria Criteria::create()
  956.             ->andWhere(Criteria::expr()->eq('disabled'false))
  957.             ->andWhere(Criteria::expr()->eq('neighborhoodFilter'true));
  958.         return $this->children->matching($criteria);
  959.     }
  960.     /**
  961.      * Get leveled children.
  962.      *
  963.      * @return Collection
  964.      */
  965.     public function getLeveledChildren()
  966.     {
  967.         $criteria Criteria::create()
  968.             ->where(Criteria::expr()->eq('disabled'false))
  969.             ->where(Criteria::expr()->lte('level'2));
  970.         return $this->children->matching($criteria);
  971.     }
  972.     /**
  973.      * Set type.
  974.      *
  975.      * @param string $type
  976.      *
  977.      * @return Location
  978.      */
  979.     public function setType($type)
  980.     {
  981.         $this->type $type;
  982.         return $this;
  983.     }
  984.     /**
  985.      * Get type.
  986.      *
  987.      * @return string
  988.      */
  989.     public function getType()
  990.     {
  991.         return $this->type;
  992.     }
  993.     // ---------------------------------------------------------------------
  994.     /**
  995.      * Get translations.
  996.      *
  997.      * @return ArrayCollection
  998.      */
  999.     public function getTranslations()
  1000.     {
  1001.         return $this->translations;
  1002.     }
  1003.     /**
  1004.      * Add translation.
  1005.      *
  1006.      * @return Location
  1007.      */
  1008.     public function addTranslation(LocationTranslation $translation)
  1009.     {
  1010.         if (!$this->translations->contains($translation)) {
  1011.             $this->translations->add($translation);
  1012.             $translation->setObject($this);
  1013.         }
  1014.         return $this;
  1015.     }
  1016.     /**
  1017.      * Remove translation.
  1018.      *
  1019.      * @return Location
  1020.      */
  1021.     public function removeTranslation(LocationTranslation $translation)
  1022.     {
  1023.         if ($this->translations->contains($translation)) {
  1024.             $this->translations->removeElement($translation);
  1025.         }
  1026.         return $this;
  1027.     }
  1028.     // ---------------------------------------------------------------------
  1029.     /**
  1030.      * Add listings.
  1031.      *
  1032.      * @return Location
  1033.      */
  1034.     public function addListing(Listing $listings)
  1035.     {
  1036.         $this->listings[] = $listings;
  1037.         return $this;
  1038.     }
  1039.     /**
  1040.      * Remove listings.
  1041.      */
  1042.     public function removeListing(Listing $listings): void
  1043.     {
  1044.         $this->listings->removeElement($listings);
  1045.     }
  1046.     /**
  1047.      * Get listings.
  1048.      *
  1049.      * @return Collection
  1050.      */
  1051.     public function getListings()
  1052.     {
  1053.         return $this->listings;
  1054.     }
  1055.     // ---------------------------------------------------------------------
  1056.     /**
  1057.      * Add notifiers.
  1058.      *
  1059.      * @return Location
  1060.      */
  1061.     public function addNotifier(Notifier $notifiers)
  1062.     {
  1063.         $this->notifiers[] = $notifiers;
  1064.         return $this;
  1065.     }
  1066.     /**
  1067.      * Remove notifiers.
  1068.      */
  1069.     public function removeNotifier(Notifier $notifiers): void
  1070.     {
  1071.         $this->notifiers->removeElement($notifiers);
  1072.     }
  1073.     /**
  1074.      * Get notifiers.
  1075.      *
  1076.      * @return Collection
  1077.      */
  1078.     public function getNotifiers()
  1079.     {
  1080.         return $this->notifiers;
  1081.     }
  1082.     // ---------------------------------------------------------------------
  1083.     /**
  1084.      * Add rules.
  1085.      *
  1086.      * @return Location
  1087.      */
  1088.     public function addRule(Rule $rules)
  1089.     {
  1090.         $this->rules[] = $rules;
  1091.         return $this;
  1092.     }
  1093.     /**
  1094.      * Remove rules.
  1095.      */
  1096.     public function removeRule(Rule $rules): void
  1097.     {
  1098.         $this->rules->removeElement($rules);
  1099.     }
  1100.     /**
  1101.      * Get rules.
  1102.      *
  1103.      * @return Collection
  1104.      */
  1105.     public function getRules()
  1106.     {
  1107.         return $this->rules;
  1108.     }
  1109.     // ---------------------------------------------------------------------
  1110.     /**
  1111.      * Get Nearest Searchable Location.
  1112.      */
  1113.     public function getNearestSearchable()
  1114.     {
  1115.         $location $this;
  1116.         while ($location && !$location->getSearchable()) {
  1117.             $location $location->getParent();
  1118.         }
  1119.         if (!$location) {
  1120.             return $this;
  1121.         }
  1122.         return $location;
  1123.     }
  1124.     // -----------------------------------------------------------------------------
  1125.     /**
  1126.      * Get Nearest Neighborhood Parent.
  1127.      */
  1128.     public function getNearestNeighborhood()
  1129.     {
  1130.         $location $this;
  1131.         while (
  1132.             !$location->getNeighborhoodFilter()
  1133.             && $location->getParent()
  1134.             && != $location->getParent()->getLevel()
  1135.         ) {
  1136.             $location $location->getParent();
  1137.         }
  1138.         if (!$location->getNeighborhoodFilter() || == $location->getLevel()) {
  1139.             return;
  1140.         }
  1141.         return $location;
  1142.     }
  1143.     /**
  1144.      * Get Nearest Location Custom Level .
  1145.      *
  1146.      * @param int $level
  1147.      *
  1148.      * @return Location
  1149.      */
  1150.     public function getNearestLeveledLocation($level 1)
  1151.     {
  1152.         $location $this;
  1153.         if (\in_array($location->getLevel(), [0$level])) {
  1154.             return $location;
  1155.         }
  1156.         while ($location->getParent() && != $location->getParent()->getLevel()) {
  1157.             $location $location->getParent();
  1158.         }
  1159.         return $location;
  1160.     }
  1161.     /**
  1162.      * @Serializer\VirtualProperty
  1163.      *
  1164.      * @Serializer\SerializedName("parent")
  1165.      *
  1166.      * @Serializer\Expose
  1167.      *
  1168.      * @Serializer\Groups({"LocationFlat"})
  1169.      */
  1170.     public function getVirtualParent()
  1171.     {
  1172.         $parent $this->getParent();
  1173.         if ($parent) {
  1174.             return [
  1175.                 'id' => $parent->getId(),
  1176.                 'title' => $parent->getTitle(),
  1177.             ];
  1178.         }
  1179.         return null;
  1180.     }
  1181.     /**
  1182.      * Gets parent by level.
  1183.      *
  1184.      * @param int $level
  1185.      *
  1186.      * @return Location|null
  1187.      */
  1188.     public function getLeveledParent($level 1)
  1189.     {
  1190.         $location $this;
  1191.         while ($location $location->getParent()) {
  1192.             if ($location->getLevel() == $level) {
  1193.                 return $location;
  1194.             }
  1195.         }
  1196.         return null;
  1197.     }
  1198.     /**
  1199.      * Get Nearest Location Custom Level .
  1200.      *
  1201.      * @return Location
  1202.      */
  1203.     public function getFirstParent()
  1204.     {
  1205.         $location $this;
  1206.         if (== $location->getLevel()) {
  1207.             return $location;
  1208.         }
  1209.         while ($location $location->getParent()) {
  1210.             if (== $location->getLevel()) {
  1211.                 return $location;
  1212.             }
  1213.         }
  1214.         return $location;
  1215.     }
  1216.     /**
  1217.      * Set level.
  1218.      *
  1219.      * @param int $level
  1220.      *
  1221.      * @return Location
  1222.      */
  1223.     public function setLevel($level)
  1224.     {
  1225.         $this->level $level;
  1226.         return $this;
  1227.     }
  1228.     /**
  1229.      * Get level.
  1230.      *
  1231.      * @return int
  1232.      */
  1233.     public function getLevel()
  1234.     {
  1235.         return $this->level;
  1236.     }
  1237.     /**
  1238.      * Set left.
  1239.      *
  1240.      * @param int $left
  1241.      *
  1242.      * @return Location
  1243.      */
  1244.     public function setLeft($left)
  1245.     {
  1246.         $this->left $left;
  1247.         return $this;
  1248.     }
  1249.     /**
  1250.      * Get left.
  1251.      *
  1252.      * @return int
  1253.      */
  1254.     public function getLeft()
  1255.     {
  1256.         return $this->left;
  1257.     }
  1258.     /**
  1259.      * Set right.
  1260.      *
  1261.      * @param int $right
  1262.      *
  1263.      * @return Location
  1264.      */
  1265.     public function setRight($right)
  1266.     {
  1267.         $this->right $right;
  1268.         return $this;
  1269.     }
  1270.     /**
  1271.      * Get right.
  1272.      *
  1273.      * @return int
  1274.      */
  1275.     public function getRight()
  1276.     {
  1277.         return $this->right;
  1278.     }
  1279.     /**
  1280.      * Set root.
  1281.      *
  1282.      * @param int $root
  1283.      *
  1284.      * @return Location
  1285.      */
  1286.     public function setRoot($root)
  1287.     {
  1288.         $this->root $root;
  1289.         return $this;
  1290.     }
  1291.     /**
  1292.      * Get root.
  1293.      *
  1294.      * @return int
  1295.      */
  1296.     public function getRoot()
  1297.     {
  1298.         return $this->root;
  1299.     }
  1300.     /**
  1301.      * Add locationSupplyDemand.
  1302.      *
  1303.      * @return Location
  1304.      */
  1305.     public function addLocationSupplyDemand(LocationSupplyDemand $locationSupplyDemand)
  1306.     {
  1307.         $this->locationSupplyDemand[] = $locationSupplyDemand;
  1308.         return $this;
  1309.     }
  1310.     /**
  1311.      * Remove locationSupplyDemand.
  1312.      */
  1313.     public function removeLocationSupplyDemand(LocationSupplyDemand $locationSupplyDemand): void
  1314.     {
  1315.         $this->locationSupplyDemand->removeElement($locationSupplyDemand);
  1316.     }
  1317.     /**
  1318.      * Get locationSupplyDemand.
  1319.      *
  1320.      * @return Collection
  1321.      */
  1322.     public function getLocationSupplyDemand()
  1323.     {
  1324.         return $this->locationSupplyDemand;
  1325.     }
  1326.     // ---------------------------------------------------------------------
  1327.     /**
  1328.      * Add photos.
  1329.      *
  1330.      * @return Location
  1331.      */
  1332.     public function addPhoto(LocationPhoto $photo)
  1333.     {
  1334.         $photo->setLocation($this);
  1335.         $this->photos[] = $photo;
  1336.         return $this;
  1337.     }
  1338.     /**
  1339.      * Set photos.
  1340.      *
  1341.      * @return Location
  1342.      */
  1343.     public function setPhotos($photos)
  1344.     {
  1345.         foreach ($photos as $photo) {
  1346.             $this->addPhoto($photo);
  1347.         }
  1348.         return $this;
  1349.     }
  1350.     /**
  1351.      * Remove photos.
  1352.      */
  1353.     public function removePhoto(LocationPhoto $photo): void
  1354.     {
  1355.         $this->photos->removeElement($photo);
  1356.     }
  1357.     /**
  1358.      * @return ArrayCollection
  1359.      */
  1360.     public function getPhotos()
  1361.     {
  1362.         return $this->photos;
  1363.     }
  1364.     /**
  1365.      * @return mixed|null
  1366.      *
  1367.      * @Serializer\VirtualProperty
  1368.      *
  1369.      * @Serializer\Groups({"Default", "LocationFlat"})
  1370.      */
  1371.     public function getMainPhoto()
  1372.     {
  1373.         // Important for API
  1374.         if ($this->getPhotos()->count() <= 0) {
  1375.             return;
  1376.         }
  1377.         /* @var Photo $photo */
  1378.         $mainPhoto $this->photos->filter(fn ($photo) => PhotoTypes::MAIN_PHOTO == $photo->getType());
  1379.         return $mainPhoto->first() ?: $this->getPhotos()->first();
  1380.     }
  1381.     // ---------------------------------------------------------------------
  1382.     public function __clone()
  1383.     {
  1384.         $this->id null;
  1385.     }
  1386.     public function __toString()
  1387.     {
  1388.         return $this->title;
  1389.     }
  1390.     /**
  1391.      * Set rating.
  1392.      *
  1393.      * @return Location
  1394.      */
  1395.     public function setRating(?LocationRating $rating null)
  1396.     {
  1397.         $this->rating $rating;
  1398.         $this->rating->setLocation($this);
  1399.         return $this;
  1400.     }
  1401.     /**
  1402.      * Get rating.
  1403.      *
  1404.      * @return LocationRating
  1405.      */
  1406.     public function getRating()
  1407.     {
  1408.         return $this->rating;
  1409.     }
  1410.     /**
  1411.      * Set neighborhoodFilter.
  1412.      *
  1413.      * @param bool $neighborhoodFilter
  1414.      *
  1415.      * @return Location
  1416.      */
  1417.     public function setNeighborhoodFilter($neighborhoodFilter)
  1418.     {
  1419.         $this->neighborhoodFilter $neighborhoodFilter;
  1420.         return $this;
  1421.     }
  1422.     /**
  1423.      * Get neighborhoodFilter.
  1424.      *
  1425.      * @return bool
  1426.      */
  1427.     public function getNeighborhoodFilter()
  1428.     {
  1429.         return $this->neighborhoodFilter;
  1430.     }
  1431.     /**
  1432.      * Add locationStatistic.
  1433.      *
  1434.      * @return Location
  1435.      */
  1436.     public function addLocationStatistic(LocationStatistics $locationStatistic)
  1437.     {
  1438.         $this->locationStatistics[] = $locationStatistic;
  1439.         return $this;
  1440.     }
  1441.     /**
  1442.      * Remove locationStatistic.
  1443.      */
  1444.     public function removeLocationStatistic(LocationStatistics $locationStatistic): void
  1445.     {
  1446.         $this->locationStatistics->removeElement($locationStatistic);
  1447.     }
  1448.     /**
  1449.      * Get locationStatistics.
  1450.      *
  1451.      * @return Collection
  1452.      */
  1453.     public function getLocationStatistics()
  1454.     {
  1455.         return $this->locationStatistics;
  1456.     }
  1457.     /**
  1458.      * Get lowest Average Price.
  1459.      *
  1460.      * @return LocationStatistics $locationStatistic
  1461.      */
  1462.     public function getSingleStatistics(?PropertyType $propertyType null)
  1463.     {
  1464.         $criteria Criteria::create()
  1465.             ->andWhere(Criteria::expr()->neq('avgPrice'null))
  1466.             ->andWhere(Criteria::expr()->gt('avgPrice'0))
  1467.             ->orderBy(['avgPrice' => Criteria::ASC]);
  1468.         if ($propertyType) {
  1469.             $criteria
  1470.                 ->andWhere(Criteria::expr()->eq('propertyType'$propertyType));
  1471.         }
  1472.         return $this->locationStatistics->matching($criteria)->first();
  1473.     }
  1474.     /**
  1475.      * Set statisticsFilter.
  1476.      *
  1477.      * @param bool $statisticsFilter
  1478.      *
  1479.      * @return Location
  1480.      */
  1481.     public function setStatisticsFilter($statisticsFilter)
  1482.     {
  1483.         $this->statisticsFilter $statisticsFilter;
  1484.         return $this;
  1485.     }
  1486.     /**
  1487.      * Get statisticsFilter.
  1488.      *
  1489.      * @return bool
  1490.      */
  1491.     public function getStatisticsFilter()
  1492.     {
  1493.         return $this->statisticsFilter;
  1494.     }
  1495.     /**
  1496.      * Add company.
  1497.      *
  1498.      * @return Location
  1499.      */
  1500.     public function addCompany(\Aqarmap\Bundle\CRMBundle\Entity\Company $company)
  1501.     {
  1502.         $this->companies[] = $company;
  1503.         return $this;
  1504.     }
  1505.     /**
  1506.      * Remove company.
  1507.      */
  1508.     public function removeCompany(\Aqarmap\Bundle\CRMBundle\Entity\Company $company): void
  1509.     {
  1510.         $this->companies->removeElement($company);
  1511.     }
  1512.     /**
  1513.      * Get companies.
  1514.      *
  1515.      * @return Collection
  1516.      */
  1517.     public function getCompanies()
  1518.     {
  1519.         return $this->companies;
  1520.     }
  1521.     /**
  1522.      * Add discussion.
  1523.      *
  1524.      * @return Location
  1525.      */
  1526.     public function addDiscussion(Discussion $discussion)
  1527.     {
  1528.         $this->discussions[] = $discussion;
  1529.         return $this;
  1530.     }
  1531.     /**
  1532.      * Remove discussion.
  1533.      */
  1534.     public function removeDiscussion(Discussion $discussion): void
  1535.     {
  1536.         $this->discussions->removeElement($discussion);
  1537.     }
  1538.     /**
  1539.      * Get discussions.
  1540.      *
  1541.      * @return Collection
  1542.      */
  1543.     public function getDiscussions()
  1544.     {
  1545.         return $this->discussions;
  1546.     }
  1547.     /**
  1548.      * Set compoundFilter.
  1549.      *
  1550.      * @param bool $compoundFilter
  1551.      *
  1552.      * @return Location
  1553.      */
  1554.     public function setCompoundFilter($compoundFilter)
  1555.     {
  1556.         $this->compoundFilter $compoundFilter;
  1557.         return $this;
  1558.     }
  1559.     /**
  1560.      * Get compoundFilter.
  1561.      *
  1562.      * @return bool
  1563.      */
  1564.     public function getCompoundFilter()
  1565.     {
  1566.         return $this->compoundFilter;
  1567.     }
  1568.     /**
  1569.      * Add propertyType.
  1570.      *
  1571.      * @return Location
  1572.      */
  1573.     public function addPropertyType(PropertyType $propertyType)
  1574.     {
  1575.         $this->propertyTypes[] = $propertyType;
  1576.         return $this;
  1577.     }
  1578.     /**
  1579.      * Remove propertyType.
  1580.      */
  1581.     public function removePropertyType(PropertyType $propertyType): void
  1582.     {
  1583.         $this->propertyTypes->removeElement($propertyType);
  1584.     }
  1585.     /**
  1586.      * Get propertyTypes.
  1587.      *
  1588.      * @return Collection
  1589.      */
  1590.     public function getPropertyTypes()
  1591.     {
  1592.         return $this->propertyTypes;
  1593.     }
  1594.     /**
  1595.      * Set listing.
  1596.      *
  1597.      * @return Location
  1598.      */
  1599.     public function setListing(?Listing $listing null)
  1600.     {
  1601.         $this->listing $listing;
  1602.         return $this;
  1603.     }
  1604.     /**
  1605.      * Set listing.
  1606.      *
  1607.      * @return Location
  1608.      */
  1609.     public function setListings(array $listings = [])
  1610.     {
  1611.         $this->listings $listings;
  1612.         return $this;
  1613.     }
  1614.     /**
  1615.      * Get listing.
  1616.      *
  1617.      * @return Listing
  1618.      */
  1619.     public function getListing()
  1620.     {
  1621.         return $this->listing;
  1622.     }
  1623.     /**
  1624.      * Set locationCompound.
  1625.      *
  1626.      * @return Location
  1627.      */
  1628.     public function setLocationCompound(?LocationCompound $locationCompound null)
  1629.     {
  1630.         $this->locationCompound $locationCompound;
  1631.         $this->locationCompound->setLocation($this);
  1632.         return $this;
  1633.     }
  1634.     /**
  1635.      * Get locationCompound.
  1636.      *
  1637.      * @return LocationCompound
  1638.      */
  1639.     public function getLocationCompound()
  1640.     {
  1641.         return $this->locationCompound;
  1642.     }
  1643.     /**
  1644.      * Add nearestLocation.
  1645.      *
  1646.      * @return Location
  1647.      */
  1648.     public function addNearestLocation(self $nearestLocation)
  1649.     {
  1650.         if (!$this->nearestLocations->contains($nearestLocation)) {
  1651.             $this->nearestLocations->add($nearestLocation);
  1652.         }
  1653.         return $this;
  1654.     }
  1655.     /**
  1656.      * Remove nearestLocation.
  1657.      *
  1658.      * @return Location
  1659.      */
  1660.     public function removeNearestLocation(self $nearestLocation)
  1661.     {
  1662.         if ($this->nearestLocations->contains($nearestLocation)) {
  1663.             $this->nearestLocations->removeElement($nearestLocation);
  1664.         }
  1665.         return $this;
  1666.     }
  1667.     /**
  1668.      * Get nearestLocations.
  1669.      *
  1670.      * @return Collection
  1671.      */
  1672.     public function getNearestLocations()
  1673.     {
  1674.         return $this->nearestLocations;
  1675.     }
  1676.     /**
  1677.      * Add interest.
  1678.      *
  1679.      * @return Location
  1680.      */
  1681.     public function addInterest(UserInterest $interest)
  1682.     {
  1683.         $this->interests[] = $interest;
  1684.         return $this;
  1685.     }
  1686.     /**
  1687.      * Remove interest.
  1688.      */
  1689.     public function removeInterest(UserInterest $interest): void
  1690.     {
  1691.         $this->interests->removeElement($interest);
  1692.     }
  1693.     /**
  1694.      * Get interests.
  1695.      *
  1696.      * @return Collection
  1697.      */
  1698.     public function getInterests()
  1699.     {
  1700.         return $this->interests;
  1701.     }
  1702.     /**
  1703.      * Get interests.
  1704.      *
  1705.      * @return UserInterest
  1706.      */
  1707.     public function getLiveInterests()
  1708.     {
  1709.         $criteria Criteria::create()
  1710.             ->andwhere(Criteria::expr()->eq('status'UserInterestStatus::LIVE));
  1711.         return $this->interests->matching($criteria);
  1712.     }
  1713.     public function setTranslatableLocale($locale): void
  1714.     {
  1715.         $this->locale $locale;
  1716.     }
  1717.     /**
  1718.      * Add exchangeRequest.
  1719.      *
  1720.      * @return Location
  1721.      */
  1722.     public function addExchangeRequest(ExchangeRequest $exchangeRequest)
  1723.     {
  1724.         $this->exchangeRequests[] = $exchangeRequest;
  1725.         return $this;
  1726.     }
  1727.     /**
  1728.      * Remove exchangeRequest.
  1729.      */
  1730.     public function removeExchangeRequest(ExchangeRequest $exchangeRequest): void
  1731.     {
  1732.         $this->exchangeRequests->removeElement($exchangeRequest);
  1733.     }
  1734.     /**
  1735.      * Get exchangeRequests.
  1736.      *
  1737.      * @return Collection
  1738.      */
  1739.     public function getExchangeRequests()
  1740.     {
  1741.         return $this->exchangeRequests;
  1742.     }
  1743.     public function setSearchTerms($searchTerms): void
  1744.     {
  1745.         $this->searchTerms $searchTerms;
  1746.     }
  1747.     public function getSearchTerms()
  1748.     {
  1749.         return $this->searchTerms;
  1750.     }
  1751.     /**
  1752.      * @return int
  1753.      */
  1754.     public function getLeadsCounter()
  1755.     {
  1756.         return $this->leadsCounter;
  1757.     }
  1758.     /**
  1759.      * @param int $leadsCounter
  1760.      */
  1761.     public function setLeadsCounter($leadsCounter): void
  1762.     {
  1763.         $this->leadsCounter $leadsCounter;
  1764.     }
  1765.     /**
  1766.      * @return int
  1767.      */
  1768.     public function getListingsCounter()
  1769.     {
  1770.         return $this->listingsCounter;
  1771.     }
  1772.     /**
  1773.      * @param int $listingsCounter
  1774.      *
  1775.      * @return Location
  1776.      */
  1777.     public function setListingsCounter($listingsCounter)
  1778.     {
  1779.         $this->listingsCounter $listingsCounter;
  1780.         return $this;
  1781.     }
  1782.     /**
  1783.      * @return int
  1784.      */
  1785.     public function getLocationParentLabel()
  1786.     {
  1787.         $parent $this->getParent() ? $this->getParent()->getTitle().' / ' null;
  1788.         return $parent.$this->getTitle();
  1789.     }
  1790.     /**
  1791.      * @return int
  1792.      */
  1793.     public function getLastSlug()
  1794.     {
  1795.         $segments explode('/'$this->slug);
  1796.         return end($segments);
  1797.     }
  1798.     /**
  1799.      * @return bool
  1800.      *
  1801.      * @Serializer\VirtualProperty()
  1802.      *
  1803.      * @Serializer\SerializedName("has_children")
  1804.      *
  1805.      * @Serializer\Expose()
  1806.      *
  1807.      * @Serializer\Groups({"LocationFlat", "AutocompleteV3", "DefaultV4"})
  1808.      */
  1809.     public function getHasChildren()
  1810.     {
  1811.         return $this->getChildren()->isEmpty() ? false true;
  1812.     }
  1813.     /**
  1814.      * @Serializer\VirtualProperty()
  1815.      *
  1816.      * @Serializer\SerializedName("text")
  1817.      *
  1818.      * @Serializer\Groups({"Autocomplete"})
  1819.      *
  1820.      * @Serializer\Expose
  1821.      *
  1822.      * @return string
  1823.      */
  1824.     public function getText()
  1825.     {
  1826.         return $this->getTitle();
  1827.     }
  1828.     /**
  1829.      * Get Title FullPath
  1830.      * e.g. takes 90th street and returns Greater Cairo / New Cairo / 90th Street.
  1831.      *
  1832.      * @Serializer\VirtualProperty()
  1833.      *
  1834.      * @Serializer\SerializedName("title_full_path")
  1835.      *
  1836.      * @Serializer\Groups({"Autocomplete", "listingDetails", "AutocompleteV3", "DefaultV4", "SearchV4", "ProjectDetailsV4", "SlugResolver", "RelatedListingsV2"})
  1837.      *
  1838.      * @Serializer\Expose
  1839.      */
  1840.     public function getTitleFullPath(): string
  1841.     {
  1842.         $location $this;
  1843.         $titlesFullPath[] = $this->getTitle();
  1844.         while ($location $location->getParent()) {
  1845.             $titlesFullPath[] = $location->getTitle();
  1846.         }
  1847.         return implode(' / 'array_reverse($titlesFullPath ?? []));
  1848.     }
  1849.     /**
  1850.      * Get searchable title keywords
  1851.      * e.g. takes 90th street and returns Greater Cairo / New Cairo / 90th Street.
  1852.      */
  1853.     public function getSearchableTitle(): string
  1854.     {
  1855.         $location $this;
  1856.         $titlesFullPath = [];
  1857.         $this->handleTitle($location$titlesFullPath);
  1858.         while ($location $location->getParent()) {
  1859.             $this->handleTitle($location$titlesFullPath);
  1860.         }
  1861.         return implode(' / 'array_reverse($titlesFullPath ?? []));
  1862.     }
  1863.     /**
  1864.      * Get Title FullPath started from children
  1865.      * e.g. takes 90th street and returns Greater 90th Street - New Cairo - Cairo.
  1866.      */
  1867.     public function getTitleFullPathStartedFromChildren(): string
  1868.     {
  1869.         $location $this;
  1870.         $titlesFullPath[] = $this->getTitle();
  1871.         while ($location $location->getParent()) {
  1872.             $titlesFullPath[] = $location->getTitle();
  1873.         }
  1874.         return implode(' - '$titlesFullPath);
  1875.     }
  1876.     /**
  1877.      * @return Location
  1878.      */
  1879.     public function setSynced($synced)
  1880.     {
  1881.         $this->synced $synced;
  1882.         return $this;
  1883.     }
  1884.     public function getSynced()
  1885.     {
  1886.         return $this->synced;
  1887.     }
  1888.     /**
  1889.      * @Serializer\VirtualProperty()
  1890.      *
  1891.      * @Serializer\Groups({"Autocomplete"})
  1892.      *
  1893.      * @Serializer\Expose
  1894.      */
  1895.     public function getTranslation(): array
  1896.     {
  1897.         $translations = [];
  1898.         foreach ($this->getTranslations()->toArray() as $trans) {
  1899.             $translations[$trans->getLocale()] = $trans->getContent();
  1900.         }
  1901.         return $translations;
  1902.     }
  1903.     /**
  1904.      * @return string|null
  1905.      */
  1906.     public function getFullPath()
  1907.     {
  1908.         return $this->fullPath;
  1909.     }
  1910.     public function setFullPath(?string $fullPath null): self
  1911.     {
  1912.         $this->fullPath $fullPath;
  1913.         return $this;
  1914.     }
  1915.     /**
  1916.      * @Serializer\VirtualProperty()
  1917.      *
  1918.      * @Serializer\SerializedName("name")
  1919.      *
  1920.      * @Serializer\Groups({"AutocompleteV3", "DefaultV4", "SearchV4"})
  1921.      *
  1922.      * @Serializer\Expose
  1923.      *
  1924.      * @return string
  1925.      */
  1926.     public function getName()
  1927.     {
  1928.         return $this->getTitle();
  1929.     }
  1930.     /**
  1931.      * @Serializer\VirtualProperty()
  1932.      *
  1933.      * @Serializer\SerializedName("latitude")
  1934.      *
  1935.      * @Serializer\Groups({"AutocompleteV3", "DefaultV4", "ProjectDetailsV4"})
  1936.      *
  1937.      * @Serializer\Expose
  1938.      *
  1939.      * @return string
  1940.      */
  1941.     public function getLatitude()
  1942.     {
  1943.         return $this->getLat();
  1944.     }
  1945.     /**
  1946.      * @Serializer\VirtualProperty()
  1947.      *
  1948.      * @Serializer\SerializedName("longitude")
  1949.      *
  1950.      * @Serializer\Groups({"AutocompleteV3", "DefaultV4", "ProjectDetailsV4"})
  1951.      *
  1952.      * @Serializer\Expose
  1953.      *
  1954.      * @return string
  1955.      */
  1956.     public function getLongitude()
  1957.     {
  1958.         return $this->getLon();
  1959.     }
  1960.     /**
  1961.      * @Serializer\VirtualProperty()
  1962.      *
  1963.      * @Serializer\Groups({"AutocompleteV3"})
  1964.      *
  1965.      * @Serializer\SerializedName("translations")
  1966.      *
  1967.      * @Serializer\Expose
  1968.      */
  1969.     public function getLocationTranslations(): array
  1970.     {
  1971.         return $this->locationTranslations;
  1972.     }
  1973.     public function setLocationTranslations(array $translation): self
  1974.     {
  1975.         $this->locationTranslations $translation;
  1976.         return $this;
  1977.     }
  1978.     /**
  1979.      * @return int|null
  1980.      */
  1981.     public function getReferenceId()
  1982.     {
  1983.         return $this->id;
  1984.     }
  1985.     /**
  1986.      * @return self
  1987.      */
  1988.     public function setReferenceId(?int $referenceId)
  1989.     {
  1990.         $this->referenceId $referenceId;
  1991.         return $this;
  1992.     }
  1993.     /**
  1994.      * @Serializer\VirtualProperty()
  1995.      *
  1996.      * @Serializer\Groups({"DefaultV4"})
  1997.      *
  1998.      * @Serializer\SerializedName("listingsCount")
  1999.      *
  2000.      * @Serializer\Expose
  2001.      *
  2002.      * @return int
  2003.      */
  2004.     public function getListingsCount()
  2005.     {
  2006.         return $this->listingsCounter;
  2007.     }
  2008.     /**
  2009.      * @return $this
  2010.      */
  2011.     public function setListingsCount(int $listingsCount): self
  2012.     {
  2013.         $this->listingsCounter $listingsCount;
  2014.         return $this;
  2015.     }
  2016.     /**
  2017.      * @Serializer\VirtualProperty
  2018.      *
  2019.      * @Serializer\SerializedName("referenceId")
  2020.      *
  2021.      * @Serializer\Expose()
  2022.      *
  2023.      * @Serializer\Groups({"DefaultV4", "AutocompleteV3", "SearchV4"})
  2024.      */
  2025.     public function getReferencedV4Id()
  2026.     {
  2027.         return $this->getId();
  2028.     }
  2029.     /**
  2030.      * @param array $translations
  2031.      *
  2032.      * @return self
  2033.      */
  2034.     public function setV4Translations($translations = [])
  2035.     {
  2036.         $this->v4Translations $translations;
  2037.         return $this;
  2038.     }
  2039.     /**
  2040.      * Get translations.
  2041.      *
  2042.      * @Serializer\VirtualProperty
  2043.      *
  2044.      * @Serializer\Groups({"DefaultV4", "MyListing", "SearchV4"})
  2045.      *
  2046.      * @Serializer\SerializedName("translations")
  2047.      *
  2048.      * @Serializer\Expose
  2049.      *
  2050.      * @return array
  2051.      */
  2052.     public function getV4Translations()
  2053.     {
  2054.         return $this->v4Translations;
  2055.     }
  2056.     /**
  2057.      * @return Location
  2058.      */
  2059.     public function setEligibleForMortgage(bool $eligibleForMortgage)
  2060.     {
  2061.         $this->eligibleForMortgage $eligibleForMortgage;
  2062.         return $this;
  2063.     }
  2064.     /**
  2065.      * Get Eligible For Mortgage.
  2066.      *
  2067.      * @return bool
  2068.      */
  2069.     public function getEligibleForMortgage()
  2070.     {
  2071.         return $this->eligibleForMortgage;
  2072.     }
  2073.     /**
  2074.      * Set isCompoundLocation.
  2075.      *
  2076.      * @param bool $isCompoundLocation
  2077.      *
  2078.      * @return Location
  2079.      */
  2080.     public function setIsCompoundLocation($isCompoundLocation)
  2081.     {
  2082.         $this->isCompoundLocation $isCompoundLocation;
  2083.         return $this;
  2084.     }
  2085.     /**
  2086.      * Get isCompoundLocation.
  2087.      *
  2088.      * @return bool
  2089.      */
  2090.     public function getIsCompoundLocation()
  2091.     {
  2092.         return $this->isCompoundLocation;
  2093.     }
  2094.     /**
  2095.      * @param self $location
  2096.      * @param array &$titlesFullPath
  2097.      */
  2098.     private function handleTitle($location, &$titlesFullPath): void
  2099.     {
  2100.         $translations $location->getTranslations() ? $location->getTranslations()->toArray() : [];
  2101.         foreach ($translations as $trans) {
  2102.             if ('en' == $trans->getLocale() && 'title' == $trans->getField()) {
  2103.                 $titlesFullPath[] = ucfirst($trans->getContent());
  2104.             }
  2105.         }
  2106.         $titlesFullPath[] = $location->getTitle();
  2107.     }
  2108.     private $listingOrNull;
  2109.     /**
  2110.      * @Serializer\VirtualProperty()
  2111.      *
  2112.      * @Serializer\Groups({"SlugResolver", "Compound", "locationListingV2", "homeCompoundV2", "listingDetailsWithLocationCompound"})
  2113.      *
  2114.      * @Serializer\SerializedName("compound_listing")
  2115.      *
  2116.      * @Serializer\Expose
  2117.      */
  2118.     public function getListingOrNull(): ?Listing
  2119.     {
  2120.         return $this->listingOrNull;
  2121.     }
  2122.     public function setListingOrNull(?Listing $listingOrNull): void
  2123.     {
  2124.         $this->listingOrNull $listingOrNull;
  2125.     }
  2126.     public function getAlias(): string
  2127.     {
  2128.         return $this->alias;
  2129.     }
  2130.     public function setAlias(string $alias): void
  2131.     {
  2132.         $this->alias $alias;
  2133.     }
  2134. }