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

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