src/Aqarmap/Bundle/ListingBundle/Entity/Listing.php line 82

  1. <?php
  2. namespace Aqarmap\Bundle\ListingBundle\Entity;
  3. use App\Entity\Label;
  4. use App\Entity\Listing\ListingValuation;
  5. use App\Entity\Listing\ListingVirtualSerialization;
  6. use App\Entity\ListingLabel;
  7. use Aqarmap\Bundle\FinancialAidsBundle\Entity\FinancialAid;
  8. use Aqarmap\Bundle\ListingBundle\Constant\CompoundStatus;
  9. use Aqarmap\Bundle\ListingBundle\Constant\EligibleForMortgageData;
  10. use Aqarmap\Bundle\ListingBundle\Constant\ListingCategories;
  11. use Aqarmap\Bundle\ListingBundle\Constant\ListingCustomFields;
  12. use Aqarmap\Bundle\ListingBundle\Constant\ListingFeaturedTypes;
  13. use Aqarmap\Bundle\ListingBundle\Constant\ListingFeatures;
  14. use Aqarmap\Bundle\ListingBundle\Constant\ListingPaymentMethod;
  15. use Aqarmap\Bundle\ListingBundle\Constant\ListingPriceLevel;
  16. use Aqarmap\Bundle\ListingBundle\Constant\ListingPropertyView;
  17. use Aqarmap\Bundle\ListingBundle\Constant\ListingRateConstant;
  18. use Aqarmap\Bundle\ListingBundle\Constant\ListingRateReviewStatus;
  19. use Aqarmap\Bundle\ListingBundle\Constant\ListingRateStatus;
  20. use Aqarmap\Bundle\ListingBundle\Constant\ListingSections;
  21. use Aqarmap\Bundle\ListingBundle\Constant\ListingSellerRoles;
  22. use Aqarmap\Bundle\ListingBundle\Constant\ListingStatus;
  23. use Aqarmap\Bundle\ListingBundle\Constant\PhotoTypes;
  24. use Aqarmap\Bundle\ListingBundle\Constant\PluralCustomFields;
  25. use Aqarmap\Bundle\ListingBundle\Constant\PropertyRegistrationStatusOption;
  26. use Aqarmap\Bundle\ListingBundle\Document\ScrapedListing;
  27. use Aqarmap\Bundle\ListingBundle\Repository\ListingRepository;
  28. use Aqarmap\Bundle\ListingBundle\Security\Authorization\OwnerInterface;
  29. use Aqarmap\Bundle\ListingBundle\Validator\Constraints as AqarMapAssert;
  30. use Aqarmap\Bundle\UserBundle\Constant\TeamCategories;
  31. use Aqarmap\Bundle\UserBundle\Entity\User;
  32. use Aqarmap\Bundle\UserBundle\Model\UserMainPhones;
  33. use Doctrine\Common\Collections\ArrayCollection;
  34. use Doctrine\Common\Collections\Collection;
  35. use Doctrine\Common\Collections\Criteria;
  36. use Doctrine\ORM\Mapping as ORM;
  37. use Gedmo\Mapping\Annotation as Gedmo;
  38. use Gedmo\Translatable\Translatable;
  39. use JMS\Serializer\Annotation as Serializer;
  40. use Symfony\Component\Validator\Constraints as Assert;
  41. #[ORM\HasLifecycleCallbacks]
  42. #[ORM\Entity(repositoryClass: ListingRepository::class)]
  43. #[ORM\Table(name: 'listings')]
  44. #[ORM\Index(columns: ['pending_photos_status'])]
  45. #[ORM\Index(columns: ['pending_payment_status'])]
  46. #[ORM\Index(columns: ['relist_status'])]
  47. #[ORM\Index(columns: ['featured'])]
  48. #[ORM\Index(columns: ['deleted_at'])]
  49. #[ORM\Index(columns: ['featured', 'deleted_at'])]
  50. #[ORM\Index(columns: ['created_at'])]
  51. #[ORM\Index(columns: ['published_at'])]
  52. #[ORM\Index(columns: ['user_id', 'deleted_at'])]
  53. #[ORM\Index(columns: ['user_id', 'status'])]
  54. #[ORM\Index(columns: ['user_id', 'status', 'deleted_at'])]
  55. #[ORM\Index(columns: ['user_id', 'status', 'location_id'])]
  56. #[ORM\Index(columns: ['user_id', 'status', 'location_id', 'parent_id', 'category', 'deleted_at'])]
  57. #[ORM\Index(columns: ['user_id', 'status', 'location_id', 'property_type_id', 'section_id', 'parent_id', 'category', 'deleted_at'])]
  58. #[ORM\Index(columns: ['user_id', 'published_at', 'category', 'parent_id'])]
  59. #[ORM\Index(columns: ['user_id', 'pending_status_created_at', 'status', 'category'])]
  60. #[ORM\Index(columns: ['location_id', 'section_id', 'property_type_id', 'status', 'published_at'])]
  61. #[ORM\Index(columns: ['user_id', 'section_id', 'leads_counter'])]
  62. #[ORM\Index(columns: ['user_id', 'section_id', 'parent_id', 'featured'])]
  63. #[ORM\Index(columns: ['category', 'parent_id', 'updated_at'])]
  64. #[ORM\Index(columns: ['category', 'parent_id', 'waiting_time'])]
  65. #[ORM\Index(columns: ['status', 'category', 'parent_id'])]
  66. #[ORM\Index(columns: ['reference_number'])]
  67. #[ORM\Index(columns: ['status', 'leads_counter'])]
  68. #[ORM\Index(columns: ['user_id', 'creation_source', 'deleted_at'])]
  69. #[ORM\Index(columns: ['status', 'location_id', 'parent_id', 'user_id', 'deleted_at'])]
  70. #[ORM\Index(columns: ['status', 'pending_payment_status', 'created_at', 'deleted_at'])]
  71. #[ORM\Index(columns: ['is_availability_email_sent'])]
  72. #[ORM\Index(columns: ['status', 'category', 'parent_id', 'updated_at'])]
  73. #[ORM\Index(columns: ['status', 'parent_id', 'deleted_at', 'published_at'])]
  74. #[ORM\Index(columns: ['auto_reviewed_at'])]
  75. #[ORM\Index(columns: ['section_id', 'property_type_id', 'status', 'featured', 'deleted_at'])]
  76. #[Gedmo\TranslationEntity(class: ListingTranslation::class)]
  77. #[Gedmo\SoftDeleteable(fieldName: 'deletedAt', timeAware: false)]
  78. #[Serializer\ExclusionPolicy('all')]
  79. class Listing implements OwnerInterface, Translatable
  80. {
  81. use ListingVirtualSerialization;
  82. /**
  83. * @var int
  84. */
  85. #[ORM\Column(name: 'id', type: 'integer')]
  86. #[ORM\Id]
  87. #[ORM\GeneratedValue(strategy: 'AUTO')]
  88. #[Serializer\Groups(['Default', 'List', 'listingDetails', 'listingDetailsWithLocationCompound', 'Details', 'Activity', 'DataLayer', 'ActivitiesData', 'DefaultV4', 'MyListing', 'MyListings', 'SearchV4', 'ProjectSearchV4', 'ProjectDetailsV4', 'UnitDetails', 'Autocomplete', 'RelatedListingsV2', 'SlugResolver', 'locationListingV2', 'homeCompoundV2', 'MyLeads', 'NewLeadGeneration', 'ListingPhotos'])]
  89. #[Serializer\Expose]
  90. private $id;
  91. #[ORM\OneToMany(mappedBy: 'parent', targetEntity: Listing::class)]
  92. #[ORM\OrderBy(['area' => 'ASC'])]
  93. #[Serializer\Groups(['List', 'Details'])]
  94. #[Serializer\Expose]
  95. #[Serializer\Until('v2.1')]
  96. private $children;
  97. #[ORM\ManyToOne(targetEntity: Listing::class, inversedBy: 'children')]
  98. #[ORM\JoinColumn(name: 'parent_id', referencedColumnName: 'id')]
  99. #[Serializer\Groups(['List', 'Details', 'DataLayer', 'UnitDetails'])]
  100. #[Serializer\Expose]
  101. #[Serializer\Until('v2.1')]
  102. #[Serializer\MaxDepth(1)]
  103. private $parent;
  104. #[ORM\OneToOne(targetEntity: Listing::class)]
  105. #[ORM\JoinColumn(name: 'relist_id', referencedColumnName: 'id')]
  106. private $relistParent;
  107. #[Assert\NotBlank(message: 'listing.title_required', groups: ['step2'])]
  108. #[ORM\Column(name: 'title', type: 'string', length: 128, nullable: true)]
  109. #[Gedmo\Translatable]
  110. #[Serializer\Groups(['Default', 'List', 'Details', 'listingDetails', 'listingDetailsWithLocationCompound', 'Activity', 'Preview', 'DefaultV4', 'MyListing', 'MyListings', 'SearchV4', 'ProjectSearchV4', 'ProjectDetailsV4', 'Autocomplete', 'RelatedListingsV2', 'SlugResolver', 'locationListingV2', 'homeCompoundV2', 'MyLeads'])]
  111. #[Serializer\Expose]
  112. private ?string $title = null;
  113. #[Assert\NotBlank(message: 'listing.description_required', groups: ['step2'])]
  114. #[ORM\Column(name: 'description', type: 'text', length: 1024, nullable: true)]
  115. #[Gedmo\Translatable]
  116. #[Serializer\Groups(['List', 'Details', 'listingDetails', 'Activity', 'DefaultV4', 'MyListing', 'MyListings', 'SearchV4', 'ProjectDetailsV4'])]
  117. #[Serializer\Expose]
  118. private ?string $description = null;
  119. #[Assert\NotBlank(groups: ['API'])]
  120. #[ORM\ManyToOne(targetEntity: Section::class, inversedBy: 'listings')]
  121. #[ORM\JoinColumn(name: 'section_id', referencedColumnName: 'id')]
  122. #[Serializer\Groups(['MyListings', 'List', 'Details', 'listingDetails', 'DataLayer', 'DefaultV4', 'MyListing', 'SearchV4'])]
  123. #[Serializer\Expose]
  124. protected $section;
  125. /**
  126. * @var int
  127. */
  128. #[ORM\Column(name: 'category', type: 'smallint', nullable: false)]
  129. #[Serializer\Groups(['List', 'Details', 'listingDetails'])]
  130. #[Serializer\Expose]
  131. private $category;
  132. /**
  133. * @var int
  134. */
  135. #[ORM\Column(name: 'pending_photos_status', type: 'smallint', nullable: true)]
  136. private $pendingPhotosStatus;
  137. /**
  138. * @var int
  139. */
  140. #[ORM\Column(name: 'pending_payment_status', type: 'smallint', nullable: true)]
  141. private $pendingPaymentStatus;
  142. /**
  143. * @var int
  144. */
  145. #[ORM\Column(name: 'relist_status', type: 'smallint', nullable: true)]
  146. private $relistStatus;
  147. #[ORM\Column(name: 'seller_role', type: 'smallint', nullable: true)]
  148. #[Serializer\Expose]
  149. #[Serializer\Groups(['Details', 'listingDetails'])]
  150. #[Serializer\Since('v2.1')]
  151. private ?int $sellerRole = null;
  152. private $sellerRoleLabel;
  153. /**
  154. * @var int
  155. */
  156. #[Assert\NotBlank(message: 'listing.area_required', groups: ['step2'])]
  157. #[Assert\GreaterThan(value: 1, message: 'listing.area_minimum', groups: ['step2'])]
  158. #[ORM\Column(name: 'area', type: 'integer', nullable: true)]
  159. #[Serializer\Groups(['List', 'Details', 'DefaultV4', 'MyListing', 'MyListings', 'SearchV4', 'UnitDetails', 'RelatedListingsV2', 'listingDetails'])]
  160. #[Serializer\Expose]
  161. private $area;
  162. /**
  163. * CAUTION: type-hint string to avoid unnecessary update on every fetch.
  164. */
  165. #[Assert\NotBlank(message: 'listing.price_required', groups: ['step2'])]
  166. #[Assert\GreaterThan(value: 100, message: 'listing.price_minimum', groups: ['step2'])]
  167. #[ORM\Column(name: 'price', type: 'bigint', nullable: true)]
  168. #[Serializer\Groups(['List', 'Details', 'listingDetails', 'Activity', 'Preview', 'DefaultV4', 'MyListing', 'MyListings', 'SearchV4', 'UnitDetails', 'RelatedListingsV2'])]
  169. #[Serializer\Expose]
  170. private ?string $price = null;
  171. /**
  172. * @var string
  173. */
  174. #[Assert\Length(max: 100)]
  175. #[Assert\NotBlank(message: 'listing.address_required', groups: ['step2'])]
  176. #[ORM\Column(name: 'address', type: 'text', length: 512, nullable: true)]
  177. #[Gedmo\Translatable]
  178. #[Serializer\Groups(['List', 'Details', 'listingDetails', 'Activity', 'Preview', 'DefaultV4', 'SearchV4', 'RelatedListingsV2', 'locationListingV2', 'homeCompoundV2', 'MyListings'])]
  179. #[Serializer\Expose]
  180. private $address;
  181. /**
  182. * @var float
  183. */
  184. #[ORM\Column(name: 'center_lat', type: 'float', nullable: true)]
  185. #[Serializer\Groups(['List', 'Details', 'listingDetails'])]
  186. #[Serializer\Expose]
  187. private $centerLat;
  188. /**
  189. * @var float
  190. */
  191. #[ORM\Column(name: 'center_lng', type: 'float', nullable: true)]
  192. #[Serializer\Groups(['List', 'Details', 'listingDetails'])]
  193. #[Serializer\Expose]
  194. private $centerLng;
  195. /**
  196. * @var int
  197. */
  198. #[ORM\Column(name: 'status', type: 'smallint', nullable: true)]
  199. #[Serializer\Groups(['List', 'Details', 'Activity', 'listingDetails'])]
  200. #[Serializer\Expose]
  201. private $status;
  202. private $statusLabel;
  203. /**
  204. * @var int
  205. */
  206. #[ORM\Column(name: 'property_view', type: 'smallint', nullable: true)]
  207. #[Serializer\Groups(['List', 'Details', 'listingDetails', 'SearchV4'])]
  208. #[Serializer\Expose]
  209. private $propertyView;
  210. private $propertyViewLabel;
  211. /**
  212. * @var int
  213. */
  214. #[ORM\Column(name: 'payment_method', type: 'smallint', nullable: true)]
  215. #[Serializer\Groups(['List', 'Details', 'listingDetails'])]
  216. #[Serializer\Expose]
  217. private $paymentMethod;
  218. private $paymentMethodLabel;
  219. /**
  220. * @var bool
  221. */
  222. #[ORM\Column(name: 'featured', type: 'smallint', nullable: true)]
  223. private $featured;
  224. /**
  225. * @var int
  226. */
  227. #[ORM\Column(name: 'views', type: 'integer', nullable: true)]
  228. #[Serializer\Groups(['Api', 'MyListing'])]
  229. #[Serializer\Expose]
  230. private $views = 0;
  231. /**
  232. * @var int
  233. */
  234. #[ORM\Column(name: 'phone_counter', type: 'integer', options: ['default' => 0])]
  235. #[Serializer\Groups(['Api'])]
  236. #[Serializer\Expose]
  237. private $phoneCounter = 0;
  238. /**
  239. * @var int
  240. */
  241. #[ORM\Column(name: 'messages_counter', type: 'integer', options: ['default' => 0])]
  242. #[Serializer\Groups(['Api'])]
  243. #[Serializer\Expose]
  244. private $messagesCounter = 0;
  245. #[ORM\Column(name: 'leads_counter', type: 'integer', options: ['default' => 0])]
  246. #[Serializer\Groups(['Api'])]
  247. #[Serializer\Expose]
  248. private int $leadsCounter = 0;
  249. /**
  250. * @var int
  251. */
  252. #[ORM\Column(name: 'sent_notifiers', type: 'integer', nullable: true)]
  253. private $sentNotifiers;
  254. /**
  255. * @var int
  256. */
  257. #[ORM\Column(name: 'relist_counter', type: 'integer', nullable: true)]
  258. private $relistCounter;
  259. /**
  260. * @var string
  261. */
  262. #[ORM\Column(name: 'ip', type: 'string', length: 50, nullable: true)]
  263. private $ip;
  264. /**
  265. * @AqarMapAssert\IsYoutubeUrlOrNull
  266. */
  267. #[ORM\Column(name: 'video_url', type: 'string', length: 150, nullable: true)]
  268. #[Serializer\Groups(['List', 'Details', 'listingDetails', 'Activity', 'DefaultV4', 'ProjectSearchV4', 'ProjectDetailsV4', 'listingDetailsWithLocationCompound', 'SearchV4'])]
  269. #[Serializer\Expose]
  270. private ?string $videoUrl = null;
  271. #[ORM\Column(name: 'slug', length: 128, nullable: true)]
  272. #[Serializer\Groups(['locationListingV2', 'SearchV4', 'listingDetails'])]
  273. #[Serializer\Expose]
  274. private $slug;
  275. #[ORM\Column(name: 'custom_slug', length: 50, unique: true, nullable: true)]
  276. #[Serializer\Groups(['DataLayer'])]
  277. #[Serializer\Expose]
  278. private $customSlug;
  279. /**
  280. * @var int
  281. */
  282. #[ORM\Column(name: 'score', type: 'float', nullable: true)]
  283. #[Serializer\Groups(['MyListings', 'MyListing', 'DefaultV4', 'listingDetails'])]
  284. #[Serializer\Expose]
  285. private ?float $score;
  286. #[ORM\Column(name: 'created_at', type: 'datetime', nullable: true)]
  287. #[Serializer\Groups(['MyListings'])]
  288. #[Serializer\Expose]
  289. private $createdAt;
  290. /**
  291. * @var \DateTime
  292. */
  293. #[ORM\Column(name: 'updated_at', type: 'datetime', nullable: true)]
  294. #[Serializer\Groups(['Details', 'DefaultV4', 'List', 'SearchV4', 'listingDetails'])]
  295. #[Serializer\Expose]
  296. private $updatedAt;
  297. /**
  298. * @var \DateTime
  299. */
  300. #[ORM\Column(name: 'pending_status_created_at', type: 'datetime', nullable: true)]
  301. #[Serializer\Groups(['Details', 'DefaultV4', 'List', 'SearchV4'])]
  302. #[Serializer\Expose]
  303. private $pendingStatusCreatedAt;
  304. /**
  305. * @var \DateTime
  306. */
  307. #[Assert\Range(maxMessage: 'listing.date_not_allowed', max: 'now')]
  308. #[ORM\Column(name: 'published_at', type: 'datetime', nullable: true)]
  309. #[Serializer\Groups(['List', 'Details', 'DefaultV4', 'SearchV4', 'ProjectSearchV4', 'ProjectDetailsV4', 'MyListings'])]
  310. #[Serializer\Expose]
  311. private $publishedAt;
  312. /**
  313. * @var \DateTime;
  314. */
  315. private $aggregatedPublishedAt;
  316. #[ORM\Column(name: 'auto_reviewed_at', type: 'datetime', nullable: true)]
  317. private ?\DateTimeInterface $autoReviewedAt = null;
  318. /**
  319. * @var \DateTime
  320. */
  321. #[ORM\Column(name: 'expires_at', type: 'datetime', nullable: true)]
  322. #[Serializer\Groups(['DefaultV4', 'MyListing', 'MyListings'])]
  323. #[Serializer\Expose]
  324. private $expiresAt;
  325. #[ORM\Column(name: 'deleted_at', type: 'datetime', nullable: true)]
  326. #[Serializer\Groups(['listingDetails'])]
  327. #[Serializer\Expose]
  328. private $deletedAt;
  329. #[ORM\Column(name: 'rejected_at', type: 'datetime', nullable: true)]
  330. private $rejectedAt;
  331. #[ORM\OrderBy(['averagePricePerMeter' => 'DESC'])]
  332. #[ORM\OneToMany(mappedBy: 'parentCompound', targetEntity: CompoundAveragePrice::class, cascade: ['all'])]
  333. private $compoundAveragePrices;
  334. #[Assert\NotBlank(groups: ['API'])]
  335. #[ORM\ManyToOne(targetEntity: PropertyType::class, inversedBy: 'listings')]
  336. #[ORM\JoinColumn(name: 'property_type_id', referencedColumnName: 'id')]
  337. #[Serializer\Groups(['MyListings', 'List', 'Details', 'listingDetails', 'Activity', 'DefaultV4', 'SearchV4', 'MyLeads'])]
  338. #[Serializer\Expose]
  339. protected $propertyType;
  340. #[ORM\ManyToOne(targetEntity: Location::class, inversedBy: 'listings')]
  341. #[ORM\JoinColumn(name: 'location_id', referencedColumnName: 'id')]
  342. #[Serializer\Groups(['List', 'Details', 'listingDetails', 'Activity', 'DefaultV4', 'SearchV4', 'ProjectDetailsV4', 'RelatedListingsV2'])]
  343. #[Serializer\Expose]
  344. protected $location;
  345. #[ORM\ManyToMany(targetEntity: Location::class)]
  346. #[ORM\JoinTable(name: 'listings_locations', joinColumns: [new ORM\JoinColumn(name: 'listing_id', referencedColumnName: 'id')], inverseJoinColumns: [new ORM\JoinColumn(name: 'location_id', referencedColumnName: 'id')])]
  347. protected $locations;
  348. #[ORM\ManyToOne(targetEntity: CompoundLocation::class, inversedBy: 'listings')]
  349. #[ORM\JoinColumn(name: 'compound_location_id', referencedColumnName: 'id', nullable: true)]
  350. #[Serializer\Groups(['Default', 'ProjectSearchV4'])]
  351. #[Serializer\Expose]
  352. protected $compoundLocation;
  353. #[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'listings')]
  354. #[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
  355. #[Serializer\Groups(['List', 'Details', 'listingDetails', 'DefaultV4', 'MyListing', 'SearchV4', 'ProjectDetailsV4', 'ProjectSearchV4', 'RelatedListingsV2', 'MyListings', 'MyLeads'])]
  356. #[Serializer\Expose]
  357. protected $user;
  358. #[ORM\ManyToMany(targetEntity: User::class, fetch: 'EXTRA_LAZY')]
  359. #[ORM\JoinTable(name: 'listings_participants', joinColumns: [new ORM\JoinColumn(name: 'listing_id', referencedColumnName: 'id')], inverseJoinColumns: [new ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id')])]
  360. protected $participants;
  361. #[Assert\Valid]
  362. #[ORM\OneToMany(mappedBy: 'listing', targetEntity: ListingAttribute::class, cascade: ['all'], orphanRemoval: true)]
  363. #[Serializer\Groups(['List', 'Details', 'Preview', 'listingDetails'])]
  364. #[Serializer\Expose]
  365. protected $attributes;
  366. #[Assert\Valid]
  367. #[ORM\OneToMany(mappedBy: 'listing', targetEntity: ListingPhone::class, cascade: ['all'], orphanRemoval: true)]
  368. protected $phones;
  369. #[ORM\OneToMany(mappedBy: 'listing', targetEntity: ListingPhoto::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
  370. #[ORM\OrderBy(['order' => 'ASC'])]
  371. protected Collection $photos;
  372. #[ORM\OneToMany(mappedBy: 'object', targetEntity: ListingTranslation::class, cascade: ['all'], orphanRemoval: true)]
  373. private $translations;
  374. #[ORM\OneToMany(mappedBy: 'listing', targetEntity: ListingLead::class, fetch: 'EXTRA_LAZY')]
  375. protected $leads;
  376. #[ORM\OneToMany(mappedBy: 'listing', targetEntity: ListingFeature::class)]
  377. protected $listingFeatures;
  378. #[ORM\OneToMany(mappedBy: 'listing', targetEntity: ListingNotification::class)]
  379. protected $ListingNotifications;
  380. #[ORM\ManyToMany(targetEntity: Rejection::class)]
  381. #[ORM\JoinTable(name: 'listings_rejections', joinColumns: [new ORM\JoinColumn(name: 'listing_id', referencedColumnName: 'id')], inverseJoinColumns: [new ORM\JoinColumn(name: 'rejection_id', referencedColumnName: 'id')])]
  382. #[Serializer\Groups(['userListing'])]
  383. #[Serializer\Expose]
  384. protected $rejections;
  385. /**
  386. * @var string
  387. */
  388. #[ORM\Column(name: 'campaign', type: 'string', length: 50, nullable: true)]
  389. #[Serializer\Groups(['List', 'Details', 'DefaultV4', 'MyListing'])]
  390. #[Serializer\Expose]
  391. private $campaign;
  392. /**
  393. * @var int
  394. */
  395. #[ORM\Column(name: 'final_price', type: 'integer', nullable: true)]
  396. private $finalPrice;
  397. /**
  398. * @var string
  399. */
  400. #[ORM\Column(name: 'source_of_sale', type: 'string', nullable: true)]
  401. private $sourceOfSale;
  402. /**
  403. * @var string
  404. */
  405. #[ORM\Column(name: 'delete_reason', type: 'string', length: 100, nullable: true)]
  406. private $deleteReason;
  407. /**
  408. * @var string
  409. */
  410. #[ORM\Column(name: 'delete_reason_details', type: 'text', nullable: true)]
  411. private $deleteReasonDetails;
  412. #[ORM\OneToMany(mappedBy: 'listing', targetEntity: Interaction::class)]
  413. private $interactions;
  414. #[Serializer\Expose]
  415. #[Serializer\Groups(['listingDetails', 'DefaultV4'])]
  416. #[ORM\Column(type: 'json', nullable: true)]
  417. private ?array $amenities = null;
  418. /**
  419. * @var string
  420. */
  421. private $userLogo;
  422. /**
  423. * @var string
  424. */
  425. private $listingLogo;
  426. #[Gedmo\Locale]
  427. private $locale;
  428. #[ORM\Column(name: 'source', type: 'string', nullable: true)]
  429. private $source;
  430. private $elasticSearchScore;
  431. /**
  432. * @var float
  433. */
  434. private $qualityScore;
  435. #[ORM\Column(name: 'impressions', type: 'integer', options: ['default' => 0])]
  436. #[Serializer\SerializedName('impressions_count')]
  437. #[Serializer\Groups(['List', 'Details', 'MyListing', 'MyListings'])]
  438. #[Serializer\Expose]
  439. private int $impressions = 0;
  440. #[ORM\Column(name: 'impressions_monthly_count', type: 'integer', options: ['default' => 0])]
  441. #[Serializer\SerializedName('impressions_monthly_count')]
  442. #[Serializer\Groups(['List', 'Details'])]
  443. #[Serializer\Expose]
  444. private int $impressionsMonthlyCount = 0;
  445. #[ORM\Column(name: 'impressions_weekly_count', type: 'integer', options: ['default' => 0])]
  446. #[Serializer\SerializedName('impressions_weekly_count')]
  447. #[Serializer\Groups(['List', 'Details'])]
  448. #[Serializer\Expose]
  449. private int $impressionsWeeklyCount = 0;
  450. /**
  451. * @var \DateTime
  452. */
  453. #[ORM\Column(name: 'impression_updated_at', type: 'datetime', nullable: true)]
  454. private $impressionUpdatedAt;
  455. #[ORM\Column(name: 'price_level', type: 'smallint', nullable: true)]
  456. #[Serializer\Expose]
  457. private $priceLevel;
  458. /**
  459. * @var string
  460. */
  461. private $priceLevelLabel;
  462. #[ORM\Column(name: 'compound_status', type: 'smallint', nullable: true)]
  463. #[Serializer\Expose]
  464. private $compoundStatus;
  465. /**
  466. * @var string
  467. */
  468. private $compoundStatusLabel;
  469. #[ORM\Column(name: 'price_per_meter', type: 'float', nullable: true)]
  470. #[Serializer\Expose]
  471. #[Serializer\Groups(['listingDetails'])]
  472. private $pricePerMeter;
  473. #[ORM\Column(name: 'is_bumped', type: 'boolean', nullable: true)]
  474. private ?bool $isBumped = false;
  475. #[ORM\Column(name: 'is_send_email', type: 'boolean', options: ['default' => 1])]
  476. #[Serializer\Expose]
  477. #[Serializer\Groups(['DefaultV4', 'SearchV4', 'RelatedListingsV2'])]
  478. private $isSendEmail = true;
  479. #[ORM\Column(name: 'is_availability_email_sent', type: 'boolean', options: ['default' => 0])]
  480. private $isAvailabilityEmailSent = false;
  481. #[ORM\Column(name: 'market_property_type', type: 'smallint', nullable: true)]
  482. #[Serializer\Groups(['DefaultV4', 'SearchV4', 'Details', 'listingDetails'])]
  483. #[Serializer\Expose]
  484. private ?int $marketPropertyType = null;
  485. /**
  486. * @var int
  487. */
  488. #[ORM\Column(name: 'creation_source', type: 'smallint', nullable: true)]
  489. private $creationSource;
  490. /**
  491. * @deprecated
  492. *
  493. * @var int
  494. */
  495. #[ORM\Column(name: 'click_through_rate', type: 'float', options: ['default' => 0])]
  496. private $clickThroughRate = 0;
  497. /**
  498. * @var int
  499. */
  500. #[ORM\Column(name: 'label', type: 'smallint', nullable: true)]
  501. private $label;
  502. #[ORM\OneToMany(mappedBy: 'listing', targetEntity: ListingLabel::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
  503. private Collection $labels;
  504. #[ORM\Column(name: 'is_top_picks', type: 'boolean', options: ['default' => 0])]
  505. private $isTopPicks = false;
  506. /**
  507. * @var int
  508. */
  509. #[ORM\Column(name: 'contact_rate', type: 'float', options: ['default' => 0])]
  510. private $contactRate = 0;
  511. #[ORM\OneToMany(mappedBy: 'listing', targetEntity: ListingRate::class, fetch: 'EXTRA_LAZY')]
  512. private $rates;
  513. /**
  514. * @var int
  515. */
  516. private $totalRates;
  517. /**
  518. * @var ArrayCollection
  519. */
  520. private $rateReasonsCollection;
  521. #[ORM\Column(name: 'synced', type: 'boolean')]
  522. private $synced = false;
  523. #[ORM\Column(name: 'reference_id', type: 'integer', nullable: true)]
  524. private $referenceId;
  525. private $featuredTypeLabel;
  526. #[ORM\OneToMany(mappedBy: 'listing', targetEntity: Favourite::class)]
  527. protected $favourite;
  528. #[ORM\Column(name: 'is_pending_featuring', type: 'boolean', nullable: true)]
  529. private $isPendingFeaturing = false;
  530. #[ORM\Column(name: 'pending_featuring_type', type: 'integer', nullable: true)]
  531. private $pendingFeaturingType;
  532. #[ORM\OneToMany(mappedBy: 'listing', targetEntity: ListingNote::class)]
  533. protected $notes;
  534. /**
  535. * @var bool
  536. */
  537. private $isFavourite = false;
  538. /**
  539. * @var string
  540. */
  541. private $userNote;
  542. #[ORM\Column(name: 'rate_status', type: 'smallint', nullable: true)]
  543. private $rateStatus;
  544. #[ORM\Column(name: 'is_rate_reviewed', type: 'boolean', nullable: true, options: ['default' => 0])]
  545. private $isRateReviewed = false;
  546. #[ORM\Column(name: 'is_call_request', type: 'boolean', options: ['default' => 0])]
  547. #[Serializer\SerializedName('isCallRequest')]
  548. #[Serializer\Groups(['List', 'Details', 'Search', 'DefaultV4', 'SearchV4', 'ProjectDetailsV4', 'RelatedListingsV2', 'listingDetails'])]
  549. #[Serializer\Expose]
  550. private $isCallRequest = false;
  551. #[ORM\Column(name: 'is_shown_in_homepage', type: 'boolean', options: ['default' => 0])]
  552. #[Serializer\Groups(['List', 'Details', 'DefaultV4'])]
  553. #[Serializer\Expose]
  554. private $isShownInHomepage = false;
  555. /**
  556. * @var DateTime
  557. */
  558. private $reportedDate;
  559. /**
  560. * @var Listing
  561. */
  562. private $parentOfSimilarListing;
  563. #[Serializer\SerializedName('attributes')]
  564. #[Serializer\Groups(['NotesDetails'])]
  565. #[Serializer\Expose]
  566. private $listingAttributes = [];
  567. /**
  568. * TODO:This Field Is maily Related To Compounds Will Be removed with new project compounds Valu.
  569. *
  570. * @var int
  571. */
  572. #[ORM\Column(name: 'is_commercial', type: 'smallint', nullable: true)]
  573. private $isCommercial = false;
  574. /**
  575. * @var array
  576. */
  577. private $mappedPhotos = [];
  578. /**
  579. * @var array
  580. */
  581. private $v4Translations = [];
  582. private ?array $mappedMainPhoto = null;
  583. /**
  584. * @var bool
  585. */
  586. #[ORM\Column(name: 'is_resale', type: 'boolean', options: ['default' => 0])]
  587. #[Serializer\SerializedName('isResale')]
  588. #[Serializer\Groups(['List', 'Details', 'Search', 'DefaultV4', 'SearchV4', 'ProjectDetailsV4'])]
  589. #[Serializer\Expose]
  590. private $isResale = false;
  591. /**
  592. * @var bool
  593. */
  594. #[ORM\Column(name: 'is_rent', type: 'boolean', options: ['default' => 0])]
  595. #[Serializer\SerializedName('isRent')]
  596. #[Serializer\Groups(['List', 'Details', 'Search', 'DefaultV4', 'SearchV4', 'ProjectDetailsV4'])]
  597. #[Serializer\Expose]
  598. private $isRent = false;
  599. /**
  600. * @var bool
  601. */
  602. #[ORM\Column(name: 'is_primary', type: 'boolean', options: ['default' => 0])]
  603. #[Serializer\SerializedName('isPrimary')]
  604. #[Serializer\Groups(['List', 'Details', 'Search', 'DefaultV4', 'SearchV4', 'ProjectDetailsV4'])]
  605. #[Serializer\Expose]
  606. private $isPrimary = false;
  607. /**
  608. * @var bool
  609. */
  610. #[ORM\Column(name: 'is_mortgage_approved', type: 'boolean', nullable: true)]
  611. #[Serializer\SerializedName('isMortgageApproved')]
  612. #[Serializer\Groups(['List', 'Details', 'Search', 'DefaultV4', 'SearchV4', 'listingDetails'])]
  613. #[Serializer\Expose]
  614. private $isMortgageApproved;
  615. #[ORM\OneToMany(mappedBy: 'listing', targetEntity: ListingsRatesNote::class)]
  616. #[Serializer\Groups(['List', 'Details'])]
  617. #[Serializer\Expose]
  618. private $ratesNotes = [];
  619. /**
  620. * @var string
  621. */
  622. #[ORM\Column(name: 'meta_title', type: 'string', length: 128, nullable: true)]
  623. #[Gedmo\Translatable]
  624. private $metaTitle;
  625. /**
  626. * @var string
  627. */
  628. #[ORM\Column(name: 'meta_description', type: 'text', length: 1024, nullable: true)]
  629. #[Gedmo\Translatable]
  630. private $metaDescription;
  631. /**
  632. * @var bool
  633. */
  634. #[ORM\Column(name: 'is_mortgage', type: 'boolean', options: ['default' => 0])]
  635. #[Serializer\SerializedName('isMortgage')]
  636. #[Serializer\Groups(['List', 'Details', 'Search', 'DefaultV4', 'SearchV4', 'RelatedListingsV2'])]
  637. #[Serializer\Expose]
  638. private $isMortgage = false;
  639. /**
  640. * @var CompoundField
  641. */
  642. #[ORM\OneToOne(targetEntity: CompoundField::class)]
  643. #[ORM\JoinColumn(name: 'compound_field_id', referencedColumnName: 'id')]
  644. protected $compoundField;
  645. /** @var array
  646. */
  647. #[ORM\Column(name: 'eligible_for_mortgage', type: 'array', nullable: true)]
  648. private $eligibleForMortgage;
  649. /**
  650. * @var array
  651. */
  652. private $propertyRegistrationStatusOptions;
  653. /**
  654. * @var array
  655. */
  656. private $eligibleForMortgageData;
  657. /**
  658. * property Registration Status , default I'm not know = 4.
  659. *
  660. * @var int
  661. */
  662. #[ORM\Column(name: 'property_registration_status', type: 'integer', nullable: true, options: ['default' => 4])]
  663. #[Serializer\SerializedName('propertyRegistrationStatus')]
  664. #[Serializer\Groups(['List', 'Details', 'Search', 'DefaultV4', 'SearchV4', 'listingDetails', 'listingDetailsWithLocationCompound'])]
  665. #[Serializer\Expose]
  666. private $propertyRegistrationStatus;
  667. /**
  668. * @var array
  669. */
  670. #[Serializer\SerializedName('propertyTypeChildren')]
  671. #[Serializer\Groups(['ProjectDetailsV4'])]
  672. #[Serializer\Expose]
  673. private $propertyTypeChilden = [];
  674. /**
  675. * @var float
  676. */
  677. private $compoundElasticScore;
  678. /**
  679. * @var FinancialAid
  680. */
  681. private $financialAid;
  682. /**
  683. * @deprecated It's bad design, and cause a performance issues
  684. */
  685. private int $similarListingsCount = 0;
  686. /**
  687. * @deprecated It's bad design, and cause a performance issues
  688. */
  689. private array $similarListingsIds = [];
  690. /**
  691. * @var string|null
  692. */
  693. #[ORM\Column(name: 'advertiser_number', type: 'string', nullable: true)]
  694. #[Serializer\SerializedName('advertiserNumber')]
  695. #[Serializer\Groups(['List', 'Details', 'Search', 'DefaultV4', 'SearchV4'])]
  696. #[Serializer\Expose]
  697. private $advertiserNumber;
  698. /**
  699. * @var string|null
  700. */
  701. #[ORM\Column(name: 'authorization_number', type: 'string', nullable: true)]
  702. #[Serializer\SerializedName('authorizationNumber')]
  703. #[Serializer\Groups(['List', 'Details', 'Search', 'DefaultV4', 'SearchV4'])]
  704. #[Serializer\Expose]
  705. private $authorizationNumber;
  706. /**
  707. * @var float
  708. */
  709. private $costPerLead = 0;
  710. #[Serializer\Groups(['ProjectDetailsV4'])]
  711. #[Serializer\SerializedName('resaleCount')]
  712. #[Serializer\Expose]
  713. private $resaleCount = 0;
  714. #[Serializer\Groups(['ProjectDetailsV4'])]
  715. #[Serializer\SerializedName('rentCount')]
  716. #[Serializer\Expose]
  717. private $rentCount = 0;
  718. /**
  719. * @var \DateTime
  720. */
  721. #[ORM\Column(name: 'freezed_at', type: 'datetime', nullable: true)]
  722. private $freezedAt;
  723. #[ORM\Column(name: 'eligible_for_bumpup', type: 'boolean', options: ['default' => 0])]
  724. private $eligibleForBumpUp = false;
  725. /**
  726. * @var string
  727. */
  728. #[ORM\Column(name: 'waiting_time', type: 'string', length: 50, nullable: true)]
  729. private $waitingTime;
  730. #[ORM\Column(name: 'reference_number', type: 'string', length: 128, nullable: true)]
  731. #[Serializer\Groups(['MyListing', 'MyListings', 'listingDetails', 'MyLeads'])]
  732. #[Serializer\Expose]
  733. private ?string $referenceNumber = null;
  734. #[Serializer\Groups(['SearchV4'])]
  735. #[Serializer\Expose]
  736. public $debug;
  737. /**
  738. * @var File|null
  739. */
  740. #[ORM\OneToOne(targetEntity: File::class, cascade: ['persist', 'remove'])]
  741. #[ORM\JoinColumn(name: 'brochure_id', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
  742. #[Serializer\Groups(['Default', 'DefaultV4', 'ProjectSearchV4', 'ProjectDetailsV4', 'locationListingV2'])]
  743. #[Serializer\Expose]
  744. private $brochure;
  745. #[ORM\Column(name: 'is_hold', type: 'boolean', options: ['default' => 0])]
  746. private $isHold = false;
  747. #[ORM\Column(name: 'is_ai_content', type: 'boolean', options: ['default' => 0])]
  748. private bool $AiContent = false;
  749. #[ORM\Column(name: 'ai_review', type: 'json', nullable: true)]
  750. private ?array $aiReview = [];
  751. private int $maxPrice;
  752. #[ORM\Column(name: 'rating_review_status', type: 'string', length: 20, nullable: false, options: ['default' => 'PENDING'])]
  753. private string $ratingReviewStatus = 'PENDING';
  754. /**
  755. * @var Collection<int, ListingValuation>
  756. */
  757. #[ORM\OneToMany(mappedBy: 'listing', targetEntity: ListingValuation::class, orphanRemoval: true)]
  758. private Collection $listingValuations;
  759. #[ORM\OneToOne(cascade: ['persist', 'remove'])]
  760. #[ORM\JoinColumn(name: 'valuation_id', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
  761. private ?ListingValuation $valuation = null;
  762. #[ORM\OneToOne(cascade: ['persist', 'remove'])]
  763. #[ORM\JoinColumn(name: 'new_valuation_id', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
  764. private ?ListingValuation $newValuation = null;
  765. /**
  766. * Constructor.
  767. */
  768. public function __construct()
  769. {
  770. $this->children = new ArrayCollection();
  771. $this->attributes = new ArrayCollection();
  772. $this->phones = new ArrayCollection();
  773. $this->photos = new ArrayCollection();
  774. $this->leads = new ArrayCollection();
  775. $this->labels = new ArrayCollection();
  776. $this->rates = new ArrayCollection();
  777. $this->listingFeatures = new ArrayCollection();
  778. $this->ListingNotifications = new ArrayCollection();
  779. $this->translations = new ArrayCollection();
  780. $this->rejections = new ArrayCollection();
  781. $this->participants = new ArrayCollection();
  782. $this->rateReasonsCollection = new ArrayCollection();
  783. $this->favourite = new ArrayCollection();
  784. $this->listingValuations = new ArrayCollection();
  785. }
  786. /**
  787. * Clone.
  788. */
  789. public function __clone()
  790. {
  791. $this->id = null;
  792. $this->slug = null;
  793. $this->children = null;
  794. $this->title = null;
  795. $this->address = null;
  796. $this->description = null;
  797. $this->translations = null;
  798. $this->leads = new ArrayCollection();
  799. $this->labels = new ArrayCollection();
  800. $this->participants = null;
  801. $this->featured = 0;
  802. $this->views = 0;
  803. $this->customSlug = null;
  804. $this->relistCounter = 0;
  805. $this->messagesCounter = 0;
  806. $this->phoneCounter = 0;
  807. $this->sentNotifiers = 0;
  808. $this->isBumped = false;
  809. $this->ratesNotes = new ArrayCollection();
  810. $this->compoundField = null;
  811. $this->compoundAveragePrices = null;
  812. }
  813. #[ORM\PrePersist]
  814. public function onPrePersist(): void
  815. {
  816. if (!$this->getCreatedAt()) {
  817. $this->setCreatedAt(new \DateTime());
  818. }
  819. if (!$this->getUpdatedAt()) {
  820. $this->setUpdatedAt(new \DateTime());
  821. }
  822. }
  823. /**
  824. * Get id.
  825. *
  826. * @return int
  827. */
  828. public function getId()
  829. {
  830. return $this->id;
  831. }
  832. /**
  833. * Set title.
  834. *
  835. * @param string $title
  836. *
  837. * @return Listing
  838. */
  839. public function setTitle($title)
  840. {
  841. $this->title = $title;
  842. return $this;
  843. }
  844. /**
  845. * Get title.
  846. */
  847. public function getTitle(): ?string
  848. {
  849. return $this->title;
  850. }
  851. /**
  852. * Set description.
  853. *
  854. * @param string $description
  855. *
  856. * @return Listing
  857. */
  858. public function setDescription($description)
  859. {
  860. $this->description = $description;
  861. return $this;
  862. }
  863. /**
  864. * Get description.
  865. */
  866. public function getDescription(): ?string
  867. {
  868. return $this->description;
  869. }
  870. /**
  871. * Set section.
  872. *
  873. * @return Listing
  874. */
  875. public function setSection(?Section $section = null)
  876. {
  877. $this->section = $section;
  878. return $this;
  879. }
  880. /**
  881. * Get section.
  882. *
  883. * @return Section
  884. */
  885. public function getSection()
  886. {
  887. return $this->section;
  888. }
  889. /**
  890. * Set category.
  891. *
  892. * @param int $category
  893. *
  894. * @return Listing
  895. */
  896. public function setCategory($category)
  897. {
  898. $this->category = $category;
  899. return $this;
  900. }
  901. /**
  902. * Get category.
  903. *
  904. * @return int
  905. */
  906. public function getCategory()
  907. {
  908. return $this->category;
  909. }
  910. /**
  911. * Get category name.
  912. *
  913. * @return string
  914. */
  915. public function getCategoryName()
  916. {
  917. return ListingCategories::getLabel($this->category);
  918. }
  919. /**
  920. * @return bool
  921. */
  922. public function isDraft()
  923. {
  924. return ListingStatus::DRAFT == $this->status;
  925. }
  926. /**
  927. * @return bool
  928. */
  929. public function isLive()
  930. {
  931. return ListingStatus::LIVE == $this->status;
  932. }
  933. /**
  934. * Set pendingPhotosStatus.
  935. *
  936. * @param int $pendingPhotosStatus
  937. *
  938. * @return Listing
  939. */
  940. public function setPendingPhotosStatus($pendingPhotosStatus)
  941. {
  942. $this->pendingPhotosStatus = $pendingPhotosStatus;
  943. return $this;
  944. }
  945. /**
  946. * Get pendingPhotosStatus.
  947. *
  948. * @return int
  949. */
  950. public function getPendingPhotosStatus()
  951. {
  952. return $this->pendingPhotosStatus;
  953. }
  954. /**
  955. * Set pendingPaymentStatus.
  956. *
  957. * @param int $pendingPaymentStatus
  958. *
  959. * @return Listing
  960. */
  961. public function setPendingPaymentStatus($pendingPaymentStatus)
  962. {
  963. $this->pendingPaymentStatus = $pendingPaymentStatus;
  964. return $this;
  965. }
  966. /**
  967. * Get pendingPaymentStatus.
  968. *
  969. * @return int
  970. */
  971. public function getPendingPaymentStatus()
  972. {
  973. return $this->pendingPaymentStatus;
  974. }
  975. /**
  976. * Set relistStatus.
  977. *
  978. * @param int $relistStatus
  979. *
  980. * @return Listing
  981. */
  982. public function setRelistStatus($relistStatus)
  983. {
  984. $this->relistStatus = $relistStatus;
  985. return $this;
  986. }
  987. /**
  988. * Get relistStatus.
  989. *
  990. * @return int
  991. */
  992. public function getRelistStatus()
  993. {
  994. return $this->relistStatus;
  995. }
  996. /**
  997. * Set sellerRole.
  998. */
  999. public function setSellerRole(?int $sellerRole): self
  1000. {
  1001. $this->sellerRole = $sellerRole;
  1002. return $this;
  1003. }
  1004. /**
  1005. * Get sellerRole.
  1006. */
  1007. public function getSellerRole(): ?int
  1008. {
  1009. return $this->sellerRole;
  1010. }
  1011. public function setSellerRoleLabel($label): void
  1012. {
  1013. $this->sellerRoleLabel = $label;
  1014. }
  1015. /**
  1016. * Set area.
  1017. *
  1018. * @param int $area
  1019. *
  1020. * @return Listing
  1021. */
  1022. public function setArea($area)
  1023. {
  1024. $this->area = $area;
  1025. return $this;
  1026. }
  1027. /**
  1028. * Get area.
  1029. *
  1030. * @return int
  1031. */
  1032. public function getArea()
  1033. {
  1034. return (int) $this->area;
  1035. }
  1036. /**
  1037. * Set price.
  1038. *
  1039. * @return Listing
  1040. */
  1041. public function setPrice(?int $price)
  1042. {
  1043. $this->price = $price;
  1044. return $this;
  1045. }
  1046. /**
  1047. * Get price.
  1048. */
  1049. public function getPrice(): ?int
  1050. {
  1051. return $this->price;
  1052. }
  1053. /**
  1054. * Set address.
  1055. *
  1056. * @param string $address
  1057. *
  1058. * @return Listing
  1059. */
  1060. public function setAddress($address)
  1061. {
  1062. $this->address = $address;
  1063. return $this;
  1064. }
  1065. /**
  1066. * Get address.
  1067. *
  1068. * @return string
  1069. */
  1070. public function getAddress()
  1071. {
  1072. return $this->address;
  1073. }
  1074. /**
  1075. * Set centerLat.
  1076. *
  1077. * @param float $centerLat
  1078. *
  1079. * @return Listing
  1080. */
  1081. public function setCenterLat($centerLat)
  1082. {
  1083. $this->centerLat = $centerLat;
  1084. return $this;
  1085. }
  1086. /**
  1087. * Get centerLat.
  1088. *
  1089. * @return float
  1090. */
  1091. public function getCenterLat()
  1092. {
  1093. return $this->centerLat;
  1094. }
  1095. /**
  1096. * Set centerLng.
  1097. *
  1098. * @param float $centerLng
  1099. *
  1100. * @return Listing
  1101. */
  1102. public function setCenterLng($centerLng)
  1103. {
  1104. $this->centerLng = $centerLng;
  1105. return $this;
  1106. }
  1107. /**
  1108. * Get centerLng.
  1109. *
  1110. * @return float
  1111. */
  1112. public function getCenterLng()
  1113. {
  1114. return $this->centerLng;
  1115. }
  1116. /**
  1117. * Set featured.
  1118. *
  1119. * @param int $featured
  1120. *
  1121. * @return Listing
  1122. */
  1123. public function setFeatured($featured)
  1124. {
  1125. $this->featured = $featured;
  1126. return $this;
  1127. }
  1128. /**
  1129. * Get featured.
  1130. *
  1131. * @return int
  1132. */
  1133. public function getFeatured()
  1134. {
  1135. return $this->featured;
  1136. }
  1137. /**
  1138. * @return bool
  1139. */
  1140. #[Serializer\VirtualProperty]
  1141. #[Serializer\SerializedName('is_featured')]
  1142. #[Serializer\Groups(['List', 'Details', 'DataLayer', 'MyListing', 'MyListings', 'listingDetails'])]
  1143. public function isFeatured()
  1144. {
  1145. return (bool) $this->getFeatured();
  1146. }
  1147. /**
  1148. * @return bool
  1149. */
  1150. #[Serializer\VirtualProperty]
  1151. #[Serializer\SerializedName('isFeatured')]
  1152. #[Serializer\Groups(['DefaultV4', 'SearchV4'])]
  1153. public function getFeaturingStatus()
  1154. {
  1155. return (bool) $this->getFeatured();
  1156. }
  1157. /**
  1158. * @return string
  1159. */
  1160. public function getFeaturedLabel()
  1161. {
  1162. return ListingFeaturedTypes::getLabel($this->getFeatured());
  1163. }
  1164. /**
  1165. * Set views.
  1166. *
  1167. * @param int $views
  1168. *
  1169. * @return Listing
  1170. */
  1171. public function setViews($views)
  1172. {
  1173. $this->views = $views;
  1174. return $this;
  1175. }
  1176. /**
  1177. * Get views.
  1178. *
  1179. * @return int
  1180. */
  1181. public function getViews()
  1182. {
  1183. return $this->views ?: 0;
  1184. }
  1185. /**
  1186. * Get views count.
  1187. *
  1188. * @return int
  1189. */
  1190. public function getTotalViews()
  1191. {
  1192. $totalViews = $this->getViews();
  1193. if ($this->getChildren()) {
  1194. foreach ($this->getChildren() as $listing) {
  1195. $totalViews += $listing->getViews();
  1196. }
  1197. }
  1198. return $totalViews;
  1199. }
  1200. /**
  1201. * Set relistCounter.
  1202. *
  1203. * @param int $relistCounter
  1204. *
  1205. * @return Listing
  1206. */
  1207. public function setRelistCounter($relistCounter)
  1208. {
  1209. $this->relistCounter = $relistCounter;
  1210. return $this;
  1211. }
  1212. /**
  1213. * Get relistCounter.
  1214. *
  1215. * @return int
  1216. */
  1217. public function getRelistCounter()
  1218. {
  1219. return $this->relistCounter;
  1220. }
  1221. /**
  1222. * Set sentNotifiers.
  1223. *
  1224. * @param int $sentNotifiers
  1225. *
  1226. * @return Listing
  1227. */
  1228. public function setSentNotifiers($sentNotifiers)
  1229. {
  1230. $this->sentNotifiers = $sentNotifiers;
  1231. return $this;
  1232. }
  1233. /**
  1234. * Get sentNotifiers.
  1235. *
  1236. * @return int
  1237. */
  1238. public function getSentNotifiers()
  1239. {
  1240. return $this->sentNotifiers;
  1241. }
  1242. /**
  1243. * Set status.
  1244. *
  1245. * @param int $status
  1246. *
  1247. * @return Listing
  1248. */
  1249. public function setStatus($status)
  1250. {
  1251. $this->status = $status;
  1252. return $this;
  1253. }
  1254. /**
  1255. * Get status.
  1256. *
  1257. * @return int
  1258. */
  1259. public function getStatus()
  1260. {
  1261. return $this->status;
  1262. }
  1263. /**
  1264. * @return string
  1265. */
  1266. #[Serializer\VirtualProperty]
  1267. #[Serializer\SerializedName('status_label')]
  1268. #[Serializer\Groups(['List', 'Details', 'listingDetails'])]
  1269. #[Serializer\Until('v2.11')]
  1270. public function getStatusLabel()
  1271. {
  1272. return ListingStatus::getLabel($this->getStatus());
  1273. }
  1274. /**
  1275. * @return string
  1276. */
  1277. #[Serializer\VirtualProperty]
  1278. #[Serializer\SerializedName('status_label')]
  1279. #[Serializer\Groups(['List', 'Details'])]
  1280. #[Serializer\Since('v2.12')]
  1281. public function getStatusTranslated()
  1282. {
  1283. return $this->statusLabel;
  1284. }
  1285. public function setStatusLabel($label): void
  1286. {
  1287. $this->statusLabel = $label;
  1288. }
  1289. /**
  1290. * @return string
  1291. */
  1292. public function getStatusDescription()
  1293. {
  1294. return ListingStatus::getDescription($this->getStatus());
  1295. }
  1296. /**
  1297. * Set ip.
  1298. *
  1299. * @param string $ip
  1300. *
  1301. * @return Listing
  1302. */
  1303. public function setIp($ip)
  1304. {
  1305. $this->ip = $ip;
  1306. return $this;
  1307. }
  1308. /**
  1309. * Get ip.
  1310. *
  1311. * @return string
  1312. */
  1313. public function getIp()
  1314. {
  1315. return $this->ip;
  1316. }
  1317. public function setVideoUrl(?string $videoUrl): static
  1318. {
  1319. $this->videoUrl = $videoUrl;
  1320. return $this;
  1321. }
  1322. public function getVideoUrl(): ?string
  1323. {
  1324. return $this->videoUrl;
  1325. }
  1326. /**
  1327. * Set slug.
  1328. *
  1329. * @param string $slug
  1330. *
  1331. * @return Listing
  1332. */
  1333. public function setSlug($slug)
  1334. {
  1335. $this->slug = $slug;
  1336. return $this;
  1337. }
  1338. /**
  1339. * Get slug.
  1340. *
  1341. * @return string
  1342. */
  1343. public function getSlug()
  1344. {
  1345. return $this->slug;
  1346. }
  1347. /**
  1348. * Set customSlug.
  1349. *
  1350. * @param string $customSlug
  1351. *
  1352. * @return Listing
  1353. */
  1354. public function setCustomSlug($customSlug)
  1355. {
  1356. $this->customSlug = str_replace(' ', '-', strtolower($customSlug));
  1357. return $this;
  1358. }
  1359. /**
  1360. * Get customSlug.
  1361. *
  1362. * @param bool $force
  1363. *
  1364. * @return string
  1365. */
  1366. public function getCustomSlug($force = false)
  1367. {
  1368. if ($force && empty($this->customSlug)) {
  1369. return $this->slug;
  1370. }
  1371. return $this->customSlug;
  1372. }
  1373. /**
  1374. * Set score.
  1375. *
  1376. * @param float $score
  1377. *
  1378. * @return Listing
  1379. */
  1380. public function setScore($score)
  1381. {
  1382. $this->score = $score;
  1383. return $this;
  1384. }
  1385. /**
  1386. * Get score.
  1387. *
  1388. * @return float
  1389. */
  1390. public function getScore()
  1391. {
  1392. return $this->score;
  1393. }
  1394. /**
  1395. * Set maxPrice.
  1396. *
  1397. * @param int $maxPrice
  1398. *
  1399. * @return Listing
  1400. */
  1401. public function setMaxPrice($maxPrice)
  1402. {
  1403. $this->maxPrice = $maxPrice;
  1404. return $this;
  1405. }
  1406. /**
  1407. * Get maxPrice.
  1408. *
  1409. * @return int
  1410. */
  1411. public function getMaxPrice()
  1412. {
  1413. return $this->maxPrice;
  1414. }
  1415. /**
  1416. * Set createdAt.
  1417. *
  1418. * @param \DateTime $createdAt
  1419. *
  1420. * @return Listing
  1421. */
  1422. public function setCreatedAt($createdAt)
  1423. {
  1424. $this->createdAt = $createdAt;
  1425. return $this;
  1426. }
  1427. /**
  1428. * Get createdAt.
  1429. *
  1430. * @return \DateTime
  1431. */
  1432. #[Serializer\VirtualProperty]
  1433. #[Serializer\Groups(['MyListing'])]
  1434. #[Serializer\Expose]
  1435. public function getCreatedAt()
  1436. {
  1437. return $this->createdAt;
  1438. }
  1439. /**
  1440. * Set updatedAt.
  1441. *
  1442. * @param \DateTime $updatedAt
  1443. *
  1444. * @return Listing
  1445. */
  1446. public function setUpdatedAt($updatedAt)
  1447. {
  1448. $this->updatedAt = $updatedAt;
  1449. return $this;
  1450. }
  1451. /**
  1452. * Get updatedAt.
  1453. *
  1454. * @return \DateTime
  1455. */
  1456. public function getUpdatedAt()
  1457. {
  1458. return $this->updatedAt;
  1459. }
  1460. /**
  1461. * Set pendingStatusCreatedAt.
  1462. *
  1463. * @param \DateTime $pendingStatusCreatedAt
  1464. *
  1465. * @return Listing
  1466. */
  1467. public function setPendingStatusCreatedAt($pendingStatusCreatedAt)
  1468. {
  1469. $this->pendingStatusCreatedAt = $pendingStatusCreatedAt;
  1470. return $this;
  1471. }
  1472. /**
  1473. * Get pendingStatusCreatedAt.
  1474. *
  1475. * @return \DateTime
  1476. */
  1477. public function getPendingStatusCreatedAt()
  1478. {
  1479. return $this->pendingStatusCreatedAt;
  1480. }
  1481. /**
  1482. * Set publishedAt.
  1483. *
  1484. * @return Listing
  1485. */
  1486. public function setPublishedAt(?\DateTime $publishedAt = null)
  1487. {
  1488. $this->publishedAt = $publishedAt;
  1489. return $this;
  1490. }
  1491. /**
  1492. * Get publishedAt.
  1493. *
  1494. * @return \DateTime
  1495. */
  1496. public function getPublishedAt()
  1497. {
  1498. return $this->publishedAt;
  1499. }
  1500. /**
  1501. * @return \DateTime|ArrayCollection|Collection
  1502. */
  1503. #[Serializer\VirtualProperty]
  1504. public function getAggregatedPublishedAt()
  1505. {
  1506. $lastBump = $this->getLastAutoBumpUp();
  1507. /** @var ListingFeature $lastFeature */
  1508. $lastFeature = $this->getLastListingFeature();
  1509. $listingFeature = null;
  1510. if ($lastBump && $lastFeature) {
  1511. $listingFeature = ($lastBump->getLastBumpedAt() > $lastFeature->getCreatedAt()) ? $lastBump : $lastFeature;
  1512. } elseif ($lastBump) {
  1513. $listingFeature = $lastBump;
  1514. } elseif ($lastFeature) {
  1515. $listingFeature = $lastFeature;
  1516. }
  1517. if (!$listingFeature) {
  1518. return $this->getPublishedAt();
  1519. }
  1520. return (ListingFeatures::BUMP_UP == $listingFeature->getType() && $listingFeature->getLastBumpedAt()) ?
  1521. $listingFeature->getLastBumpedAt() : $listingFeature->getCreatedAt();
  1522. }
  1523. public function getAutoReviewedAt(): ?\DateTimeInterface
  1524. {
  1525. return $this->autoReviewedAt;
  1526. }
  1527. public function setAutoReviewedAt(?\DateTimeInterface $autoReviewedAt): self
  1528. {
  1529. $this->autoReviewedAt = $autoReviewedAt;
  1530. return $this;
  1531. }
  1532. /**
  1533. * Set expiresAt.
  1534. *
  1535. * @param \DateTime $expiresAt
  1536. *
  1537. * @return Listing
  1538. */
  1539. public function setExpiresAt($expiresAt)
  1540. {
  1541. $this->expiresAt = $expiresAt;
  1542. return $this;
  1543. }
  1544. /**
  1545. * Get expiresAt.
  1546. *
  1547. * @return \DateTime
  1548. */
  1549. public function getExpiresAt()
  1550. {
  1551. return $this->expiresAt;
  1552. }
  1553. public function setDeletedAt(?\DateTime $deletedAt): Listing
  1554. {
  1555. $this->deletedAt = $deletedAt;
  1556. return $this;
  1557. }
  1558. /**
  1559. * Get deletedAt.
  1560. *
  1561. * @return \DateTime
  1562. */
  1563. public function getDeletedAt()
  1564. {
  1565. return $this->deletedAt;
  1566. }
  1567. /**
  1568. * Set rejectedAt.
  1569. *
  1570. * @param \DateTime $rejectedAt
  1571. *
  1572. * @return Listing
  1573. */
  1574. public function setRejectedAt($rejectedAt)
  1575. {
  1576. $this->rejectedAt = $rejectedAt;
  1577. return $this;
  1578. }
  1579. /**
  1580. * Get rejectedAt.
  1581. *
  1582. * @return \DateTime
  1583. */
  1584. public function getRejectedAt()
  1585. {
  1586. return $this->rejectedAt;
  1587. }
  1588. /**
  1589. * Add children.
  1590. *
  1591. * @return Listing
  1592. */
  1593. public function addChild(self $children)
  1594. {
  1595. $this->children[] = $children;
  1596. return $this;
  1597. }
  1598. /**
  1599. * Remove children.
  1600. */
  1601. public function removeChild(self $children): void
  1602. {
  1603. $this->children->removeElement($children);
  1604. }
  1605. /**
  1606. * Get children.
  1607. *
  1608. * @return Collection
  1609. */
  1610. public function getChildren()
  1611. {
  1612. $criteria = Criteria::create()
  1613. ->orderBy(['id' => Criteria::ASC]);
  1614. if (!$this->children) {
  1615. return null;
  1616. }
  1617. return $this->children->matching($criteria);
  1618. }
  1619. /**
  1620. * Get only live listing children (live units) and order by area.
  1621. */
  1622. public function getLiveChildren(?PropertyType $propertyType = null)
  1623. {
  1624. $criteria = Criteria::create()->where(Criteria::expr()->eq('status', ListingStatus::LIVE));
  1625. if ($propertyType) {
  1626. $criteria->where(Criteria::expr()->eq('propertyType', $propertyType));
  1627. }
  1628. $criteria->orderBy(['area' => Criteria::ASC]);
  1629. if (empty($this->children)) {
  1630. return null;
  1631. }
  1632. return $this->children->matching($criteria);
  1633. }
  1634. public function getLiveChildrenIDs()
  1635. {
  1636. $ids = [];
  1637. foreach ($this->getLiveChildren() as $listing) {
  1638. $ids[] = $listing->getId();
  1639. }
  1640. return $ids;
  1641. }
  1642. /**
  1643. * Get only pending listing children (live units) and order by area.
  1644. */
  1645. public function getPendingChildren()
  1646. {
  1647. $criteria = Criteria::create()
  1648. ->where(Criteria::expr()->in('status', ListingStatus::$pendingStatusArray))
  1649. ->orderBy(['area' => Criteria::ASC]);
  1650. return $this->children->matching($criteria);
  1651. }
  1652. /**
  1653. * Set parent.
  1654. *
  1655. * @return Listing
  1656. */
  1657. public function setParent(?self $parent = null)
  1658. {
  1659. $this->parent = $parent;
  1660. return $this;
  1661. }
  1662. /**
  1663. * Get parent.
  1664. *
  1665. * @return Listing
  1666. */
  1667. public function getParent()
  1668. {
  1669. return $this->parent;
  1670. }
  1671. /**
  1672. * Get Relist Parent.
  1673. *
  1674. * @return Listing
  1675. */
  1676. public function getRelistParent()
  1677. {
  1678. return $this->relistParent;
  1679. }
  1680. public function setRelistParent(self $relistParent): void
  1681. {
  1682. $this->relistParent = $relistParent;
  1683. }
  1684. /**
  1685. * Set propertyType.
  1686. *
  1687. * @return Listing
  1688. */
  1689. public function setPropertyType(?PropertyType $propertyType = null)
  1690. {
  1691. $this->propertyType = $propertyType;
  1692. return $this;
  1693. }
  1694. /**
  1695. * Get propertyType.
  1696. *
  1697. * @return PropertyType
  1698. */
  1699. public function getPropertyType()
  1700. {
  1701. return $this->propertyType;
  1702. }
  1703. public function getPropertyTypeForValuation(): ?PropertyType
  1704. {
  1705. $propertyType = $this->getPropertyType();
  1706. while ($propertyType) {
  1707. if ($propertyType->getIsEvaluable()) {
  1708. return $propertyType;
  1709. }
  1710. // Guard self-parenting's
  1711. if ($propertyType->getParent() === $propertyType) {
  1712. break;
  1713. }
  1714. $propertyType = $propertyType->getParent();
  1715. }
  1716. return null;
  1717. }
  1718. /**
  1719. * Set location.
  1720. *
  1721. * @return Listing
  1722. */
  1723. public function setLocation(?Location $location = null)
  1724. {
  1725. $this->location = $location;
  1726. return $this;
  1727. }
  1728. /**
  1729. * Get location.
  1730. *
  1731. * @return Location
  1732. */
  1733. public function getLocation()
  1734. {
  1735. return $this->location;
  1736. }
  1737. /**
  1738. * Add location.
  1739. *
  1740. * @return Listing
  1741. */
  1742. public function addLocation(Location $location)
  1743. {
  1744. $this->locations[] = $location;
  1745. return $this;
  1746. }
  1747. /**
  1748. * Has location.
  1749. *
  1750. * @return bool
  1751. */
  1752. public function hasLocation(Location $location)
  1753. {
  1754. return $this->locations->contains($location);
  1755. }
  1756. /**
  1757. * Set Locations.
  1758. *
  1759. * @return Listing
  1760. */
  1761. public function setLocations($locations)
  1762. {
  1763. foreach ($locations as $location) {
  1764. $this->addLocation($location);
  1765. }
  1766. return $this;
  1767. }
  1768. /**
  1769. * Remove location.
  1770. */
  1771. public function removeLocation(Location $location): void
  1772. {
  1773. $this->locations->removeElement($location);
  1774. }
  1775. /**
  1776. * Get locations.
  1777. *
  1778. * @return Collection
  1779. */
  1780. public function getLocations()
  1781. {
  1782. return $this->locations;
  1783. }
  1784. /**
  1785. * @return $this
  1786. */
  1787. public function setCompoundLocation(?CompoundLocation $compoundLocation = null)
  1788. {
  1789. $this->compoundLocation = $compoundLocation;
  1790. return $this;
  1791. }
  1792. /**
  1793. * @return CompoundLocation
  1794. */
  1795. public function getCompoundLocation()
  1796. {
  1797. if (!$this->compoundLocation && $this->hasParent()) {
  1798. return $this->getParent()->getCompoundLocation();
  1799. }
  1800. return $this->compoundLocation;
  1801. }
  1802. /**
  1803. * @return mixed|string
  1804. */
  1805. public function getCompoundLocationTitle()
  1806. {
  1807. $compoundLocation = $this->getCompoundLocation();
  1808. if ($compoundLocation instanceof CompoundLocation) {
  1809. return $compoundLocation->getTitle();
  1810. }
  1811. return '';
  1812. }
  1813. /**
  1814. * Set user.
  1815. *
  1816. * @return Listing
  1817. */
  1818. public function setUser(?User $user = null)
  1819. {
  1820. $this->user = $user;
  1821. return $this;
  1822. }
  1823. /**
  1824. * Get user.
  1825. *
  1826. * @return User
  1827. */
  1828. public function getUser()
  1829. {
  1830. return $this->user;
  1831. }
  1832. /**
  1833. * Add participants.
  1834. *
  1835. * @return Listing
  1836. */
  1837. public function addParticipant(User $participants)
  1838. {
  1839. $this->participants[] = $participants;
  1840. return $this;
  1841. }
  1842. /**
  1843. * Remove participants.
  1844. */
  1845. public function removeParticipant(User $participants): void
  1846. {
  1847. $this->participants->removeElement($participants);
  1848. }
  1849. /**
  1850. * Get participants.
  1851. *
  1852. * @return Collection
  1853. */
  1854. public function getParticipants()
  1855. {
  1856. return $this->participants;
  1857. }
  1858. /**
  1859. * Has participant.
  1860. *
  1861. * @return bool
  1862. */
  1863. public function hasParticipant(User $participant)
  1864. {
  1865. $participants = $this->getParticipants();
  1866. if (\is_object($participants)) {
  1867. return $this->getParticipants()->contains($participant) ? true : false;
  1868. }
  1869. return false;
  1870. }
  1871. /**
  1872. * @return ArrayCollection
  1873. */
  1874. public function getAllParticipants()
  1875. {
  1876. $participants = new ArrayCollection();
  1877. $participants->add($this->getUser());
  1878. foreach ($this->getParticipants() as $participant) {
  1879. if (!$participants->contains($participant)) {
  1880. $participants->add($participant);
  1881. }
  1882. }
  1883. if ($this->getParent()) {
  1884. foreach ($this->getParent()->getAllParticipants() as $participant) {
  1885. if (!$participants->contains($participant)) {
  1886. $participants->add($participant);
  1887. }
  1888. }
  1889. }
  1890. return $participants;
  1891. }
  1892. /**
  1893. * @return ArrayCollection
  1894. */
  1895. public function getAllLocations()
  1896. {
  1897. $locations = new ArrayCollection();
  1898. $locations->add($this->getLocation());
  1899. foreach ($this->getLocations() as $location) {
  1900. if (!$locations->contains($location)) {
  1901. $locations->add($location);
  1902. }
  1903. }
  1904. return $locations;
  1905. }
  1906. /**
  1907. * @return array
  1908. */
  1909. public function getAllLocationsIDs()
  1910. {
  1911. $locations = new ArrayCollection();
  1912. $locations->add($this->getLocation()->getId());
  1913. foreach ($this->getLocations() as $location) {
  1914. if (!$locations->contains($location->getId())) {
  1915. $locations->add($location->getId());
  1916. }
  1917. }
  1918. return $locations->toArray();
  1919. }
  1920. /**
  1921. * Add attribute.
  1922. *
  1923. * @return Listing
  1924. */
  1925. public function addAttribute(ListingAttribute $attribute)
  1926. {
  1927. if (!$attribute->isValid()) {
  1928. return $this;
  1929. }
  1930. $attribute->setListing($this);
  1931. $this->attributes[] = $attribute;
  1932. return $this;
  1933. }
  1934. /**
  1935. * Set attributes.
  1936. *
  1937. * @return Listing
  1938. */
  1939. public function setAttributes($attributes)
  1940. {
  1941. foreach ($attributes as $attribute) {
  1942. if (
  1943. $attribute instanceof ListingAttribute
  1944. && !$attribute->isValid()
  1945. ) {
  1946. continue;
  1947. }
  1948. $this->addAttribute($attribute);
  1949. }
  1950. return $this;
  1951. }
  1952. /**
  1953. * Remove attribute.
  1954. */
  1955. public function removeAttribute(ListingAttribute $attribute): void
  1956. {
  1957. $this->attributes->removeElement($attribute);
  1958. }
  1959. /**
  1960. * Clear attributes.
  1961. */
  1962. public function clearAttributes(): void
  1963. {
  1964. $this->attributes->clear();
  1965. }
  1966. /**
  1967. * Get attributes.
  1968. *
  1969. * @return Collection
  1970. */
  1971. public function getAttributes()
  1972. {
  1973. return $this->attributes;
  1974. }
  1975. /**
  1976. * Get Attributes in List.
  1977. *
  1978. * @return array
  1979. */
  1980. public function getAttributesList()
  1981. {
  1982. $attributeList = [];
  1983. foreach ($this->attributes as $attribute) {
  1984. $value = $attribute->getValue();
  1985. if (
  1986. PluralCustomFields::MAX_VALUE == $value
  1987. && \in_array($attribute->getCustomField()->getName(), PluralCustomFields::getChoices())
  1988. ) {
  1989. $value = PluralCustomFields::MAX_VALUE_LABEL;
  1990. }
  1991. $attributeList[$attribute->getCustomField()->getName()] = $value;
  1992. if (ListingCustomFields::FINISH_TYPE_NAME == $attribute->getCustomField()->getName()) {
  1993. $attributeList[$attribute->getCustomField()->getName()] = $attribute->getValue();
  1994. }
  1995. }
  1996. return $attributeList;
  1997. }
  1998. /**
  1999. * Get attributes.
  2000. *
  2001. * @return Collection
  2002. */
  2003. public function getAttribute($attrName)
  2004. {
  2005. foreach ($this->attributes as $attribute) {
  2006. if ($attrName == $attribute->getCustomField()->getName()) {
  2007. return $attribute;
  2008. }
  2009. }
  2010. }
  2011. /**
  2012. * Add phones.
  2013. *
  2014. * @param ListingPhone $phone
  2015. *
  2016. * @return Listing
  2017. */
  2018. public function addPhone($phone)
  2019. {
  2020. $phone->setListing($this); // Synchronously updating inverse side
  2021. $criteria = Criteria::create()->where(Criteria::expr()->eq('number', $phone->getNumber()));
  2022. if ($this->getPhones()->matching($criteria)->isEmpty()) {
  2023. $this->phones[] = $phone;
  2024. }
  2025. return $this;
  2026. }
  2027. /**
  2028. * Set Phones.
  2029. *
  2030. * @return Listing
  2031. */
  2032. public function setPhones($phones)
  2033. {
  2034. foreach ($phones as $phone) {
  2035. $this->addPhone($phone);
  2036. }
  2037. return $this;
  2038. }
  2039. /**
  2040. * Remove phone.
  2041. */
  2042. public function removePhone(ListingPhone $phone): void
  2043. {
  2044. $phone->setListing(null);
  2045. $this->phones->removeElement($phone);
  2046. }
  2047. public function removePhones(): void
  2048. {
  2049. foreach ($this->phones as $phone) {
  2050. $this->removePhone($phone);
  2051. }
  2052. }
  2053. /**
  2054. * Get phones.
  2055. */
  2056. #[Serializer\Groups(['List', 'Details', 'RelatedListingsV2', 'listingDetails'])]
  2057. #[Serializer\VirtualProperty]
  2058. #[Serializer\Expose]
  2059. public function getPhones(): ArrayCollection
  2060. {
  2061. return $this->listMainListingPhonesFromUser();
  2062. }
  2063. /**
  2064. * Get Mapped Phones For V4.
  2065. */
  2066. #[Serializer\Groups(['DefaultV4', 'SearchV4', 'ProjectDetailsV4', 'ProjectSearchV4', 'locationListingV2'])]
  2067. #[Serializer\VirtualProperty]
  2068. #[Serializer\SerializedName('phones')]
  2069. #[Serializer\Expose]
  2070. public function getMappedPhones(): array
  2071. {
  2072. $phones = [];
  2073. /** @var ListingPhone $phone */
  2074. foreach ($this->getPhones() as $phone) {
  2075. $phones[] = $phone->getPhone();
  2076. }
  2077. return $phones;
  2078. }
  2079. /**
  2080. * Get phones for listing from the user phones.
  2081. */
  2082. #[Serializer\Groups(['List', 'Details', 'listingDetails', 'SearchV4', 'ListingPhones'])]
  2083. #[Serializer\VirtualProperty]
  2084. #[Serializer\Expose]
  2085. public function getListingPhones(): ArrayCollection
  2086. {
  2087. $phones = new ArrayCollection();
  2088. $i = 0;
  2089. /** @var UserPhone $phone */
  2090. foreach ($this->getUser()->getPhones() as $phone) {
  2091. if ($i > 2) {
  2092. break;
  2093. }
  2094. $criteria = Criteria::create()->where(Criteria::expr()->eq('number', $phone->getNumber()));
  2095. if ($phones->matching($criteria)->isEmpty() && $phone->getPhone() instanceof Phone) {
  2096. $phones->add($phone->getPhone());
  2097. }
  2098. ++$i;
  2099. }
  2100. return $phones;
  2101. }
  2102. /**
  2103. * Add photos.
  2104. */
  2105. public function addPhoto(ListingPhoto $photo): static
  2106. {
  2107. $photo->setListing($this);
  2108. $this->photos->add($photo);
  2109. return $this;
  2110. }
  2111. /**
  2112. * Set photos.
  2113. */
  2114. public function setPhotos($photos): static
  2115. {
  2116. foreach ($photos as $photo) {
  2117. $this->addPhoto($photo);
  2118. }
  2119. return $this;
  2120. }
  2121. /**
  2122. * Remove photos.
  2123. */
  2124. public function removePhoto(ListingPhoto $photo): void
  2125. {
  2126. $this->photos->removeElement($photo);
  2127. }
  2128. /**
  2129. * @return $this
  2130. */
  2131. public function clearPhotos(): static
  2132. {
  2133. $this->photos->clear();
  2134. return $this;
  2135. }
  2136. /**
  2137. * @return $this
  2138. */
  2139. public function clearPhones()
  2140. {
  2141. $this->phones->clear();
  2142. return $this;
  2143. }
  2144. /**
  2145. * @return CompoundAveragePrice|null
  2146. */
  2147. public function getCompoundAveragePrices()
  2148. {
  2149. return $this->compoundAveragePrices;
  2150. }
  2151. /**
  2152. * @param CompoundAveragePrice|null
  2153. */
  2154. public function setCompoundAveragePrices(?CompoundAveragePrice $compoundAveragePrices): void
  2155. {
  2156. $this->compoundAveragePrices = $compoundAveragePrices;
  2157. }
  2158. /**
  2159. * @return ArrayCollection
  2160. */
  2161. public function getPhotos($excludedTypes = [])
  2162. {
  2163. $criteria = Criteria::create();
  2164. if (!empty($excludedTypes)) {
  2165. $criteria->andWhere(Criteria::expr()->notIn('type', $excludedTypes));
  2166. }
  2167. $criteria->orderBy(['order' => Criteria::ASC]);
  2168. return $this->photos->matching($criteria);
  2169. }
  2170. #[Serializer\Groups(['List', 'Details', 'listingDetails', 'ListingPhotos'])]
  2171. #[Serializer\VirtualProperty]
  2172. #[Serializer\SerializedName('photos')]
  2173. public function getPhotosForSlider(): ArrayCollection
  2174. {
  2175. $slider = new ArrayCollection();
  2176. $photos = $this->getPhotos()->toArray();
  2177. // Manually sort photos, as "Criteria" does not sort them, not sure why
  2178. usort($photos, function($a, $b) {
  2179. return $a->getOrder() <=> $b->getOrder();
  2180. });
  2181. $mainPhoto = $this->getMainPhoto();
  2182. if ($mainPhoto) {
  2183. $slider->add($mainPhoto);
  2184. }
  2185. // Add all other photos, except the main photo, because It's already added
  2186. /** @var ListingPhoto $photo */
  2187. foreach ($photos as $photo) {
  2188. if (!$slider->contains($photo) && PhotoTypes::LOGO_PHOTO !== $photo->getType()) {
  2189. $slider->add($photo);
  2190. }
  2191. }
  2192. return $slider;
  2193. }
  2194. public function buildMappedMainPhoto(): self
  2195. {
  2196. // Important for API
  2197. if ($this->getPhotos()->count() <= 0) {
  2198. return $this;
  2199. }
  2200. /* @var ListingPhoto $photo */
  2201. $mainPhotos = $this->photos->filter(fn ($photo) => PhotoTypes::MAIN_PHOTO == $photo->getType());
  2202. $mappedMainPhoto = $mainPhotos->first() ?: $this->getPhotos()->first();
  2203. if ($mappedMainPhoto instanceof ListingPhoto) {
  2204. $this->mappedMainPhoto = $this->mapPhoto($mappedMainPhoto);
  2205. }
  2206. return $this;
  2207. }
  2208. public function setMappedMainPhoto(?array $mainPhoto): self
  2209. {
  2210. $this->mappedMainPhoto = $mainPhoto;
  2211. return $this;
  2212. }
  2213. #[Serializer\Groups(['DefaultV4', 'MyListing', 'MyListings', 'SearchV4', 'ProjectSearchV4', 'RelatedListingsV2', 'locationListingV2', 'homeCompoundV2'])]
  2214. #[Serializer\VirtualProperty]
  2215. #[Serializer\SerializedName('mainPhoto')]
  2216. public function getMappedMainPhoto(): ?array
  2217. {
  2218. return $this->mappedMainPhoto;
  2219. }
  2220. private function mapPhoto(ListingPhoto $listingPhoto): array
  2221. {
  2222. return [
  2223. 'id' => $listingPhoto->getId(),
  2224. 'name' => $listingPhoto->getName(),
  2225. 'caption' => $listingPhoto->getCaption(),
  2226. 'order' => $listingPhoto->getOrder(),
  2227. 'type' => $listingPhoto->getTypeName(),
  2228. 'photo' => $listingPhoto->getFile(),
  2229. 'file' => $listingPhoto->getPath(),
  2230. 'thumbnails' => [],
  2231. ];
  2232. }
  2233. public function buildMappedPhotos(): self
  2234. {
  2235. $mainPhotoId = null;
  2236. // Set the main photo as the first photo in the slider
  2237. if ($this->getMainPhoto() instanceof ListingPhoto) {
  2238. $mainPhoto = $this->getMainPhoto();
  2239. $mainPhotoId = $mainPhoto->getId();
  2240. $this->mappedPhotos[] = $this->mapPhoto($mainPhoto);
  2241. }
  2242. /** @var ListingPhoto $photo */
  2243. foreach ($this->getPhotos() as $photo) {
  2244. if (PhotoTypes::LOGO_PHOTO != $photo->getType()) {
  2245. if (($mainPhotoId && $mainPhotoId == $photo->getId()) || !$photo instanceof ListingPhoto) {
  2246. continue;
  2247. }
  2248. $this->mappedPhotos[] = $this->mapPhoto($photo);
  2249. }
  2250. }
  2251. return $this;
  2252. }
  2253. /**
  2254. * @return array
  2255. */
  2256. #[Serializer\Groups(['DefaultV4', 'SearchV4', 'ProjectDetailsV4', 'RelatedListingsV2'])]
  2257. #[Serializer\VirtualProperty]
  2258. #[Serializer\SerializedName('photos')]
  2259. public function getMappedPhotos()
  2260. {
  2261. return $this->mappedPhotos;
  2262. }
  2263. public function setMappedPhotos(array $mappedPhotos): self
  2264. {
  2265. $this->mappedPhotos = $mappedPhotos;
  2266. return $this;
  2267. }
  2268. #[Serializer\Groups(['List', 'Api', 'Preview'])]
  2269. #[Serializer\VirtualProperty]
  2270. public function getMainPhoto(): ?ListingPhoto
  2271. {
  2272. // Important for API
  2273. if ($this->getPhotos()->count() <= 0) {
  2274. return null;
  2275. }
  2276. /* @var ListingPhoto $photo */
  2277. $mainPhotos = $this->photos->filter(fn ($photo) => PhotoTypes::MAIN_PHOTO == $photo->getType());
  2278. return $mainPhotos->first() ?: $this->getPhotos()->first();
  2279. }
  2280. /**
  2281. * @return int
  2282. */
  2283. #[Serializer\Groups(['DefaultV4', 'MyListing', 'SearchV4', 'ProjectSearchV4'])]
  2284. #[Serializer\VirtualProperty]
  2285. public function getPhotosCount()
  2286. {
  2287. return $this->getPhotos()->count();
  2288. }
  2289. /**
  2290. * @return ListingPhoto|null
  2291. */
  2292. public function getLogo()
  2293. {
  2294. /** @var ArrayCollection $logos */
  2295. $logos = $this->photos->filter(fn (ListingPhoto $photo) => PhotoTypes::LOGO_PHOTO == $photo->getType());
  2296. return $logos->first() ?: null;
  2297. }
  2298. /**
  2299. * @return ArrayCollection
  2300. */
  2301. public function getLeads()
  2302. {
  2303. return $this->leads;
  2304. }
  2305. /**
  2306. * Count leads.
  2307. *
  2308. * @return int
  2309. */
  2310. public function getLeadsCount()
  2311. {
  2312. return $this->getLeadsCounter();
  2313. }
  2314. /**
  2315. * Count all leads with children.
  2316. *
  2317. * @return int
  2318. */
  2319. public function getTotalLeadsCount()
  2320. {
  2321. $leadsCount = $this->getLeadsCounter();
  2322. if ($this->getChildren()) {
  2323. /** @var self $listing */
  2324. foreach ($this->getChildren() as $listing) {
  2325. $leadsCount += $listing->getLeadsCounter();
  2326. }
  2327. }
  2328. return $leadsCount;
  2329. }
  2330. public function setLeads($leads): void
  2331. {
  2332. $this->leads = $leads;
  2333. }
  2334. /**
  2335. * @return int
  2336. */
  2337. #[Serializer\VirtualProperty]
  2338. public function getAggregatedLeadsCount()
  2339. {
  2340. /** @var ListingFeature $lastBump */
  2341. $lastBump = $this->getLastAutoBumpUp();
  2342. /** @var ListingFeature $lastFeature */
  2343. $lastFeature = $this->getLastListingFeature();
  2344. $listingFeature = null;
  2345. if ($lastBump && $lastFeature) {
  2346. $listingFeature = ($lastBump->getLastBumpedAt() > $lastFeature->getCreatedAt()) ? $lastBump : $lastFeature;
  2347. } elseif ($lastBump) {
  2348. $listingFeature = $lastBump;
  2349. } elseif ($lastFeature) {
  2350. $listingFeature = $lastFeature;
  2351. }
  2352. return $listingFeature ?
  2353. $this->getLeadsCounter() - $listingFeature->getLeadsCountSnapshot() :
  2354. $this->getLeadsCounter();
  2355. }
  2356. /**
  2357. * Add listingFeatures.
  2358. *
  2359. * @return Listing
  2360. */
  2361. public function addListingFeature(ListingFeature $listingFeatures)
  2362. {
  2363. $this->listingFeatures[] = $listingFeatures;
  2364. return $this;
  2365. }
  2366. /**
  2367. * Remove listingFeatures.
  2368. */
  2369. public function removeListingFeature(ListingFeature $listingFeatures): void
  2370. {
  2371. $this->listingFeatures->removeElement($listingFeatures);
  2372. }
  2373. /**
  2374. * Get listingFeatures.
  2375. *
  2376. * @return Collection
  2377. */
  2378. public function getListingFeatures()
  2379. {
  2380. return $this->listingFeatures;
  2381. }
  2382. /**
  2383. * @return ListingFeature
  2384. */
  2385. public function getLastAutoBumpUp()
  2386. {
  2387. $criteria = new Criteria();
  2388. $criteria
  2389. ->where(Criteria::expr()->eq('type', ListingFeatures::BUMP_UP))
  2390. ->andWhere(Criteria::expr()->gte('expiresAt', new \DateTime()))
  2391. ->orWhere(Criteria::expr()->isNull('expiresAt'))
  2392. ->orderBy([
  2393. 'id' => Criteria::DESC,
  2394. ])
  2395. ;
  2396. return $this->listingFeatures->matching($criteria)->first();
  2397. }
  2398. /**
  2399. * @return bool
  2400. */
  2401. #[Serializer\VirtualProperty]
  2402. #[Serializer\SerializedName('was_featured')]
  2403. #[Serializer\Groups(['List', 'Details', 'listingDetails'])]
  2404. public function wasFeatured()
  2405. {
  2406. return !$this->getCurrentListingFeature() && $this->getLastListingFeature() ? true : false;
  2407. }
  2408. /**
  2409. * Get current listing feature.
  2410. *
  2411. * @return ListingFeatures
  2412. */
  2413. public function getCurrentListingFeature()
  2414. {
  2415. $criteria = Criteria::create()
  2416. ->where(Criteria::expr()->gte('expiresAt', new \DateTime('now')))
  2417. ->andWhere(Criteria::expr()->neq('type', ListingFeatures::PAID))
  2418. ->andWhere(Criteria::expr()->neq('type', ListingFeatures::BUMP_UP))
  2419. ->orderBy(['id' => Criteria::DESC])
  2420. ->setMaxResults(1);
  2421. return $this->getListingFeatures()->matching($criteria)->first();
  2422. }
  2423. /**
  2424. * Get current listing feature expiry date.
  2425. *
  2426. * @return \DateTime|null
  2427. */
  2428. #[Serializer\VirtualProperty]
  2429. #[Serializer\Groups(['DefaultV4', 'MyListing'])]
  2430. #[Serializer\SerializedName('feature_expires_at')]
  2431. #[Serializer\Expose]
  2432. public function getCurrentListingFeatureExpiryDate()
  2433. {
  2434. /* @var ListingFeature $listingFeature */
  2435. if ($this->isFeatured()) {
  2436. $listingFeature = $this->getCurrentListingFeature();
  2437. return $listingFeature ? $listingFeature->getExpiresAt() : null;
  2438. }
  2439. return null;
  2440. }
  2441. /**
  2442. * Get all current active listing features.
  2443. *
  2444. * @return ListingFeatures
  2445. */
  2446. public function getCurrentListingFeatures()
  2447. {
  2448. $criteria = Criteria::create()
  2449. ->where(Criteria::expr()->orX(
  2450. Criteria::expr()->isNull('expiresAt'),
  2451. Criteria::expr()->gte('expiresAt', new \DateTime('now'))
  2452. ))
  2453. ->orderBy(['id' => Criteria::DESC]);
  2454. return $this->getListingFeatures()->matching($criteria);
  2455. }
  2456. /**
  2457. * Get last listing feature.
  2458. */
  2459. public function getLastListingFeature()
  2460. {
  2461. $criteria = Criteria::create()
  2462. ->andWhere(Criteria::expr()->neq('type', ListingFeatures::PAID))
  2463. ->andWhere(Criteria::expr()->neq('type', ListingFeatures::BUMP_UP))
  2464. ->orderBy(['id' => Criteria::DESC])
  2465. ->setMaxResults(1);
  2466. return $this->getListingFeatures()->matching($criteria)->first();
  2467. }
  2468. /**
  2469. * Get the latest featured credit transaction for listing publishing.
  2470. *
  2471. * @param mixed $type = null
  2472. *
  2473. * @throws \Exception
  2474. */
  2475. public function getFeaturedPublicationCredit(mixed $type = null)
  2476. {
  2477. if (!$type) {
  2478. $lastFeaturedType = $this->getLastListingFeature() ? $this->getLastListingFeature()->getType() : [];
  2479. $type = !empty($lastFeaturedType) ? [$lastFeaturedType] : [ListingFeatures::FEATURED, ListingFeatures::SPOTLIGHT, ListingFeatures::PREMIUM, ListingFeatures::SPONSORED];
  2480. }
  2481. $criteria = Criteria::create()
  2482. ->where(Criteria::expr()->orX(
  2483. Criteria::expr()->isNull('expiresAt'),
  2484. Criteria::expr()->gte('expiresAt', new \DateTime('now'))
  2485. ))
  2486. ->andWhere(Criteria::expr()->in('type', $type))
  2487. ->orderBy(['id' => Criteria::DESC])
  2488. ->setMaxResults(1);
  2489. return $this->getListingFeatures()->matching($criteria)->first();
  2490. }
  2491. /**
  2492. * Get the latest credit transaction for listing publishing.
  2493. *
  2494. * @return ListingFeature
  2495. */
  2496. public function getPublicationCredit()
  2497. {
  2498. $criteria = Criteria::create()
  2499. ->where(Criteria::expr()->orX(
  2500. Criteria::expr()->isNull('expiresAt'),
  2501. Criteria::expr()->gte('expiresAt', new \DateTime('now'))
  2502. ))
  2503. ->andWhere(Criteria::expr()->eq('type', ListingFeatures::PAID))
  2504. ->orderBy(['id' => Criteria::DESC])
  2505. ->setMaxResults(1);
  2506. return $this->getListingFeatures()->matching($criteria)->first();
  2507. }
  2508. /**
  2509. * Get the latest credit transaction for special add listing publishing.
  2510. *
  2511. * @return ListingFeature
  2512. */
  2513. public function getSpecialPublicationCredit()
  2514. {
  2515. $criteria = Criteria::create()
  2516. ->where(Criteria::expr()->orX(
  2517. Criteria::expr()->isNull('expiresAt'),
  2518. Criteria::expr()->gte('expiresAt', new \DateTime('now'))
  2519. ))
  2520. ->andWhere(Criteria::expr()->in('type', [ListingFeatures::SPONSORED, ListingFeatures::SPOTLIGHT]))
  2521. ->orderBy(['id' => Criteria::DESC])
  2522. ->setMaxResults(1);
  2523. return $this->getListingFeatures()->matching($criteria)->first();
  2524. }
  2525. /**
  2526. * Get all credit transactions for listing that not expired yet.
  2527. *
  2528. * @return ListingFeature
  2529. */
  2530. public function getNotExpiredCredit()
  2531. {
  2532. $criteria = Criteria::create()
  2533. ->where(Criteria::expr()->orX(
  2534. Criteria::expr()->isNull('expiresAt'),
  2535. Criteria::expr()->gte('expiresAt', new \DateTime('now'))
  2536. ))
  2537. ->orderBy(['id' => Criteria::DESC]);
  2538. return $this->getListingFeatures()->matching($criteria)->toArray();
  2539. }
  2540. /**
  2541. * Get translations.
  2542. *
  2543. * @return ArrayCollection
  2544. */
  2545. #[Serializer\VirtualProperty]
  2546. #[Serializer\Groups(['Default', 'List'])]
  2547. #[Serializer\SerializedName('translations')]
  2548. #[Serializer\Expose]
  2549. public function getTranslations()
  2550. {
  2551. return $this->translations;
  2552. }
  2553. public function deleteExistingTranslation($field, $locale): void
  2554. {
  2555. /** @var ListingTranslation $translation */
  2556. foreach ($this->getTranslations() as $translation) {
  2557. if ($translation->getField() == $field && $translation->getLocale() == $locale) {
  2558. $this->removeTranslation($translation);
  2559. }
  2560. }
  2561. }
  2562. /**
  2563. * Add translation.
  2564. *
  2565. * @return Listing
  2566. */
  2567. public function addTranslation(ListingTranslation $translation)
  2568. {
  2569. if (!$this->translations->contains($translation)) {
  2570. $this->translations->add($translation);
  2571. $translation->setObject($this);
  2572. }
  2573. return $this;
  2574. }
  2575. /**
  2576. * Set Translations.
  2577. *
  2578. * @return Listing
  2579. */
  2580. public function setTranslations($translations)
  2581. {
  2582. foreach ($translations as $translation) {
  2583. $this->addTranslation($translation);
  2584. }
  2585. return $this;
  2586. }
  2587. /**
  2588. * Get listing translation by locale.
  2589. */
  2590. public function getTranslation(string $locale): ?ListingTranslation
  2591. {
  2592. $translation = $this->translations
  2593. ->filter(fn (ListingTranslation $translation) => $translation->getLocale() === $locale)
  2594. ->first();
  2595. return $translation ?: null;
  2596. }
  2597. /**
  2598. * Remove translation.
  2599. *
  2600. * @return Listing
  2601. */
  2602. public function removeTranslation(ListingTranslation $translation)
  2603. {
  2604. if ($this->translations->contains($translation)) {
  2605. $this->translations->removeElement($translation);
  2606. }
  2607. return $this;
  2608. }
  2609. /**
  2610. * @return $this
  2611. */
  2612. public function clearTranslations()
  2613. {
  2614. $this->translations->clear();
  2615. return $this;
  2616. }
  2617. /**
  2618. * Set campaign.
  2619. *
  2620. * @param string $campaign
  2621. *
  2622. * @return Listing
  2623. */
  2624. public function setCampaign($campaign)
  2625. {
  2626. $this->campaign = $campaign;
  2627. return $this;
  2628. }
  2629. /**
  2630. * Get campaign.
  2631. *
  2632. * @return string
  2633. */
  2634. public function getCampaign()
  2635. {
  2636. return $this->campaign;
  2637. }
  2638. /**
  2639. * Set propertyView.
  2640. *
  2641. * @param int $propertyView
  2642. *
  2643. * @return Listing
  2644. */
  2645. public function setPropertyView($propertyView)
  2646. {
  2647. $this->propertyView = $propertyView;
  2648. return $this;
  2649. }
  2650. /**
  2651. * Get propertyView.
  2652. *
  2653. * @return int
  2654. */
  2655. public function getPropertyView()
  2656. {
  2657. return $this->propertyView;
  2658. }
  2659. #[Serializer\SerializedName('property_view_label')]
  2660. #[Serializer\VirtualProperty]
  2661. #[Serializer\Groups(['Details', 'listingDetails'])]
  2662. #[Serializer\Expose]
  2663. public function getPropertyViewLabel()
  2664. {
  2665. return ListingPropertyView::getLabel($this->getPropertyView());
  2666. }
  2667. #[Serializer\SerializedName('property_view_label')]
  2668. #[Serializer\VirtualProperty]
  2669. #[Serializer\Since('v2.12')]
  2670. #[Serializer\Expose]
  2671. public function getPropertyViewTranslatedLabel()
  2672. {
  2673. return $this->getTranslatedPropertyViewLabel();
  2674. }
  2675. #[Serializer\SerializedName('property_view')]
  2676. #[Serializer\VirtualProperty]
  2677. #[Serializer\Groups(['DefaultV4'])]
  2678. #[Serializer\Expose]
  2679. public function getPropertyViewName()
  2680. {
  2681. return ListingPropertyView::getNameByConstant($this->getPropertyView());
  2682. }
  2683. /**
  2684. * @return $this
  2685. */
  2686. public function setPropertyViewLabel($label)
  2687. {
  2688. $this->propertyViewLabel = $label;
  2689. return $this;
  2690. }
  2691. /**
  2692. * Set paymentMethod.
  2693. *
  2694. * @param int $paymentMethod
  2695. *
  2696. * @return Listing
  2697. */
  2698. public function setPaymentMethod($paymentMethod)
  2699. {
  2700. if (
  2701. ListingSections::FOR_RENT == $this->getSection()->getId()
  2702. ) {
  2703. $paymentMethod = ListingPaymentMethod::CASH;
  2704. }
  2705. $this->paymentMethod = $paymentMethod;
  2706. return $this;
  2707. }
  2708. /**
  2709. * Set paymentMethod Label.
  2710. *
  2711. * @param int $paymentMethod
  2712. *
  2713. * @return Listing
  2714. */
  2715. public function setPaymentMethodLabel($paymentMethod)
  2716. {
  2717. $this->paymentMethodLabel = $paymentMethod;
  2718. return $this;
  2719. }
  2720. #[Serializer\SerializedName('payment_method_label')]
  2721. #[Serializer\VirtualProperty]
  2722. #[Serializer\Since('v2.12')]
  2723. #[Serializer\Expose]
  2724. public function getPaymentMethodLabelTranslated()
  2725. {
  2726. return $this->paymentMethodLabel;
  2727. }
  2728. /**
  2729. * @return int|null
  2730. */
  2731. #[Serializer\SerializedName('user')]
  2732. #[Serializer\VirtualProperty]
  2733. #[Serializer\Groups(['DefaultV4'])]
  2734. #[Serializer\Expose]
  2735. public function getUserId()
  2736. {
  2737. return $this->getUser() instanceof User ? $this->getUser()->getId() : null;
  2738. }
  2739. /**
  2740. * Get paymentMethod.
  2741. *
  2742. * @return int
  2743. */
  2744. public function getPaymentMethod()
  2745. {
  2746. if (
  2747. ListingSections::FOR_RENT == $this->getSection()->getId()
  2748. ) {
  2749. $this->paymentMethod = ListingPaymentMethod::CASH;
  2750. }
  2751. return $this->paymentMethod;
  2752. }
  2753. #[Serializer\SerializedName('paymentMethodLabel')]
  2754. #[Serializer\VirtualProperty]
  2755. #[Serializer\Groups(['Default', 'SearchV4', 'listingDetails'])]
  2756. #[Serializer\Expose]
  2757. public function getPaymentMethodLabel()
  2758. {
  2759. return ListingPaymentMethod::getLabel($this->getPaymentMethod());
  2760. }
  2761. /**
  2762. * Add listingNotification.
  2763. *
  2764. * @return Listing
  2765. */
  2766. public function addListingNotification(ListingNotification $listingNotification)
  2767. {
  2768. $this->ListingNotifications[] = $listingNotification;
  2769. return $this;
  2770. }
  2771. /**
  2772. * Remove listingNotification.
  2773. */
  2774. public function removeListingNotification(ListingNotification $listingNotification): void
  2775. {
  2776. $this->ListingNotifications->removeElement($listingNotification);
  2777. }
  2778. /**
  2779. * Get listingNotifications.
  2780. *
  2781. * @return Collection
  2782. */
  2783. public function getListingNotifications()
  2784. {
  2785. return $this->ListingNotifications;
  2786. }
  2787. /**
  2788. * Add rejections.
  2789. *
  2790. * @return Listing
  2791. */
  2792. public function addRejection(Rejection $rejections)
  2793. {
  2794. $this->rejections[] = $rejections;
  2795. return $this;
  2796. }
  2797. /**
  2798. * Add rejections.
  2799. *
  2800. * @param ArrayCollection $rejections
  2801. *
  2802. * @return Listing
  2803. */
  2804. public function addRejections($rejections)
  2805. {
  2806. $this->rejections = $rejections;
  2807. return $this;
  2808. }
  2809. /**
  2810. * Remove rejections.
  2811. */
  2812. public function removeRejections(Rejection $rejections): void
  2813. {
  2814. $this->rejections->removeElement($rejections);
  2815. }
  2816. /**
  2817. * Get rejections.
  2818. *
  2819. * @return Collection
  2820. */
  2821. public function getRejections()
  2822. {
  2823. return $this->rejections;
  2824. }
  2825. public function setRejections($rejections): void
  2826. {
  2827. $this->rejections = $rejections;
  2828. }
  2829. /**
  2830. * Set phoneCounter.
  2831. *
  2832. * @param int $phoneCounter
  2833. *
  2834. * @return Listing
  2835. */
  2836. public function setPhoneCounter($phoneCounter)
  2837. {
  2838. $this->phoneCounter = $phoneCounter;
  2839. return $this;
  2840. }
  2841. /**
  2842. * Get phoneCounter.
  2843. *
  2844. * @return int
  2845. */
  2846. public function getPhoneCounter()
  2847. {
  2848. return $this->phoneCounter;
  2849. }
  2850. /**
  2851. * Set messagesCounter.
  2852. *
  2853. * @param int $messagesCounter
  2854. *
  2855. * @return Listing
  2856. */
  2857. public function setMessagesCounter($messagesCounter)
  2858. {
  2859. $this->messagesCounter = $messagesCounter;
  2860. return $this;
  2861. }
  2862. /**
  2863. * Get messagesCounter.
  2864. *
  2865. * @return int
  2866. */
  2867. public function getMessagesCounter()
  2868. {
  2869. return $this->messagesCounter;
  2870. }
  2871. /**
  2872. * @return int
  2873. */
  2874. public function getFinalPrice()
  2875. {
  2876. return $this->finalPrice;
  2877. }
  2878. /**
  2879. * @param int $finalPrice
  2880. */
  2881. public function setFinalPrice($finalPrice): void
  2882. {
  2883. $this->finalPrice = $finalPrice;
  2884. }
  2885. /**
  2886. * @return string
  2887. */
  2888. public function getSourceOfSale()
  2889. {
  2890. return $this->sourceOfSale;
  2891. }
  2892. /**
  2893. * @param string $sourceOfSale
  2894. */
  2895. public function setSourceOfSale($sourceOfSale): void
  2896. {
  2897. $this->sourceOfSale = $sourceOfSale;
  2898. }
  2899. /**
  2900. * @return string
  2901. */
  2902. public function getDeleteReason()
  2903. {
  2904. return $this->deleteReason;
  2905. }
  2906. /**
  2907. * @param string $deleteReason
  2908. */
  2909. public function setDeleteReason($deleteReason): void
  2910. {
  2911. $this->deleteReason = $deleteReason;
  2912. }
  2913. /**
  2914. * @return string
  2915. */
  2916. public function getDeleteReasonDetails()
  2917. {
  2918. return $this->deleteReasonDetails;
  2919. }
  2920. /**
  2921. * @param string $deleteReasonDetails
  2922. */
  2923. public function setDeleteReasonDetails($deleteReasonDetails): void
  2924. {
  2925. $this->deleteReasonDetails = $deleteReasonDetails;
  2926. }
  2927. public function getInteractions()
  2928. {
  2929. return $this->interactions;
  2930. }
  2931. public function setInteractions($interactions): void
  2932. {
  2933. $this->interactions = $interactions;
  2934. }
  2935. #[Serializer\VirtualProperty]
  2936. #[Serializer\SerializedName('logo')]
  2937. #[Serializer\Groups(['ProjectSearchV4', 'ProjectDetailsV4', 'locationListingV2'])]
  2938. public function getSerializedLogo()
  2939. {
  2940. // Giving priority for listing logo then userLogo. value set on ListingPreSerializerListener.
  2941. return $this->getListingLogo() ?: ($this->getUserLogo() ?: null);
  2942. }
  2943. /**
  2944. * @return string
  2945. */
  2946. public function getUserLogo()
  2947. {
  2948. return $this->userLogo;
  2949. }
  2950. /**
  2951. * @param string $userLogo
  2952. */
  2953. public function setUserLogo($userLogo): void
  2954. {
  2955. $this->userLogo = $userLogo;
  2956. }
  2957. public function getValidUserLogo(): ?Photo
  2958. {
  2959. if ($user = $this->getUser()) {
  2960. if ($user->hasValidAccessToLogoExposure()) {
  2961. return $user->getLogo();
  2962. }
  2963. }
  2964. return null;
  2965. }
  2966. /**
  2967. * @return string
  2968. */
  2969. public function getListingLogo()
  2970. {
  2971. return $this->listingLogo;
  2972. }
  2973. /**
  2974. * @param string $listingLogo
  2975. */
  2976. public function setListingLogo($listingLogo): void
  2977. {
  2978. $this->listingLogo = $listingLogo;
  2979. }
  2980. public function setTranslatableLocale($locale): void
  2981. {
  2982. $this->locale = $locale;
  2983. }
  2984. /**
  2985. * @return bool
  2986. */
  2987. public function canChangeScrapedListing()
  2988. {
  2989. return ListingCategories::SCRAPPED == $this->category
  2990. && ScrapedListing::USER_EMAIL === $this->getUser()->getEmail();
  2991. }
  2992. /**
  2993. * @return bool
  2994. */
  2995. public function validateScrapedListingHash($hash = null)
  2996. {
  2997. $secretHash = md5($this->getPhones()->first()->getNumber().''.$this->getId());
  2998. if ($hash === $secretHash) {
  2999. return true;
  3000. }
  3001. return false;
  3002. }
  3003. public function getSource()
  3004. {
  3005. return $this->source;
  3006. }
  3007. public function setSource($source): void
  3008. {
  3009. $this->source = $source;
  3010. }
  3011. public function setElasticSearchScore($elasticSearchScore): void
  3012. {
  3013. $this->elasticSearchScore = $elasticSearchScore;
  3014. }
  3015. /**
  3016. * @return float
  3017. */
  3018. public function getElasticSearchScore()
  3019. {
  3020. return $this->elasticSearchScore;
  3021. }
  3022. /**
  3023. * @param float $qualityScore
  3024. */
  3025. public function setQualityScore($qualityScore): void
  3026. {
  3027. $this->qualityScore = $qualityScore;
  3028. }
  3029. /**
  3030. * @return float
  3031. */
  3032. public function getQualityScore()
  3033. {
  3034. return $this->photos->count();
  3035. }
  3036. public function getLeadsCounter(): int
  3037. {
  3038. return $this->leadsCounter;
  3039. }
  3040. /**
  3041. * @param int $leadsCounter
  3042. *
  3043. * @return Listing
  3044. */
  3045. public function setLeadsCounter($leadsCounter)
  3046. {
  3047. $this->leadsCounter = $leadsCounter;
  3048. return $this;
  3049. }
  3050. /**
  3051. * Get price per meter.
  3052. */
  3053. public function calculatePricePerMeter(): ?float
  3054. {
  3055. return $this->getArea() > 0 ? $this->getPrice() / $this->getArea() : null;
  3056. }
  3057. /**
  3058. * @return int
  3059. */
  3060. public function getImpressions()
  3061. {
  3062. return $this->impressions;
  3063. }
  3064. /**
  3065. * @param int $impressions
  3066. *
  3067. * @return Listing
  3068. */
  3069. public function setImpressions($impressions)
  3070. {
  3071. $this->impressions = $impressions;
  3072. return $this;
  3073. }
  3074. /**
  3075. * @return $this
  3076. */
  3077. public function setImpressionsMonthlyCount(?int $impressions = null)
  3078. {
  3079. $this->impressionsMonthlyCount = $impressions;
  3080. return $this;
  3081. }
  3082. /**
  3083. * @return int
  3084. */
  3085. public function getImpressionsMonthlyCount()
  3086. {
  3087. return $this->impressionsMonthlyCount;
  3088. }
  3089. /**
  3090. * @return $this
  3091. */
  3092. public function setImpressionsWeeklyCount(?int $impressions = null)
  3093. {
  3094. $this->impressionsWeeklyCount = $impressions;
  3095. return $this;
  3096. }
  3097. public function getImpressionsWeeklyCount()
  3098. {
  3099. return $this->impressionsWeeklyCount;
  3100. }
  3101. /**
  3102. * Get impressionUpdatedAt.
  3103. *
  3104. * @return \DateTime
  3105. */
  3106. public function getImpressionUpdatedAt()
  3107. {
  3108. return $this->impressionUpdatedAt;
  3109. }
  3110. /**
  3111. * Set impressionUpdatedAt.
  3112. *
  3113. * @param \DateTime $impressionUpdatedAt
  3114. *
  3115. * @return Listing
  3116. */
  3117. public function setImpressionUpdatedAt($impressionUpdatedAt)
  3118. {
  3119. $this->impressionUpdatedAt = $impressionUpdatedAt;
  3120. return $this;
  3121. }
  3122. public function getCompoundStatus()
  3123. {
  3124. return $this->compoundStatus;
  3125. }
  3126. public function setCompoundStatus($compoundStatus)
  3127. {
  3128. $this->compoundStatus = $compoundStatus;
  3129. return $this;
  3130. }
  3131. /**
  3132. * @return string
  3133. */
  3134. #[Serializer\VirtualProperty]
  3135. #[Serializer\SerializedName('compound_status')]
  3136. public function getCompoundStatusLabel()
  3137. {
  3138. return CompoundStatus::getLabel($this->getCompoundStatus());
  3139. }
  3140. public function setCompoundStatusLabel($label): void
  3141. {
  3142. $this->compoundStatusLabel = $label;
  3143. }
  3144. public function getPriceLevel()
  3145. {
  3146. return $this->priceLevel;
  3147. }
  3148. public function setPriceLevel($priceLevel)
  3149. {
  3150. $this->priceLevel = $priceLevel;
  3151. return $this;
  3152. }
  3153. /**
  3154. * @return string
  3155. */
  3156. #[Serializer\VirtualProperty]
  3157. #[Serializer\SerializedName('price_level')]
  3158. public function getPriceLevelLabel()
  3159. {
  3160. if (!$this->getPriceLevel() && $this->hasParent()) {
  3161. return ListingPriceLevel::getLabel($this->getParent()->getPriceLevel());
  3162. }
  3163. return ListingPriceLevel::getLabel($this->getPriceLevel());
  3164. }
  3165. /**
  3166. * Check if the Listing desn't have the flag and fall back to the parent.
  3167. *
  3168. * @return string
  3169. */
  3170. public function isParentCommercial()
  3171. {
  3172. if (!$this->isCommercial() && $this->hasParent()) {
  3173. return $this->getParent()->isCommercial();
  3174. }
  3175. return $this->isCommercial();
  3176. }
  3177. public function setPriceLevelLabel($label): void
  3178. {
  3179. $this->priceLevelLabel = $label;
  3180. }
  3181. public function getPricePerMeter()
  3182. {
  3183. return $this->pricePerMeter;
  3184. }
  3185. public function setPricePerMeter($pricePerMeter)
  3186. {
  3187. $this->pricePerMeter = $pricePerMeter;
  3188. return $this;
  3189. }
  3190. public function getChildrenArea()
  3191. {
  3192. $result = [];
  3193. if (empty($this->getChildren())) {
  3194. return;
  3195. }
  3196. foreach ($this->getChildren() as $child) {
  3197. $result['area'] = (int) $child->getArea();
  3198. }
  3199. return $result;
  3200. }
  3201. public function getChildrenPrice()
  3202. {
  3203. $result = [];
  3204. if (empty($this->getChildren())) {
  3205. return;
  3206. }
  3207. foreach ($this->getChildren() as $child) {
  3208. $result['price'] = (int) $child->getPrice();
  3209. }
  3210. return $result;
  3211. }
  3212. public function getChildrenPricePerMeter()
  3213. {
  3214. $result = [];
  3215. if (empty($this->getChildren())) {
  3216. return;
  3217. }
  3218. foreach ($this->getChildren() as $child) {
  3219. $result['pricePerMeter'] = (int) $child->getPricePerMeter();
  3220. }
  3221. return $result;
  3222. }
  3223. public function getChildrenAttributesList()
  3224. {
  3225. $result = [];
  3226. if (empty($this->getChildren())) {
  3227. return;
  3228. }
  3229. foreach ($this->getChildren() as $child) {
  3230. foreach ($child->getAttributes() as $attribute) {
  3231. $result[$attribute->getCustomField()->getName()] = $attribute->getValue();
  3232. }
  3233. }
  3234. return $result;
  3235. }
  3236. /**
  3237. * Returns array of children's property types.
  3238. */
  3239. public function getChildrenPropertyType()
  3240. {
  3241. $propertyType = [];
  3242. if (empty($this->getLiveChildren())) {
  3243. return;
  3244. }
  3245. foreach ($this->getLiveChildren() as $child) {
  3246. $propertyType['id'] = $child->getPropertyType()->getId();
  3247. }
  3248. return $propertyType;
  3249. }
  3250. /**
  3251. * Returns array of children's property types.
  3252. */
  3253. #[Serializer\VirtualProperty]
  3254. #[Serializer\SerializedName('childrenPropertyTypes')]
  3255. #[Serializer\Groups(['locationListingV2', 'homeCompoundV2'])]
  3256. #[Serializer\Expose]
  3257. public function getChildrenPropertyTypeTitle(): array
  3258. {
  3259. $propertyTypes = [];
  3260. if (empty($this->getLiveChildren())) {
  3261. return [];
  3262. }
  3263. foreach ($this->getLiveChildren() as $child) {
  3264. $propertyTypes[] = $child->getPropertyType()->getTitle();
  3265. }
  3266. return array_values(array_unique($propertyTypes));
  3267. }
  3268. public function isBumped(): bool
  3269. {
  3270. return (bool) $this->isBumped;
  3271. }
  3272. public function setBumped(bool $status = true): self
  3273. {
  3274. $this->isBumped = $status;
  3275. return $this;
  3276. }
  3277. /**
  3278. * @return bool
  3279. */
  3280. public function isSendEmail()
  3281. {
  3282. return $this->isSendEmail;
  3283. }
  3284. /**
  3285. * @return $this
  3286. */
  3287. public function setIsSendEmail(bool $isSendEmail = true)
  3288. {
  3289. $this->isSendEmail = $isSendEmail;
  3290. return $this;
  3291. }
  3292. public function isAvailabilityEmailSentl(): bool
  3293. {
  3294. return $this->isAvailabilityEmailSent;
  3295. }
  3296. /**
  3297. * @return $this
  3298. */
  3299. public function setIsAvailabilityEmailSent(bool $isAvailabilityEmailSent = false)
  3300. {
  3301. $this->isAvailabilityEmailSent = $isAvailabilityEmailSent;
  3302. return $this;
  3303. }
  3304. /**
  3305. * @return bool
  3306. */
  3307. #[Serializer\VirtualProperty]
  3308. #[Serializer\Groups(['DataLayer', 'Details', 'Search', 'DefaultV4', 'SearchV4', 'listingDetails'])]
  3309. #[Serializer\Expose]
  3310. public function hasParent()
  3311. {
  3312. return !empty($this->parent);
  3313. }
  3314. #[Serializer\VirtualProperty]
  3315. #[Serializer\Groups(['Details', 'Search', 'DefaultV4', 'SearchV4', 'listingDetails'])]
  3316. #[Serializer\Expose]
  3317. public function isProjectOrUnit(): bool
  3318. {
  3319. return $this->hasParent() || $this->isProject();
  3320. }
  3321. #[Serializer\VirtualProperty]
  3322. #[Serializer\Groups(['DataLayer'])]
  3323. #[Serializer\Expose]
  3324. public function hasChildren(): bool
  3325. {
  3326. return $this->isProject();
  3327. }
  3328. /**
  3329. * Gets Geo point.
  3330. */
  3331. public function getGeoPoint()
  3332. {
  3333. if (!$this->getCenterLat() || !$this->getCenterLng()) {
  3334. return;
  3335. }
  3336. return implode(',', [$this->getCenterLat(), $this->getCenterLng()]);
  3337. }
  3338. /**
  3339. * @return ArrayCollection
  3340. */
  3341. public function getRates(?\DateTime $startDate = null)
  3342. {
  3343. $criteria = Criteria::create()
  3344. ->andWhere(Criteria::expr()->lt(
  3345. 'createdAt',
  3346. new \DateTime()
  3347. ))
  3348. ->andWhere(Criteria::expr()->gt(
  3349. 'createdAt',
  3350. $startDate ?? new \DateTime(sprintf('-%d Days', ListingRateConstant::DATE_RANGE_START))
  3351. ));
  3352. return $this->rates->matching($criteria);
  3353. }
  3354. /**
  3355. * @return int
  3356. */
  3357. #[Serializer\VirtualProperty]
  3358. #[Serializer\Groups(['Rates'])]
  3359. #[Serializer\Expose]
  3360. public function getTotalRates(?\DateTime $startDate = null)
  3361. {
  3362. $totalRates = $this->getRates($startDate)->count();
  3363. if (!$totalRates) {
  3364. return null;
  3365. }
  3366. return round(($this->getPositiveRatesCount($startDate) / $totalRates) * 100);
  3367. }
  3368. #[Serializer\VirtualProperty]
  3369. #[Serializer\Groups(['DefaultV4', 'MyListing'])]
  3370. #[Serializer\SerializedName('score')]
  3371. #[Serializer\Expose]
  3372. public function getRateScore()
  3373. {
  3374. return $this->getTotalRates();
  3375. }
  3376. public function setTotalRates($totalRates): self
  3377. {
  3378. $this->totalRates = $totalRates;
  3379. return $this;
  3380. }
  3381. #[Serializer\VirtualProperty]
  3382. #[Serializer\Groups(['Rates'])]
  3383. #[Serializer\SerializedName('positive_rates')]
  3384. #[Serializer\Expose]
  3385. public function getPositiveRatesCount(?\DateTime $startDate = null)
  3386. {
  3387. $criteria = Criteria::create()
  3388. ->where(Criteria::expr()->eq('rate', ListingRateConstant::SATISFYING));
  3389. return $this->getRates($startDate)->matching($criteria)->count();
  3390. }
  3391. /**
  3392. * @return int
  3393. */
  3394. #[Serializer\VirtualProperty]
  3395. #[Serializer\Groups(['Rates'])]
  3396. #[Serializer\SerializedName('negative_rates')]
  3397. #[Serializer\Expose]
  3398. public function getNegativeRatesCount(?\DateTime $startDate = null)
  3399. {
  3400. $criteria = Criteria::create()
  3401. ->where(Criteria::expr()->eq('rate', ListingRateConstant::UNSATISFYING));
  3402. return $this->getRates($startDate)->matching($criteria)->count();
  3403. }
  3404. /**
  3405. * @return array
  3406. */
  3407. #[Serializer\VirtualProperty]
  3408. #[Serializer\Groups(['Rates'])]
  3409. #[Serializer\SerializedName('rates_reasons')]
  3410. #[Serializer\Expose]
  3411. public function getRateReasonsCollection()
  3412. {
  3413. return $this->rateReasonsCollection;
  3414. }
  3415. /**
  3416. * @return array
  3417. */
  3418. public function setRateReasonsCollection(array $rateReasonsCollection): self
  3419. {
  3420. $this->rateReasonsCollection = new ArrayCollection($rateReasonsCollection);
  3421. return $this;
  3422. }
  3423. /**
  3424. * @return array
  3425. */
  3426. #[Serializer\VirtualProperty]
  3427. #[Serializer\Groups(['Rates'])]
  3428. #[Serializer\SerializedName('rates_comments')]
  3429. #[Serializer\Expose]
  3430. public function getRatesComments()
  3431. {
  3432. $criteria = Criteria::create()
  3433. ->orderBy(['createdAt' => Criteria::DESC]);
  3434. $comments = [];
  3435. foreach ($this->getRates()->matching($criteria) as $rate) {
  3436. $comments[] = $rate->getcomment();
  3437. }
  3438. return $comments;
  3439. }
  3440. public function getSynced()
  3441. {
  3442. return $this->synced;
  3443. }
  3444. /**
  3445. * @return self
  3446. */
  3447. public function setSynced(bool $synced)
  3448. {
  3449. $this->synced = $synced;
  3450. return $this;
  3451. }
  3452. /**
  3453. * @deprecated used to migrate to Skull service. Not needed anymore.
  3454. */
  3455. #[Serializer\VirtualProperty]
  3456. #[Serializer\Groups(['Details', 'Default', 'ActivitiesData'])]
  3457. #[Serializer\Expose]
  3458. public function getReferenceId()
  3459. {
  3460. return $this->id;
  3461. }
  3462. /**
  3463. * @param int $referenceId
  3464. *
  3465. * @return self
  3466. */
  3467. public function setReferenceId($referenceId)
  3468. {
  3469. $this->referenceId = $referenceId;
  3470. return $this;
  3471. }
  3472. public function setFeaturedTypeLabel($featuredTypeLabel): void
  3473. {
  3474. $this->featuredTypeLabel = $featuredTypeLabel;
  3475. }
  3476. #[Serializer\VirtualProperty]
  3477. #[Serializer\SerializedName('featuredType')]
  3478. #[Serializer\Groups(['List', 'Details', 'listingDetails', 'RelatedListingsV2'])]
  3479. #[Serializer\Expose]
  3480. public function getFeaturedType()
  3481. {
  3482. return ['type' => $this->getFeatured(), 'label' => $this->featuredTypeLabel];
  3483. }
  3484. #[Serializer\VirtualProperty]
  3485. #[Serializer\SerializedName('featuredType')]
  3486. #[Serializer\Groups(['DefaultV4', 'SearchV4', 'ProjectSearchV4', 'locationListingV2', 'MyListings'])]
  3487. public function getFeaturedName()
  3488. {
  3489. return ListingFeaturedTypes::getFeaturedName($this->getFeatured());
  3490. }
  3491. #[Serializer\VirtualProperty]
  3492. #[Serializer\SerializedName('referenceId')]
  3493. #[Serializer\Expose]
  3494. #[Serializer\Groups(['DefaultV4', 'SearchV4'])]
  3495. public function getReferencedV4Id()
  3496. {
  3497. return $this->getId();
  3498. }
  3499. /**
  3500. * @return ArrayCollection
  3501. */
  3502. public function getFavourite()
  3503. {
  3504. return $this->favourite;
  3505. }
  3506. public function setFavourite(array $favourites): self
  3507. {
  3508. foreach ($favourites as $favourite) {
  3509. $this->addFavourite($favourite);
  3510. }
  3511. return $this;
  3512. }
  3513. /**
  3514. * Add favourite.
  3515. *
  3516. * @return Listing
  3517. */
  3518. public function addFavourite(Favourite $favourite)
  3519. {
  3520. $favourite->setListing($this);
  3521. $this->favourite[] = $favourite;
  3522. return $this;
  3523. }
  3524. public function isPendingFeaturing()
  3525. {
  3526. return $this->isPendingFeaturing;
  3527. }
  3528. /**
  3529. * @return $this
  3530. */
  3531. public function setPendingFeaturing($pendingFeaturing)
  3532. {
  3533. $this->isPendingFeaturing = $pendingFeaturing;
  3534. return $this;
  3535. }
  3536. public function getPendingFeaturingType()
  3537. {
  3538. return $this->pendingFeaturingType;
  3539. }
  3540. /**
  3541. * @return Listing
  3542. */
  3543. public function setPendingFeaturingType($pendingFeaturingType)
  3544. {
  3545. $this->pendingFeaturingType = $pendingFeaturingType;
  3546. return $this;
  3547. }
  3548. /**
  3549. * @return bool
  3550. */
  3551. #[Serializer\VirtualProperty]
  3552. #[Serializer\SerializedName('is_favourite')]
  3553. #[Serializer\Groups(['List', 'Details'])]
  3554. public function getIsFavourite()
  3555. {
  3556. return $this->isFavourite;
  3557. }
  3558. /**
  3559. * @return Listing
  3560. */
  3561. public function setIsFavourite(bool $isFavourite)
  3562. {
  3563. $this->isFavourite = $isFavourite;
  3564. return $this;
  3565. }
  3566. /**
  3567. * @return string
  3568. */
  3569. #[Serializer\VirtualProperty]
  3570. #[Serializer\SerializedName('user_note')]
  3571. #[Serializer\Groups(['List', 'Details'])]
  3572. public function getUserNote()
  3573. {
  3574. return $this->userNote;
  3575. }
  3576. /**
  3577. * @return Listing
  3578. */
  3579. public function setUserNote(?string $userNote)
  3580. {
  3581. $this->userNote = $userNote;
  3582. return $this;
  3583. }
  3584. public function isProject(): bool
  3585. {
  3586. return ListingCategories::PROJECTS == $this->getCategory();
  3587. }
  3588. /**
  3589. * @return int
  3590. */
  3591. public function getListingFeaturesFromFeaturedType()
  3592. {
  3593. return match ($this->getFeatured()) {
  3594. ListingFeaturedTypes::SPOTLIGHT => ListingFeatures::SPOTLIGHT,
  3595. ListingFeaturedTypes::SPONSORED => ListingFeatures::SPONSORED,
  3596. ListingFeaturedTypes::PREMIUM => ListingFeatures::PREMIUM,
  3597. default => ListingFeatures::FEATURED,
  3598. };
  3599. }
  3600. /**
  3601. * @return bool
  3602. */
  3603. #[Serializer\VirtualProperty]
  3604. #[Serializer\SerializedName('isExcludedFromWhatsApp')]
  3605. #[Serializer\Groups(['List', 'Details', 'DefaultV4'])]
  3606. public function getIsExcludedFromWhatsApp()
  3607. {
  3608. if (
  3609. !empty($this->getUser()->getTeam())
  3610. && TeamCategories::EXCLUDED_FROM_WHATSAPP == $this->getUser()->getTeam()->getCategory()
  3611. && ListingCategories::PROJECTS == $this->getCategory()
  3612. ) {
  3613. return true;
  3614. }
  3615. return false;
  3616. }
  3617. /**
  3618. * @return int|null
  3619. */
  3620. public function getRateStatus()
  3621. {
  3622. return $this->rateStatus;
  3623. }
  3624. /**
  3625. * @return Listing
  3626. */
  3627. public function setRateStatus(?int $rateStatus)
  3628. {
  3629. $this->rateStatus = $rateStatus;
  3630. return $this;
  3631. }
  3632. /**
  3633. * @return string
  3634. */
  3635. #[Serializer\VirtualProperty]
  3636. public function getRateStatusLabel()
  3637. {
  3638. return ListingRateStatus::getLabel($this->getRateStatus());
  3639. }
  3640. /**
  3641. * @return boolean||null
  3642. */
  3643. public function getIsRateReviewed()
  3644. {
  3645. return $this->isRateReviewed;
  3646. }
  3647. /**
  3648. * @return Listing
  3649. */
  3650. public function setIsRateReviewed(?bool $isRateReviewed)
  3651. {
  3652. $this->isRateReviewed = $isRateReviewed;
  3653. return $this;
  3654. }
  3655. public function isHold(): bool
  3656. {
  3657. return (bool) $this->isHold;
  3658. }
  3659. public function setIsHold(bool $isHold = true): self
  3660. {
  3661. $this->isHold = $isHold;
  3662. return $this;
  3663. }
  3664. #[Serializer\VirtualProperty]
  3665. public function getRateReviewStatusLabel(): string
  3666. {
  3667. return ListingRateReviewStatus::getLabel($this->getIsRateReviewed() ? ListingRateReviewStatus::REVIEWED : ListingRateReviewStatus::PENDING_REVIEW);
  3668. }
  3669. /**
  3670. * @return array
  3671. */
  3672. #[Serializer\VirtualProperty]
  3673. #[Serializer\Groups(['Rates'])]
  3674. #[Serializer\SerializedName('reported_date')]
  3675. #[Serializer\Expose]
  3676. public function getReportedDate()
  3677. {
  3678. return $this->reportedDate;
  3679. }
  3680. /**
  3681. * @param \DateTime|string $reportedDate
  3682. *
  3683. * @return array
  3684. */
  3685. public function setReportedDate($reportedDate): self
  3686. {
  3687. $this->reportedDate = $reportedDate;
  3688. return $this;
  3689. }
  3690. /**
  3691. * @return array
  3692. */
  3693. public function getReasonIds()
  3694. {
  3695. $rateReasonsCollection = $this->getRateReasonsCollection();
  3696. if (!isset($rateReasonsCollection['reason_ids'])) {
  3697. return [];
  3698. }
  3699. $reasonsIds = [];
  3700. foreach ($rateReasonsCollection['reason_ids'] as $key => $value) {
  3701. $reasonsIds[] = [
  3702. 'key' => $key,
  3703. 'value' => $value,
  3704. ];
  3705. }
  3706. return $reasonsIds;
  3707. }
  3708. /**
  3709. * @return array
  3710. */
  3711. public function getReasonLabels()
  3712. {
  3713. $rateReasonsCollection = $this->getRateReasonsCollection();
  3714. if (!isset($rateReasonsCollection['reason_labels'])) {
  3715. return [];
  3716. }
  3717. $reasonLabels = [];
  3718. foreach ($rateReasonsCollection['reason_labels'] as $label => $count) {
  3719. $reasonLabels[] = [
  3720. 'label' => $label,
  3721. 'count' => $count,
  3722. ];
  3723. }
  3724. return $reasonLabels;
  3725. }
  3726. private function listMainListingPhonesFromUser(): ArrayCollection
  3727. {
  3728. $phones = new ArrayCollection();
  3729. if ($this->getUser()) {
  3730. foreach ($this->getUser()->getMainPhones(UserMainPhones::BUILD_FORMATTER_USER_PHONES) as $phone) {
  3731. if ($phone) {
  3732. $phones->add($this->castUserPhonesAsListingPhones($phone));
  3733. }
  3734. }
  3735. }
  3736. return $phones;
  3737. }
  3738. private function castUserPhonesAsListingPhones(UserPhone $userPhone): ListingPhone
  3739. {
  3740. $phone = $userPhone->getPhone();
  3741. $phone->setWhatsApp($userPhone->isWhatsApp());
  3742. return new ListingPhone(
  3743. convert_arabic_numbers($phone->getNumber()),
  3744. $this,
  3745. $phone->getCountryCode(),
  3746. $phone
  3747. );
  3748. }
  3749. /**
  3750. * @param Listing $parentOfSimilarListing
  3751. *
  3752. * @return Listing
  3753. */
  3754. public function setParentOfSimilarListing($parentOfSimilarListing)
  3755. {
  3756. $this->parentOfSimilarListing = $parentOfSimilarListing;
  3757. return $this;
  3758. }
  3759. /**
  3760. * @return Listing
  3761. */
  3762. #[Serializer\VirtualProperty]
  3763. #[Serializer\SerializedName('parentOfSimilarListing')]
  3764. #[Serializer\Groups(['SimilarListings'])]
  3765. #[Serializer\Expose]
  3766. public function getParentOfSimilarListing()
  3767. {
  3768. return $this->parentOfSimilarListing;
  3769. }
  3770. public function isCallRequest(): bool
  3771. {
  3772. return $this->isCallRequest;
  3773. }
  3774. public function setIsCallRequest(bool $isCallRequest): self
  3775. {
  3776. $this->isCallRequest = $isCallRequest;
  3777. return $this;
  3778. }
  3779. public function getNotMigratedFields()
  3780. {
  3781. return [
  3782. 'impressionUpdatedAt',
  3783. 'impressions',
  3784. ];
  3785. }
  3786. public function generateCoordinates(): self
  3787. {
  3788. if ($this->getLocation() && (!$this->centerLat || !$this->centerLng)) {
  3789. /** @var Location $location */
  3790. $location = $this->location;
  3791. $this->setCenterLat($location->getLat());
  3792. $this->setCenterLng($location->getLon());
  3793. }
  3794. return $this;
  3795. }
  3796. public function buildListingAttributes(): self
  3797. {
  3798. /** @var ListingAttribute $attribute */
  3799. foreach ($this->attributes as $attribute) {
  3800. if (!$attribute->getCustomField() instanceof CustomField) {
  3801. continue;
  3802. }
  3803. $attributeName = $attribute->getFormattedAttributeName();
  3804. $attributeValue = $attribute->getValue();
  3805. if (null != $attributeValue) {
  3806. $this->listingAttributes[$attributeName] = $attributeValue;
  3807. }
  3808. if (ListingCustomFields::FINISH_TYPE_VALUE == $attributeName) {
  3809. $this->listingAttributes[ListingCustomFields::FINISH_TYPE_LABEL_VALUE] = $attributeValue;
  3810. }
  3811. }
  3812. return $this;
  3813. }
  3814. /**
  3815. * @return array
  3816. */
  3817. #[Serializer\VirtualProperty]
  3818. #[Serializer\SerializedName('attributes')]
  3819. #[Serializer\Groups(['DefaultV4', 'SearchV4', 'RelatedListingsV2', 'MyListings'])]
  3820. #[Serializer\Expose]
  3821. public function getListingAttributesList()
  3822. {
  3823. if (empty($this->listingAttributes)) {
  3824. return null;
  3825. }
  3826. return $this->listingAttributes;
  3827. }
  3828. /**
  3829. * @return array
  3830. */
  3831. public function setListingAttributesList(array $attributesList)
  3832. {
  3833. $this->listingAttributes = $attributesList;
  3834. return $this->listingAttributes;
  3835. }
  3836. /**
  3837. * @return float
  3838. */
  3839. #[Serializer\VirtualProperty]
  3840. #[Serializer\SerializedName('latitude')]
  3841. #[Serializer\Groups(['DefaultV4', 'SearchV4', 'RelatedListingsV2'])]
  3842. #[Serializer\Expose]
  3843. public function getLatitude()
  3844. {
  3845. return $this->centerLat;
  3846. }
  3847. /**
  3848. * @return float
  3849. */
  3850. #[Serializer\VirtualProperty]
  3851. #[Serializer\SerializedName('longitude')]
  3852. #[Serializer\Groups(['DefaultV4', 'SearchV4', 'RelatedListingsV2'])]
  3853. #[Serializer\Expose]
  3854. public function getLongitude()
  3855. {
  3856. return $this->centerLng;
  3857. }
  3858. /**
  3859. * @return string
  3860. */
  3861. #[Serializer\VirtualProperty]
  3862. #[Serializer\SerializedName('status')]
  3863. #[Serializer\Groups(['DefaultV4', 'MyListing', 'MyListings'])]
  3864. #[Serializer\Expose]
  3865. public function getLabeledStatus()
  3866. {
  3867. return ListingStatus::getName($this->getStatus());
  3868. }
  3869. #[Serializer\SerializedName('propertyViewLabel')]
  3870. #[Serializer\VirtualProperty]
  3871. #[Serializer\Groups(['DefaultV4', 'SearchV4'])]
  3872. #[Serializer\Expose]
  3873. public function getTranslatedPropertyViewLabel()
  3874. {
  3875. return $this->propertyViewLabel;
  3876. }
  3877. #[Serializer\SerializedName('paymentMethodLabel')]
  3878. #[Serializer\VirtualProperty]
  3879. #[Serializer\Groups(['DefaultV4'])]
  3880. #[Serializer\Expose]
  3881. public function getTranslatedPaymentMethodLabel()
  3882. {
  3883. return $this->getPaymentMethodLabelTranslated();
  3884. }
  3885. #[Serializer\SerializedName('paymentMethod')]
  3886. #[Serializer\VirtualProperty]
  3887. #[Serializer\Groups(['DefaultV4'])]
  3888. #[Serializer\Expose]
  3889. public function getPaymentMethodText()
  3890. {
  3891. return ListingPaymentMethod::getText($this->paymentMethod);
  3892. }
  3893. #[Serializer\SerializedName('sellerRole')]
  3894. #[Serializer\VirtualProperty]
  3895. #[Serializer\Groups(['Details', 'DefaultV4', 'SearchV4'])]
  3896. #[Serializer\Expose]
  3897. public function getSellerRoleText()
  3898. {
  3899. return ListingSellerRoles::getName($this->getSellerRole());
  3900. }
  3901. public function generateAddress(): self
  3902. {
  3903. if ($this->address || !$this->location) {
  3904. return $this;
  3905. }
  3906. $this->setAddress($this->getLocation()->getTitleFullPath());
  3907. return $this;
  3908. }
  3909. public function setIsPriceNegotiable(bool $isPriceNegotiable, ?CustomField $isPriceNegotiableAttribute = null): self
  3910. {
  3911. if (!$isPriceNegotiableAttribute) {
  3912. return $this;
  3913. }
  3914. /** @var ListingAttribute $attribute */
  3915. foreach ($this->attributes as $attribute) {
  3916. if ($attribute->getCustomField()->getId() === $isPriceNegotiableAttribute->getId()) {
  3917. $attribute->setValue($isPriceNegotiable);
  3918. return $this;
  3919. }
  3920. }
  3921. $listingAttribute = new ListingAttribute();
  3922. $listingAttribute->setCustomField($isPriceNegotiableAttribute);
  3923. $listingAttribute->setValue($isPriceNegotiable);
  3924. $this->addAttribute($listingAttribute);
  3925. return $this;
  3926. }
  3927. #[Serializer\SerializedName('isPriceNegotiable')]
  3928. #[Serializer\VirtualProperty]
  3929. #[Serializer\Groups(['DefaultV4', 'SearchV4'])]
  3930. #[Serializer\Expose]
  3931. public function getIsPriceNegotiable(): bool
  3932. {
  3933. /** @var ListingAttribute $attribute */
  3934. foreach ($this->attributes as $attribute) {
  3935. if (ListingCustomFields::IS_NEGOTIABLE_NAME === $attribute->getCustomField()->getName()) {
  3936. return true;
  3937. }
  3938. }
  3939. return false;
  3940. }
  3941. #[Serializer\VirtualProperty]
  3942. #[Serializer\Groups(['Statistics'])]
  3943. #[Serializer\SerializedName('clickRate')]
  3944. #[Serializer\Expose]
  3945. public function getClickRate(): float
  3946. {
  3947. $impressions = $this->getImpressions() > 0 ? $this->getImpressions() : 1;
  3948. return round(($this->getViews() / $impressions) * 100, 2);
  3949. }
  3950. /**
  3951. * @return int|null
  3952. * @return float|int
  3953. */
  3954. #[Serializer\VirtualProperty]
  3955. #[Serializer\Groups(['Statistics'])]
  3956. #[Serializer\SerializedName('contactRate')]
  3957. #[Serializer\Expose]
  3958. public function getContactRate()
  3959. {
  3960. return ($this->getLeadsCounter() / ($this->getViewsCount() ?: 1)) * 100;
  3961. }
  3962. /**
  3963. * @return float|int
  3964. */
  3965. public function getComputedContactRate()
  3966. {
  3967. if (empty($this->leadsCounter) || empty($this->views)) {
  3968. return 0;
  3969. }
  3970. return round($this->leadsCounter / $this->views * 100, 2);
  3971. }
  3972. /**
  3973. * @param float
  3974. *
  3975. * @return self
  3976. */
  3977. public function setContactRate(float $contactRate)
  3978. {
  3979. $this->contactRate = $contactRate;
  3980. return $this;
  3981. }
  3982. /**
  3983. * @return float|int
  3984. */
  3985. #[Serializer\VirtualProperty]
  3986. #[Serializer\Groups(['Statistics', 'MyListing'])]
  3987. #[Serializer\SerializedName('impressionsCount')]
  3988. #[Serializer\Expose]
  3989. public function getImpressionsCount()
  3990. {
  3991. return $this->getImpressions() ?: 0;
  3992. }
  3993. /**
  3994. * @return float|int
  3995. */
  3996. #[Serializer\VirtualProperty]
  3997. #[Serializer\Groups(['Statistics', 'MyListing', 'MyListings'])]
  3998. #[Serializer\SerializedName('viewsCount')]
  3999. #[Serializer\Expose]
  4000. public function getViewsCount()
  4001. {
  4002. return $this->getViews() ?: 0;
  4003. }
  4004. /**
  4005. * @return float|int
  4006. */
  4007. #[Serializer\VirtualProperty]
  4008. #[Serializer\Groups(['Statistics', 'MyListing', 'MyListings'])]
  4009. #[Serializer\SerializedName('leadsCount')]
  4010. #[Serializer\Expose]
  4011. public function getLeadCount()
  4012. {
  4013. return $this->getLeadsCounter() ?: 0;
  4014. }
  4015. /**
  4016. * @return int|null
  4017. */
  4018. public function isCommercial()
  4019. {
  4020. return $this->isCommercial;
  4021. }
  4022. public function setIsCommercial(int $isCommercial): void
  4023. {
  4024. $this->isCommercial = $isCommercial;
  4025. }
  4026. /**
  4027. * @return string|null
  4028. */
  4029. #[Serializer\VirtualProperty]
  4030. #[Serializer\Groups(['DefaultV4', 'SearchV4'])]
  4031. #[Serializer\SerializedName('category')]
  4032. #[Serializer\Expose]
  4033. public function getCategoryByName()
  4034. {
  4035. return ListingCategories::getLabel($this->getCategory());
  4036. }
  4037. #[Serializer\VirtualProperty]
  4038. #[Serializer\Groups(['Default', 'Details', 'listingDetails'])]
  4039. #[Serializer\SerializedName('categoryLabel')]
  4040. #[Serializer\Expose]
  4041. public function getCategoryLabel(): ?string
  4042. {
  4043. return $this->getCategoryName();
  4044. }
  4045. /**
  4046. * @return int|null
  4047. */
  4048. #[Serializer\VirtualProperty]
  4049. #[Serializer\Groups(['Statistics', 'MyListing'])]
  4050. #[Serializer\SerializedName('messagesCount')]
  4051. #[Serializer\Expose]
  4052. public function getMessagesCount()
  4053. {
  4054. return $this->getMessagesCounter() ?: 0;
  4055. }
  4056. /**
  4057. * Get WhatsApp Number.
  4058. */
  4059. #[Serializer\VirtualProperty]
  4060. #[Serializer\SerializedName('whatsAppNumber')]
  4061. #[Serializer\Groups(['DefaultV4', 'SearchV4', 'ProjectDetailsV4', 'ProjectSearchV4', 'RelatedListingsV2', 'locationListingV2', 'listingDetails'])]
  4062. public function getWhatsAppNumber()
  4063. {
  4064. $user = $this->getUser();
  4065. if ($user->getWhatsAppNumber()) {
  4066. $whatsAppNumber = $user->getWhatsAppNumber()->getNumber();
  4067. if (!preg_match('/^\+\d+$/', (string) $whatsAppNumber)) {
  4068. return $user->getCountryCode().$whatsAppNumber;
  4069. }
  4070. return $whatsAppNumber;
  4071. }
  4072. return null;
  4073. }
  4074. public function getTranslatableLocale()
  4075. {
  4076. return $this->locale;
  4077. }
  4078. /**
  4079. * @return Listing
  4080. */
  4081. public function setV4Translations($translations)
  4082. {
  4083. $this->v4Translations = $translations;
  4084. return $this;
  4085. }
  4086. /**
  4087. * Get translations.
  4088. *
  4089. * @return array
  4090. */
  4091. #[Serializer\VirtualProperty]
  4092. #[Serializer\Groups(['DefaultV4', 'MyListing'])]
  4093. #[Serializer\SerializedName('translations')]
  4094. #[Serializer\Expose]
  4095. public function getV4Translations()
  4096. {
  4097. return is_array($this->v4Translations) ? $this->v4Translations : [$this->v4Translations];
  4098. }
  4099. /**
  4100. * @return ArrayCollection
  4101. */
  4102. #[Serializer\VirtualProperty]
  4103. #[Serializer\Groups(['DefaultV4', 'MyListing', 'MyListings'])]
  4104. #[Serializer\Expose]
  4105. public function getRejectionReasons()
  4106. {
  4107. return $this->rejections;
  4108. }
  4109. /**
  4110. * @return array
  4111. */
  4112. public function getExistingTranslationsLanguages()
  4113. {
  4114. $existingLanguages = [];
  4115. /** @var ListingTranslation $translation */
  4116. foreach ($this->getTranslations() as $translation) {
  4117. if ((!('title' == $translation->getField() || 'description' == $translation->getField()))
  4118. || \in_array($translation->getLocale(), $existingLanguages) || !$translation->getContent()
  4119. ) {
  4120. continue;
  4121. }
  4122. $existingLanguages[] = $translation->getLocale();
  4123. }
  4124. return $existingLanguages;
  4125. }
  4126. public function isShownInHomepage(): bool
  4127. {
  4128. return $this->isShownInHomepage;
  4129. }
  4130. public function setIsShownInHomepage(bool $isShownInHomepage): self
  4131. {
  4132. $this->isShownInHomepage = $isShownInHomepage;
  4133. return $this;
  4134. }
  4135. public function isResale(): bool
  4136. {
  4137. return $this->isResale;
  4138. }
  4139. public function setIsResale(bool $isResale): self
  4140. {
  4141. $this->isResale = $isResale;
  4142. return $this;
  4143. }
  4144. public function setIsRent(bool $isRent): self
  4145. {
  4146. $this->isRent = $isRent;
  4147. return $this;
  4148. }
  4149. public function isRent(): bool
  4150. {
  4151. return $this->isRent;
  4152. }
  4153. public function setIsPrimary(bool $isPrimary): self
  4154. {
  4155. $this->isPrimary = $isPrimary;
  4156. return $this;
  4157. }
  4158. public function isPrimary(): bool
  4159. {
  4160. return $this->isPrimary;
  4161. }
  4162. /**
  4163. * @return boolean||null
  4164. */
  4165. public function getIsMortgageApproved()
  4166. {
  4167. return $this->isMortgageApproved;
  4168. }
  4169. public function setIsMortgageApproved(?bool $isMortgageApproved): self
  4170. {
  4171. $this->isMortgageApproved = $isMortgageApproved;
  4172. return $this;
  4173. }
  4174. public function getRatesNotes()
  4175. {
  4176. return $this->ratesNotes;
  4177. }
  4178. public function getRatesNote()
  4179. {
  4180. if ($this->ratesNotes->isEmpty()) {
  4181. return null;
  4182. }
  4183. return $this->ratesNotes->last();
  4184. }
  4185. public function setRatesNotes($ratesNotes): void
  4186. {
  4187. $this->ratesNotes = $ratesNotes;
  4188. }
  4189. public function getMetaTitle(): ?string
  4190. {
  4191. return $this->metaTitle;
  4192. }
  4193. public function setMetaTitle(?string $metaTitle): self
  4194. {
  4195. $this->metaTitle = $metaTitle;
  4196. return $this;
  4197. }
  4198. public function getMetaDescription(): ?string
  4199. {
  4200. return $this->metaDescription;
  4201. }
  4202. public function setMetaDescription(?string $metaDescription): self
  4203. {
  4204. $this->metaDescription = $metaDescription;
  4205. return $this;
  4206. }
  4207. public function getIsMortgage(): bool
  4208. {
  4209. return $this->isMortgage;
  4210. }
  4211. public function setIsMortgage(bool $isMortgage): self
  4212. {
  4213. $this->isMortgage = $isMortgage;
  4214. return $this;
  4215. }
  4216. #[Serializer\VirtualProperty]
  4217. #[Serializer\SerializedName('compound_field')]
  4218. #[Serializer\Groups(['Default', 'DefaultV4', 'ProjectSearchV4', 'ProjectDetailsV4', 'locationListingV2', 'homeCompoundV2'])]
  4219. #[Serializer\Expose]
  4220. public function getCompoundField(): ?CompoundField
  4221. {
  4222. $compoundField = $this->compoundField;
  4223. if ($this->hasParent()) {
  4224. $compoundField = $this->getParent()->getCompoundField();
  4225. }
  4226. return $compoundField;
  4227. }
  4228. public function setCompoundField(?CompoundField $compoundField): void
  4229. {
  4230. $this->compoundField = $compoundField;
  4231. }
  4232. /**
  4233. * @return array|null
  4234. */
  4235. public function getEligibleForMortgage()
  4236. {
  4237. return $this->eligibleForMortgage;
  4238. }
  4239. public function setEligibleForMortgage(?array $eligibleForMortgage = null): self
  4240. {
  4241. $this->eligibleForMortgage = $eligibleForMortgage;
  4242. return $this;
  4243. }
  4244. public function setPropertyRegistrationStatusOptions(?array $propertyRegistrationStatusOptions = null): self
  4245. {
  4246. $this->propertyRegistrationStatusOptions = $propertyRegistrationStatusOptions;
  4247. return $this;
  4248. }
  4249. /**
  4250. * Get Mortgage Options.
  4251. *
  4252. * @return array|null
  4253. */
  4254. #[Serializer\VirtualProperty]
  4255. #[Serializer\Groups(['DefaultV4'])]
  4256. #[Serializer\SerializedName('property_registration_status_options')]
  4257. #[Serializer\Expose]
  4258. public function getPropertyRegistrationStatusOptions()
  4259. {
  4260. return $this->propertyRegistrationStatusOptions;
  4261. }
  4262. /**
  4263. * @return bool
  4264. */
  4265. public function hasPropertyRegistrationStatusOptions()
  4266. {
  4267. if (!$this->getSection() || !$this->getLocation()) {
  4268. return false;
  4269. }
  4270. return $this->getLocation()->getEligibleForMortgage()
  4271. && (ListingSections::FOR_SALE == $this->getSection()->getId());
  4272. }
  4273. /**
  4274. * Get Eligible For Mortgage Data.
  4275. *
  4276. * @return array|null
  4277. */
  4278. #[Serializer\VirtualProperty]
  4279. #[Serializer\Groups(['DefaultV4', 'SearchV4', 'Default', 'listingDetails'])]
  4280. #[Serializer\SerializedName('eligibleForMortgageData')]
  4281. #[Serializer\Expose]
  4282. public function getEligibleForMortgageData()
  4283. {
  4284. return $this->eligibleForMortgageData;
  4285. }
  4286. public function setEligibleForMortgageData(?array $eligibleForMortgageData = null): self
  4287. {
  4288. $this->eligibleForMortgageData = $eligibleForMortgageData;
  4289. return $this;
  4290. }
  4291. /**
  4292. * Get Eligible For Mortgage with Label.
  4293. *
  4294. * @return array
  4295. */
  4296. public function getEligibleForMortgageWithLabel()
  4297. {
  4298. $eligibleForMortgageWithLabel = [];
  4299. if (!empty($this->getEligibleForMortgage())) {
  4300. foreach ($this->getEligibleForMortgage() as $mortgage) {
  4301. $eligibleForMortgageWithLabel[] = [
  4302. 'id' => $mortgage,
  4303. 'title' => EligibleForMortgageData::getLabel($mortgage),
  4304. ];
  4305. }
  4306. }
  4307. return $eligibleForMortgageWithLabel;
  4308. }
  4309. /**
  4310. * @return PropertyTypeChildren
  4311. */
  4312. public function setPropertyTypeChildren($propertyTypeChilden)
  4313. {
  4314. $this->propertyTypeChilden = $propertyTypeChilden;
  4315. return $this;
  4316. }
  4317. /**
  4318. * Get PropertyTypeChildren.
  4319. *
  4320. * @return array
  4321. */
  4322. public function getPropertyTypeChildren()
  4323. {
  4324. return $this->propertyTypeChilden;
  4325. }
  4326. /**
  4327. * @return float
  4328. */
  4329. public function getCompoundElasticScore()
  4330. {
  4331. return $this->compoundElasticScore;
  4332. }
  4333. /**
  4334. * @param float $compoundElasticScore
  4335. *
  4336. * @return Listing
  4337. */
  4338. public function setCompoundElasticScore($compoundElasticScore)
  4339. {
  4340. $this->compoundElasticScore = $compoundElasticScore;
  4341. return $this;
  4342. }
  4343. /**.
  4344. * @return int|null
  4345. */
  4346. public function getPropertyRegistrationStatus()
  4347. {
  4348. return $this->propertyRegistrationStatus;
  4349. }
  4350. public function setPropertyRegistrationStatus(?int $propertyRegistrationStatus): self
  4351. {
  4352. $this->propertyRegistrationStatus = $propertyRegistrationStatus;
  4353. return $this;
  4354. }
  4355. /**
  4356. * Get property registration status data options.
  4357. *
  4358. * @return array|null
  4359. */
  4360. #[Serializer\VirtualProperty]
  4361. #[Serializer\Groups(['List', 'Details', 'Search', 'DefaultV4', 'SearchV4'])]
  4362. #[Serializer\SerializedName('property_registration_status_data')]
  4363. #[Serializer\Expose]
  4364. public function getPropertyRegistrationStatusData()
  4365. {
  4366. if (empty($this->propertyRegistrationStatus)) {
  4367. return null;
  4368. }
  4369. return [
  4370. 'id' => $this->propertyRegistrationStatus,
  4371. 'title' => PropertyRegistrationStatusOption::getLabel($this->propertyRegistrationStatus),
  4372. ];
  4373. }
  4374. #[Serializer\VirtualProperty]
  4375. #[Serializer\Groups(['Details', 'DefaultV4', 'SearchV4'])]
  4376. #[Serializer\SerializedName('financialAidURL')]
  4377. #[Serializer\Expose]
  4378. public function getFinancialAidURL(): ?string
  4379. {
  4380. // Deprecated. Return null for now.
  4381. return null;
  4382. }
  4383. public function setFinancialAid(FinancialAid $financialAid): void
  4384. {
  4385. $this->financialAid = $financialAid;
  4386. }
  4387. /**
  4388. * @return bool
  4389. */
  4390. public function isExcludedFromClientServed()
  4391. {
  4392. $user = $this->getUser();
  4393. if ($user && $user->hasRole('ROLE_HOME_EG')) {
  4394. return true;
  4395. }
  4396. return false;
  4397. }
  4398. #[Serializer\VirtualProperty]
  4399. #[Serializer\Groups(['Details', 'DefaultV4', 'SearchV4'])]
  4400. #[Serializer\SerializedName('hasSimilarListings')]
  4401. #[Serializer\Expose]
  4402. public function hasSimilarListings(): bool
  4403. {
  4404. return !empty($this->getSimilarListingsCount());
  4405. }
  4406. #[Serializer\VirtualProperty]
  4407. #[Serializer\Groups(['Details', 'DefaultV4', 'SearchV4'])]
  4408. #[Serializer\SerializedName('similarListingsCount')]
  4409. #[Serializer\Expose]
  4410. public function getSimilarListingsCount(): int
  4411. {
  4412. return $this->similarListingsCount;
  4413. }
  4414. public function setSimilarListingsCount(int $count): self
  4415. {
  4416. $this->similarListingsCount = $count;
  4417. return $this;
  4418. }
  4419. /**
  4420. * Set similar listings ids.
  4421. */
  4422. public function setSimilarListingsIds(array $arrayOfIds): self
  4423. {
  4424. $this->similarListingsIds = $arrayOfIds;
  4425. return $this;
  4426. }
  4427. #[Serializer\VirtualProperty]
  4428. #[Serializer\Groups(['Details', 'DefaultV4', 'SearchV4'])]
  4429. #[Serializer\SerializedName('similarListingsIds')]
  4430. #[Serializer\Expose]
  4431. public function getSimilarListingsIds(): array
  4432. {
  4433. return $this->similarListingsIds;
  4434. }
  4435. public function getAdvertiserNumber(): ?string
  4436. {
  4437. return $this->advertiserNumber;
  4438. }
  4439. public function setAdvertiserNumber(?string $advertiserNumber): void
  4440. {
  4441. $this->advertiserNumber = $advertiserNumber;
  4442. }
  4443. public function getAuthorizationNumber(): ?string
  4444. {
  4445. return $this->authorizationNumber;
  4446. }
  4447. public function setAuthorizationNumber(?string $authorizationNumber): void
  4448. {
  4449. $this->authorizationNumber = $authorizationNumber;
  4450. }
  4451. /**
  4452. * Get the value of marketPropertyType.
  4453. *
  4454. * @return int|null
  4455. */
  4456. public function getMarketPropertyType()
  4457. {
  4458. return $this->marketPropertyType;
  4459. }
  4460. /**
  4461. * Set the value of marketPropertyType.
  4462. *
  4463. * @return self
  4464. */
  4465. public function setMarketPropertyType(?int $marketPropertyType)
  4466. {
  4467. $this->marketPropertyType = $marketPropertyType;
  4468. return $this;
  4469. }
  4470. /**
  4471. * Get the value of creationSource.
  4472. *
  4473. * @return int
  4474. */
  4475. public function getCreationSource()
  4476. {
  4477. return $this->creationSource;
  4478. }
  4479. /**
  4480. * Set the value of creationSource.
  4481. *
  4482. * @return self
  4483. */
  4484. public function setCreationSource(int $creationSource)
  4485. {
  4486. $this->creationSource = $creationSource;
  4487. return $this;
  4488. }
  4489. /**
  4490. * @return float
  4491. */
  4492. #[Serializer\VirtualProperty]
  4493. #[Serializer\Groups(['Statistics', 'MyListings'])]
  4494. #[Serializer\SerializedName('costPerLead')]
  4495. #[Serializer\Expose]
  4496. public function getCostPerLead()
  4497. {
  4498. return $this->costPerLead;
  4499. }
  4500. /**
  4501. * Set the value of costPerLead.
  4502. *
  4503. * @return self
  4504. */
  4505. public function setCostPerLead(float $costPerLead)
  4506. {
  4507. $this->costPerLead = $costPerLead;
  4508. return $this;
  4509. }
  4510. /**
  4511. * Get the value of resaleCount.
  4512. *
  4513. * @return int
  4514. */
  4515. public function getResaleCount()
  4516. {
  4517. return $this->resaleCount;
  4518. }
  4519. /**
  4520. * Set the value of resaleCount.
  4521. *
  4522. * @return self
  4523. */
  4524. public function setResaleCount(int $resaleCount)
  4525. {
  4526. $this->resaleCount = $resaleCount;
  4527. return $this;
  4528. }
  4529. /**
  4530. * Get the value of resaleCount.
  4531. *
  4532. * @return int
  4533. */
  4534. public function getRentCount()
  4535. {
  4536. return $this->rentCount;
  4537. }
  4538. /**
  4539. * Set the value of rentCount.
  4540. *
  4541. * @return self
  4542. */
  4543. public function setRentCount(int $rentCount)
  4544. {
  4545. $this->rentCount = $rentCount;
  4546. return $this;
  4547. }
  4548. /**
  4549. * Get the value of clickThroughRate.
  4550. */
  4551. public function getClickThroughRate(): float
  4552. {
  4553. return $this->getClickRate();
  4554. }
  4555. /**
  4556. * Set the value of clickThroughRate.
  4557. */
  4558. public function setClickThroughRate(float $clickThroughRate): self
  4559. {
  4560. $this->clickThroughRate = $clickThroughRate;
  4561. return $this;
  4562. }
  4563. /**
  4564. * Get the value of label.
  4565. *
  4566. * @return int
  4567. */
  4568. public function getLabel()
  4569. {
  4570. return $this->label;
  4571. }
  4572. /**
  4573. * Set the value of label.
  4574. *
  4575. * @return self
  4576. */
  4577. public function setLabel($label)
  4578. {
  4579. $this->label = $label;
  4580. return $this;
  4581. }
  4582. public function addLabel(Label $label, ?string $comment = null): self
  4583. {
  4584. $listingLabel = $this->findListingLabel($label);
  4585. if (null !== $listingLabel) {
  4586. $listingLabel->setComment($comment);
  4587. return $this;
  4588. }
  4589. $this->labels->add(new ListingLabel($this, $label, $comment));
  4590. return $this;
  4591. }
  4592. public function removeLabel(Label $label): void
  4593. {
  4594. $listingLabel = $this->findListingLabel($label);
  4595. if (null !== $listingLabel) {
  4596. $this->labels->removeElement($listingLabel);
  4597. }
  4598. }
  4599. /**
  4600. * @return Collection<int, Label>
  4601. */
  4602. public function getLabels(): Collection
  4603. {
  4604. return $this->labels->map(static fn (ListingLabel $listingLabel) => $listingLabel->getLabel());
  4605. }
  4606. public function getLabelCodes(): array
  4607. {
  4608. return $this->labels->map(static fn (ListingLabel $listingLabel) => $listingLabel->getLabel()->getCode())->toArray();
  4609. }
  4610. /**
  4611. * @return Collection<int, ListingLabel>
  4612. */
  4613. public function getListingLabels(): Collection
  4614. {
  4615. return $this->labels;
  4616. }
  4617. public function hasLabel(Label $label): bool
  4618. {
  4619. return null !== $this->findListingLabel($label);
  4620. }
  4621. public function hasLabelCode(string $code): bool
  4622. {
  4623. return $this->labels->exists(static fn (int $key, ListingLabel $listingLabel) => $listingLabel->getLabel()->getCode() === $code);
  4624. }
  4625. private function findListingLabel(Label $label): ?ListingLabel
  4626. {
  4627. foreach ($this->labels as $listingLabel) {
  4628. if ($listingLabel->getLabel()->getId() === $label->getId()) {
  4629. return $listingLabel;
  4630. }
  4631. }
  4632. return null;
  4633. }
  4634. /**
  4635. * Get the value of isTopPicks.
  4636. */
  4637. public function getIsTopPicks()
  4638. {
  4639. return $this->isTopPicks;
  4640. }
  4641. /**
  4642. * Set the value of isTopPicks.
  4643. *
  4644. * @return self
  4645. */
  4646. public function setIsTopPicks($isTopPicks)
  4647. {
  4648. $this->isTopPicks = $isTopPicks;
  4649. return $this;
  4650. }
  4651. /**
  4652. * Get freezedAt date.
  4653. *
  4654. * @return \DateTime
  4655. */
  4656. public function getFreezedAt()
  4657. {
  4658. return $this->freezedAt;
  4659. }
  4660. /**
  4661. * Set freezedAt date.
  4662. *
  4663. * @return Listing
  4664. */
  4665. public function setFreezedAt($freezedAt)
  4666. {
  4667. $this->freezedAt = $freezedAt;
  4668. return $this;
  4669. }
  4670. public function getEligibleForBumpUp(): bool
  4671. {
  4672. return $this->eligibleForBumpUp;
  4673. }
  4674. public function setEligibleForBumpUp(bool $eligibleForBumpUp): self
  4675. {
  4676. $this->eligibleForBumpUp = $eligibleForBumpUp;
  4677. return $this;
  4678. }
  4679. /**
  4680. * Get waiting time.
  4681. *
  4682. * @return string
  4683. */
  4684. public function getWaitingTime()
  4685. {
  4686. return $this->waitingTime;
  4687. }
  4688. /**
  4689. * Set waiting time.
  4690. *
  4691. * @param string $waitingTime
  4692. *
  4693. * @return Listing
  4694. */
  4695. public function setWaitingTime($waitingTime)
  4696. {
  4697. $this->waitingTime = $waitingTime;
  4698. return $this;
  4699. }
  4700. /**
  4701. * Get reference number.
  4702. */
  4703. public function getReferenceNumber(): ?string
  4704. {
  4705. return $this->referenceNumber;
  4706. }
  4707. /**
  4708. * Set reference number.
  4709. *
  4710. * @param string $referenceNumber
  4711. */
  4712. public function setReferenceNumber($referenceNumber): self
  4713. {
  4714. $this->referenceNumber = $referenceNumber;
  4715. return $this;
  4716. }
  4717. public function getBrochure(): ?File
  4718. {
  4719. return $this->brochure;
  4720. }
  4721. public function setBrochure(?File $file): self
  4722. {
  4723. $this->brochure = $file;
  4724. return $this;
  4725. }
  4726. public function isAiContent(): ?bool
  4727. {
  4728. return $this->AiContent;
  4729. }
  4730. public function setAiContent(bool $AiContent): self
  4731. {
  4732. $this->AiContent = $AiContent;
  4733. return $this;
  4734. }
  4735. public function getAiReview(): ?array
  4736. {
  4737. return $this->aiReview;
  4738. }
  4739. public function setAiReview(?array $aiReview): self
  4740. {
  4741. $this->aiReview = $aiReview;
  4742. return $this;
  4743. }
  4744. /**
  4745. * @return Collection<int, ListingValuation>
  4746. */
  4747. public function getListingValuations(): Collection
  4748. {
  4749. return $this->listingValuations;
  4750. }
  4751. public function addListingValuation(ListingValuation $listingValuation): static
  4752. {
  4753. if (!$this->listingValuations->contains($listingValuation)) {
  4754. $this->listingValuations->add($listingValuation);
  4755. $listingValuation->setListing($this);
  4756. }
  4757. return $this;
  4758. }
  4759. public function removeListingValuation(ListingValuation $listingValuation): static
  4760. {
  4761. if ($this->listingValuations->removeElement($listingValuation)) {
  4762. // set the owning side to null (unless already changed)
  4763. if ($listingValuation->getListing() === $this) {
  4764. $listingValuation->setListing(null);
  4765. }
  4766. }
  4767. return $this;
  4768. }
  4769. public function getValuation(): ?ListingValuation
  4770. {
  4771. return $this->valuation;
  4772. }
  4773. public function setValuation(?ListingValuation $valuation): static
  4774. {
  4775. $this->valuation = $valuation;
  4776. return $this;
  4777. }
  4778. public function getNewValuation(): ?ListingValuation
  4779. {
  4780. return $this->newValuation;
  4781. }
  4782. public function setNewValuation(?ListingValuation $newValuation): static
  4783. {
  4784. $this->newValuation = $newValuation;
  4785. return $this;
  4786. }
  4787. public function setRatingReviewStatus(string $ratingReviewStatus): self
  4788. {
  4789. $this->ratingReviewStatus = $ratingReviewStatus;
  4790. return $this;
  4791. }
  4792. public function getRatingReviewStatus(): string
  4793. {
  4794. return $this->ratingReviewStatus;
  4795. }
  4796. public function getAmenities(): array
  4797. {
  4798. return $this->amenities ?? [];
  4799. }
  4800. public function setAmenities(?array $amenities): self
  4801. {
  4802. $this->amenities = array_values($amenities ?? []);
  4803. return $this;
  4804. }
  4805. }