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