src/Entity/Prestataire.php line 613

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use DateTime;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\HttpFoundation\File\UploadedFile;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. use App\Validation as ExcAssert;
  11. use App\Validation\Siret;
  12. /**
  13. * Prestataire
  14. *
  15. *
  16. * @ORM\Table(name="Prestataire")
  17. * @ORM\Entity(repositoryClass="App\Entity\PrestataireRepository")
  18. * @ORM\HasLifecycleCallbacks
  19. * @UniqueEntity(
  20. * fields="siret",
  21. * message="Ce numéro SIRET est déjà utilisé."
  22. * )
  23. */
  24. class Prestataire
  25. {
  26. public static function createWithId($id)
  27. {
  28. $instance = new self();
  29. $instance->id = $id;
  30. return $instance;
  31. }
  32. public const STATUS_NEW = 'new';
  33. public const STATUS_VALIDATED = 'valid';
  34. public const STATUS_DELETED = 'deleted';
  35. private static $statusLabels = array(
  36. self::STATUS_NEW => 'Nouveau',
  37. self::STATUS_VALIDATED => 'Validé',
  38. self::STATUS_DELETED => 'Supprimé',
  39. );
  40. /**
  41. * @var integer
  42. *
  43. * @ORM\Column(name="id", type="integer")
  44. * @ORM\Id
  45. * @ORM\GeneratedValue(strategy="AUTO")
  46. */
  47. private $id;
  48. /**
  49. * @var string
  50. *
  51. * @ORM\Column(name="status", type="string")
  52. */
  53. private $status;
  54. /**
  55. * @var DateTime
  56. *
  57. * @ORM\Column(name="register_date", type="datetime")
  58. */
  59. private $registerDate;
  60. /**
  61. * @var DateTime
  62. *
  63. * @ORM\Column(name="modified_date", type="datetime")
  64. */
  65. private $modifiedDate;
  66. /**
  67. * @var integer
  68. *
  69. * @ORM\Column(name="credits", type="integer")
  70. */
  71. private $credits;
  72. /**
  73. * @var string
  74. *
  75. * @ORM\Column(name="entreprise", type="string", length=255)
  76. * @Assert\NotBlank(
  77. * message="Veuillez renseigner ce champ.",
  78. * groups={"registration", "update"}
  79. * )
  80. */
  81. private $entreprise;
  82. /**
  83. * @var integer
  84. *
  85. * @ORM\Column(name="siret", type="bigint", nullable=true)
  86. * @Assert\NotBlank(
  87. * message="Veuillez renseigner ce champ.",
  88. * groups={"registration", "update"}
  89. * )
  90. * @Siret()
  91. */
  92. private $siret;
  93. /**
  94. * @var string
  95. *
  96. * @ORM\Column(name="nom", type="string", length=255)
  97. * @Assert\NotBlank(
  98. * message="Veuillez renseigner ce champ.",
  99. * groups={"registration", "update"}
  100. * )
  101. */
  102. private $nom;
  103. /**
  104. * @var string
  105. *
  106. * @ORM\Column(name="adresse", type="string", length=255)
  107. * @Assert\NotBlank(
  108. * message="Veuillez renseigner ce champ.",
  109. * groups={"registration", "update"}
  110. * )
  111. */
  112. private $adresse;
  113. /**
  114. * @var string
  115. *
  116. * @ORM\Column(name="code_postal", type="string", length=20)
  117. * @Assert\NotBlank(
  118. * message="Veuillez renseigner ce champ.",
  119. * groups={"registration", "update"}
  120. * )
  121. */
  122. private $codePostal;
  123. /**
  124. * @var string
  125. *
  126. * @ORM\Column(name="ville", type="string", length=255)
  127. * @Assert\NotBlank(
  128. * message="Veuillez renseigner ce champ.",
  129. * groups={"registration", "update"}
  130. * )
  131. */
  132. private $ville;
  133. /**
  134. * @var string
  135. * @ORM\Column(name="coordinates", type="string", length=255, nullable=true)
  136. */
  137. private $coordinates;
  138. /**
  139. * @var string
  140. *
  141. * @ORM\Column(name="telephone", type="string", length=255)
  142. * @Assert\NotBlank(
  143. * message="Veuillez renseigner ce champ.",
  144. * groups={"registration", "update"}
  145. * )
  146. */
  147. private $telephone;
  148. /**
  149. * @var string
  150. *
  151. * @ORM\Column(name="fax", type="string", length=255, nullable=true)
  152. */
  153. private $fax;
  154. /**
  155. * @var string
  156. *
  157. * @ORM\Column(name="website", type="string", length=255, nullable=true)
  158. * @Assert\Url(
  159. * message="Veuillez entrer une adresse valide.",
  160. * groups={"registration", "update"}
  161. * )
  162. */
  163. private $website;
  164. /**
  165. * @var string
  166. *
  167. * @ORM\Column(name="logo", type="string", length=255, nullable=true)
  168. */
  169. private $logoPath;
  170. /**
  171. * @Assert\Image(
  172. * maxSize="10M",
  173. * maxSizeMessage="Le poids maximum possible est de 10 Mo.",
  174. * groups={"registration", "update"}
  175. * )
  176. */
  177. private $logo;
  178. /**
  179. * @var boolean
  180. * @Assert\IsTrue(
  181. * message="Veuillez confirmer votre adhésion aux CGUV.",
  182. * groups={"registration"}
  183. * )
  184. */
  185. private $declaration;
  186. /**
  187. * @var User
  188. *
  189. * @ORM\OneToOne(targetEntity="User", inversedBy="prestataire", cascade={"persist","remove"})
  190. * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
  191. */
  192. private $user;
  193. /**
  194. * @var ArrayCollection
  195. *
  196. * @ORM\ManyToMany(targetEntity="Departement", inversedBy="prestataires")
  197. * @ORM\JoinTable(name="PrestataireDepartement")
  198. * @Assert\Count(
  199. * min=1,
  200. * minMessage="Veuillez sélectionner au moins un secteur d'intervention.",
  201. * groups={"registration", "update"}
  202. * )
  203. */
  204. private $departements;
  205. /**
  206. * @var ArrayCollection
  207. *
  208. * @ORM\ManyToMany(targetEntity="Categorie", inversedBy="prestataires")
  209. * @ORM\JoinTable(name="PrestataireCategorie")
  210. * @Assert\Count(
  211. * min=1,
  212. * minMessage="Veuillez sélectionner au moins un domaine d'intervention.",
  213. * groups={"registration", "update"}
  214. * )
  215. */
  216. private $categories;
  217. /**
  218. * @var ArrayCollection
  219. *
  220. * @ORM\OneToMany(targetEntity="Transaction", mappedBy="prestataire", cascade={"remove"})
  221. */
  222. private $transactions;
  223. /**
  224. * @var ArrayCollection
  225. *
  226. * @ORM\OneToMany(targetEntity="RefundRequest", mappedBy="prestataire")
  227. */
  228. private $refundRequests;
  229. public function __construct()
  230. {
  231. $this->status = self::STATUS_NEW;
  232. $this->registerDate = new DateTime();
  233. $this->modifiedDate = new DateTime();
  234. $this->departements = new ArrayCollection();
  235. $this->categories = new ArrayCollection();
  236. $this->credits = 0;
  237. }
  238. /**
  239. * Get id
  240. *
  241. * @return integer
  242. */
  243. public function getId()
  244. {
  245. return $this->id;
  246. }
  247. /**
  248. * @param boolean $status
  249. *
  250. * @return Prestataire
  251. */
  252. public function setStatus($status)
  253. {
  254. $this->status = $status;
  255. return $this;
  256. }
  257. public function getStatus()
  258. {
  259. return $this->status;
  260. }
  261. /**
  262. * Get validated
  263. *
  264. * @return boolean
  265. */
  266. public function isValidated()
  267. {
  268. return $this->status === self::STATUS_VALIDATED;
  269. }
  270. public function isNew()
  271. {
  272. return $this->status === self::STATUS_NEW;
  273. }
  274. public function isDeleted()
  275. {
  276. return $this->status === self::STATUS_DELETED;
  277. }
  278. /**
  279. * Set registerDate
  280. *
  281. * @param DateTime $registerDate
  282. *
  283. * @return Prestataire
  284. */
  285. public function setRegisterDate($registerDate)
  286. {
  287. $this->registerDate = $registerDate;
  288. return $this;
  289. }
  290. /**
  291. * Get registerDate
  292. *
  293. * @return DateTime
  294. */
  295. public function getRegisterDate()
  296. {
  297. return $this->registerDate;
  298. }
  299. /**
  300. * Set credits
  301. *
  302. * @param integer $credits
  303. *
  304. * @return Prestataire
  305. */
  306. public function setCredits($credits)
  307. {
  308. $this->credits = $credits;
  309. return $this;
  310. }
  311. public function addCredits($credits)
  312. {
  313. $this->credits += $credits;
  314. }
  315. public function removeCredits($credits)
  316. {
  317. $this->credits -= $credits;
  318. }
  319. /**
  320. * Get credits
  321. *
  322. * @return integer
  323. */
  324. public function getCredits()
  325. {
  326. return $this->credits;
  327. }
  328. /**
  329. * Set company
  330. *
  331. * @param string $entreprise
  332. *
  333. * @return Prestataire
  334. */
  335. public function setEntreprise($entreprise)
  336. {
  337. $this->entreprise = $entreprise;
  338. return $this;
  339. }
  340. /**
  341. * Get company
  342. *
  343. * @return string
  344. */
  345. public function getEntreprise()
  346. {
  347. return $this->entreprise;
  348. }
  349. /**
  350. * Set siret
  351. *
  352. * @param integer $siret
  353. *
  354. * @return Prestataire
  355. */
  356. public function setSiret($siret)
  357. {
  358. $this->siret = $siret;
  359. return $this;
  360. }
  361. /**
  362. * Get siret
  363. *
  364. * @return integer
  365. */
  366. public function getSiret()
  367. {
  368. return $this->siret;
  369. }
  370. /**
  371. * Set name
  372. *
  373. * @param string $nom
  374. *
  375. * @return Prestataire
  376. */
  377. public function setNom($nom)
  378. {
  379. $this->nom = $nom;
  380. return $this;
  381. }
  382. /**
  383. * Get name
  384. *
  385. * @return string
  386. */
  387. public function getNom()
  388. {
  389. return $this->nom;
  390. }
  391. /**
  392. * Set address
  393. *
  394. * @param string $adresse
  395. *
  396. * @return Prestataire
  397. */
  398. public function setAdresse($adresse)
  399. {
  400. $this->adresse = $adresse;
  401. return $this;
  402. }
  403. /**
  404. * Get address
  405. *
  406. * @return string
  407. */
  408. public function getAdresse()
  409. {
  410. return $this->adresse;
  411. }
  412. /**
  413. * Set zipCode
  414. *
  415. * @param string $codePostal
  416. *
  417. * @return Prestataire
  418. */
  419. public function setCodePostal($codePostal)
  420. {
  421. $this->codePostal = $codePostal;
  422. return $this;
  423. }
  424. /**
  425. * Get zipCode
  426. *
  427. * @return string
  428. */
  429. public function getCodePostal()
  430. {
  431. return $this->codePostal;
  432. }
  433. /**
  434. * Set ville
  435. *
  436. * @param string $ville
  437. *
  438. * @return Prestataire
  439. */
  440. public function setVille($ville)
  441. {
  442. $this->ville = $ville;
  443. return $this;
  444. }
  445. /**
  446. * Get ville
  447. *
  448. * @return string
  449. */
  450. public function getVille()
  451. {
  452. return $this->ville;
  453. }
  454. /**
  455. * Set telephone
  456. *
  457. * @param string $telephone
  458. *
  459. * @return Prestataire
  460. */
  461. public function setTelephone($telephone)
  462. {
  463. $this->telephone = $telephone;
  464. return $this;
  465. }
  466. /**
  467. * Get telephone
  468. *
  469. * @return string
  470. */
  471. public function getTelephone()
  472. {
  473. return $this->telephone;
  474. }
  475. /**
  476. * Set fax
  477. *
  478. * @param string $fax
  479. *
  480. * @return Prestataire
  481. */
  482. public function setFax($fax)
  483. {
  484. $this->fax = $fax;
  485. return $this;
  486. }
  487. /**
  488. * Get fax
  489. *
  490. * @return string
  491. */
  492. public function getFax()
  493. {
  494. return $this->fax;
  495. }
  496. /**
  497. * Set website
  498. *
  499. * @param string $website
  500. *
  501. * @return Prestataire
  502. */
  503. public function setWebsite($website)
  504. {
  505. $this->website = $website;
  506. return $this;
  507. }
  508. /**
  509. * Get website
  510. *
  511. * @return string
  512. */
  513. public function getWebsite()
  514. {
  515. if ($this->website && !str_starts_with($this->website, 'http://') && !str_starts_with($this->website, 'https://') && !str_starts_with($this->website, '://')):
  516. return 'http://' . $this->website;
  517. else: return $this->website; endif;
  518. }
  519. /**
  520. * Set logo
  521. *
  522. * @param string $logoPath
  523. *
  524. * @return Prestataire
  525. */
  526. public function setLogoPath($logoPath)
  527. {
  528. $this->logoPath = $logoPath;
  529. return $this;
  530. }
  531. /**
  532. * Get logo
  533. *
  534. * @return string
  535. */
  536. public function getLogoPath()
  537. {
  538. return sprintf(
  539. $this->logoPath,
  540. $this->getId() ? $this->getId() : '%s'
  541. );
  542. }
  543. /**
  544. */
  545. public function getLogo()
  546. {
  547. return $this->logo;
  548. }
  549. /**
  550. *
  551. * @return $this
  552. */
  553. public function setLogo($logo)
  554. {
  555. $this->logo = $logo;
  556. return $this;
  557. }
  558. /**
  559. * Set user
  560. *
  561. * @param User $user
  562. *
  563. * @return Prestataire
  564. */
  565. public function setUser(User $user)
  566. {
  567. $this->user = $user;
  568. return $this;
  569. }
  570. /**
  571. * Get user
  572. *
  573. * @return User
  574. */
  575. public function getUser()
  576. {
  577. return $this->user;
  578. }
  579. /**
  580. * Add departement
  581. *
  582. * @param Departement $departement
  583. *
  584. * @return Prestataire
  585. */
  586. public function addDepartement(Departement $departement)
  587. {
  588. $this->departements[] = $departement;
  589. return $this;
  590. }
  591. /**
  592. * Remove departement
  593. *
  594. * @param Departement $departement
  595. */
  596. public function removeDepartement(Departement $departement)
  597. {
  598. $this->departements->removeElement($departement);
  599. }
  600. /**
  601. * Get departements
  602. *
  603. * @return Collection
  604. */
  605. public function getDepartements()
  606. {
  607. return $this->departements;
  608. }
  609. /**
  610. * Add categories
  611. *
  612. * @param Categorie $categorie
  613. *
  614. * @return Prestataire
  615. */
  616. public function addCategorie(Categorie $categorie)
  617. {
  618. $this->categories[] = $categorie;
  619. return $this;
  620. }
  621. /**
  622. * Remove categories
  623. *
  624. * @param Categorie $categorie
  625. */
  626. public function removeCategorie(Categorie $categorie)
  627. {
  628. $this->categories->removeElement($categorie);
  629. }
  630. /**
  631. * Get categories
  632. *
  633. * @return Collection
  634. */
  635. public function getCategories()
  636. {
  637. return $this->categories;
  638. }
  639. /**
  640. * Add categories
  641. *
  642. * @param Categorie $categories
  643. * @return Prestataire
  644. */
  645. public function addCategory(Categorie $categories)
  646. {
  647. $this->categories[] = $categories;
  648. return $this;
  649. }
  650. /**
  651. * Remove categories
  652. *
  653. * @param Categorie $categories
  654. */
  655. public function removeCategory(Categorie $categories)
  656. {
  657. $this->categories->removeElement($categories);
  658. }
  659. /**
  660. * Add transactions
  661. *
  662. * @param Transaction $transactions
  663. * @return Prestataire
  664. */
  665. public function addTransaction(Transaction $transactions)
  666. {
  667. $this->transactions[] = $transactions;
  668. return $this;
  669. }
  670. /**
  671. * Remove transactions
  672. *
  673. * @param Transaction $transactions
  674. */
  675. public function removeTransaction(Transaction $transactions)
  676. {
  677. $this->transactions->removeElement($transactions);
  678. }
  679. /**
  680. * Get transactions
  681. *
  682. * @return Collection
  683. */
  684. public function getTransactions()
  685. {
  686. return $this->transactions;
  687. }
  688. /**
  689. * Set modifiedDate
  690. *
  691. * @param \DateTime $modifiedDate
  692. * @return Prestataire
  693. */
  694. public function setModifiedDate($modifiedDate)
  695. {
  696. $this->modifiedDate = $modifiedDate;
  697. return $this;
  698. }
  699. /**
  700. * Get modifiedDate
  701. *
  702. * @return \DateTime
  703. */
  704. public function getModifiedDate()
  705. {
  706. return $this->modifiedDate;
  707. }
  708. /**
  709. * @ORM\PrePersist()
  710. * @ORM\PreUpdate()
  711. */
  712. public function preSave()
  713. {
  714. $this->nom = mb_convert_case($this->nom, MB_CASE_TITLE);
  715. }
  716. /**
  717. * @return boolean
  718. */
  719. public function isDeclaration()
  720. {
  721. return $this->declaration;
  722. }
  723. /**
  724. * @param boolean $declaration
  725. */
  726. public function setDeclaration($declaration)
  727. {
  728. $this->declaration = $declaration;
  729. }
  730. /**
  731. * @return ArrayCollection
  732. */
  733. public function getRefundRequests()
  734. {
  735. return $this->refundRequests;
  736. }
  737. /**
  738. * @param ArrayCollection $refundRequests
  739. */
  740. public function setRefundRequests($refundRequests)
  741. {
  742. $this->refundRequests = $refundRequests;
  743. }
  744. public function getStatusLabel()
  745. {
  746. return self::$statusLabels[$this->status];
  747. }
  748. public function __toString()
  749. {
  750. return $this->entreprise;
  751. }
  752. /**
  753. * @return string
  754. */
  755. public function getCoordinates()
  756. {
  757. return $this->coordinates;
  758. }
  759. /**
  760. * @param string $coordinates
  761. */
  762. public function setCoordinates($coordinates)
  763. {
  764. $this->coordinates = $coordinates;
  765. }
  766. public function getLat()
  767. {
  768. if ($this->coordinates) {
  769. return json_decode($this->coordinates)->lat;
  770. }
  771. return null;
  772. }
  773. public function getLng()
  774. {
  775. if ($this->coordinates) {
  776. return json_decode($this->coordinates)->lng;
  777. }
  778. return null;
  779. }
  780. }