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

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