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

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