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

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