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

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