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

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