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