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

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