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

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