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