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

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