src/Entity/Demande.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use DateTime;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use App\Validation as ExcAssert;
  7. use Symfony\Component\HttpFoundation\File\UploadedFile;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. /**
  10. * Demande
  11. *
  12. * @ORM\Table(name="Demande")
  13. * @ORM\Entity(repositoryClass="App\Entity\DemandeRepository")
  14. * @ORM\HasLifecycleCallbacks
  15. */
  16. class Demande
  17. {
  18. /**
  19. * Newly created demande, waiting for validation
  20. */
  21. public const STATUS_NEW = 0;
  22. /**
  23. * Valid demande, visible on site, available to purchase
  24. */
  25. public const STATUS_AVAILABLE = 1;
  26. /**
  27. * Valid demande, visible on site, has been purchased 3 times already
  28. */
  29. public const STATUS_BOUGHT = 2;
  30. /**
  31. * Manually disabled or expired. Not visible on site anymore
  32. */
  33. public const STATUS_DISABLED = 4;
  34. /**
  35. * Deleted through admin interface
  36. */
  37. public const STATUS_DELETED = 5;
  38. /**
  39. * En attente d'envoi de notification aux prestataires
  40. */
  41. public const STATUS_NOTIFICATION_PRESTATAIRES = 6;
  42. public static $statusLabels = array(
  43. self::STATUS_NEW => 'Nouvelle',
  44. self::STATUS_AVAILABLE => "Visible / Disponible à l'achat",
  45. self::STATUS_BOUGHT => "Visible / Non disponible à l'achat",
  46. self::STATUS_DISABLED => 'Désactivée',
  47. self::STATUS_DELETED => 'Supprimée',
  48. self::STATUS_NOTIFICATION_PRESTATAIRES => 'Notification aux prestataires',
  49. );
  50. public static $clientStatuts = array(
  51. 0 => 'Propriétaire',
  52. 1 => 'Acquéreur',
  53. 2 => 'Mandataire',
  54. 3 => 'Autre'
  55. );
  56. public static $bienTypes = array(
  57. 1 => 'Maison',
  58. 2 => 'Appartement',
  59. 3 => 'Immeuble',
  60. 4 => 'Partie commune',
  61. 5 => 'Dépendance',
  62. 6 => 'Garage',
  63. 7 => 'Local professionnel',
  64. 8 => 'Local industriel',
  65. 9 => 'Local agricole',
  66. 10 => 'Bureau',
  67. 11 => 'Terrain',
  68. 12 => 'Autre',
  69. );
  70. public static $nombrePieces = array(
  71. 1 => 1,
  72. 2 => 2,
  73. 3 => 3,
  74. 4 => 4,
  75. 5 => 5,
  76. 6 => 6,
  77. 7 => '7 et +',
  78. 0 => 'Sans objet'
  79. );
  80. public static $coproprieteAnswers = array(
  81. 1 => 'Oui',
  82. 0 => 'Non',
  83. 3 => 'Sans objet'
  84. );
  85. public static $prestationAnswers = array(
  86. 1 => 'Fourniture et pose',
  87. 2 => 'Fourniture',
  88. 3 => 'Pose',
  89. 4 => 'Dépannage / Maintenance',
  90. 0 => 'Sans objet'
  91. );
  92. public static $answers = array(
  93. 1 => 'Oui',
  94. 0 => 'Non',
  95. 2 => 'Je ne sais pas',
  96. 3 => 'Sans objet'
  97. );
  98. public static $constructYears = array(
  99. 1 => 'Avant 1949',
  100. 2 => 'Entre 1949 et 1997',
  101. 3 => 'Après 1997',
  102. 0 => 'Sans objet'
  103. );
  104. public static function createWithId($id)
  105. {
  106. $instance = new self();
  107. $instance->id = $id;
  108. return $instance;
  109. }
  110. /**
  111. * @var integer
  112. *
  113. * @ORM\Column(name="id", type="integer")
  114. * @ORM\Id
  115. * @ORM\GeneratedValue(strategy="AUTO")
  116. */
  117. private $id;
  118. /**
  119. * @var integer
  120. *
  121. * @ORM\Column(name="prix", type="integer")
  122. */
  123. private $prix;
  124. /**
  125. * @var integer
  126. *
  127. * @ORM\Column(name="credits", type="integer")
  128. */
  129. private $credits;
  130. /**
  131. * @var int
  132. *
  133. * @ORM\Column(name="status", type="integer")
  134. */
  135. private $status;
  136. /**
  137. * @var DateTime
  138. *
  139. * @ORM\Column(name="creation_date", type="datetime")
  140. */
  141. private $creationDate;
  142. /**
  143. * @var DateTime
  144. *
  145. * @ORM\Column(name="modified_date", type="datetime")
  146. */
  147. private $modifiedDate;
  148. /**
  149. * @var int
  150. *
  151. * @ORM\Column(name="client_statut", type="integer")
  152. * @Assert\NotBlank(message="Veuillez renseigner ce champ.")
  153. */
  154. private $clientStatut;
  155. /**
  156. * @var string
  157. *
  158. * @ORM\Column(name="client_nom", type="string", length=255)
  159. * @Assert\NotBlank(message="Veuillez renseigner ce champ.")
  160. */
  161. private $clientNom;
  162. /**
  163. * @var string
  164. *
  165. * @ORM\Column(name="client_email", type="string", length=255)
  166. * @Assert\NotBlank(message="Veuillez renseigner ce champ.")
  167. * @Assert\Email(message="Veuillez entrer une adresse email valide.")
  168. */
  169. private $clientEmail;
  170. /**
  171. * @var string
  172. *
  173. * @ORM\Column(name="client_telephone", type="string", length=255)
  174. * @Assert\NotBlank(message="Veuillez renseigner ce champ.")
  175. * @ExcAssert\Phone
  176. */
  177. private $clientTelephone;
  178. /**
  179. * @var int
  180. *
  181. * @ORM\Column(name="bien_type", type="integer")
  182. * @Assert\NotBlank(message="Veuillez renseigner ce champ.")
  183. */
  184. private $bienType;
  185. /**
  186. * @var string
  187. *
  188. * @ORM\Column(name="bien_localisation", type="string", length=255, nullable=true)
  189. */
  190. private $bienLocalisation;
  191. /**
  192. * @var string
  193. *
  194. * @ORM\Column(name="bien_code_postal", type="string", length=20)
  195. * @Assert\NotBlank(message="Veuillez renseigner ce champ.")
  196. */
  197. private $bienCodePostal;
  198. /**
  199. * @var string
  200. *
  201. * @ORM\Column(name="bien_ville", type="string", length=255)
  202. * @Assert\NotBlank(message="Veuillez renseigner ce champ.")
  203. */
  204. private $bienVille;
  205. /**
  206. * @var string
  207. *
  208. * @ORM\Column(name="bien_nombre_pieces", type="string", length=255)
  209. * @Assert\NotBlank(message="Veuillez renseigner ce champ.")
  210. */
  211. private $bienNombrePieces;
  212. /**
  213. * @var string
  214. *
  215. * @ORM\Column(name="bien_surface", type="string", length=255)
  216. * @Assert\NotBlank(message="Veuillez renseigner ce champ.")
  217. */
  218. private $bienSurface;
  219. /**
  220. * @var string
  221. *
  222. * @ORM\Column(name="bien_annee_construction", type="string", length=60)
  223. * @Assert\NotBlank(message="Veuillez renseigner ce champ.")
  224. */
  225. private $bienAnneeConstruction;
  226. /**
  227. * @var integer
  228. *
  229. * @ORM\Column(name="bien_copropriete", type="integer", nullable=true)
  230. * @Assert\NotBlank(message="Veuillez renseigner ce champ.")
  231. */
  232. private $bienCopropriete;
  233. /**
  234. * @var integer
  235. *
  236. * @ORM\Column(name="bien_gaz", type="integer", nullable=true)
  237. * @Assert\NotBlank(groups={"diagnostics"}, message="Veuillez renseigner ce champ.")
  238. */
  239. private $bienGaz;
  240. /**
  241. * @var integer
  242. *
  243. * @ORM\Column(name="bien_electricite", type="integer", nullable=true)
  244. * @Assert\NotBlank(groups={"diagnostics"}, message="Veuillez renseigner ce champ.")
  245. */
  246. private $bienElectricite;
  247. /**
  248. * @var string
  249. *
  250. * @ORM\Column(name="bien_photo", type="string", length=255, nullable=true)
  251. */
  252. private $bienPhotoPath;
  253. /**
  254. * @Assert\Image(
  255. * maxSize="10M",
  256. * maxSizeMessage="Le poids maximum possible est de 10 Mo."
  257. * )
  258. *
  259. */
  260. private $bienPhoto;
  261. /**
  262. * @var string
  263. *
  264. * @ORM\Column(name="description_file", type="string", length=255, nullable=true)
  265. */
  266. private $descriptionFilePath;
  267. /**
  268. * @Assert\File(
  269. * maxSize="10000000",
  270. * maxSizeMessage="Le poids maximum possible est de 10 Mo."
  271. * )
  272. */
  273. private $descriptionFile;
  274. /**
  275. * @var DateTime
  276. *
  277. * @ORM\Column(name="expiration", type="datetime")
  278. */
  279. private $expiration;
  280. /**
  281. * @var string
  282. *
  283. * @ORM\Column(name="comment", type="text", nullable=true)
  284. */
  285. private $comment;
  286. /**
  287. * @var int
  288. *
  289. * @Assert\NotBlank(
  290. * message="Veuillez renseigner ce champ.",
  291. * groups={"solutions", "energies"}
  292. * )
  293. * @ORM\Column(name="prestation", type="integer", nullable=true)
  294. */
  295. private $prestation;
  296. /**
  297. * @var string
  298. *
  299. * @ORM\Column(name="provenance", type="string", nullable=true)
  300. */
  301. private $provenance;
  302. /**
  303. * @var array
  304. * @ORM\Column(name="similar", type="simple_array", nullable=true)
  305. */
  306. private $similar;
  307. /**
  308. * @var ArrayCollection
  309. *
  310. * @ORM\ManyToMany(targetEntity="Transaction", mappedBy="demandes")
  311. */
  312. private $transactions;
  313. /**
  314. * @var Categorie
  315. *
  316. * @ORM\ManyToOne(targetEntity="Categorie")
  317. * @ORM\JoinColumn(name="categorie_id", referencedColumnName="id")
  318. * @Assert\NotBlank(message="Veuillez renseigner ce champ.")
  319. */
  320. private $categorie;
  321. /**
  322. * @var ArrayCollection
  323. *
  324. * @ORM\OneToMany(targetEntity="RefundRequest", mappedBy="demande", cascade={"remove"})
  325. */
  326. private $refundRequests;
  327. /**
  328. * @ORM\Column(type="boolean", nullable=true)
  329. */
  330. private $estimation;
  331. public function __construct()
  332. {
  333. $this->creationDate = new DateTime();
  334. $this->modifiedDate = new DateTime();
  335. $this->transactions = new ArrayCollection();
  336. $this->refundRequests = new ArrayCollection();
  337. }
  338. /**
  339. * Get id
  340. *
  341. * @return integer
  342. */
  343. public function getId()
  344. {
  345. return $this->id;
  346. }
  347. /**
  348. * Set price
  349. *
  350. * @param integer $prix
  351. *
  352. * @return Demande
  353. */
  354. public function setPrix($prix)
  355. {
  356. $this->prix = $prix;
  357. return $this;
  358. }
  359. /**
  360. * Get price
  361. *
  362. * @return integer
  363. */
  364. public function getPrix()
  365. {
  366. return $this->prix;
  367. }
  368. /**
  369. * Set credits
  370. *
  371. * @param integer $credits
  372. *
  373. * @return Demande
  374. */
  375. public function setCredits($credits)
  376. {
  377. $this->credits = $credits;
  378. return $this;
  379. }
  380. /**
  381. * Get credits
  382. *
  383. * @return integer
  384. */
  385. public function getCredits()
  386. {
  387. if ($this->credits):
  388. return $this->credits;
  389. else:
  390. if ($credits = $this->getCategorie()->getCredits()):
  391. $this->setCredits($credits);
  392. elseif ($credits = $this->getCategorie()->getParent()->getCredits()):
  393. $this->setCredits($credits);
  394. endif;
  395. endif;
  396. return $this->credits;
  397. }
  398. /**
  399. * Set validated
  400. *
  401. * @param boolean $status
  402. *
  403. * @return Demande
  404. */
  405. public function setStatus($status)
  406. {
  407. $this->status = $status;
  408. return $this;
  409. }
  410. /**
  411. * Get validated
  412. *
  413. * @return boolean
  414. */
  415. public function getStatus()
  416. {
  417. return $this->status;
  418. }
  419. public function getStatusLabel()
  420. {
  421. return self::$statusLabels[$this->status];
  422. }
  423. /**
  424. * Set creationDate
  425. *
  426. * @param DateTime $creationDate
  427. *
  428. * @return Demande
  429. */
  430. public function setCreationDate($creationDate)
  431. {
  432. $this->creationDate = $creationDate;
  433. return $this;
  434. }
  435. /**
  436. * Get creationDate
  437. *
  438. * @return DateTime
  439. */
  440. public function getCreationDate()
  441. {
  442. return $this->creationDate;
  443. }
  444. /**
  445. * Set clientStatus
  446. *
  447. * @param int $clientStatu
  448. *
  449. * @return Demande
  450. */
  451. public function setClientStatut($clientStatu)
  452. {
  453. $this->clientStatut = $clientStatu;
  454. return $this;
  455. }
  456. /**
  457. * Get clientStatus
  458. *
  459. * @return int
  460. */
  461. public function getClientStatut()
  462. {
  463. return $this->clientStatut;
  464. }
  465. public function getClientStatusLabel()
  466. {
  467. return self::$clientStatuts[$this->clientStatut];
  468. }
  469. /**
  470. * Set clientName
  471. *
  472. * @param string $clientNom
  473. *
  474. * @return Demande
  475. */
  476. public function setClientNom($clientNom)
  477. {
  478. $this->clientNom = $clientNom;
  479. return $this;
  480. }
  481. /**
  482. * Get clientName
  483. *
  484. * @return string
  485. */
  486. public function getClientNom()
  487. {
  488. return $this->clientNom;
  489. }
  490. /**
  491. * Set clientEmail
  492. *
  493. * @param string $clientEmail
  494. *
  495. * @return Demande
  496. */
  497. public function setClientEmail($clientEmail)
  498. {
  499. $this->clientEmail = $clientEmail;
  500. return $this;
  501. }
  502. /**
  503. * Get clientEmail
  504. *
  505. * @return string
  506. */
  507. public function getClientEmail()
  508. {
  509. return $this->clientEmail;
  510. }
  511. /**
  512. * Set clientPhone
  513. *
  514. * @param string $clientTelephone
  515. *
  516. * @return Demande
  517. */
  518. public function setClientTelephone($clientTelephone)
  519. {
  520. $this->clientTelephone = $clientTelephone;
  521. return $this;
  522. }
  523. /**
  524. * Get clientPhone
  525. *
  526. * @return string
  527. */
  528. public function getClientTelephone()
  529. {
  530. return $this->clientTelephone;
  531. }
  532. /**
  533. * @param int $bienType
  534. *
  535. * @return Demande
  536. */
  537. public function setBienType($bienType)
  538. {
  539. $this->bienType = $bienType;
  540. return $this;
  541. }
  542. /**
  543. * @return int
  544. */
  545. public function getBienType()
  546. {
  547. return $this->bienType;
  548. }
  549. public function getBienTypeLabel()
  550. {
  551. return self::$bienTypes[$this->bienType];
  552. }
  553. /**
  554. * @param string $bienLocalisation
  555. *
  556. * @return Demande
  557. */
  558. public function setBienLocalisation($bienLocalisation)
  559. {
  560. $this->bienLocalisation = $bienLocalisation;
  561. return $this;
  562. }
  563. /**
  564. * @return string
  565. */
  566. public function getBienLocalisation()
  567. {
  568. return $this->bienLocalisation;
  569. }
  570. /**
  571. * @param string $bienCodePostal
  572. *
  573. * @return Demande
  574. */
  575. public function setBienCodePostal($bienCodePostal)
  576. {
  577. $this->bienCodePostal = $bienCodePostal;
  578. return $this;
  579. }
  580. /**
  581. * @return string
  582. */
  583. public function getBienCodePostal()
  584. {
  585. return $this->bienCodePostal;
  586. }
  587. public function getBienDepartement()
  588. {
  589. if (strlen($this->bienCodePostal) === 5) {
  590. return substr($this->bienCodePostal, 0, 2);
  591. }
  592. return $this->bienCodePostal;
  593. }
  594. /**
  595. * @param string $bienVille
  596. *
  597. * @return Demande
  598. */
  599. public function setBienVille($bienVille)
  600. {
  601. $this->bienVille = $bienVille;
  602. return $this;
  603. }
  604. /**
  605. * @return string
  606. */
  607. public function getBienVille()
  608. {
  609. return $this->bienVille;
  610. }
  611. /**
  612. * @param string $bienNombrePieces
  613. *
  614. * @return Demande
  615. */
  616. public function setBienNombrePieces($bienNombrePieces)
  617. {
  618. $this->bienNombrePieces = $bienNombrePieces;
  619. return $this;
  620. }
  621. /**
  622. * Get goodRoomCount
  623. *
  624. * @return string
  625. */
  626. public function getBienNombrePieces()
  627. {
  628. return $this->bienNombrePieces;
  629. }
  630. public function getBienNombrePiecesLabel()
  631. {
  632. return self::$nombrePieces[$this->bienNombrePieces];
  633. }
  634. /**
  635. * @param string $bienSurface
  636. *
  637. * @return Demande
  638. */
  639. public function setBienSurface($bienSurface)
  640. {
  641. $this->bienSurface = $bienSurface;
  642. return $this;
  643. }
  644. /**
  645. * @return string
  646. */
  647. public function getBienSurface()
  648. {
  649. return $this->bienSurface;
  650. }
  651. /**
  652. * @param string $bienAnneeConstruction
  653. *
  654. * @return Demande
  655. */
  656. public function setBienAnneeConstruction($bienAnneeConstruction)
  657. {
  658. $this->bienAnneeConstruction = $bienAnneeConstruction;
  659. return $this;
  660. }
  661. /**
  662. * @return string
  663. */
  664. public function getBienAnneeConstruction()
  665. {
  666. return $this->bienAnneeConstruction;
  667. }
  668. /**
  669. * @param integer $bienGaz
  670. *
  671. * @return Demande
  672. */
  673. public function setBienGaz($bienGaz)
  674. {
  675. $this->bienGaz = $bienGaz;
  676. return $this;
  677. }
  678. /**
  679. * @return integer
  680. */
  681. public function getBienGaz()
  682. {
  683. return $this->bienGaz;
  684. }
  685. public function getBienGazLabel()
  686. {
  687. return self::$answers[$this->bienGaz];
  688. }
  689. public function getBienElectriciteLabel()
  690. {
  691. return self::$answers[$this->bienElectricite];
  692. }
  693. /**
  694. * @param integer $bienElectricite
  695. *
  696. * @return Demande
  697. */
  698. public function setBienElectricite($bienElectricite)
  699. {
  700. $this->bienElectricite = $bienElectricite;
  701. return $this;
  702. }
  703. /**
  704. * @return integer
  705. */
  706. public function getBienElectricite()
  707. {
  708. return $this->bienElectricite;
  709. }
  710. /**
  711. * Set goodPhoto
  712. *
  713. * @param string $bienPhotoPath
  714. *
  715. * @return Demande
  716. */
  717. public function setBienPhotoPath($bienPhotoPath)
  718. {
  719. $this->bienPhotoPath = $bienPhotoPath;
  720. return $this;
  721. }
  722. /**
  723. * Get goodPhoto
  724. *
  725. * @return string
  726. */
  727. public function getBienPhotoPath()
  728. {
  729. return $this->bienPhotoPath;
  730. }
  731. /**
  732. */
  733. public function getBienPhoto()
  734. {
  735. return $this->bienPhoto;
  736. }
  737. /**
  738. */
  739. public function setBienPhoto($bienPhoto)
  740. {
  741. $this->bienPhoto = $bienPhoto;
  742. }
  743. /**
  744. * Set descriptionFile
  745. *
  746. * @param string $descriptionFilePath
  747. *
  748. * @return Demande
  749. */
  750. public function setDescriptionFilePath($descriptionFilePath)
  751. {
  752. $this->descriptionFilePath = $descriptionFilePath;
  753. return $this;
  754. }
  755. /**
  756. * Get descriptionFile
  757. *
  758. * @return string
  759. */
  760. public function getDescriptionFilePath()
  761. {
  762. return $this->descriptionFilePath;
  763. }
  764. /**
  765. */
  766. public function getDescriptionFile()
  767. {
  768. return $this->descriptionFile;
  769. }
  770. /**
  771. */
  772. public function setDescriptionFile($descriptionFile)
  773. {
  774. $this->descriptionFile = $descriptionFile;
  775. }
  776. /**
  777. * Set expiration
  778. *
  779. * @param DateTime $expiration
  780. *
  781. * @return Demande
  782. */
  783. public function setExpiration($expiration)
  784. {
  785. if ($expiration) {
  786. $expiration->setTime(23, 59, 00);
  787. }
  788. $this->expiration = $expiration;
  789. return $this;
  790. }
  791. /**
  792. * Get expiration
  793. *
  794. * @return DateTime
  795. */
  796. public function getExpiration()
  797. {
  798. return $this->expiration;
  799. }
  800. /**
  801. * Set comment
  802. *
  803. * @param string $comment
  804. *
  805. * @return Demande
  806. */
  807. public function setComment($comment)
  808. {
  809. $this->comment = $comment;
  810. return $this;
  811. }
  812. /**
  813. * Get comment
  814. *
  815. * @return string
  816. */
  817. public function getComment()
  818. {
  819. return $this->comment;
  820. }
  821. /**
  822. * Add transactions
  823. *
  824. * @param Transaction $transactions
  825. *
  826. * @return Demande
  827. */
  828. public function addTransaction(Transaction $transactions)
  829. {
  830. $this->transactions[] = $transactions;
  831. return $this;
  832. }
  833. /**
  834. * Remove transactions
  835. *
  836. * @param Transaction $transactions
  837. */
  838. public function removeTransaction(Transaction $transactions)
  839. {
  840. $this->transactions->removeElement($transactions);
  841. }
  842. /**
  843. * Get transactions
  844. *
  845. * @return Transaction[]
  846. */
  847. public function getTransactions()
  848. {
  849. return $this->transactions;
  850. }
  851. /**
  852. * Set categorie
  853. *
  854. * @param Categorie $categorie
  855. *
  856. * @return Demande
  857. */
  858. public function setCategorie(Categorie $categorie)
  859. {
  860. $this->categorie = $categorie;
  861. return $this;
  862. }
  863. /**
  864. * Get categorie
  865. *
  866. * @return Categorie
  867. */
  868. public function getCategorie()
  869. {
  870. return $this->categorie;
  871. }
  872. /**
  873. * Set bienCopropriete
  874. *
  875. * @param boolean $bienCopropriete
  876. *
  877. * @return Demande
  878. */
  879. public function setBienCopropriete($bienCopropriete)
  880. {
  881. $this->bienCopropriete = $bienCopropriete;
  882. return $this;
  883. }
  884. /**
  885. * Get bienCopropriete
  886. *
  887. * @return boolean
  888. */
  889. public function getBienCopropriete()
  890. {
  891. return $this->bienCopropriete;
  892. }
  893. public function getBienCoproprieteLabel()
  894. {
  895. return self::$coproprieteAnswers[$this->bienCopropriete];
  896. }
  897. /**
  898. * Set prestation
  899. *
  900. * @param integer $prestation
  901. *
  902. * @return Demande
  903. */
  904. public function setPrestation($prestation)
  905. {
  906. $this->prestation = $prestation;
  907. return $this;
  908. }
  909. /**
  910. * Get prestation
  911. *
  912. * @return integer
  913. */
  914. public function getPrestation()
  915. {
  916. return $this->prestation;
  917. }
  918. public function getPrestationLabel()
  919. {
  920. return self::$prestationAnswers[$this->prestation];
  921. }
  922. /**
  923. * @param string $provenance
  924. *
  925. * @return Demande
  926. */
  927. public function setProvenance($provenance)
  928. {
  929. $this->provenance = preg_replace('/(https?:\/\/)?(www.)?([^\/]+)(.*)?/i', '\3', $provenance);
  930. // $this->provenance = $provenance;
  931. return $this;
  932. }
  933. /**
  934. * @return string
  935. */
  936. public function getProvenance()
  937. {
  938. return $this->provenance;
  939. }
  940. /**
  941. * @param DateTime $modifiedDate
  942. * @return Demande
  943. */
  944. public function setModifiedDate($modifiedDate)
  945. {
  946. $this->modifiedDate = $modifiedDate;
  947. return $this;
  948. }
  949. /**
  950. * @return DateTime
  951. */
  952. public function getModifiedDate()
  953. {
  954. return $this->modifiedDate;
  955. }
  956. public function isDisabled()
  957. {
  958. return $this->status === self::STATUS_NEW ||
  959. $this->status === self::STATUS_DISABLED ||
  960. $this->expiration < new DateTime();
  961. }
  962. public function isDeleted()
  963. {
  964. return $this->status === self::STATUS_DELETED;
  965. }
  966. public function isExpired()
  967. {
  968. return $this->expiration < new DateTime();
  969. }
  970. public function isEmpty()
  971. {
  972. $props = array(
  973. 'clientStatut',
  974. 'clientNom',
  975. 'clientEmail',
  976. 'clientTelephone',
  977. 'bienType',
  978. 'bienCodePostal',
  979. 'bienVille',
  980. 'bienNombrePieces',
  981. 'bienSurface',
  982. 'bienAnneeConstruction',
  983. 'bienCopropriete',
  984. 'bienGaz',
  985. 'bienElectricite',
  986. 'comment'
  987. );
  988. foreach ($props as $prop) {
  989. if ($this->{$prop} !== null) {
  990. return false;
  991. }
  992. }
  993. return true;
  994. }
  995. public function isNew()
  996. {
  997. return $this->status === self::STATUS_NEW;
  998. }
  999. public function isBought()
  1000. {
  1001. return $this->status === self::STATUS_BOUGHT;
  1002. }
  1003. public function __toString()
  1004. {
  1005. return 'Demande n°'. $this->getId();
  1006. }
  1007. /**
  1008. * @return mixed
  1009. */
  1010. public function getRefundRequests()
  1011. {
  1012. return $this->refundRequests;
  1013. }
  1014. public function getRefundRequest($prestataireId)
  1015. {
  1016. if ($this->refundRequests) {
  1017. /** @var RefundRequest $request */
  1018. foreach ($this->refundRequests as $request) {
  1019. if ($request->getPrestataire()->getId() == $prestataireId) {
  1020. return $request;
  1021. }
  1022. }
  1023. }
  1024. return null;
  1025. }
  1026. /**
  1027. * @param mixed $refundRequests
  1028. */
  1029. public function setRefundRequests($refundRequests)
  1030. {
  1031. $this->refundRequests = $refundRequests;
  1032. }
  1033. public function getNbAchats()
  1034. {
  1035. $count = 0;
  1036. /** @var Transaction $transaction */
  1037. foreach ($this->transactions as $transaction) {
  1038. if ($transaction->isConfirmed()) {
  1039. ++$count;
  1040. }
  1041. }
  1042. return $count;
  1043. }
  1044. /**
  1045. * @ORM\PrePersist()
  1046. * @ORM\PreUpdate()
  1047. */
  1048. public function preSave()
  1049. {
  1050. $this->clientNom = mb_convert_case($this->clientNom, MB_CASE_TITLE);
  1051. }
  1052. /**
  1053. * @return array
  1054. */
  1055. public function getSimilar()
  1056. {
  1057. return $this->similar;
  1058. }
  1059. /**
  1060. * @param array $similar
  1061. */
  1062. public function setSimilar($similar)
  1063. {
  1064. $this->similar = $similar;
  1065. }
  1066. public function getEstimation(): ?bool
  1067. {
  1068. return $this->estimation;
  1069. }
  1070. public function setEstimation(?bool $estimation): self
  1071. {
  1072. $this->estimation = $estimation;
  1073. return $this;
  1074. }
  1075. }