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