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

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