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

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