src/Entity/User.php line 49

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Annotation\Exportable;
  4. use App\Annotation\ExportableEntity;
  5. use App\Annotation\ExportableMethod;
  6. use App\Constants\UserExtension as UserExtensionConstants;
  7. use App\Factory\UserExtensionFactory;
  8. use App\Repository\UserRepository;
  9. use App\Services\Common\Point\UserPointService;
  10. use App\Traits\DateTrait;
  11. use App\Traits\UserExtensionTrait;
  12. use App\Validator\NotInPasswordHistory;
  13. use App\Validator\UserMail;
  14. use DateInterval;
  15. use DateInvalidOperationException;
  16. use DateTime;
  17. use DateTimeImmutable;
  18. use DateTimeInterface;
  19. use Doctrine\Common\Collections\ArrayCollection;
  20. use Doctrine\Common\Collections\Collection;
  21. use Doctrine\ORM\Event\PreUpdateEventArgs;
  22. use Doctrine\ORM\Mapping as ORM;
  23. use Exception;
  24. use InvalidArgumentException;
  25. use JMS\Serializer\Annotation as Serializer;
  26. use JMS\Serializer\Annotation\Expose;
  27. use JMS\Serializer\Annotation\Groups;
  28. use JMS\Serializer\Annotation\SerializedName;
  29. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  30. use Symfony\Component\HttpFoundation\File\File;
  31. use Symfony\Component\HttpFoundation\File\UploadedFile;
  32. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  33. use Symfony\Component\Security\Core\User\UserInterface;
  34. use Symfony\Component\Serializer\Annotation\Ignore;
  35. use Symfony\Component\Validator\Constraints as Assert;
  36. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  37. /**
  38. * @ORM\Entity(repositoryClass=UserRepository::class)
  39. * @UniqueEntity("uniqueSlugConstraint")
  40. * @\App\Validator\UniqueActiveAccountId()
  41. * @ORM\HasLifecycleCallbacks()
  42. * @Vich\Uploadable
  43. * @Serializer\ExclusionPolicy("ALL")
  44. * @ExportableEntity
  45. */
  46. class User implements UserInterface, PasswordAuthenticatedUserInterface
  47. {
  48. use DateTrait;
  49. use UserExtensionTrait;
  50. // TODO Check à quoi sert cette constante
  51. public const SUPER_ADMINISTRATEUR = 1;
  52. // tous les status utilisateur
  53. public const STATUS_CGU_DECLINED = "cgu_declined";
  54. public const STATUS_REGISTER_PENDING = "register_pending";
  55. public const STATUS_CGU_PENDING = "cgu_pending";
  56. public const STATUS_ADMIN_PENDING = "admin_pending";
  57. public const STATUS_UNSUBSCRIBED = "unsubscribed";
  58. public const STATUS_ENABLED = "enabled";
  59. public const STATUS_DISABLED = "disabled";
  60. public const STATUS_ARCHIVED = "archived";
  61. public const STATUS_DELETED = "deleted";
  62. public const STATUS_FAKE = "fake";
  63. public const BASE_STATUS = [
  64. self::STATUS_ADMIN_PENDING,
  65. self::STATUS_CGU_PENDING,
  66. self::STATUS_ENABLED,
  67. self::STATUS_DISABLED,
  68. self::STATUS_CGU_DECLINED,
  69. self::STATUS_REGISTER_PENDING
  70. ];
  71. public const INACTIVE_STATUS = [
  72. self::STATUS_DISABLED,
  73. self::STATUS_ARCHIVED,
  74. self::STATUS_DELETED,
  75. self::STATUS_FAKE,
  76. ];
  77. public const ROLE_ALLOWED_TO_HAVE_JOBS = [
  78. 'Super admin' => 'ROLE_SUPER_ADMIN',
  79. 'Administrateur' => 'ROLE_ADMIN',
  80. 'Utilisateur' => 'ROLE_USER',
  81. ];
  82. public ?string $accountIdTmp = null;
  83. /**
  84. * @ORM\Id
  85. * @ORM\GeneratedValue
  86. * @ORM\Column(type="integer")
  87. *
  88. * @Expose()
  89. * @Groups({
  90. * "default",
  91. * "user:id",
  92. * "user:list","user:item", "sale_order:item", "sale_order:post", "cdp", "user",
  93. * "user_citroentf",
  94. * "export_user_citroentf_datatable",
  95. * "export_agency_manager_commercial_datatable",
  96. * "export_agency_manager_datatable", "export_commercial_installer_datatable",
  97. * "export_installer_datatable",
  98. * "sale_order", "purchase", "get:read","post:read", "export_user_datatable", "export_admin_datatable",
  99. * "export_commercial_datatable",
  100. * "regate-list", "point_of_sale", "parameter", "export_request_registration_datatable"
  101. * })
  102. *
  103. * @Exportable()
  104. */
  105. private ?int $id = null;
  106. /**
  107. * @ORM\Column(type="string", length=130)
  108. * @Assert\NotBlank()
  109. * @Assert\Email(
  110. * message = "Cette adresse email n'est pas valide."
  111. * )
  112. *
  113. * @Expose()
  114. * @Groups({
  115. * "default",
  116. * "user:email",
  117. * "user:list", "user:item", "user:post", "sale_order:item", "cdp", "user","email", "user_citroentf",
  118. * "export_user_citroentf_datatable",
  119. * "export_purchase_declaration_datatable", "export_agency_manager_commercial_datatable",
  120. * "export_agency_manager_datatable", "export_commercial_installer_datatable",
  121. * "export_commercial_datatable",
  122. * "export_installer_datatable","get:read", "export_order_datatable", "purchase", "export_user_datatable", "export_admin_datatable",
  123. * "user_bussiness_result", "sale_order","export_request_registration_datatable", "request_registration",
  124. * "univers", "saleordervalidation", "parameter","chatbot_message",
  125. * "idea_box_list", "idea_box_stats", "export_idea_box_datatable", "objective_target_score", "objective_target", "upload_communication_export"
  126. * })
  127. *
  128. * @Exportable()
  129. * @UserMail()
  130. */
  131. private ?string $email = null;
  132. /**
  133. * @ORM\Column(type="array")
  134. *
  135. * @Expose()
  136. * @Groups({
  137. * "user:post",
  138. * "user:roles",
  139. * "roles",
  140. * "cdp", "user", "user_citroentf","get:read", "export_user_citroentf_datatable", "export_user_datatable", "export_admin_datatable",
  141. * "idea_box_list", "idea_box_stats", "export_idea_box_datatable"
  142. * })
  143. */
  144. private array $roles = [];
  145. /**
  146. * @ORM\Column(type="string")
  147. *
  148. * @Expose()
  149. * @Groups({ "user:post" })
  150. */
  151. private ?string $password = null;
  152. /**
  153. * @ORM\Column(type="string", length=50, nullable=true)
  154. *
  155. * @Expose()
  156. * @Groups({
  157. * "default",
  158. * "user:first_name",
  159. * "user:list", "user:item", "user:post", "cdp", "user","email", "user_citroentf",
  160. * "export_order_datatable", "export_user_citroentf_datatable",
  161. * "user_bussiness_result", "export_purchase_declaration_datatable",
  162. * "export_agency_manager_commercial_datatable",
  163. * "export_agency_manager_datatable", "export_commercial_installer_datatable",
  164. * "export_commercial_datatable",
  165. * "purchase", "sale_order","get:read", "export_user_datatable", "export_admin_datatable", "export_installer_datatable",
  166. * "request_registration","customProductOrder:list", "parameter", "export_request_registration_datatable",
  167. * "idea_box_list", "idea_box_stats", "export_idea_box_datatable", "objective_target", "upload_communication_export"
  168. * })
  169. *
  170. * @Exportable()
  171. */
  172. private ?string $firstName = null;
  173. /**
  174. * @ORM\Column(type="string", length=50, nullable=true)
  175. *
  176. * @Expose()
  177. * @Groups({
  178. * "user:last_name",
  179. * "default",
  180. * "user:list", "user:item", "user:post", "cdp", "user","email", "user_citroentf",
  181. * "export_order_datatable",
  182. * "export_user_citroentf_datatable",
  183. * "user_bussiness_result", "export_purchase_declaration_datatable",
  184. * "export_agency_manager_commercial_datatable",
  185. * "export_agency_manager_datatable", "export_commercial_installer_datatable",
  186. * "export_commercial_datatable",
  187. * "purchase", "sale_order","get:read", "export_user_datatable", "export_admin_datatable", "export_installer_datatable",
  188. * "request_registration","export_request_registration_datatable", "customProductOrder:list", "parameter",
  189. * "idea_box_list", "idea_box_stats", "export_idea_box_datatable", "objective_target", "upload_communication_export"
  190. * })
  191. *
  192. * @Exportable()
  193. */
  194. private ?string $lastName = null;
  195. /**
  196. * Numéro téléphone portable
  197. *
  198. * @ORM\Column(type="string", length=20, nullable=true)
  199. *
  200. * @Expose()
  201. * @Groups({
  202. * "user:post",
  203. * "user:mobile",
  204. * "commercial:mobile",
  205. * "user:item", "user:post", "user", "export_user_citroentf_datatable",
  206. * "export_purchase_declaration_datatable",
  207. * "export_agency_manager_commercial_datatable",
  208. * "export_agency_manager_datatable", "export_commercial_installer_datatable",
  209. * "export_commercial_datatable", "export_user_datatable", "export_admin_datatable",
  210. * "export_installer_datatable"})
  211. *
  212. * @Exportable()
  213. */
  214. private ?string $mobile = null;
  215. /**
  216. * Numéro téléphone fix
  217. * @ORM\Column(type="string", length=20, nullable=true)
  218. *
  219. * @Expose()
  220. * @Groups({
  221. * "user:post",
  222. * "user:phone",
  223. * "user:item", "user:post", "user", "export_user_citroentf_datatable", "export_order_datatable",
  224. * "export_purchase_declaration_datatable",
  225. * "export_agency_manager_commercial_datatable", "export_agency_manager_datatable",
  226. * "export_commercial_installer_datatable",
  227. * "export_commercial_datatable","get:read", "export_user_datatable", "export_admin_datatable",
  228. * "export_installer_datatable"})
  229. *
  230. * @Exportable()
  231. */
  232. private ?string $phone = null;
  233. /**
  234. * @ORM\Column(type="datetime", nullable=true)
  235. *
  236. * @Expose()
  237. * @Groups({
  238. * "user:post","welcome_email","user", "user_citroentf"
  239. * })
  240. */
  241. private ?DateTimeInterface $welcomeEmail = null;
  242. /**
  243. * @deprecated Utiliser la fonction getAvailablePointOfUser de PointService
  244. * @ORM\Column(type="integer", options={"default": 0})
  245. */
  246. private int $availablePoint = 0;
  247. /**
  248. * @deprecated
  249. * @ORM\Column(type="integer", options={"default": 0})
  250. */
  251. private int $potentialPoint = 0;
  252. /**
  253. * On passe par un userExtension maintenant
  254. *
  255. * @deprecated
  256. * @ORM\Column(type="string", length=10, nullable=true)
  257. */
  258. private ?string $locale = null;
  259. /**
  260. * Code du pays
  261. *
  262. * @ORM\ManyToOne(targetEntity=Country::class, inversedBy="users")
  263. * @ORM\JoinColumn(name="country_id", referencedColumnName="id",nullable="true")
  264. *
  265. * @Expose()
  266. * @Groups({
  267. * "user:post",
  268. * "country",
  269. * "user:item", "user:post", "export_user_datatable", "export_admin_datatable", "export_user_citroentf_datatable",
  270. * "export_agency_manager_commercial_datatable",
  271. * "export_agency_manager_datatable", "export_commercial_datatable"})
  272. *
  273. * @Exportable()
  274. */
  275. private ?Country $country = null;
  276. /**
  277. * Ancien job conservé pour la migration vers jobs.
  278. *
  279. * @ORM\Column(name="job", type="string", length=255, nullable=true)
  280. */
  281. private ?string $oldJob = null;
  282. /**
  283. * @ORM\Column(type="json", nullable=true)
  284. *
  285. * @Expose()
  286. * @Groups({
  287. * "user:post",
  288. * "jobs",
  289. * "user:jobs",
  290. * "user","get:read", "export_user_datatable", "export_admin_datatable", "univers", "parameter", "purchase" , "export_purchase_declaration_datatable", "objective_target_score", "objective_target"})
  291. *
  292. * @Exportable()
  293. */
  294. private ?array $jobs = [];
  295. /**
  296. * Société
  297. *
  298. * @ORM\Column(type="string", length=255, nullable=true)
  299. *
  300. * @Expose()
  301. * @Groups({
  302. * "user:post",
  303. * "user:company",
  304. * "default",
  305. * "user:item", "user:post", "user","email", "export_purchase_declaration_datatable",
  306. * "export_order_datatable",
  307. * "export_agency_manager_commercial_datatable",
  308. * "export_agency_manager_datatable", "export_commercial_installer_datatable",
  309. * "export_commercial_datatable",
  310. * "export_installer_datatable", "purchase","get:read","post:read", "export_user_datatable"
  311. * })
  312. *
  313. * @Exportable()
  314. */
  315. private ?string $company = null;
  316. /**
  317. * Numéro de Siret
  318. *
  319. * @ORM\Column(type="string", length=255, nullable=true)
  320. *
  321. * @Expose()
  322. * @Groups({
  323. * "user:post",
  324. * "company_siret",
  325. * "export_order_datatable",
  326. * "export_purchase_declaration_datatable",
  327. * "export_installer_datatable",
  328. * "user:list", "user:item", "user", "get:read", "post:read", "export_user_datatable"})
  329. *
  330. * @Exportable()
  331. */
  332. private ?string $companySiret = null;
  333. /**
  334. * Forme juridique
  335. *
  336. * @ORM\Column(type="string", length=128, nullable=true)
  337. *
  338. * @Expose()
  339. * @Groups({
  340. * "user:post",
  341. * "company_legal_status",
  342. * "user:list", "user:item", "user", "get:read", "post:read", "export_user_datatable"})
  343. *
  344. * @Exportable()
  345. */
  346. private ?string $companyLegalStatus = null;
  347. /**
  348. * Access token chiffré par OidcTokenStorage.
  349. * @ORM\Column(type="text", nullable=true)
  350. * @Serializer\Exclude()
  351. */
  352. #[Ignore]
  353. private ?string $oidcAccessToken = null;
  354. /**
  355. * Refresh token chiffré par OidcTokenStorage.
  356. * @ORM\Column(type="text", nullable=true)
  357. * @Serializer\Exclude()
  358. */
  359. #[Ignore]
  360. private ?string $oidcRefreshToken = null;
  361. /**
  362. * Expiration de l'access token, calculée depuis expires_in ; inconnue si non fournie.
  363. * @ORM\Column(type="datetime_immutable", nullable=true)
  364. * @Serializer\Exclude()
  365. */
  366. #[Ignore]
  367. private ?DateTimeImmutable $oidcTokenExpiresAt = null;
  368. /**
  369. * Empreinte de la configuration du fournisseur ayant délivré les jetons.
  370. * @ORM\Column(type="string", length=64, nullable=true)
  371. * @Serializer\Exclude()
  372. */
  373. #[Ignore]
  374. private ?string $oidcTokenConfiguration = null;
  375. /**
  376. * Identifiant du contact fourni par l'API OIDC.
  377. * @ORM\Column(type="string", length=255, nullable=true)
  378. * @Serializer\Exclude()
  379. */
  380. #[Ignore]
  381. private ?string $oidcApiUsername = null;
  382. /**
  383. * Civilité
  384. *
  385. * @ORM\Column(type="string", length=16, nullable=true)
  386. *
  387. * @Expose()
  388. * @Groups({
  389. * "user:civility",
  390. * "user:item", "default", "email","user:post", "user", "export_installer_datatable",
  391. * "export_purchase_declaration_datatable", "export_commercial_installer_datatable",
  392. * "export_user_datatable"})
  393. *
  394. * @Exportable()
  395. */
  396. private ?string $civility = null;
  397. /**
  398. * Adresse
  399. *
  400. * @ORM\Column(type="string", length=255, nullable=true)
  401. *
  402. * @Expose()
  403. * @Groups ({
  404. * "user:post","user", "user:address1", "user:item", "user:post", "email","export_installer_datatable",
  405. * "export_order_datatable",
  406. * "export_user_citroentf_datatable", "export_commercial_installer_datatable", "export_user_datatable", "export_admin_datatable",
  407. * "export_commercial_datatable","export_agency_manager_datatable"})
  408. *
  409. * @Exportable()
  410. */
  411. private ?string $address1 = null;
  412. /**
  413. * Complément d'adresse
  414. *
  415. * @ORM\Column(type="string", length=255, nullable=true)
  416. *
  417. * @Expose()
  418. * @Groups ({
  419. * "user:post","address2", "user:item", "user:post", "email"})
  420. *
  421. * @Exportable()
  422. */
  423. private ?string $address2 = null;
  424. /**
  425. * Code postal
  426. *
  427. * @ORM\Column(type="string", length=255, nullable=true)
  428. *
  429. * @Expose()
  430. * @Groups ({
  431. * "user:post","user", "user:postcode", "user:item", "user:post", "email","export_installer_datatable",
  432. * "export_order_datatable",
  433. * "export_user_citroentf_datatable", "export_commercial_installer_datatable", "export_user_datatable", "export_admin_datatable",
  434. * "export_commercial_datatable","export_agency_manager_datatable"})
  435. *
  436. * @Exportable()
  437. */
  438. private ?string $postcode = null;
  439. /**
  440. * Ville
  441. *
  442. * @ORM\Column(type="string", length=255, nullable=true)
  443. *
  444. * @Expose()
  445. * @Groups({
  446. * "user:post","user", "user:city", "user:item", "user:post", "email","export_user_datatable", "export_admin_datatable",
  447. * "export_order_datatable", "export_installer_datatable",
  448. * "export_commercial_installer_datatable",
  449. * "export_commercial_datatable","export_agency_manager_datatable"})
  450. *
  451. * @Exportable()
  452. */
  453. private ?string $city = null;
  454. /**
  455. * @ORM\Column(type="boolean", nullable=true)
  456. *
  457. * @Expose()
  458. * @Groups({
  459. * "user:post","user:list", "user:item", "user", "get:read", "post:read", "export_user_datatable"})
  460. *
  461. * @Exportable()
  462. */
  463. private ?bool $canOrder = true;
  464. /**
  465. * Date de suppression
  466. * @ORM\Column(type="datetime", nullable=true)
  467. *
  468. * @Expose()
  469. * @Groups({ "user:post","user"})
  470. *
  471. * @Exportable()
  472. */
  473. private ?DateTimeInterface $deletedAt = null;
  474. /**
  475. * Date de naissance
  476. *
  477. * @ORM\Column(type="datetime", nullable=true)
  478. *
  479. * @Expose()
  480. * @Groups({ "user:post","user"})
  481. *
  482. * @deprecated
  483. */
  484. private ?DateTimeInterface $birthDate = null;
  485. /**
  486. * Lieu de naissance
  487. *
  488. * @deprecated
  489. * @ORM\Column(type="string", length=255, nullable=true)
  490. */
  491. private ?string $birthPlace = null;
  492. /**
  493. * Identifiant interne
  494. *
  495. * @ORM\Column(type="string", length=80, nullable=true)
  496. *
  497. * @Expose()
  498. * @Groups({
  499. * "user:internal_code",
  500. * "request_registration",
  501. * "export_user_datatable", "export_admin_datatable",
  502. * "user:list", "user", "user:item", "user:post", "user", "export_purchase_declaration_datatable",
  503. * "export_installer_datatable",
  504. * "export_commercial_installer_datatable"})
  505. *
  506. * @Exportable()
  507. */
  508. private ?string $internalCode = null;
  509. /**
  510. * @ORM\Column(type="datetime", nullable=true)
  511. *
  512. * @Expose()
  513. * @Groups({
  514. * "user:post",
  515. * "default",
  516. * "user:cgu_at",
  517. * "user", "export_installer_datatable", "export_commercial_installer_datatable"
  518. * })
  519. *
  520. * @Exportable()
  521. */
  522. private ?DateTimeInterface $cguAt = null;
  523. /**
  524. * @ORM\Column(type="datetime", nullable=true)
  525. *
  526. * @Expose()
  527. * @Groups({
  528. * "user:post",
  529. * "default",
  530. * "user:register_at",
  531. * "user", "export_installer_datatable", "export_commercial_installer_datatable"
  532. * })
  533. *
  534. * @Exportable()
  535. */
  536. private ?DateTimeInterface $registerAt = null;
  537. /**
  538. * @ORM\Column(type="datetime", nullable=true)
  539. *
  540. * @Expose()
  541. * @Groups ({
  542. * "user:imported_at",
  543. * "export_installer_datatable", "export_commercial_installer_datatable"})
  544. *
  545. * @Exportable()
  546. */
  547. private ?DateTimeInterface $importedAt = null;
  548. /**
  549. * @ORM\Column(type="boolean", options={"default": true})
  550. *
  551. * @Exportable()
  552. */
  553. private bool $canBeContacted = true;
  554. /**
  555. * @deprecated
  556. * @ORM\Column(type="string", length=64, nullable=true)
  557. */
  558. private ?string $capacity = null;
  559. /**
  560. * @ORM\Column(type="string", length=255, nullable=true)
  561. *
  562. * @Exportable()
  563. */
  564. private ?string $address3 = null;
  565. /**
  566. * @ORM\Column(type="boolean", options={"default": false})
  567. *
  568. * @Exportable()
  569. */
  570. private bool $optinMail = false;
  571. /**
  572. * @ORM\Column(type="boolean", options={"default": false})
  573. *
  574. * @Exportable()
  575. */
  576. private bool $optinSMS = false;
  577. /**
  578. * @ORM\Column(type="boolean", options={"default": false})
  579. *
  580. * @Exportable()
  581. */
  582. private bool $optinPostal = false;
  583. /**
  584. * @ORM\Column(type="text", nullable=true)
  585. *
  586. * @Exportable()
  587. */
  588. private ?string $optinPostalAddress = null;
  589. /**
  590. * @ORM\Column(type="string", length=255, nullable=true)
  591. *
  592. * @Exportable()
  593. */
  594. private ?string $source = null;
  595. /**
  596. * @deprecated
  597. * @ORM\Column(type="integer", options={"default": 0})
  598. */
  599. private int $level = 0;
  600. /**
  601. * @deprecated
  602. * @ORM\Column(type="datetime", nullable=true)
  603. */
  604. private ?DateTimeInterface $level0UpdatedAt = null;
  605. /**
  606. * @deprecated
  607. * @ORM\Column(type="datetime", nullable=true)
  608. */
  609. private ?DateTimeInterface $level1UpdatedAt = null;
  610. /**
  611. * @deprecated
  612. * @ORM\Column(type="datetime", nullable=true)
  613. */
  614. private ?DateTimeInterface $level2UpdatedAt = null;
  615. /**
  616. * @deprecated
  617. * @ORM\Column(type="datetime", nullable=true)
  618. */
  619. private ?DateTimeInterface $level3UpdatedAt = null;
  620. /**
  621. * @deprecated
  622. * @ORM\Column(type="datetime", nullable=true)
  623. */
  624. private ?DateTimeInterface $levelUpdateSeenAt = null;
  625. /**
  626. * @ORM\Column(type="boolean", options={"default": true})
  627. *
  628. * @Expose()
  629. * @Groups ({
  630. * "user:is_email_ok",
  631. * "user",
  632. * "export_installer_datatable", "export_commercial_installer_datatable"})
  633. */
  634. private bool $isEmailOk = true;
  635. /**
  636. * @ORM\Column(type="datetime", nullable=true)
  637. */
  638. private ?DateTimeInterface $lastEmailCheck = null;
  639. /**
  640. * @ORM\Column(type="string", length=255, nullable=true)
  641. * @Assert\NotBlank(groups={"installateur"})
  642. * @Assert\Regex(
  643. * groups={"installateur"},
  644. * message="Le numéro SAP est invalide",
  645. * pattern = "/^\d{6,8}$/"),
  646. *
  647. * @Expose()
  648. * @Groups({
  649. * "default",
  650. * "user:sap_account",
  651. * "user", "user_bussiness_result", "export_purchase_declaration_datatable",
  652. * "export_agency_manager_commercial_datatable",
  653. * "export_agency_manager_datatable", "export_commercial_installer_datatable",
  654. * "export_commercial_datatable","get:read", "purchase",
  655. * "export_installer_datatable"
  656. * })
  657. *
  658. * @Exportable()
  659. */
  660. private ?string $sapAccount = null;
  661. /**
  662. * @ORM\Column(type="string", length=255, nullable=true)
  663. *
  664. * @Expose()
  665. * @Groups({
  666. * "user:sap_distributor",
  667. * "export_installer_datatable", "export_commercial_installer_datatable"})
  668. *
  669. * @Exportable()
  670. */
  671. private ?string $sapDistributor = null;
  672. /**
  673. * @ORM\Column(type="string", length=255, nullable=true)
  674. *
  675. * @Expose()
  676. * @Groups({
  677. * "user:distributor",
  678. * "export_installer_datatable", "export_commercial_installer_datatable"})
  679. *
  680. * @Exportable()
  681. */
  682. private ?string $distributor = null;
  683. /**
  684. * @ORM\Column(type="string", length=255, nullable=true)
  685. *
  686. * @Expose()
  687. * @Groups({
  688. * "user:distributor2",
  689. * "export_installer_datatable", "export_commercial_installer_datatable"})
  690. *
  691. * @Exportable()
  692. */
  693. private ?string $distributor2 = null;
  694. /**
  695. * @ORM\Column(type="boolean", nullable=true)
  696. *
  697. * @Exportable()
  698. */
  699. private ?bool $aggreement = null;
  700. /**
  701. * @ORM\Column(type="datetime", nullable=true)
  702. *
  703. * @Expose()
  704. * @Groups({
  705. * "user:post",
  706. * "user:unsubscribed_at",
  707. * "user","get:read","post:read", "export_installer_datatable", "export_commercial_installer_datatable"})
  708. *
  709. * @Exportable()
  710. */
  711. private ?DateTimeInterface $unsubscribedAt = null;
  712. /**
  713. * True if the salesman is chauffage
  714. * @ORM\Column(type="boolean", options={"default": false}, nullable=true)
  715. *
  716. * @Expose()
  717. * @Groups ({
  718. * "user:chauffage",
  719. * "user", "export_agency_manager_commercial_datatable", "export_agency_manager_datatable",
  720. * "export_commercial_datatable"})
  721. *
  722. * @Exportable()
  723. */
  724. private bool $chauffage = false;
  725. /**
  726. * @ORM\OneToMany(targetEntity=Address::class, mappedBy="user", cascade={"remove", "persist"})
  727. *
  728. * @Exportable("addresses")
  729. */
  730. private Collection $addresses;
  731. /**
  732. * @ORM\OneToMany(targetEntity=Cart::class, mappedBy="user", cascade={"remove", "persist"})
  733. */
  734. private Collection $carts;
  735. /**
  736. * @ORM\ManyToOne(targetEntity=User::class, inversedBy="subAccountUsers", cascade={"persist"})
  737. * @ORM\JoinColumn(onDelete="SET null", nullable=true)
  738. *
  739. * @var User|null
  740. */
  741. private ?User $mainAccountUser = null;
  742. /**
  743. * @ORM\OneToMany(targetEntity=User::class, mappedBy="mainAccountUser")
  744. *
  745. * @var Collection|User[]
  746. */
  747. private Collection $subAccountUsers;
  748. /**
  749. * @ORM\ManyToMany(targetEntity=Distributor::class, inversedBy="users", cascade={"persist"})
  750. *
  751. * @Expose()
  752. * @Groups({
  753. * "user:distributors",
  754. * "export_installer_datatable", "export_commercial_installer_datatable"})
  755. */
  756. private Collection $distributors;
  757. /**
  758. * @ORM\OneToMany(targetEntity=Purchase::class, mappedBy="user", cascade={"remove"})
  759. */
  760. private Collection $purchases;
  761. /**
  762. * @ORM\OneToMany(targetEntity=Purchase::class, mappedBy="validator", cascade={"remove"})
  763. */
  764. private Collection $purchasesIHaveProcessed;
  765. /**
  766. * @ORM\OneToMany(targetEntity=SaleOrder::class, mappedBy="user")
  767. *
  768. * @Exportable()
  769. */
  770. private Collection $orders;
  771. /**
  772. * @var Collection<int, User>
  773. *
  774. * @ORM\OneToMany(targetEntity=User::class, mappedBy="godfather")
  775. */
  776. private Collection $godchilds;
  777. /**
  778. * @var User|null
  779. *
  780. * @ORM\ManyToOne(targetEntity=User::class, inversedBy="godchilds")
  781. * @ORM\JoinColumn(onDelete="SET null")
  782. */
  783. private ?User $godfather = null;
  784. /**
  785. * @deprecated
  786. * @ORM\OneToMany(targetEntity=Satisfaction::class, mappedBy="user")
  787. */
  788. private Collection $satisfactions;
  789. /**
  790. * @ORM\OneToMany(targetEntity=RequestProductAvailable::class, mappedBy="user")
  791. */
  792. private Collection $requestProductAvailables;
  793. /**
  794. * @ORM\OneToMany(targetEntity=UserImportHistory::class, mappedBy="importer")
  795. *
  796. * @Exportable()
  797. */
  798. private Collection $userImportHistories;
  799. /**
  800. * @ORM\ManyToMany(targetEntity=ContactList::class, mappedBy="users")
  801. *
  802. * @Exportable()
  803. */
  804. private Collection $contactLists;
  805. /**
  806. * @ORM\Column(type="string", length=255, nullable=true)
  807. *
  808. * @Expose()
  809. * @Groups({"user", "sale_order","get:read","post:read"})
  810. */
  811. private ?string $username = null;
  812. /**
  813. * @deprecated
  814. * @ORM\Column(type="string", length=255, nullable=true)
  815. */
  816. private ?string $usernameCanonical = null;
  817. /**
  818. * @deprecated
  819. * @ORM\Column(type="string", length=255, nullable=true)
  820. */
  821. private $emailCanonical;
  822. /**
  823. * @deprecated
  824. * @ORM\Column(type="string", length=255, nullable=true)
  825. */
  826. private ?string $salt = null;
  827. /**
  828. * Date de dernière connexion
  829. *
  830. * @ORM\Column(type="datetime", nullable=true)
  831. *
  832. * @Expose()
  833. * @Groups({
  834. * "user:last_login",
  835. * "user", "user:item", "export_installer_datatable", "export_commercial_installer_datatable",
  836. * "export_user_datatable"})
  837. *
  838. * @Exportable()
  839. */
  840. private ?DateTimeInterface $lastLogin = null;
  841. /**
  842. * @ORM\Column(type="string", length=64, nullable=true)
  843. */
  844. private ?string $confirmationToken = null;
  845. /**
  846. * @ORM\Column(type="datetime", nullable=true)
  847. *
  848. * @Exportable()
  849. */
  850. private ?DateTimeInterface $passwordRequestedAt = null;
  851. /**
  852. * @Expose()
  853. * @Groups ({"user:post"})
  854. *
  855. * @NotInPasswordHistory
  856. */
  857. private ?string $plainPassword = null;
  858. /**
  859. * @ORM\Column(type="boolean", nullable=true)
  860. *
  861. * @Expose()
  862. * @Groups({"get:read"})
  863. */
  864. private ?bool $credentialExpired = null;
  865. /**
  866. * @ORM\Column(type="datetime", nullable=true)
  867. */
  868. private ?DateTimeInterface $credentialExpiredAt = null;
  869. // Arguments requis pour LaPoste
  870. /**
  871. * @ORM\OneToMany(targetEntity=Devis::class, mappedBy="user")
  872. *
  873. * @Exportable()
  874. */
  875. private Collection $devis;
  876. /**
  877. * @ORM\ManyToOne(targetEntity=Regate::class, inversedBy="members")
  878. * @ORM\JoinColumn(name="regate_id", referencedColumnName="id", onDelete="SET null")
  879. *
  880. * @Expose()
  881. * @Groups({"user", "export_user_datatable"})
  882. *
  883. * @Exportable()
  884. */
  885. private ?Regate $regate = null;
  886. /**
  887. * @ORM\Column(type="boolean", nullable=true)
  888. *
  889. * @Exportable()
  890. */
  891. private ?bool $donneesPersonnelles = null;
  892. /**
  893. * @var PointTransaction[]|Collection
  894. *
  895. * @ORM\OneToMany(targetEntity=PointTransaction::class, mappedBy="user", orphanRemoval=true, cascade={"persist"})
  896. *
  897. * @Exportable()
  898. */
  899. private Collection $pointTransactions;
  900. /**
  901. * @ORM\ManyToOne(targetEntity=User::class, inversedBy="installers")
  902. *
  903. * @Expose()
  904. * @Groups({
  905. * "user:commercial",
  906. * "user","export_request_registration_datatable", "request_registration", "sale_order", "purchase",
  907. * "export_purchase_declaration_datatable",
  908. * "export_installer_datatable", "export_commercial_installer_datatable"})
  909. */
  910. private $commercial;
  911. /**
  912. * @ORM\OneToMany(targetEntity=User::class, mappedBy="commercial")
  913. *
  914. * @Expose()
  915. * @Groups({
  916. * "user:installers"
  917. * })
  918. */
  919. private $installers;
  920. /**
  921. * @ORM\ManyToOne(targetEntity=User::class, inversedBy="heatingInstallers")
  922. *
  923. * @Expose()
  924. * @Groups({
  925. * "user:heating_commercial",
  926. * "export_installer_datatable", "export_commercial_installer_datatable"})
  927. */
  928. private $heatingCommercial;
  929. /**
  930. * @ORM\OneToMany(targetEntity=User::class, mappedBy="heatingCommercial")
  931. */
  932. private $heatingInstallers;
  933. /**
  934. * @ORM\ManyToOne(targetEntity=Agence::class, inversedBy="users", fetch="EAGER")
  935. *
  936. * @Expose()
  937. * @Groups({
  938. * "default",
  939. * "user:agency",
  940. * "user", "user_bussiness_result", "export_purchase_declaration_datatable",
  941. * "export_agency_manager_commercial_datatable",
  942. * "export_agency_manager_datatable", "export_commercial_installer_datatable",
  943. * "export_commercial_datatable","get:read", "purchase",
  944. * "export_installer_datatable"
  945. * })
  946. */
  947. private $agency;
  948. /**
  949. * Date d'archivage
  950. *
  951. * @ORM\Column(type="datetime", nullable=true)
  952. *
  953. * @Expose()
  954. * @Groups({
  955. * "user:archived_at",
  956. * "default",
  957. * "user", "export_installer_datatable", "export_commercial_installer_datatable"
  958. * })
  959. *
  960. * @Exportable()
  961. */
  962. private $archivedAt;
  963. /**
  964. * @ORM\Column(type="boolean", options={"default":false})
  965. *
  966. * @Exportable()
  967. */
  968. private $newsletter = false;
  969. /**
  970. * @ORM\OneToMany(targetEntity=UserBusinessResult::class, mappedBy="user", cascade={"persist", "remove"})
  971. *
  972. * @Expose()
  973. * @Groups({"user:userBusinessResults","user","export_user_datatable"})
  974. *
  975. * @Exportable()
  976. *
  977. * @var Collection|UserBusinessResult[]
  978. */
  979. private Collection $userBusinessResults;
  980. /**
  981. * @ORM\Column(type="string", length=255, nullable=true)
  982. *
  983. * @Expose()
  984. * @Groups({
  985. * "user:post","cdp", "user", "user:extension1","export_user_citroentf_datatable", "user_citroentf",
  986. * "export_user_citroentf_datatable",
  987. * "export_agency_manager_commercial_datatable", "export_agency_manager_datatable",
  988. * "export_commercial_installer_datatable",
  989. * "export_commercial_datatable", "export_user_datatable", "export_admin_datatable", "export_installer_datatable"})
  990. *
  991. * @Exportable()
  992. */
  993. private ?string $extension1 = null;
  994. /**
  995. * @ORM\Column(type="string", length=255, nullable=true)
  996. *
  997. * @Expose()
  998. * @Groups({
  999. * "user:post","cdp", "user", "user:extension2", "export_user_citroentf_datatable", "user_citroentf",
  1000. * "export_user_citroentf_datatable",
  1001. * "export_agency_manager_commercial_datatable", "export_agency_manager_datatable",
  1002. * "export_commercial_installer_datatable",
  1003. * "export_commercial_datatable", "export_user_datatable", "export_admin_datatable", "export_installer_datatable"})
  1004. *
  1005. * @Exportable()
  1006. */
  1007. private ?string $extension2 = null;
  1008. /**
  1009. * @ORM\Column(type="integer", nullable=true, unique=true)
  1010. *
  1011. * @Exportable()
  1012. */
  1013. private $wdg;
  1014. /**
  1015. * @ORM\Column(type="string", nullable=true, unique=true)
  1016. *
  1017. * @Exportable()
  1018. */
  1019. private $gladyUuid;
  1020. /**
  1021. * @ORM\OneToMany(targetEntity=Project::class, mappedBy="referent")
  1022. *
  1023. * @Exportable()
  1024. */
  1025. private $projects;
  1026. /**
  1027. * @ORM\ManyToOne(targetEntity=Programme::class, inversedBy="users")
  1028. *
  1029. * @Expose()
  1030. * @Groups({"user"})
  1031. *
  1032. * @Exportable()
  1033. */
  1034. private $programme;
  1035. /**
  1036. * @ORM\OneToMany(targetEntity=ServiceUser::class, mappedBy="user", orphanRemoval=true)
  1037. *
  1038. * @Exportable()
  1039. */
  1040. private $serviceUsers;
  1041. /**
  1042. * @ORM\ManyToOne(targetEntity=SaleOrderValidation::class, inversedBy="users")
  1043. *
  1044. * @Expose()
  1045. * @Groups({"user", "export_user_datatable"})
  1046. */
  1047. private $saleOrderValidation;
  1048. /**
  1049. * @ORM\ManyToMany(targetEntity=Univers::class, inversedBy="users")
  1050. *
  1051. */
  1052. private $universes;
  1053. /**
  1054. * @ORM\ManyToOne(targetEntity=BillingPoint::class, inversedBy="users")
  1055. *
  1056. * @Expose()
  1057. * @Groups({"user", "export_user_datatable", "export_admin_datatable", "billingpoint"})
  1058. */
  1059. private $billingPoint;
  1060. /**
  1061. * @ORM\OneToMany(targetEntity=Score::class, mappedBy="user", cascade={"remove"})
  1062. *
  1063. * @Exportable()
  1064. */
  1065. private $scores;
  1066. /**
  1067. * @ORM\OneToMany(targetEntity=ScoreObjective::class, mappedBy="user", cascade={"remove"})
  1068. *
  1069. * @Exportable()
  1070. */
  1071. private $scoreObjectives;
  1072. /**
  1073. * Dans la relation : target
  1074. *
  1075. * @ORM\ManyToMany(targetEntity=User::class, inversedBy="parents", cascade={"persist"})
  1076. */
  1077. private $children;
  1078. /**
  1079. * Dans la relation : source
  1080. *
  1081. * @ORM\ManyToMany(targetEntity=User::class, mappedBy="children", cascade={"persist"})
  1082. */
  1083. private $parents;
  1084. /**
  1085. * @ORM\OneToMany(targetEntity=Message::class, mappedBy="sender")
  1086. *
  1087. * @Exportable()
  1088. */
  1089. private $senderMessages;
  1090. /**
  1091. * @ORM\OneToMany(targetEntity=Message::class, mappedBy="receiver")
  1092. *
  1093. * @Exportable()
  1094. */
  1095. private $receiverMessages;
  1096. /**
  1097. * @ORM\OneToOne(targetEntity=RequestRegistration::class, inversedBy="user", cascade={"persist", "remove"})
  1098. *
  1099. * @Exportable()
  1100. */
  1101. private $requestRegistration;
  1102. /**
  1103. * @ORM\OneToMany(targetEntity=RequestRegistration::class, mappedBy="referent")
  1104. *
  1105. * @Exportable()
  1106. */
  1107. private $requestRegistrationsToValidate;
  1108. /**
  1109. * @ORM\OneToMany(targetEntity=CustomProductOrder::class, mappedBy="user", orphanRemoval=false)
  1110. *
  1111. * @Exportable()
  1112. */
  1113. private $customProductOrders;
  1114. /**
  1115. * @ORM\Column(type="string", length=255, options={"default":"cgu_pending"})
  1116. *
  1117. * @Expose()
  1118. * @Groups({
  1119. * "user:post",
  1120. * "user:status",
  1121. * "user:list", "user:item", "cdp", "user", "export_user_citroentf_datatable", "user_citroentf",
  1122. * "export_user_citroentf_datatable",
  1123. * "export_agency_manager_commercial_datatable", "export_agency_manager_datatable",
  1124. * "export_commercial_installer_datatable",
  1125. * "export_commercial_datatable","export_request_registration_datatable",
  1126. * "export_user_datatable", "export_admin_datatable", "export_installer_datatable"})
  1127. *
  1128. * @Exportable()
  1129. */
  1130. private string $status = '';
  1131. /**
  1132. * @ORM\Column(type="text", nullable=true)
  1133. */
  1134. private ?string $calculatedPoints = null;
  1135. /**
  1136. * @ORM\OneToMany(targetEntity=CustomProduct::class, mappedBy="createdBy")
  1137. *
  1138. * @Exportable()
  1139. */
  1140. private $customProducts;
  1141. /**
  1142. * Adhésion de l'utilisateur
  1143. *
  1144. * @ORM\OneToOne(targetEntity=UserSubscription::class, inversedBy="user", cascade={"persist", "remove"})
  1145. * @Expose()
  1146. * @Groups({"user" ,"user:subscription", "export_user_datatable"})
  1147. *
  1148. * @Exportable()
  1149. */
  1150. private ?UserSubscription $subscription = null;
  1151. /**
  1152. * @ORM\OneToMany(targetEntity=UserExtension::class, mappedBy="user", cascade={"persist", "remove"})
  1153. *
  1154. * @Exportable(type="oneToMany")
  1155. *
  1156. * @Exportable()
  1157. */
  1158. private $extensions;
  1159. /**
  1160. * @ORM\Column(type="string", length=255, nullable=true)
  1161. *
  1162. * @Exportable()
  1163. */
  1164. private $avatar;
  1165. /**
  1166. * @Vich\UploadableField(mapping="user_avatar", fileNameProperty="avatar")
  1167. * @var File
  1168. */
  1169. private $avatarFile;
  1170. /**
  1171. * @ORM\Column(type="string", length=255, nullable=true)
  1172. *
  1173. * @Exportable()
  1174. */
  1175. private $logo;
  1176. /**
  1177. * @Vich\UploadableField(mapping="user_logo", fileNameProperty="logo")
  1178. * @var File
  1179. */
  1180. private $logoFile;
  1181. /**
  1182. * @ORM\ManyToOne(targetEntity=PointOfSale::class, inversedBy="users",fetch="EAGER")
  1183. *
  1184. * @Expose()
  1185. * @Groups({"user:list", "user:item", "user", "get:read", "post:read", "export_user_datatable"})
  1186. */
  1187. private ?PointOfSale $pointOfSale = null;
  1188. /**
  1189. * @ORM\ManyToMany(targetEntity=PointOfSale::class, mappedBy="managers")
  1190. */
  1191. private Collection $managedPointOfSales;
  1192. /**
  1193. * @ORM\OneToMany(targetEntity=Parameter::class, mappedBy="userRelated")
  1194. *
  1195. * @Expose()
  1196. * @Groups({"parameter"})
  1197. * @Exportable()
  1198. */
  1199. private Collection $relatedParameters;
  1200. /**
  1201. * @ORM\OneToMany(targetEntity=PointOfSale::class, mappedBy="createdBy")
  1202. *
  1203. * @Exportable()
  1204. */
  1205. private Collection $createdPointOfSales;
  1206. /**
  1207. * @ORM\OneToMany(targetEntity=ObjectiveTarget::class, mappedBy="owner", orphanRemoval=true)
  1208. *
  1209. * @Exportable()
  1210. */
  1211. private Collection $ownerObjectiveTargets;
  1212. /**
  1213. * @ORM\ManyToMany(targetEntity=ObjectiveTarget::class, inversedBy="users")
  1214. * @ORM\JoinTable(name="objective_target_user")
  1215. *
  1216. * @Expose()
  1217. * @Groups({"objective_target"})
  1218. */
  1219. private Collection $objectiveTargets;
  1220. /**
  1221. * @ORM\Column(type="string", length=255, nullable=true)
  1222. *
  1223. * @Exportable()
  1224. */
  1225. private ?string $fonction = null;
  1226. /**
  1227. * @ORM\OneToOne(targetEntity=Regate::class, inversedBy="responsable", cascade={"persist", "remove"}, fetch="EXTRA_LAZY")
  1228. *
  1229. * @Expose()
  1230. * @Groups({"user", "export_user_datatable"})
  1231. *
  1232. * @Exportable()
  1233. */
  1234. private ?Regate $responsableRegate = null;
  1235. /**
  1236. * @ORM\Column(type="string", length=255, nullable=true)
  1237. *
  1238. * @Exportable()
  1239. */
  1240. private ?string $registrationDocument = null;
  1241. /**
  1242. * @Vich\UploadableField(mapping="user_registration_document", fileNameProperty="registrationDocument")
  1243. * @var File
  1244. */
  1245. private $registrationDocumentFile;
  1246. /**
  1247. * @ORM\OneToOne(targetEntity=CoverageArea::class, inversedBy="user", cascade={"persist", "remove"})
  1248. * @ORM\JoinColumn(nullable=true)
  1249. *
  1250. * @Exportable()
  1251. */
  1252. private $coverageArea;
  1253. /**
  1254. * @ORM\OneToMany(targetEntity=QuizUserAnswer::class, mappedBy="user")
  1255. *
  1256. * @Exportable()
  1257. */
  1258. private $quizUserAnswers;
  1259. /**
  1260. * @ORM\OneToMany(targetEntity=IdeaBoxAnswer::class, mappedBy="user")
  1261. *
  1262. * @Expose
  1263. * @Groups({
  1264. * "user:idea_box_answers",
  1265. * "idea_box_list", "idea_box_stats", "export_idea_box_datatable"
  1266. * })
  1267. *
  1268. * @Exportable()
  1269. */
  1270. private Collection $ideaBoxAnswers;
  1271. /**
  1272. * @ORM\OneToMany(targetEntity=IdeaBoxRating::class, mappedBy="user")
  1273. *
  1274. * @Expose
  1275. * @Groups({
  1276. * "user:idea_box_ratings",
  1277. * "idea_box_list", "idea_box_stats", "export_idea_box_datatable"
  1278. * })
  1279. *
  1280. * @Exportable()
  1281. */
  1282. private Collection $ideaBoxRatings;
  1283. /**
  1284. * @ORM\OneToMany(targetEntity=IdeaBoxRecipient::class, mappedBy="user")
  1285. *
  1286. * @Expose
  1287. * @Groups({
  1288. * "user:idea_box_recipients",
  1289. * "idea_box_list", "idea_box_stats", "export_idea_box_datatable"
  1290. * })
  1291. *
  1292. * @Exportable()
  1293. */
  1294. private Collection $ideaBoxRecipients;
  1295. /**
  1296. * @ORM\Column(type="string", length=128, nullable=true)
  1297. */
  1298. private ?string $oldStatus = null;
  1299. /**
  1300. * @ORM\Column(type="datetime", nullable=true)
  1301. */
  1302. private ?DateTimeInterface $disabledAt = null;
  1303. /**
  1304. * @ORM\Column(type="string", length=255, nullable=true)
  1305. *
  1306. * @Exportable()
  1307. */
  1308. private ?string $archiveReason = null;
  1309. /**
  1310. * @ORM\Column(type="string", length=255, nullable=true)
  1311. *
  1312. * @Exportable()
  1313. */
  1314. private ?string $unsubscribeReason = null;
  1315. /**
  1316. * @ORM\OneToMany(targetEntity=ActionLog::class, mappedBy="user")
  1317. *
  1318. * @Expose()
  1319. * @Groups({
  1320. * "user:actionLog",
  1321. * "actionLog"
  1322. * })
  1323. *
  1324. * @Exportable()
  1325. */
  1326. private Collection $actionLogs;
  1327. /**
  1328. * @ORM\Column(type="integer")
  1329. *
  1330. * @Exportable()
  1331. */
  1332. private int $failedAttempts = 0;
  1333. /**
  1334. * @ORM\Column(type="datetime", nullable=true)
  1335. *
  1336. * @Exportable()
  1337. */
  1338. private ?DateTimeInterface $lastFailedAttempt = null;
  1339. /**
  1340. * @ORM\Column(type="datetime", nullable=true)
  1341. *
  1342. * @Exportable()
  1343. */
  1344. private ?DateTimeInterface $passwordUpdatedAt = null;
  1345. /**
  1346. * @ORM\OneToMany(targetEntity=PasswordHistory::class, mappedBy="user", orphanRemoval=true, cascade={"persist"})
  1347. */
  1348. private Collection $passwordHistories;
  1349. /**
  1350. * @ORM\OneToMany(targetEntity=UserFavorites::class, mappedBy="user")
  1351. *
  1352. * @Exportable()
  1353. */
  1354. private Collection $userFavorites;
  1355. /**
  1356. * @ORM\Column(type="datetime", nullable=true)
  1357. *
  1358. * @Exportable()
  1359. */
  1360. private ?DateTimeInterface $lastActivity = null;
  1361. /**
  1362. * Variables pour stocker la valeur avant modification
  1363. * @Expose()
  1364. * @Groups ({"user:post"})
  1365. */
  1366. private ?string $oldEmail = null;
  1367. /**
  1368. * @ORM\Column(type="string", length=255, nullable=true)
  1369. *
  1370. * @Expose()
  1371. * @Groups({
  1372. * "default",
  1373. * "user:accountId",
  1374. * "user:post", "user:list","user:item", "cdp", "user",
  1375. * "user_bussiness_result", "user_bussiness_result:user",
  1376. * "export_user_datatable"
  1377. * })
  1378. */
  1379. private ?string $accountId = null;
  1380. /**
  1381. * @ORM\Column(type="string", nullable=true, unique=true)
  1382. */
  1383. private ?string $uniqueSlugConstraint = null;
  1384. /**
  1385. * @ORM\OneToMany(targetEntity=BoosterProductResult::class, mappedBy="user", orphanRemoval=true)
  1386. */
  1387. private Collection $boosterProductResults;
  1388. /**
  1389. * @ORM\OneToMany(targetEntity=PushSubscription::class, mappedBy="user")
  1390. */
  1391. private Collection $pushSubscriptions;
  1392. /**
  1393. * @ORM\Column(type="string", length=50, nullable=true)
  1394. */
  1395. private ?string $azureId = null;
  1396. /**
  1397. * @ORM\ManyToMany(targetEntity=AzureGroup::class, mappedBy="members")
  1398. */
  1399. private Collection $azureGroups;
  1400. /**
  1401. * @ORM\ManyToOne(targetEntity=User::class)
  1402. */
  1403. private ?User $activatedBy = null;
  1404. /**
  1405. * @ORM\OneToMany(targetEntity=QuotaProductUser::class, mappedBy="user", orphanRemoval=true)
  1406. */
  1407. private Collection $quotaProductUsers;
  1408. /**
  1409. * @ORM\ManyToMany(targetEntity=QuotasProductFree::class, mappedBy="users")
  1410. *
  1411. * @var Collection<int, QuotasProductFree>
  1412. */
  1413. private Collection $quotaProductFrees;
  1414. /**
  1415. * @ORM\OneToMany(targetEntity=RankingScore::class, mappedBy="user")
  1416. */
  1417. private Collection $rankingScores;
  1418. /**
  1419. * @ORM\OneToMany(targetEntity=ObjectiveTargetScore::class, mappedBy="user")
  1420. */
  1421. private Collection $objectiveTargetScores;
  1422. /**
  1423. * @ORM\Column(type="text", length=255, nullable=true)
  1424. *
  1425. * @Exportable()
  1426. */
  1427. private ?string $emailUnsubscribeReason = null;
  1428. /**
  1429. * @ORM\Column(type="datetime", nullable=true)
  1430. */
  1431. private ?DateTimeInterface $emailUnsubscribedAt = null;
  1432. public function __construct()
  1433. {
  1434. $this->addresses = new ArrayCollection();
  1435. $this->subAccountUsers = new ArrayCollection();
  1436. $this->carts = new ArrayCollection();
  1437. $this->distributors = new ArrayCollection();
  1438. $this->purchases = new ArrayCollection();
  1439. $this->orders = new ArrayCollection();
  1440. $this->godchilds = new ArrayCollection();
  1441. $this->requestProductAvailables = new ArrayCollection();
  1442. $this->userImportHistories = new ArrayCollection();
  1443. $this->contactLists = new ArrayCollection();
  1444. $this->devis = new ArrayCollection();
  1445. $this->pointTransactions = new ArrayCollection();
  1446. $this->installers = new ArrayCollection();
  1447. $this->heatingInstallers = new ArrayCollection();
  1448. $this->userBusinessResults = new ArrayCollection();
  1449. $this->projects = new ArrayCollection();
  1450. $this->serviceUsers = new ArrayCollection();
  1451. $this->universes = new ArrayCollection();
  1452. $this->scores = new ArrayCollection();
  1453. $this->scoreObjectives = new ArrayCollection();
  1454. $this->children = new ArrayCollection();
  1455. $this->parents = new ArrayCollection();
  1456. $this->requestRegistrationsToValidate = new ArrayCollection();
  1457. $this->customProductOrders = new ArrayCollection();
  1458. $this->extensions = new ArrayCollection();
  1459. $this->managedPointOfSales = new ArrayCollection();
  1460. $this->relatedParameters = new ArrayCollection();
  1461. $this->createdPointOfSales = new ArrayCollection();
  1462. $this->status = self::STATUS_CGU_PENDING;
  1463. $this->ideaBoxAnswers = new ArrayCollection();
  1464. $this->ideaBoxRatings = new ArrayCollection();
  1465. $this->ideaBoxRecipients = new ArrayCollection();
  1466. $this->actionLogs = new ArrayCollection();
  1467. $this->passwordHistories = new ArrayCollection();
  1468. $this->userFavorites = new ArrayCollection();
  1469. $this->boosterProductResults = new ArrayCollection();
  1470. $this->pushSubscriptions = new ArrayCollection();
  1471. $this->azureGroups = new ArrayCollection();
  1472. $this->quotaProductUsers = new ArrayCollection();
  1473. $this->quotaProductFrees = new ArrayCollection();
  1474. $this->rankingScores = new ArrayCollection();
  1475. $this->objectiveTargets = new ArrayCollection();
  1476. $this->objectiveTargetScores = new ArrayCollection();
  1477. }
  1478. private function generateSlug(): void
  1479. {
  1480. $parts = [$this->email, $this->accountId, $this->extension1, $this->extension2];
  1481. $parts = array_filter($parts);
  1482. $this->uniqueSlugConstraint = implode('-', $parts);
  1483. }
  1484. /**
  1485. * @ORM\PreUpdate()
  1486. */
  1487. public function preUpdate(PreUpdateEventArgs $eventArgs): void
  1488. {
  1489. if ($eventArgs->getObject() instanceof User) {
  1490. if ($eventArgs->hasChangedField('email') || $eventArgs->hasChangedField(
  1491. 'extension1'
  1492. ) || $eventArgs->hasChangedField('extension2') || $eventArgs->hasChangedField('accountId')) {
  1493. $this->generateSlug();
  1494. }
  1495. }
  1496. }
  1497. // Typed property App\Entity\User::$email must not be accessed before initialization
  1498. // Modif prePersist() vers postPersist()
  1499. /**
  1500. * @ORM\PostPersist()
  1501. */
  1502. public function postPersist(): void
  1503. {
  1504. $this->generateSlug();
  1505. }
  1506. /**
  1507. * @ORM\PostUpdate()
  1508. */
  1509. public function postUpdate(): void
  1510. {
  1511. $this->oldEmail = null;
  1512. }
  1513. public function __toString(): string
  1514. {
  1515. return $this->getFullName();
  1516. }
  1517. /**
  1518. * @Serializer\VirtualProperty
  1519. * @SerializedName("fullName")
  1520. *
  1521. * @Expose()
  1522. * @Groups({"user:full_name","email", "export_order_datatable", "purchase", "service_user",
  1523. * "univers","customProductOrder:list"})
  1524. *
  1525. * @return string
  1526. *
  1527. * @ExportableMethod()
  1528. */
  1529. public function getFullName(): string
  1530. {
  1531. $fullName = trim($this->firstName . ' ' . $this->lastName);
  1532. if (empty($fullName)) {
  1533. return $this->getEmail();
  1534. }
  1535. return $fullName;
  1536. }
  1537. public function getEmail(): ?string
  1538. {
  1539. return $this->email;
  1540. }
  1541. public function setEmail(string $email): User
  1542. {
  1543. $email = trim($email);
  1544. if (isset($this->email)) {
  1545. $this->setOldEmail($this->email);
  1546. } else {
  1547. $this->setOldEmail($email);
  1548. }
  1549. $this->email = $email;
  1550. return $this;
  1551. }
  1552. public function __toArray(): array
  1553. {
  1554. return array_diff_key(get_object_vars($this), array_flip([
  1555. 'oidcAccessToken', 'oidcRefreshToken', 'oidcTokenExpiresAt', 'oidcTokenConfiguration', 'oidcApiUsername',
  1556. ]));
  1557. }
  1558. /**
  1559. * ============================================================================================
  1560. * =============================== FONCTIONS CUSTOM ===========================================
  1561. * ============================================================================================
  1562. */
  1563. public function serialize(): string
  1564. {
  1565. return serialize([
  1566. $this->id,
  1567. ],);
  1568. }
  1569. public function __serialize(): array
  1570. {
  1571. return [
  1572. 'id' => $this->id,
  1573. 'email' => $this->email,
  1574. 'password' => $this->password,
  1575. 'salt' => $this->salt,
  1576. ];
  1577. }
  1578. public function __unserialize($serialized): void
  1579. {
  1580. $this->id = $serialized['id'];
  1581. $this->email = $serialized['email'];
  1582. $this->password = $serialized['password'];
  1583. $this->salt = $serialized['salt'];
  1584. }
  1585. /**
  1586. * @Serializer\VirtualProperty()
  1587. * @SerializedName ("unsubscribed")
  1588. *
  1589. * @Expose()
  1590. * @Groups({
  1591. * "user:unsubscribed",
  1592. * "default",
  1593. * "unsubscribed",
  1594. * "user:list", "user:item", "cdp", "user", "export_user_citroentf_datatable", "user_citroentf",
  1595. * "export_user_citroentf_datatable",
  1596. * "export_agency_manager_commercial_datatable", "export_agency_manager_datatable",
  1597. * "export_commercial_installer_datatable",
  1598. * "export_commercial_datatable", "export_user_datatable", "export_admin_datatable", "export_installer_datatable"
  1599. * })
  1600. *
  1601. * @return bool
  1602. */
  1603. public function isUnsubscribed(): bool
  1604. {
  1605. return $this->status === self::STATUS_UNSUBSCRIBED;
  1606. }
  1607. /**
  1608. * @Serializer\VirtualProperty()
  1609. * @SerializedName ("enabled")
  1610. *
  1611. * @Expose()
  1612. * @Groups({
  1613. * "user:enabled",
  1614. * "default",
  1615. * "enabled",
  1616. * "user:list", "user:item", "cdp", "user", "export_user_citroentf_datatable", "user_citroentf",
  1617. * "export_user_citroentf_datatable",
  1618. * "export_agency_manager_commercial_datatable", "export_agency_manager_datatable",
  1619. * "export_commercial_installer_datatable",
  1620. * "export_commercial_datatable", "export_user_datatable", "export_admin_datatable", "export_installer_datatable"
  1621. * })
  1622. *
  1623. * @return bool
  1624. */
  1625. public function isEnabled(): bool
  1626. {
  1627. return $this->status === self::STATUS_ENABLED;
  1628. }
  1629. /**
  1630. * @Serializer\VirtualProperty()
  1631. * @SerializedName ("disabled")
  1632. *
  1633. * @Expose()
  1634. * @Groups({
  1635. * "user:disabled",
  1636. * "user:list", "user:item", "cdp", "user", "export_user_citroentf_datatable", "user_citroentf",
  1637. * "export_user_citroentf_datatable",
  1638. * "export_agency_manager_commercial_datatable", "export_agency_manager_datatable",
  1639. * "export_commercial_installer_datatable",
  1640. * "export_commercial_datatable", "export_user_datatable", "export_admin_datatable", "export_installer_datatable"})
  1641. *
  1642. * @return bool
  1643. */
  1644. public function isDisabled(): bool
  1645. {
  1646. return $this->status === self::STATUS_DISABLED;
  1647. }
  1648. /**
  1649. * @Serializer\VirtualProperty()
  1650. * @SerializedName ("cgu_pending")
  1651. *
  1652. * @Expose()
  1653. * @Groups({
  1654. * "user:cgu_pending",
  1655. * "cgu_pending",
  1656. * "user:list", "user:item", "cdp", "user", "export_user_citroentf_datatable", "user_citroentf",
  1657. * "export_user_citroentf_datatable",
  1658. * "export_agency_manager_commercial_datatable", "export_agency_manager_datatable",
  1659. * "export_commercial_installer_datatable",
  1660. * "export_commercial_datatable", "export_user_datatable", "export_admin_datatable", "export_installer_datatable"})
  1661. *
  1662. * @return bool
  1663. */
  1664. public function isCguPending(): bool
  1665. {
  1666. return $this->status === self::STATUS_CGU_PENDING;
  1667. }
  1668. /**
  1669. * @Serializer\VirtualProperty()
  1670. * @SerializedName ("cgu_declined")
  1671. *
  1672. * @Expose()
  1673. * @Groups({
  1674. * "user:cgu_declined",
  1675. * "cgu_declined",
  1676. * "user:list", "user:item", "cdp", "user", "export_user_citroentf_datatable", "user_citroentf",
  1677. * "export_user_citroentf_datatable",
  1678. * "export_agency_manager_commercial_datatable", "export_agency_manager_datatable",
  1679. * "export_commercial_installer_datatable",
  1680. * "export_commercial_datatable", "export_user_datatable", "export_admin_datatable", "export_installer_datatable"})
  1681. *
  1682. * @return bool
  1683. */
  1684. public function isCguDeclined(): bool
  1685. {
  1686. return $this->status === self::STATUS_CGU_DECLINED;
  1687. }
  1688. /**
  1689. * @Serializer\VirtualProperty()
  1690. * @SerializedName ("archived")
  1691. *
  1692. * @Expose()
  1693. * @Groups({
  1694. * "user:archived",
  1695. * "default",
  1696. * "is_archived",
  1697. * "user:list", "user:item", "cdp", "user", "export_user_citroentf_datatable", "user_citroentf",
  1698. * "export_user_citroentf_datatable",
  1699. * "export_agency_manager_commercial_datatable", "export_agency_manager_datatable",
  1700. * "export_commercial_installer_datatable",
  1701. * "export_commercial_datatable", "export_user_datatable", "export_admin_datatable", "export_installer_datatable"
  1702. * })
  1703. *
  1704. * @return bool
  1705. */
  1706. public function isArchived(): bool
  1707. {
  1708. return $this->status === self::STATUS_ARCHIVED;
  1709. }
  1710. /**
  1711. * @Serializer\VirtualProperty()
  1712. * @SerializedName ("deleted")
  1713. *
  1714. * @Expose()
  1715. * @Groups({
  1716. * "user:deleted",
  1717. * "user:list", "user:item", "cdp", "user", "export_user_citroentf_datatable", "user_citroentf",
  1718. * "export_user_citroentf_datatable",
  1719. * "export_agency_manager_commercial_datatable", "export_agency_manager_datatable",
  1720. * "export_commercial_installer_datatable",
  1721. * "export_commercial_datatable", "export_user_datatable", "export_admin_datatable", "export_installer_datatable"})
  1722. *
  1723. * @return bool
  1724. */
  1725. public function isDeleted(): bool
  1726. {
  1727. return $this->status === self::STATUS_DELETED;
  1728. }
  1729. /**
  1730. * @Serializer\VirtualProperty()
  1731. * @SerializedName ("admin_pending")
  1732. *
  1733. * @return bool
  1734. */
  1735. public function isAdminPending(): bool
  1736. {
  1737. return $this->status === self::STATUS_ADMIN_PENDING;
  1738. }
  1739. /**
  1740. * @return bool
  1741. */
  1742. public function isRegisterPending(): bool
  1743. {
  1744. return $this->status === self::STATUS_REGISTER_PENDING;
  1745. }
  1746. public function getUsers()
  1747. {
  1748. return $this->installers;
  1749. }
  1750. /**
  1751. * @Serializer\VirtualProperty()
  1752. * @SerializedName("count_installers")
  1753. *
  1754. * @Expose()
  1755. * @Groups({
  1756. * "user:count_installers"
  1757. * })
  1758. *
  1759. * @return int
  1760. */
  1761. public function countInstallers(): int
  1762. {
  1763. return count($this->installers);
  1764. }
  1765. /**
  1766. * @Serializer\VirtualProperty()
  1767. * @SerializedName("count_commercials")
  1768. *
  1769. * @Expose()
  1770. * @Groups({
  1771. * "user:count_commercials"
  1772. * })
  1773. *
  1774. * @return int
  1775. */
  1776. public function countCommercials(): int
  1777. {
  1778. $commercials = $this->children;
  1779. if (empty($commercials)) {
  1780. return 0;
  1781. }
  1782. foreach ($commercials as $index => $commercial) {
  1783. if (!in_array('ROLE_COMMERCIAL', $commercial->getRoles())) {
  1784. unset($commercials[$index]);
  1785. }
  1786. }
  1787. return count($commercials);
  1788. }
  1789. public function getRoles(): ?array
  1790. {
  1791. return $this->roles;
  1792. }
  1793. public function setRoles(array $roles): User
  1794. {
  1795. $this->roles = $roles;
  1796. return $this;
  1797. }
  1798. /**
  1799. * @Serializer\VirtualProperty
  1800. * @SerializedName("preferredEmail")
  1801. *
  1802. * @Expose()
  1803. * @Groups({"email"})
  1804. *
  1805. * @return string
  1806. */
  1807. public function getPreferredEmail(): string
  1808. {
  1809. if ($this->isFakeUser()) {
  1810. $secondaryEmails = $this->getSecondaryEmails();
  1811. if (!empty($secondaryEmails)) {
  1812. return array_values($secondaryEmails)[0];
  1813. }
  1814. }
  1815. return $this->email;
  1816. }
  1817. /**
  1818. * @Serializer\VirtualProperty()
  1819. * @SerializedName ("roleToString")
  1820. *
  1821. * @Expose()
  1822. * @Groups({"export_user_datatable", "export_admin_datatable", "export_user_citroentf_datatable"})
  1823. *
  1824. * @return string
  1825. */
  1826. public function roleToString(): string
  1827. {
  1828. if ($this->isDemo()) {
  1829. return 'Démo';
  1830. }
  1831. if ($this->isInstaller()) {
  1832. return 'Installateur';
  1833. }
  1834. if ($this->isValidation()) {
  1835. return 'Validation';
  1836. }
  1837. if ($this->isUser()) {
  1838. return 'Utilisateur';
  1839. }
  1840. if ($this->isCommercial()) {
  1841. if ($this->isHeatingCommercial()) {
  1842. return 'Commercial chauffage';
  1843. }
  1844. return 'Commercial';
  1845. }
  1846. if ($this->isAgencyManager()) {
  1847. return "Directeur d'agence";
  1848. }
  1849. if ($this->isDtvLogistique()) {
  1850. return "Logistique";
  1851. }
  1852. if ($this->isDtvCommercial()) {
  1853. return "Commercial";
  1854. }
  1855. if ($this->isDtvCompta()) {
  1856. return "Comptabilité";
  1857. }
  1858. if ($this->isDtvCdp()) {
  1859. return "Chef de projet";
  1860. }
  1861. if ($this->isAdmin()) {
  1862. return 'Administrateur';
  1863. }
  1864. if ($this->isSuperAdmin()) {
  1865. return 'Super Administrateur';
  1866. }
  1867. if ($this->isDeveloper()) {
  1868. return 'Développeur';
  1869. }
  1870. return 'Rôle non défini';
  1871. }
  1872. /**
  1873. * @Serializer\VirtualProperty()
  1874. * @SerializedName ("jobsToString")
  1875. *
  1876. * @Expose()
  1877. * @Groups({"export_user_datatable", "export_admin_datatable", "export_user_citroentf_datatable"})
  1878. *
  1879. * @return string
  1880. */
  1881. public function jobsToString(): string
  1882. {
  1883. return implode(', ', $this->getJobs());
  1884. }
  1885. public function isDemo(): bool
  1886. {
  1887. // return in_array('ROLE_DEMO', $this->getRoles(), TRUE);
  1888. return in_array('demo', $this->getJobs(), true);
  1889. }
  1890. public function isInstaller(): bool
  1891. {
  1892. // return in_array('ROLE_INSTALLER', $this->getRoles(), TRUE);
  1893. return in_array('installer', $this->getJobs(), true);
  1894. }
  1895. public function isValidation(): bool
  1896. {
  1897. // return in_array('ROLE_VALIDATION', $this->getRoles(), TRUE);
  1898. return in_array('validation', $this->getJobs(), true);
  1899. }
  1900. public function isUser(): bool
  1901. {
  1902. return in_array('ROLE_USER', $this->getRoles(), true);
  1903. }
  1904. public function isCommercial(): bool
  1905. {
  1906. // return in_array('ROLE_COMMERCIAL', $this->getRoles(), TRUE);
  1907. return in_array('commercial_agent', $this->getJobs(), true);
  1908. }
  1909. public function isHeatingCommercial(): bool
  1910. {
  1911. return in_array('ROLE_COMMERCIAL', $this->getRoles(), true) && $this->getChauffage();
  1912. }
  1913. public function getChauffage(): ?bool
  1914. {
  1915. return $this->chauffage;
  1916. }
  1917. public function setChauffage(?bool $chauffage): User
  1918. {
  1919. $this->chauffage = $chauffage;
  1920. return $this;
  1921. }
  1922. public function isAgencyManager(): bool
  1923. {
  1924. return in_array('ROLE_AGENCY_MANAGER', $this->getRoles(), true);
  1925. }
  1926. public function isDtvLogistique(): bool
  1927. {
  1928. return in_array('ROLE_DTV_LOGISTIQUE', $this->getRoles(), true);
  1929. }
  1930. public function isDtvCommercial(): bool
  1931. {
  1932. return in_array('ROLE_DTV_COMMERCIAL', $this->getRoles(), true);
  1933. }
  1934. public function isDtvCompta(): bool
  1935. {
  1936. return in_array('ROLE_DTV_COMPTA', $this->getRoles(), true);
  1937. }
  1938. public function isDtvCdp(): bool
  1939. {
  1940. return in_array('ROLE_DTV_CDP', $this->getRoles(), true);
  1941. }
  1942. public function isAdmin(): bool
  1943. {
  1944. return in_array('ROLE_ADMIN', $this->getRoles(), true);
  1945. }
  1946. public function isSuperAdmin(): bool
  1947. {
  1948. return in_array('ROLE_SUPER_ADMIN', $this->getRoles(), true);
  1949. }
  1950. public function isDeveloper(): bool
  1951. {
  1952. return in_array('ROLE_DEVELOPER', $this->getRoles(), true);
  1953. }
  1954. public function isDeveloperOrSuperAdmin(): bool
  1955. {
  1956. return $this->isDeveloper() || $this->isSuperAdmin();
  1957. }
  1958. public function hasOneOfItsRoles(array $roles): bool
  1959. {
  1960. return count(array_intersect($roles, $this->getRoles())) > 0;
  1961. }
  1962. /**
  1963. * @Serializer\VirtualProperty()
  1964. * @SerializedName ("nbrValidatedPurchases")
  1965. *
  1966. * @Expose()
  1967. * @Groups({
  1968. * "user:nbr_validated_purchases",
  1969. * "export_installer_datatable", "export_commercial_installer_datatable"})
  1970. *
  1971. * @return int
  1972. */
  1973. public function getNbrValidatedPurchases(): int
  1974. {
  1975. $nbr = 0;
  1976. /** @var Purchase $purchase */
  1977. foreach ($this->purchases as $purchase) {
  1978. if ((int)$purchase->getStatus() === Purchase::STATUS_VALIDATED) {
  1979. $nbr++;
  1980. }
  1981. }
  1982. return $nbr;
  1983. }
  1984. public function getStatus(): string
  1985. {
  1986. return $this->status;
  1987. }
  1988. public function setStatus(string $status): User
  1989. {
  1990. $this->status = $status;
  1991. return $this;
  1992. }
  1993. /**
  1994. * @Serializer\VirtualProperty()
  1995. * @SerializedName ("nbrPendingPurchases")
  1996. *
  1997. * @Expose()
  1998. * @Groups({"export_installer_datatable", "export_commercial_installer_datatable"})
  1999. *
  2000. * @return int
  2001. */
  2002. public function getNbrPendingPurchases(): int
  2003. {
  2004. $nbr = 0;
  2005. /** @var Purchase $purchase */
  2006. foreach ($this->purchases as $purchase) {
  2007. if ((int)$purchase->getStatus() === Purchase::STATUS_PENDING) {
  2008. $nbr++;
  2009. }
  2010. }
  2011. return $nbr;
  2012. }
  2013. /**
  2014. * @Serializer\VirtualProperty()
  2015. * @SerializedName ("nbrRejectedPurchases")
  2016. *
  2017. * @Expose()
  2018. * @Groups({
  2019. * "user:nbr_rejected_purchases",
  2020. * "export_installer_datatable", "export_commercial_installer_datatable"})
  2021. *
  2022. * @return int
  2023. */
  2024. public function getNbrRejectedPurchases(): int
  2025. {
  2026. $nbr = 0;
  2027. /** @var Purchase $purchase */
  2028. foreach ($this->purchases as $purchase) {
  2029. if ((int)$purchase->getStatus() === Purchase::STATUS_REJECTED) {
  2030. $nbr++;
  2031. }
  2032. }
  2033. return $nbr;
  2034. }
  2035. /**
  2036. * @Serializer\VirtualProperty()
  2037. * @SerializedName ("nbrReturnedPurchases")
  2038. *
  2039. * @Expose()
  2040. * @Groups({
  2041. * "user:nbr_returned_purchases",
  2042. * "export_installer_datatable", "export_commercial_installer_datatable"})
  2043. *
  2044. * @return int
  2045. */
  2046. public function getNbrReturnedPurchases(): int
  2047. {
  2048. $nbr = 0;
  2049. /** @var Purchase $purchase */
  2050. foreach ($this->purchases as $purchase) {
  2051. if ((int)$purchase->getStatus() === Purchase::STATUS_RETURNED) {
  2052. $nbr++;
  2053. }
  2054. }
  2055. return $nbr;
  2056. }
  2057. /**
  2058. * Nombre de commandes de l'utilisateur
  2059. *
  2060. * @Serializer\VirtualProperty()
  2061. * @SerializedName ("nbrOrder")
  2062. *
  2063. * @Expose()
  2064. * @Groups({"export_user_datatable", "export_admin_datatable", "export_installer_datatable", "export_commercial_installer_datatable"})
  2065. *
  2066. * @return int
  2067. */
  2068. public function getNbrOrder(): int
  2069. {
  2070. return count($this->orders);
  2071. }
  2072. /**
  2073. * @Serializer\VirtualProperty()
  2074. * @SerializedName ("nbrPurchases")
  2075. *
  2076. * @Expose()
  2077. * @Groups({
  2078. * "user:nbr_purchases",
  2079. * "export_installer_datatable", "export_commercial_installer_datatable"})
  2080. *
  2081. * @return int
  2082. */
  2083. public function getNbrPurchases(): int
  2084. {
  2085. return count($this->purchases);
  2086. }
  2087. /**
  2088. * @Serializer\VirtualProperty()
  2089. * @SerializedName ("has_heating_commercial")
  2090. * @Groups ({
  2091. * "default",
  2092. * "user:has_heating_commercial",
  2093. * "user"
  2094. * })
  2095. */
  2096. public function hasHeatingCommercial()
  2097. {
  2098. return $this->heatingCommercial instanceof User;
  2099. }
  2100. /**
  2101. * @Serializer\VirtualProperty()
  2102. * @SerializedName ("pointDateExpiration")
  2103. *
  2104. * @Expose()
  2105. * @Groups({"user:list", "user:item", "user", "get:read", "post:read", "export_user_datatable"})
  2106. *
  2107. * @return null|string
  2108. */
  2109. public function getPointDateExpiration(): ?string
  2110. {
  2111. return $this->getExtensionBySlug(\App\Constants\UserExtension::POINT_DATE_EXPIRATION);
  2112. }
  2113. /**
  2114. * Retourne la valeur d'une extension depuis son slug
  2115. *
  2116. * @param string $slug
  2117. *
  2118. * @return string|null
  2119. */
  2120. public function getExtensionBySlug(string $slug): ?string
  2121. {
  2122. if (!empty($this->extensions)) {
  2123. foreach ($this->extensions as $extension) {
  2124. if ($extension->getSlug() === $slug) {
  2125. return $extension->getValue();
  2126. }
  2127. }
  2128. }
  2129. return null;
  2130. }
  2131. /**
  2132. * Retourne les données synchronisées stockées dans l'extension `module_synchronisation`.
  2133. *
  2134. * @param string|null $domain
  2135. * @param string|null $key
  2136. *
  2137. * @return mixed
  2138. */
  2139. public function getSynchronisationDatas(?string $domain = null, ?string $key = null): mixed
  2140. {
  2141. $value = $this->getExtensionBySlug(UserExtensionConstants::MODULE_SYNCHRONISATION);
  2142. if (!is_string($value) || trim($value) === '') {
  2143. return null;
  2144. }
  2145. $synchronisationData = json_decode($value, true);
  2146. $synchronisationData = is_array($synchronisationData) ? $synchronisationData : null;
  2147. if (!$synchronisationData) {
  2148. return null;
  2149. }
  2150. if (!$domain && !$key) {
  2151. return $synchronisationData;
  2152. }
  2153. if ($domain !== null) {
  2154. $domainData = $synchronisationData[$domain] ?? null;
  2155. if (!is_array($domainData)) {
  2156. return null;
  2157. }
  2158. if ($key === null) {
  2159. return $domainData;
  2160. }
  2161. return $domainData[$key] ?? null;
  2162. }
  2163. $valuesByDomain = [];
  2164. foreach ($synchronisationData as $currentDomain => $domainData) {
  2165. if (!is_array($domainData)) {
  2166. continue;
  2167. }
  2168. $valuesByDomain[$currentDomain] = $domainData[$key] ?? null;
  2169. }
  2170. return $valuesByDomain;
  2171. }
  2172. /**
  2173. * @Serializer\VirtualProperty()
  2174. * @SerializedName ("objCa")
  2175. *
  2176. * @Expose()
  2177. * @Groups({"user:list", "user:item", "user", "get:read", "post:read", "export_user_datatable"})
  2178. *
  2179. * @return int
  2180. */
  2181. public function getObjCa(): int
  2182. {
  2183. $value = $this->getExtensionBySlug(\App\Constants\UserExtension::OBJ_CA);
  2184. if ($value === null) {
  2185. return 0;
  2186. }
  2187. return intval($value);
  2188. }
  2189. public function setObjCa(?string $value): User
  2190. {
  2191. if ($value === null) {
  2192. return $this;
  2193. }
  2194. $this->addExtension(UserExtensionFactory::setObjCa($this, $value));
  2195. return $this;
  2196. }
  2197. public function addExtension(?UserExtension $extension): User
  2198. {
  2199. if ($extension !== null && !$this->extensions->contains($extension)) {
  2200. $this->extensions[] = $extension;
  2201. $extension->setUser($this);
  2202. }
  2203. return $this;
  2204. }
  2205. /**
  2206. * @Serializer\VirtualProperty()
  2207. * @SerializedName ("commitment_level")
  2208. *
  2209. * @Expose()
  2210. * @Groups({"user:list", "user:item", "user", "get:read", "post:read", "export_user_datatable"})
  2211. *
  2212. * @return string
  2213. */
  2214. public function getCommitmentLevel(): string
  2215. {
  2216. $value = $this->getExtensionBySlug(\App\Constants\UserExtension::COMMITMENT_LEVEL);
  2217. if ($value === null) {
  2218. return '';
  2219. }
  2220. return $value;
  2221. }
  2222. public function setCommitmentLevel(?string $value): User
  2223. {
  2224. if ($value === null) {
  2225. return $this;
  2226. }
  2227. $this->addExtension(UserExtensionFactory::setCommitmentLevel($this, $value));
  2228. return $this;
  2229. }
  2230. /**
  2231. * @Serializer\VirtualProperty()
  2232. * @SerializedName ("objPoint")
  2233. *
  2234. * @Expose()
  2235. * @Groups({"user:list", "user:item", "user", "get:read", "post:read", "export_user_datatable"})
  2236. *
  2237. * @return int
  2238. */
  2239. public function getObjPoint(): int
  2240. {
  2241. $value = $this->getExtensionBySlug(\App\Constants\UserExtension::OBJ_POINT);
  2242. if ($value === null) {
  2243. return 0;
  2244. }
  2245. return intval($value);
  2246. }
  2247. public function setObjPoint(?string $value): User
  2248. {
  2249. if ($value === null) {
  2250. return $this;
  2251. }
  2252. $this->addExtension(UserExtensionFactory::setObjPoint($this, $value));
  2253. return $this;
  2254. }
  2255. /**
  2256. * @Serializer\VirtualProperty()
  2257. * @SerializedName ("language")
  2258. *
  2259. * @Expose()
  2260. * @Groups({ "user:language", "user:item"})
  2261. *
  2262. * @return string|null
  2263. */
  2264. public function getLanguage(): ?string
  2265. {
  2266. return $this->getExtensionBySlug(\App\Constants\UserExtension::LANGUAGE);
  2267. }
  2268. public function setInternalIdentification1(?string $value): User
  2269. {
  2270. if ($value === null) {
  2271. return $this;
  2272. }
  2273. $this->addExtension(UserExtensionFactory::setInternalIdentification1($this, $value));
  2274. return $this;
  2275. }
  2276. /**
  2277. * @Serializer\VirtualProperty()
  2278. * @SerializedName ("internalIdentification2")
  2279. *
  2280. * @Expose()
  2281. * @Groups({"user:list", "user:item", "user", "get:read", "post:read", "export_user_datatable", "export_admin_datatable", "sale_order",
  2282. * "export_order_datatable"})
  2283. *
  2284. * @return string|null
  2285. */
  2286. public function getInternalIdentification2(): ?string
  2287. {
  2288. return $this->getExtensionBySlug(\App\Constants\UserExtension::INTERNAL_IDENTIFICATION_2);
  2289. }
  2290. public function setInternalIdentification2(?string $value): User
  2291. {
  2292. if ($value === null) {
  2293. return $this;
  2294. }
  2295. $this->addExtension(UserExtensionFactory::setInternalIdentification2($this, $value));
  2296. return $this;
  2297. }
  2298. /**
  2299. * @Serializer\VirtualProperty()
  2300. * @SerializedName ("internalIdentification3")
  2301. *
  2302. * @Expose()
  2303. * @Groups({"user:list", "user:item", "user", "get:read", "post:read", "export_user_datatable"})
  2304. *
  2305. * @return string|null
  2306. */
  2307. public function getInternalIdentification3(): ?string
  2308. {
  2309. return $this->getExtensionBySlug(\App\Constants\UserExtension::INTERNAL_IDENTIFICATION_3);
  2310. }
  2311. public function setInternalIdentification3(?string $value): User
  2312. {
  2313. if ($value === null) {
  2314. return $this;
  2315. }
  2316. $this->addExtension(UserExtensionFactory::setInternalIdentification3($this, $value));
  2317. return $this;
  2318. }
  2319. /**
  2320. * @Serializer\VirtualProperty()
  2321. * @SerializedName ("potentialPoints")
  2322. *
  2323. * @Expose
  2324. * @Groups({
  2325. * "user:potentialPoints",
  2326. * "user:list",
  2327. * "user:item", "user", "get:read", "post:read", "export_user_datatable"})
  2328. *
  2329. * @return int|null
  2330. */
  2331. public function getPotentialPoints(): ?int
  2332. {
  2333. return $this->getExtensionBySlug(\App\Constants\UserExtension::POTENTIAL_POINTS);
  2334. }
  2335. /**
  2336. * @param $value
  2337. *
  2338. * @return $this
  2339. */
  2340. public function setPotentialPoints($value): User
  2341. {
  2342. $this->addExtension(UserExtensionFactory::setPotentialPoints($this, (int)$value));
  2343. return $this;
  2344. }
  2345. /**
  2346. * @param int $step
  2347. *
  2348. * @return string|null
  2349. */
  2350. public function getGoalByStep(int $step): ?string
  2351. {
  2352. $slug = \App\Constants\UserExtension::GOAL . '_' . $step;
  2353. return $this->getExtensionBySlug($slug);
  2354. }
  2355. public function setGoalByStep(string $value, int $step): User
  2356. {
  2357. $this->addExtension(UserExtensionFactory::setGoal($this, $value, $step));
  2358. return $this;
  2359. }
  2360. /**
  2361. * @param int $step
  2362. *
  2363. * @return string|null
  2364. */
  2365. public function getBonusPro(int $step): ?string
  2366. {
  2367. $slug = \App\Constants\UserExtension::BONUS_PRO . '_' . $step;
  2368. return $this->getExtensionBySlug($slug);
  2369. }
  2370. public function setBonusPro(?string $value, int $step): User
  2371. {
  2372. if ($value === null) {
  2373. return $this;
  2374. }
  2375. $this->addExtension(UserExtensionFactory::setBonusPro($this, $value, $step));
  2376. return $this;
  2377. }
  2378. public function setGoalPoints(?string $value): User
  2379. {
  2380. if ($value === null) {
  2381. return $this;
  2382. }
  2383. $this->addExtension(UserExtensionFactory::setGoalPoints($this, $value));
  2384. return $this;
  2385. }
  2386. /**
  2387. * @Serializer\VirtualProperty()
  2388. * @SerializedName ("parent_lvl_1")
  2389. * @Groups ({"user", "point_of_sale"})
  2390. *
  2391. * @return int
  2392. */
  2393. public function getParentLvl1(): int
  2394. {
  2395. // Boucle sur les commerciaux et retourne le premier
  2396. foreach ($this->parents as $parent) {
  2397. return $parent->getId();
  2398. }
  2399. return -1;
  2400. }
  2401. /**
  2402. * ============================================================================================
  2403. * ============================= FIN FONCTIONS CUSTOM =========================================
  2404. * ============================================================================================
  2405. */
  2406. public function getId(): ?int
  2407. {
  2408. return $this->id;
  2409. }
  2410. /**
  2411. * Le setter est obligatoire pour la partie portail lorsqu'on crée un utilisateur non mappé en bdd
  2412. *
  2413. * @param $id
  2414. *
  2415. * @return $this
  2416. */
  2417. public function setId($id): User
  2418. {
  2419. $this->id = $id;
  2420. return $this;
  2421. }
  2422. /**
  2423. * @Serializer\VirtualProperty()
  2424. * @SerializedName ("parent_lvl_1_code")
  2425. *
  2426. * @Expose()
  2427. * @Groups ({"user", "export_user_datatable", "export_admin_datatable", "sale_order", "export_order_datatable",
  2428. * "export_commercial_datatable"})
  2429. *
  2430. * @return string|null
  2431. */
  2432. public function getParentLvl1Code(): ?string
  2433. {
  2434. // Boucle sur les commerciaux et retourne le premier
  2435. foreach ($this->parents as $parent) {
  2436. return $parent->getInternalIdentification1();
  2437. }
  2438. return null;
  2439. }
  2440. /**
  2441. * @Serializer\VirtualProperty()
  2442. * @SerializedName ("internalIdentification1")
  2443. *
  2444. * @Expose()
  2445. * @Groups({
  2446. * "user:internal_identification_1",
  2447. * "user:list", "user:item", "user", "get:read", "post:read", "export_user_datatable", "export_admin_datatable", "sale_order",
  2448. * "export_order_datatable",
  2449. * "export_installer_datatable",
  2450. * "export_commercial_datatable","export_agency_manager_datatable"})
  2451. *
  2452. * @return string|null
  2453. */
  2454. public function getInternalIdentification1(): ?string
  2455. {
  2456. return $this->getExtensionBySlug(\App\Constants\UserExtension::INTERNAL_IDENTIFICATION_1);
  2457. }
  2458. /**
  2459. * @Serializer\VirtualProperty()
  2460. * @SerializedName ("parent_lvl_2")
  2461. * @Groups ({"user", "point_of_sale"})
  2462. *
  2463. * @return int
  2464. */
  2465. public function getParentLvl2(): int
  2466. {
  2467. // Boucle sur les commerciaux
  2468. foreach ($this->parents as $parent) {
  2469. // Boucle sur les chefs d'agence et retourne le premier
  2470. foreach ($parent->getParents() as $grandParent) {
  2471. return $grandParent->getId();
  2472. }
  2473. }
  2474. return -1;
  2475. }
  2476. /**
  2477. * @return Collection<int, User>
  2478. */
  2479. public function getParents(): Collection
  2480. {
  2481. return $this->parents;
  2482. }
  2483. /**
  2484. * @Serializer\VirtualProperty()
  2485. * @SerializedName ("parent_lvl_3")
  2486. * @Groups ({"user", "point_of_sale"})
  2487. *
  2488. * @return int
  2489. */
  2490. public function getParentLvl3(): int
  2491. {
  2492. // Boucle sur les commerciaux
  2493. foreach ($this->parents as $parent) {
  2494. // Boucle sur les chefs d'agence et retourne le premier
  2495. foreach ($parent->getParents() as $grandParent) {
  2496. // Boucle sur les admins et retourne le premier
  2497. foreach ($grandParent->getParents() as $ggparent) {
  2498. return $ggparent->getId();
  2499. }
  2500. }
  2501. }
  2502. return -1;
  2503. }
  2504. /**
  2505. * @Serializer\VirtualProperty()
  2506. * @SerializedName ("pointOfSaleOfClient")
  2507. * @Groups({"user:list", "user:item", "user", "get:read", "post:read", "export_user_datatable"})
  2508. *
  2509. * @return string|null
  2510. */
  2511. public function getPointOfSaleOfClient(): ?string
  2512. {
  2513. // Boucle sur les commerciaux
  2514. if (!empty($this->parents)) {
  2515. foreach ($this->parents as $parent) {
  2516. if ($parent->getPointOfSale() !== null) {
  2517. return $parent->getPointOfSale()->getCode();
  2518. } else {
  2519. return null;
  2520. }
  2521. }
  2522. }
  2523. return null;
  2524. }
  2525. public function getPointOfSale(): ?PointOfSale
  2526. {
  2527. return $this->pointOfSale;
  2528. }
  2529. public function setPointOfSale(?PointOfSale $pointOfSale): User
  2530. {
  2531. $this->pointOfSale = $pointOfSale;
  2532. return $this;
  2533. }
  2534. /**
  2535. * @Serializer\VirtualProperty()
  2536. * @SerializedName ("pointOfSaleOfCommercial")
  2537. * @Groups({"user:list", "user:item", "user", "get:read", "post:read", "export_user_datatable"})
  2538. *
  2539. * @return string|null
  2540. */
  2541. public function getPointOfSaleOfCommercial(): ?string
  2542. {
  2543. // Boucle sur les commerciaux
  2544. if ($this->getPointOfSale() !== null) {
  2545. return $this->getPointOfSale()->getCode();
  2546. } else {
  2547. return null;
  2548. }
  2549. }
  2550. /**
  2551. * Retourne la date d'adhésion du client s'il en a une
  2552. *
  2553. * @Serializer\VirtualProperty()
  2554. * @SerializedName ("subscribedAt")
  2555. * @Groups({"user:list", "user:item", "user", "get:read", "post:read", "export_user_datatable"})
  2556. *
  2557. * @return string
  2558. */
  2559. public function getSubscribedAt(): string
  2560. {
  2561. if ($this->subscription instanceof UserSubscription) {
  2562. return $this->subscription->getSubscribedAt()->format('d/m/Y');
  2563. }
  2564. return '';
  2565. }
  2566. public function getNameCiv(): string
  2567. {
  2568. return trim($this->getCivility() . ' ' . trim($this->lastName . " " . $this->firstName));
  2569. }
  2570. public function getCivility(): ?string
  2571. {
  2572. return $this->civility;
  2573. }
  2574. public function setCivility(?string $civility): User
  2575. {
  2576. $this->civility = $civility;
  2577. return $this;
  2578. }
  2579. /*
  2580. * ============================================================================================
  2581. * ============================== FIN FONCTIONS CUSTOM ========================================
  2582. * ============================================================================================
  2583. */
  2584. public function getCivCode(): int
  2585. {
  2586. if ($this->getCivility() == 'M.') {
  2587. return 0;
  2588. } elseif ($this->getCivility() == 'Mme') {
  2589. return 1;
  2590. } else {
  2591. return 2;
  2592. }
  2593. }
  2594. /**
  2595. * @return void
  2596. * @deprecated
  2597. */
  2598. public function setActive()
  2599. {
  2600. $this->deletedAt = null;
  2601. $this->archivedAt = null;
  2602. }
  2603. public function isPurchaseAuthorized(): bool
  2604. {
  2605. return in_array('ROLE_INSTALLER', $this->getRoles()) || in_array('ROLE_SUPER_ADMIN', $this->getRoles());
  2606. }
  2607. public function getBillingAddresses(): ArrayCollection|Collection
  2608. {
  2609. return $this->getAddressByType(Address::getAddressTypes()[Address::TYPE_BILLING_ADDRESS]);
  2610. }
  2611. /**
  2612. * @param $type
  2613. *
  2614. * @return ArrayCollection|Collection
  2615. */
  2616. private function getAddressByType($type): ArrayCollection|Collection
  2617. {
  2618. $shippingAddress = new ArrayCollection();
  2619. foreach ($this->getAddresses() as $address) {
  2620. if ($address->getAddressType() == $type) {
  2621. $shippingAddress->add($address);
  2622. }
  2623. }
  2624. return $shippingAddress;
  2625. }
  2626. /**
  2627. * @return Collection|Address[]
  2628. */
  2629. public function getAddresses(): Collection
  2630. {
  2631. return $this->addresses;
  2632. }
  2633. /**
  2634. * @return DateTimeInterface|null
  2635. * @deprecated
  2636. */
  2637. public function getLevel1UpdatedAt(): ?DateTimeInterface
  2638. {
  2639. return $this->level1UpdatedAt;
  2640. }
  2641. /**
  2642. * @param DateTimeInterface|null $level1UpdatedAt
  2643. *
  2644. * @return $this
  2645. * @deprecated
  2646. */
  2647. public function setLevel1UpdatedAt(?DateTimeInterface $level1UpdatedAt): User
  2648. {
  2649. $this->level1UpdatedAt = $level1UpdatedAt;
  2650. return $this;
  2651. }
  2652. /**
  2653. * @return DateTimeInterface|null
  2654. * @deprecated
  2655. */
  2656. public function getLevel2UpdatedAt(): ?DateTimeInterface
  2657. {
  2658. return $this->level2UpdatedAt;
  2659. }
  2660. /**
  2661. * @param DateTimeInterface|null $level2UpdatedAt
  2662. *
  2663. * @return $this
  2664. * @deprecated
  2665. */
  2666. public function setLevel2UpdatedAt(?DateTimeInterface $level2UpdatedAt): User
  2667. {
  2668. $this->level2UpdatedAt = $level2UpdatedAt;
  2669. return $this;
  2670. }
  2671. /**
  2672. * @Serializer\VirtualProperty
  2673. * @SerializedName("name")
  2674. * @Groups({
  2675. * "user:name",
  2676. * "export_installer_datatable", "export_purchase_declaration_datatable",
  2677. * "export_agency_manager_commercial_datatable",
  2678. * "export_commercial_installer_datatable"})
  2679. *
  2680. * @return string
  2681. */
  2682. public function getName(): string
  2683. {
  2684. return $this->lastName . " " . $this->firstName;
  2685. }
  2686. /**
  2687. * @Serializer\VirtualProperty()
  2688. * @SerializedName("codeDep")
  2689. * @Expose()
  2690. * @Groups({
  2691. * "user:code_dep",
  2692. * "export_installer_datatable", "export_commercial_installer_datatable"})
  2693. *
  2694. * @return false|string|null
  2695. */
  2696. public function getCodeDep()
  2697. {
  2698. return $this->getPostcode() !== null ? substr($this->getPostcode(), 0, 2) : null;
  2699. }
  2700. public function getPostcode(): ?string
  2701. {
  2702. return $this->postcode;
  2703. }
  2704. public function setPostcode(?string $postcode): User
  2705. {
  2706. $this->postcode = $postcode;
  2707. return $this;
  2708. }
  2709. /**
  2710. * @return array|ArrayCollection|Collection
  2711. */
  2712. public function getShippingAddresses(): array|ArrayCollection|Collection
  2713. {
  2714. return $this->getAddressByType(Address::getAddressTypes()[Address::TYPE_SHIPPING_ADDRESS]);
  2715. }
  2716. /**
  2717. * @return Address|null
  2718. */
  2719. public function getPreferredBillingAddress(): ?Address
  2720. {
  2721. foreach ($this->getBillingAddresses() as $address) {
  2722. if ($address->getPreferred()) {
  2723. return $address;
  2724. }
  2725. }
  2726. return null;
  2727. }
  2728. /**
  2729. * @return Address|null
  2730. */
  2731. public function getPreferredShippingAddress(): ?Address
  2732. {
  2733. foreach ($this->getShippingAddresses() as $address) {
  2734. if ($address->getPreferred()) {
  2735. return $address;
  2736. }
  2737. }
  2738. return null;
  2739. }
  2740. /**
  2741. * GARDER POUR LA SSO
  2742. *
  2743. * @return string
  2744. */
  2745. public function getUsername(): string
  2746. {
  2747. return (string)$this->email;
  2748. }
  2749. /**
  2750. * @return string
  2751. */
  2752. public function getRawUsername(): string
  2753. {
  2754. return (string)$this->username;
  2755. }
  2756. /**
  2757. * @param string|null $username
  2758. *
  2759. * @return $this
  2760. * @deprecated
  2761. */
  2762. public function setUsername(?string $username): User
  2763. {
  2764. $this->username = $username;
  2765. return $this;
  2766. }
  2767. /**
  2768. * GARDER POUR LA SSO
  2769. *
  2770. * @return string
  2771. */
  2772. public function getUserIdentifier(): string
  2773. {
  2774. return (string)$this->email;
  2775. }
  2776. public function isDex(): bool
  2777. {
  2778. return true;
  2779. }
  2780. public function getWelcomeEmail(): ?DateTimeInterface
  2781. {
  2782. return $this->welcomeEmail;
  2783. }
  2784. public function setWelcomeEmail(?DateTimeInterface $welcomeEmail): User
  2785. {
  2786. $this->welcomeEmail = $welcomeEmail;
  2787. return $this;
  2788. }
  2789. public function getAccountAddress(): string
  2790. {
  2791. return trim($this->address1 . ' ' . $this->address2) . ' ' . $this->postcode . ' ' . $this->city;
  2792. }
  2793. public function eraseCredentials()
  2794. {
  2795. // If you store any temporary, sensitive data on the user, clear it here
  2796. $this->plainPassword = null;
  2797. }
  2798. public function generateAndSetPassword()
  2799. {
  2800. $pwd = substr(str_shuffle('23456789QWERTYUPASDFGHJKLZXCVBNM'), 0, 12);
  2801. $this->setPassword($pwd);
  2802. return $pwd;
  2803. }
  2804. public function getOldEmail(): ?string
  2805. {
  2806. return $this->oldEmail;
  2807. }
  2808. public function setOldEmail(?string $oldEmail): void
  2809. {
  2810. if (is_string($oldEmail)) {
  2811. $oldEmail = trim($oldEmail);
  2812. }
  2813. $this->oldEmail = $oldEmail;
  2814. }
  2815. public function getPassword(): ?string
  2816. {
  2817. return $this->password;
  2818. }
  2819. public function setPassword(string $password): User
  2820. {
  2821. // Chaque fois que le mot de passe est modifié, mettre à jour la date
  2822. // et remettre à 0 le compteur d'essai
  2823. $this->passwordUpdatedAt = new DateTime();
  2824. $this->setFailedAttempts(0);
  2825. $this->password = $password;
  2826. return $this;
  2827. }
  2828. public function getSalt(): ?string
  2829. {
  2830. return $this->salt;
  2831. }
  2832. public function setSalt(?string $salt): User
  2833. {
  2834. $this->salt = $salt;
  2835. return $this;
  2836. }
  2837. public function getPlainPassword(): ?string
  2838. {
  2839. return $this->plainPassword;
  2840. }
  2841. public function setPlainPassword($plainPassword): User
  2842. {
  2843. // Ajout de l'ancien mot de passe dans l'historique
  2844. if ($plainPassword !== null) {
  2845. $passwordHistory = new PasswordHistory();
  2846. $passwordHistory->setUser($this);
  2847. $passwordHistory->setHashedPassword(md5($plainPassword));
  2848. $this->passwordHistories[] = $passwordHistory;
  2849. }
  2850. $this->plainPassword = $plainPassword;
  2851. return $this;
  2852. }
  2853. public function getFirstName(): ?string
  2854. {
  2855. return $this->firstName;
  2856. }
  2857. public function setFirstName(?string $firstName): User
  2858. {
  2859. if ($firstName) {
  2860. $firstName = ucfirst(strtolower(trim($firstName)));
  2861. }
  2862. $this->firstName = $firstName;
  2863. return $this;
  2864. }
  2865. public function getLastName(): ?string
  2866. {
  2867. return $this->lastName;
  2868. }
  2869. public function setLastName(?string $lastName): User
  2870. {
  2871. if ($lastName) {
  2872. $lastName = strtoupper(trim($lastName));
  2873. }
  2874. $this->lastName = $lastName;
  2875. return $this;
  2876. }
  2877. public function getMobile(): ?string
  2878. {
  2879. if (!$this->mobile) {
  2880. return null;
  2881. }
  2882. $mobile = str_replace(['-', '/', '.', ' '], '-', $this->mobile);
  2883. $re = '/^(?:(?:(?:\+|00)33[ ]?(?:\(0\)[ ]?)?)|0){1}[1-9]{1}([ .-]?)(?:\d{2}\1?){3}\d{2}$/m';
  2884. preg_match_all($re, '0' . $mobile, $matches, PREG_SET_ORDER);
  2885. if (!empty($matches)) {
  2886. $mobile = '0' . $mobile;
  2887. }
  2888. return $mobile;
  2889. }
  2890. public function setMobile(?string $mobile): User
  2891. {
  2892. $this->mobile = $mobile;
  2893. return $this;
  2894. }
  2895. public function getPhone(): ?string
  2896. {
  2897. if (!$this->phone) {
  2898. return null;
  2899. }
  2900. $phone = str_replace(['-', '/', '.', ' '], '-', $this->phone);
  2901. $re = '/^(?:(?:(?:\+|00)33[ ]?(?:\(0\)[ ]?)?)|0){1}[1-9]{1}([ .-]?)(?:\d{2}\1?){3}\d{2}$/m';
  2902. preg_match_all($re, '0' . $phone, $matches, PREG_SET_ORDER);
  2903. if (!empty($matches)) {
  2904. $phone = '0' . $phone;
  2905. }
  2906. return $phone;
  2907. }
  2908. public function setPhone(?string $phone): User
  2909. {
  2910. $this->phone = $phone;
  2911. return $this;
  2912. }
  2913. /**
  2914. * @return int|null
  2915. * @deprecated
  2916. */
  2917. public function getAvailablePoint(): ?int
  2918. {
  2919. return $this->availablePoint;
  2920. }
  2921. /**
  2922. * @param int $availablePoint
  2923. *
  2924. * @return $this
  2925. * @deprecated
  2926. */
  2927. public function setAvailablePoint(int $availablePoint): User
  2928. {
  2929. $this->availablePoint = $availablePoint;
  2930. return $this;
  2931. }
  2932. /**
  2933. * @return int|null
  2934. * @deprecated
  2935. */
  2936. public function getPotentialPoint(): ?int
  2937. {
  2938. return $this->potentialPoint;
  2939. }
  2940. /**
  2941. * @param int $potentialPoint
  2942. *
  2943. * @return $this
  2944. * @deprecated
  2945. */
  2946. public function setPotentialPoint(int $potentialPoint): User
  2947. {
  2948. $this->potentialPoint = $potentialPoint;
  2949. return $this;
  2950. }
  2951. /**
  2952. * @return string|null
  2953. * @deprecated
  2954. */
  2955. public function getLocale(): ?string
  2956. {
  2957. return $this->locale;
  2958. }
  2959. /**
  2960. * @param string|null $locale
  2961. *
  2962. * @return $this
  2963. * @deprecated
  2964. */
  2965. public function setLocale(?string $locale): User
  2966. {
  2967. $this->locale = $locale;
  2968. return $this;
  2969. }
  2970. public function getCountry(): ?Country
  2971. {
  2972. return $this->country;
  2973. }
  2974. public function setCountry(?Country $country): User
  2975. {
  2976. $this->country = $country;
  2977. return $this;
  2978. }
  2979. public function getOldJob(): ?string
  2980. {
  2981. return $this->oldJob === '' ? null : $this->oldJob;
  2982. }
  2983. public function setOldJob(?string $oldJob): User
  2984. {
  2985. $this->oldJob = $oldJob;
  2986. return $this;
  2987. }
  2988. public function getJobs(): array
  2989. {
  2990. return $this->jobs ?? [];
  2991. }
  2992. public function hasJob(?string $job = null): bool
  2993. {
  2994. if (null === $job && !empty($this->jobs)) {
  2995. return true;
  2996. }
  2997. return in_array($job, $this->getJobs(), true);
  2998. }
  2999. public function setJobs(?array $jobs): User
  3000. {
  3001. $this->jobs = $jobs;
  3002. return $this;
  3003. }
  3004. public function addJob(string $job): User
  3005. {
  3006. $jobs = $this->getJobs();
  3007. if (!in_array($job, $jobs, true)) {
  3008. $jobs[] = $job;
  3009. $this->jobs = $jobs;
  3010. }
  3011. return $this;
  3012. }
  3013. public function addJobs(array $jobs): User
  3014. {
  3015. foreach ($jobs as $job) {
  3016. $this->addJob($job);
  3017. }
  3018. return $this;
  3019. }
  3020. public function getCompany(): ?string
  3021. {
  3022. return $this->company;
  3023. }
  3024. public function setCompany(?string $company): User
  3025. {
  3026. $this->company = $company;
  3027. return $this;
  3028. }
  3029. public function getAddress1(): ?string
  3030. {
  3031. return $this->address1;
  3032. }
  3033. public function setAddress1(?string $address1): User
  3034. {
  3035. $this->address1 = $address1;
  3036. return $this;
  3037. }
  3038. public function getAddress2(): ?string
  3039. {
  3040. return $this->address2;
  3041. }
  3042. public function setAddress2(?string $address2): User
  3043. {
  3044. $this->address2 = $address2;
  3045. return $this;
  3046. }
  3047. // /**
  3048. // * @Serializer\VirtualProperty()
  3049. // * @SerializedName ("birthDate")
  3050. // * @Groups({"user:list", "user:item", "user", "get:read", "post:read", "export_user_datatable"})
  3051. // *
  3052. // *
  3053. // * @return DateTimeInterface|null
  3054. // */
  3055. // public function getBirthDate(): ?DateTimeInterface
  3056. // {
  3057. // try {
  3058. // return new DateTime( $this->getExtensionBySlug( \App\Constants\UserExtension::BIRTH_DATE ) );
  3059. // }
  3060. // catch ( Exception $e ) {
  3061. // return null;
  3062. // }
  3063. // }
  3064. public function getCity(): ?string
  3065. {
  3066. return $this->city;
  3067. }
  3068. public function setCity(?string $city): User
  3069. {
  3070. $this->city = $city;
  3071. return $this;
  3072. }
  3073. public function getCanOrder(): ?bool
  3074. {
  3075. return $this->canOrder;
  3076. }
  3077. public function setCanOrder(?bool $canOrder): User
  3078. {
  3079. $this->canOrder = $canOrder;
  3080. return $this;
  3081. }
  3082. public function getDeletedAt(): ?DateTimeInterface
  3083. {
  3084. return $this->deletedAt;
  3085. }
  3086. public function setDeletedAt(?DateTimeInterface $deletedAt): User
  3087. {
  3088. $this->deletedAt = $deletedAt;
  3089. return $this;
  3090. }
  3091. /**
  3092. * @Serializer\VirtualProperty()
  3093. * @SerializedName ("birthDate")
  3094. * @Groups({"user:list", "user:item", "user", "get:read", "post:read", "export_user_datatable"})
  3095. *
  3096. *
  3097. * @return DateTimeInterface|null
  3098. */
  3099. public function getBirthDate(): ?DateTimeInterface
  3100. {
  3101. try {
  3102. return new DateTime($this->getExtensionBySlug(\App\Constants\UserExtension::BIRTH_DATE));
  3103. } catch (Exception $e) {
  3104. return null;
  3105. }
  3106. }
  3107. /**
  3108. * @throws Exception
  3109. */
  3110. public function setBirthDate($value): User
  3111. {
  3112. if ($value === null) {
  3113. return $this;
  3114. }
  3115. if ($value instanceof DateTimeInterface) {
  3116. $value = $value->format('Y-m-d');
  3117. }
  3118. $this->addExtension(UserExtensionFactory::setBirthDate($this, $value));
  3119. return $this;
  3120. }
  3121. public function getBirthCity(): ?string
  3122. {
  3123. return $this->getExtensionBySlug(\App\Constants\UserExtension::BIRTH_CITY);
  3124. }
  3125. public function setBirthCity(?string $value): User
  3126. {
  3127. if ($value === null) {
  3128. return $this;
  3129. }
  3130. $this->addExtension(UserExtensionFactory::setBirthCity($this, $value));
  3131. return $this;
  3132. }
  3133. public function getSocialSecurityNumber(): ?string
  3134. {
  3135. return $this->getExtensionBySlug(\App\Constants\UserExtension::SOCIAL_SECURITY_NUMBER);
  3136. }
  3137. public function setSocialSecurityNumber(?string $value): User
  3138. {
  3139. if ($value === null) {
  3140. return $this;
  3141. }
  3142. $this->addExtension(UserExtensionFactory::setSocialSecurityNbr($this, $value));
  3143. return $this;
  3144. }
  3145. /**
  3146. * @return array
  3147. */
  3148. public function getSecondaryEmails(): array
  3149. {
  3150. $emails = $this->getExtensionBySlug(\App\Constants\UserExtension::SECONDARY_EMAILS);
  3151. if (empty($emails)) {
  3152. return [];
  3153. }
  3154. return json_decode($emails, true);
  3155. }
  3156. /**
  3157. * @param array $emails
  3158. *
  3159. * @return $this
  3160. */
  3161. public function setSecondaryEmails(array $emails): User
  3162. {
  3163. $val = [];
  3164. foreach ($emails as $email) {
  3165. $email = trim(strtolower($email));
  3166. if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  3167. throw new InvalidArgumentException('email invalide');
  3168. }
  3169. $val[] = $email;
  3170. }
  3171. $this->addExtension(UserExtensionFactory::setSecondaryEmails($this, json_encode($val)));
  3172. return $this;
  3173. }
  3174. /**
  3175. * @param string $email
  3176. *
  3177. * @return $this
  3178. */
  3179. public function addSecondaryEmail(string $email): User
  3180. {
  3181. $email = trim(strtolower($email));
  3182. if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  3183. throw new InvalidArgumentException("email ($email) invalide");
  3184. }
  3185. $emails = $this->getSecondaryEmails();
  3186. if (!in_array($email, $emails)) {
  3187. $emails[] = $email;
  3188. $this->addExtension(UserExtensionFactory::setSecondaryEmails($this, json_encode($emails)));
  3189. }
  3190. return $this;
  3191. }
  3192. /**
  3193. * @param string $email
  3194. *
  3195. * @return $this
  3196. */
  3197. public function removeSecondaryEmail(string $email): User
  3198. {
  3199. $email = trim(strtolower($email));
  3200. $emails = $this->getSecondaryEmails();
  3201. $key = array_search($email, $emails);
  3202. if ($key) {
  3203. unset($emails[$key]);
  3204. $this->addExtension(UserExtensionFactory::setSecondaryEmails($this, json_encode($emails)));
  3205. }
  3206. return $this;
  3207. }
  3208. public function getInternalCode(): ?string
  3209. {
  3210. return $this->internalCode;
  3211. }
  3212. public function setInternalCode(?string $internalCode): User
  3213. {
  3214. $this->internalCode = $internalCode;
  3215. return $this;
  3216. }
  3217. public function getCguAt(): ?DateTimeInterface
  3218. {
  3219. return $this->cguAt;
  3220. }
  3221. public function setCguAt(?DateTimeInterface $cguAt): User
  3222. {
  3223. $this->cguAt = $cguAt;
  3224. return $this;
  3225. }
  3226. public function getRegisterAt(): ?DateTimeInterface
  3227. {
  3228. return $this->registerAt;
  3229. }
  3230. public function setRegisterAt(?DateTimeInterface $registerAt): User
  3231. {
  3232. $this->registerAt = $registerAt;
  3233. return $this;
  3234. }
  3235. public function getImportedAt(): ?DateTimeInterface
  3236. {
  3237. return $this->importedAt;
  3238. }
  3239. public function setImportedAt(?DateTimeInterface $importedAt): User
  3240. {
  3241. $this->importedAt = $importedAt;
  3242. return $this;
  3243. }
  3244. public function getCanBeContacted(): ?bool
  3245. {
  3246. return $this->canBeContacted;
  3247. }
  3248. public function setCanBeContacted(bool $canBeContacted): User
  3249. {
  3250. $this->canBeContacted = $canBeContacted;
  3251. return $this;
  3252. }
  3253. /**
  3254. * @deprecated
  3255. */
  3256. public function getCapacity(): ?string
  3257. {
  3258. return $this->capacity;
  3259. }
  3260. /**
  3261. * @deprecated
  3262. */
  3263. public function setCapacity(?string $capacity): User
  3264. {
  3265. $this->capacity = $capacity;
  3266. return $this;
  3267. }
  3268. public function getAddress3(): ?string
  3269. {
  3270. return $this->address3;
  3271. }
  3272. public function setAddress3(?string $address3): User
  3273. {
  3274. $this->address3 = $address3;
  3275. return $this;
  3276. }
  3277. public function getOptinMail(): ?bool
  3278. {
  3279. return $this->optinMail;
  3280. }
  3281. public function setOptinMail(bool $optinMail): User
  3282. {
  3283. $this->optinMail = $optinMail;
  3284. return $this;
  3285. }
  3286. public function getOptinSMS(): ?bool
  3287. {
  3288. return $this->optinSMS;
  3289. }
  3290. public function setOptinSMS(bool $optinSMS): User
  3291. {
  3292. $this->optinSMS = $optinSMS;
  3293. return $this;
  3294. }
  3295. public function getOptinPostal(): ?bool
  3296. {
  3297. return $this->optinPostal;
  3298. }
  3299. public function setOptinPostal(bool $optinPostal): User
  3300. {
  3301. $this->optinPostal = $optinPostal;
  3302. return $this;
  3303. }
  3304. public function getOptinPostalAddress(): ?string
  3305. {
  3306. return $this->optinPostalAddress;
  3307. }
  3308. public function setOptinPostalAddress(?string $optinPostalAddress): User
  3309. {
  3310. $this->optinPostalAddress = $optinPostalAddress;
  3311. return $this;
  3312. }
  3313. public function getSource(): ?string
  3314. {
  3315. return $this->source;
  3316. }
  3317. public function setSource(?string $source): User
  3318. {
  3319. $this->source = $source;
  3320. return $this;
  3321. }
  3322. /**
  3323. * @return int|null
  3324. * @deprecated {@see UserPointService::getLevel()}
  3325. */
  3326. public function getLevel(): ?int
  3327. {
  3328. return $this->level;
  3329. }
  3330. /**
  3331. * @param int $level
  3332. *
  3333. * @return $this
  3334. * @deprecated
  3335. */
  3336. public function setLevel(int $level): User
  3337. {
  3338. $this->level = $level;
  3339. return $this;
  3340. }
  3341. /**
  3342. * @return DateTimeInterface|null
  3343. * @deprecated
  3344. */
  3345. public function getLevel0UpdatedAt(): ?DateTimeInterface
  3346. {
  3347. return $this->level0UpdatedAt;
  3348. }
  3349. /**
  3350. * @param DateTimeInterface|null $level0UpdatedAt
  3351. *
  3352. * @return $this
  3353. * @deprecated
  3354. */
  3355. public function setLevel0UpdatedAt(?DateTimeInterface $level0UpdatedAt): User
  3356. {
  3357. $this->level0UpdatedAt = $level0UpdatedAt;
  3358. return $this;
  3359. }
  3360. public function getLevel3UpdatedAt(): ?DateTimeInterface
  3361. {
  3362. return $this->level3UpdatedAt;
  3363. }
  3364. /**
  3365. * @param DateTimeInterface|null $level3UpdatedAt
  3366. *
  3367. * @return $this
  3368. * @deprecated
  3369. */
  3370. public function setLevel3UpdatedAt(?DateTimeInterface $level3UpdatedAt): User
  3371. {
  3372. $this->level3UpdatedAt = $level3UpdatedAt;
  3373. return $this;
  3374. }
  3375. /**
  3376. * @return DateTimeInterface|null
  3377. * @deprecated
  3378. */
  3379. public function getLevelUpdateSeenAt(): ?DateTimeInterface
  3380. {
  3381. return $this->levelUpdateSeenAt;
  3382. }
  3383. /**
  3384. * @param DateTimeInterface|null $levelUpdateSeenAt
  3385. *
  3386. * @return $this
  3387. * @deprecated
  3388. */
  3389. public function setLevelUpdateSeenAt(?DateTimeInterface $levelUpdateSeenAt): User
  3390. {
  3391. $this->levelUpdateSeenAt = $levelUpdateSeenAt;
  3392. return $this;
  3393. }
  3394. /**
  3395. * @return bool|null
  3396. */
  3397. public function getIsEmailOk(): ?bool
  3398. {
  3399. return $this->isEmailOk;
  3400. }
  3401. /**
  3402. * @param bool $isEmailOk
  3403. *
  3404. * @return $this
  3405. */
  3406. public function setIsEmailOk(bool $isEmailOk): User
  3407. {
  3408. $this->isEmailOk = $isEmailOk;
  3409. return $this;
  3410. }
  3411. /**
  3412. * @return DateTimeInterface|null
  3413. */
  3414. public function getLastEmailCheck(): ?DateTimeInterface
  3415. {
  3416. return $this->lastEmailCheck;
  3417. }
  3418. /**
  3419. * @param DateTimeInterface|null $lastEmailCheck
  3420. *
  3421. * @return $this
  3422. */
  3423. public function setLastEmailCheck(?DateTimeInterface $lastEmailCheck): User
  3424. {
  3425. $this->lastEmailCheck = $lastEmailCheck;
  3426. return $this;
  3427. }
  3428. public function getSapDistributor(): ?string
  3429. {
  3430. return $this->sapDistributor;
  3431. }
  3432. public function setSapDistributor(?string $sapDistributor): User
  3433. {
  3434. $this->sapDistributor = $sapDistributor;
  3435. return $this;
  3436. }
  3437. public function getDistributor(): ?string
  3438. {
  3439. return $this->distributor;
  3440. }
  3441. public function setDistributor(?string $distributor): User
  3442. {
  3443. $this->distributor = $distributor;
  3444. return $this;
  3445. }
  3446. public function getDistributor2(): ?string
  3447. {
  3448. return $this->distributor2;
  3449. }
  3450. public function setDistributor2(?string $distributor2): User
  3451. {
  3452. $this->distributor2 = $distributor2;
  3453. return $this;
  3454. }
  3455. public function getAggreement(): ?bool
  3456. {
  3457. return $this->aggreement;
  3458. }
  3459. public function setAggreement(?bool $aggreement): User
  3460. {
  3461. $this->aggreement = $aggreement;
  3462. return $this;
  3463. }
  3464. public function getUnsubscribedAt(): ?DateTimeInterface
  3465. {
  3466. return $this->unsubscribedAt;
  3467. }
  3468. public function setUnsubscribedAt(?DateTimeInterface $unsubscribedAt): User
  3469. {
  3470. $this->unsubscribedAt = $unsubscribedAt;
  3471. return $this;
  3472. }
  3473. public function addAddress(Address $address): User
  3474. {
  3475. if (!$this->addresses->contains($address)) {
  3476. $this->addresses->add($address);
  3477. $user = $address->getUser();
  3478. if ($user) {
  3479. $user->removeAddress($address);
  3480. }
  3481. $address->setUser($this);
  3482. }
  3483. return $this;
  3484. }
  3485. public function removeAddress(Address $address): User
  3486. {
  3487. if ($this->addresses->removeElement($address)) {
  3488. // set the owning side to null (unless already changed)
  3489. if ($address->getUser() === $this) {
  3490. $address->setUser(null);
  3491. }
  3492. }
  3493. return $this;
  3494. }
  3495. public function getCarts(): Collection
  3496. {
  3497. return $this->carts;
  3498. }
  3499. public function addCart(Cart $cart): User
  3500. {
  3501. if (!$this->carts->contains($cart)) {
  3502. $this->carts[] = $cart;
  3503. $cart->setUser($this);
  3504. }
  3505. return $this;
  3506. }
  3507. public function removeCart(Cart $cart): User
  3508. {
  3509. if ($this->carts->removeElement($cart)) {
  3510. // set the owning side to null (unless already changed)
  3511. if ($cart->getUser() === $this) {
  3512. $cart->setUser(null);
  3513. }
  3514. }
  3515. return $this;
  3516. }
  3517. public function getSapAccount(): ?string
  3518. {
  3519. return $this->sapAccount;
  3520. }
  3521. public function setSapAccount(?string $sapAccount): User
  3522. {
  3523. $this->sapAccount = $sapAccount;
  3524. return $this;
  3525. }
  3526. /**
  3527. * @return User|null
  3528. */
  3529. public function getMainAccountUser(): ?User
  3530. {
  3531. return $this->mainAccountUser;
  3532. }
  3533. /**
  3534. * @param User|null $mainAccountUser
  3535. *
  3536. * @return $this
  3537. */
  3538. public function setMainAccountUser(?User $mainAccountUser = null, bool $setSubAccountUser = true): User
  3539. {
  3540. if ($setSubAccountUser) {
  3541. if ($mainAccountUser) {
  3542. $mainAccountUser->addSubAccountUser($this, false);
  3543. } elseif ($this->mainAccountUser) {
  3544. $this->mainAccountUser->removeSubAccountUser($this, false);
  3545. }
  3546. }
  3547. $this->mainAccountUser = $mainAccountUser;
  3548. return $this;
  3549. }
  3550. /**
  3551. * @return Collection|User[]
  3552. */
  3553. public function getSubAccountUsers(): Collection
  3554. {
  3555. $subAccountUsers = clone $this->subAccountUsers;
  3556. $subAccountUsers->removeElement($this);
  3557. return $subAccountUsers;
  3558. }
  3559. /**
  3560. * @param iterable|User[] $subAccountUsers
  3561. *
  3562. * @return User
  3563. */
  3564. public function setSubAccountUsers(iterable $subAccountUsers, bool $setMainAccountUser = true): User
  3565. {
  3566. foreach ($this->subAccountUsers as $subAccountUser) {
  3567. $this->removeSubAccountUser($subAccountUser, $setMainAccountUser);
  3568. }
  3569. foreach ($subAccountUsers as $subAccountUser) {
  3570. $this->addSubAccountUser($subAccountUser, $setMainAccountUser);
  3571. }
  3572. return $this;
  3573. }
  3574. /**
  3575. * @param User $subAccountUser
  3576. * @param bool $setMainAccountUser
  3577. *
  3578. * @return $this
  3579. */
  3580. public function addSubAccountUser(User $subAccountUser, bool $setMainAccountUser = true): User
  3581. {
  3582. if (!$this->subAccountUsers->contains($subAccountUser)) {
  3583. $this->subAccountUsers->add($subAccountUser);
  3584. if ($setMainAccountUser) {
  3585. $subAccountUser->setMainAccountUser($this, false);
  3586. }
  3587. }
  3588. return $this;
  3589. }
  3590. /**
  3591. * @param User $subAccountUser
  3592. * @param bool $setMainAccountUser
  3593. *
  3594. * @return User
  3595. */
  3596. public function removeSubAccountUser(User $subAccountUser, bool $setMainAccountUser = true): User
  3597. {
  3598. if ($this->subAccountUsers->contains($subAccountUser)) {
  3599. $this->subAccountUsers->removeElement($subAccountUser);
  3600. if ($setMainAccountUser) {
  3601. $subAccountUser->setMainAccountUser(null, false);
  3602. }
  3603. }
  3604. return $this;
  3605. }
  3606. public function getDistributors(): Collection
  3607. {
  3608. return $this->distributors;
  3609. }
  3610. public function addDistributor(Distributor $distributor): User
  3611. {
  3612. if (!$this->distributors->contains($distributor)) {
  3613. $this->distributors[] = $distributor;
  3614. }
  3615. return $this;
  3616. }
  3617. public function removeDistributor(Distributor $distributor): User
  3618. {
  3619. $this->distributors->removeElement($distributor);
  3620. return $this;
  3621. }
  3622. public function getPurchases(): Collection
  3623. {
  3624. return $this->purchases;
  3625. }
  3626. public function addPurchase(Purchase $purchase): User
  3627. {
  3628. if (!$this->purchases->contains($purchase)) {
  3629. $this->purchases[] = $purchase;
  3630. $purchase->setValidator($this);
  3631. }
  3632. return $this;
  3633. }
  3634. public function removePurchase(Purchase $purchase): User
  3635. {
  3636. if ($this->purchases->removeElement($purchase)) {
  3637. // set the owning side to null (unless already changed)
  3638. if ($purchase->getValidator() === $this) {
  3639. $purchase->setValidator(null);
  3640. }
  3641. }
  3642. return $this;
  3643. }
  3644. public function getPurchasesIHaveProcessed(): Collection
  3645. {
  3646. return $this->purchasesIHaveProcessed;
  3647. }
  3648. public function addPurchaseIHaveProcessed(Purchase $purchasesIHaveProcessed): User
  3649. {
  3650. if (!$this->purchasesIHaveProcessed->contains($purchasesIHaveProcessed)) {
  3651. $this->purchasesIHaveProcessed[] = $purchasesIHaveProcessed;
  3652. $purchasesIHaveProcessed->setValidator($this);
  3653. }
  3654. return $this;
  3655. }
  3656. public function removePurchaseIHaveProcessed(Purchase $purchasesIHaveProcessed): User
  3657. {
  3658. if ($this->purchasesIHaveProcessed->removeElement($purchasesIHaveProcessed)) {
  3659. // set the owning side to null (unless already changed)
  3660. if ($purchasesIHaveProcessed->getValidator() === $this) {
  3661. $purchasesIHaveProcessed->setValidator(null);
  3662. }
  3663. }
  3664. return $this;
  3665. }
  3666. /**
  3667. * @param array|null $status
  3668. *
  3669. * @return Collection|SaleOrder[]
  3670. */
  3671. public function getOrders(?array $status = null): Collection
  3672. {
  3673. if (empty($status)) {
  3674. return $this->orders;
  3675. }
  3676. $orders = new ArrayCollection();
  3677. foreach ($this->orders as $order) {
  3678. if (in_array($order->getStatus(), $status)) {
  3679. $orders->add($order);
  3680. }
  3681. }
  3682. return $orders;
  3683. }
  3684. public function addOrder(SaleOrder $order): User
  3685. {
  3686. if (!$this->orders->contains($order)) {
  3687. $this->orders->add($order);
  3688. $user = $order->getUser();
  3689. if ($user) {
  3690. $user->removeOrder($order);
  3691. }
  3692. $order->setUser($this);
  3693. }
  3694. return $this;
  3695. }
  3696. public function removeOrder(SaleOrder $order): User
  3697. {
  3698. if ($this->orders->removeElement($order)) {
  3699. // set the owning side to null (unless already changed)
  3700. if ($order->getUser() === $this) {
  3701. $order->setUser(null);
  3702. }
  3703. }
  3704. return $this;
  3705. }
  3706. /**
  3707. * @return Collection|User[]
  3708. */
  3709. public function getGodchilds(): Collection
  3710. {
  3711. return $this->godchilds;
  3712. }
  3713. /**
  3714. * @param User $godchild
  3715. *
  3716. * @return $this
  3717. */
  3718. public function addGodchild(User $godchild, bool $setGodFather = true): User
  3719. {
  3720. if (!$this->godchilds->contains($godchild)) {
  3721. $this->godchilds->add($godchild);
  3722. if ($setGodFather) {
  3723. $godchild->setGodfather($this, false);
  3724. }
  3725. }
  3726. return $this;
  3727. }
  3728. /**
  3729. * @param User $godchild
  3730. *
  3731. * @return $this
  3732. */
  3733. public function removeGodchild(User $godchild, bool $setGodFather = true): User
  3734. {
  3735. if ($this->godchilds->removeElement($godchild) && $setGodFather) {
  3736. $godchild->setGodfather(null, false);
  3737. }
  3738. return $this;
  3739. }
  3740. /**
  3741. * @return User
  3742. */
  3743. public function getGodfather(): ?User
  3744. {
  3745. return $this->godfather;
  3746. }
  3747. /**
  3748. * @param User|null $godfather
  3749. *
  3750. * @return $this
  3751. */
  3752. public function setGodfather(?User $godfather = null, bool $updateGodchild = true): User
  3753. {
  3754. if ($this->godfather !== $godfather) {
  3755. if ($updateGodchild && $this->godfather) {
  3756. $this->godfather->removeGodchild($this, false);
  3757. }
  3758. if ($updateGodchild && $godfather) {
  3759. $godfather->addGodchild($this, false);
  3760. }
  3761. $this->godfather = $godfather;
  3762. }
  3763. return $this;
  3764. }
  3765. public function isGodFather(): bool
  3766. {
  3767. return !$this->godchilds->isEmpty();
  3768. }
  3769. public function isGodChild(): bool
  3770. {
  3771. return $this->godfather !== null;
  3772. }
  3773. /**
  3774. * @deprecated
  3775. */
  3776. public function getSatisfactions(): Collection
  3777. {
  3778. return $this->satisfactions;
  3779. }
  3780. /**
  3781. * @deprecated
  3782. */
  3783. public function addSatisfaction(Satisfaction $satisfaction): User
  3784. {
  3785. if (!$this->satisfactions->contains($satisfaction)) {
  3786. $this->satisfactions[] = $satisfaction;
  3787. $satisfaction->setUser($this);
  3788. }
  3789. return $this;
  3790. }
  3791. /**
  3792. * @deprecated
  3793. */
  3794. public function removeSatisfaction(Satisfaction $satisfaction): User
  3795. {
  3796. if ($this->satisfactions->removeElement($satisfaction)) {
  3797. // set the owning side to null (unless already changed)
  3798. if ($satisfaction->getUser() === $this) {
  3799. $satisfaction->setUser(null);
  3800. }
  3801. }
  3802. return $this;
  3803. }
  3804. public function getRequestProductAvailables(): Collection
  3805. {
  3806. return $this->requestProductAvailables;
  3807. }
  3808. public function addRequestProductAvailable(RequestProductAvailable $requestProductAvailable): User
  3809. {
  3810. if (!$this->requestProductAvailables->contains($requestProductAvailable)) {
  3811. $this->requestProductAvailables[] = $requestProductAvailable;
  3812. $requestProductAvailable->setUser($this);
  3813. }
  3814. return $this;
  3815. }
  3816. public function removeRequestProductAvailable(RequestProductAvailable $requestProductAvailable): User
  3817. {
  3818. if ($this->requestProductAvailables->removeElement($requestProductAvailable)) {
  3819. // set the owning side to null (unless already changed)
  3820. if ($requestProductAvailable->getUser() === $this) {
  3821. $requestProductAvailable->setUser(null);
  3822. }
  3823. }
  3824. return $this;
  3825. }
  3826. public function getUserImportHistories(): Collection
  3827. {
  3828. return $this->userImportHistories;
  3829. }
  3830. public function addUserImportHistory(UserImportHistory $userImportHistory): User
  3831. {
  3832. if (!$this->userImportHistories->contains($userImportHistory)) {
  3833. $this->userImportHistories[] = $userImportHistory;
  3834. $userImportHistory->setImporter($this);
  3835. }
  3836. return $this;
  3837. }
  3838. public function removeUserImportHistory(UserImportHistory $userImportHistory): User
  3839. {
  3840. if ($this->userImportHistories->removeElement($userImportHistory)) {
  3841. // set the owning side to null (unless already changed)
  3842. if ($userImportHistory->getImporter() === $this) {
  3843. $userImportHistory->setImporter(null);
  3844. }
  3845. }
  3846. return $this;
  3847. }
  3848. public function getContactLists(): Collection
  3849. {
  3850. return $this->contactLists;
  3851. }
  3852. public function addContactList(ContactList $contactList): User
  3853. {
  3854. if (!$this->contactLists->contains($contactList)) {
  3855. $this->contactLists[] = $contactList;
  3856. $contactList->addUser($this);
  3857. }
  3858. return $this;
  3859. }
  3860. public function removeContactList(ContactList $contactList): User
  3861. {
  3862. if ($this->contactLists->removeElement($contactList)) {
  3863. $contactList->removeUser($this);
  3864. }
  3865. return $this;
  3866. }
  3867. /**
  3868. * @deprecated
  3869. */
  3870. public function getUsernameCanonical(): ?string
  3871. {
  3872. return $this->usernameCanonical;
  3873. }
  3874. /**
  3875. * @deprecated
  3876. */
  3877. public function setUsernameCanonical(?string $usernameCanonical): User
  3878. {
  3879. $this->usernameCanonical = $usernameCanonical;
  3880. return $this;
  3881. }
  3882. /**
  3883. * @deprecated
  3884. */
  3885. public function getEmailCanonical(): ?string
  3886. {
  3887. return $this->emailCanonical;
  3888. }
  3889. /**
  3890. * @deprecated
  3891. */
  3892. public function setEmailCanonical(?string $emailCanonical): User
  3893. {
  3894. $this->emailCanonical = $emailCanonical;
  3895. return $this;
  3896. }
  3897. public function getLastLogin(): ?DateTimeInterface
  3898. {
  3899. return $this->lastLogin;
  3900. }
  3901. public function setLastLogin(?DateTimeInterface $lastLogin): User
  3902. {
  3903. $this->lastLogin = $lastLogin;
  3904. return $this;
  3905. }
  3906. public function getConfirmationToken(): ?string
  3907. {
  3908. return $this->confirmationToken;
  3909. }
  3910. public function setConfirmationToken(?string $confirmationToken): User
  3911. {
  3912. $this->confirmationToken = $confirmationToken;
  3913. return $this;
  3914. }
  3915. public function getPasswordRequestedAt(): ?DateTimeInterface
  3916. {
  3917. return $this->passwordRequestedAt;
  3918. }
  3919. public function setPasswordRequestedAt(?DateTimeInterface $passwordRequestedAt): User
  3920. {
  3921. $this->passwordRequestedAt = $passwordRequestedAt;
  3922. return $this;
  3923. }
  3924. public function getCredentialExpired(): ?bool
  3925. {
  3926. return $this->credentialExpired;
  3927. }
  3928. public function setCredentialExpired(?bool $credentialExpired): User
  3929. {
  3930. $this->credentialExpired = $credentialExpired;
  3931. return $this;
  3932. }
  3933. public function getCredentialExpiredAt(): ?DateTimeInterface
  3934. {
  3935. return $this->credentialExpiredAt;
  3936. }
  3937. public function setCredentialExpiredAt(?DateTimeInterface $credentialExpiredAt): User
  3938. {
  3939. $this->credentialExpiredAt = $credentialExpiredAt;
  3940. return $this;
  3941. }
  3942. public function getDevis(): Collection
  3943. {
  3944. return $this->devis;
  3945. }
  3946. public function addDevi(Devis $devi): User
  3947. {
  3948. if (!$this->devis->contains($devi)) {
  3949. $this->devis[] = $devi;
  3950. $devi->setUser($this);
  3951. }
  3952. return $this;
  3953. }
  3954. public function removeDevi(Devis $devi): User
  3955. {
  3956. if ($this->devis->removeElement($devi)) {
  3957. // set the owning side to null (unless already changed)
  3958. if ($devi->getUser() === $this) {
  3959. $devi->setUser(null);
  3960. }
  3961. }
  3962. return $this;
  3963. }
  3964. public function __call($name, $arguments)
  3965. {
  3966. // TODO: Implement @method string getUserIdentifier()
  3967. }
  3968. public function getRegateName(): string
  3969. {
  3970. if ($this->regate) {
  3971. return $this->regate->getName();
  3972. }
  3973. return "";
  3974. }
  3975. public function getRegateAffectation(): string
  3976. {
  3977. if ($this->regate) {
  3978. return $this->regate->getAffectation();
  3979. }
  3980. return "";
  3981. }
  3982. public function getRegate(): ?Regate
  3983. {
  3984. return $this->regate;
  3985. }
  3986. public function setRegate(?Regate $regate): User
  3987. {
  3988. $this->regate = $regate;
  3989. return $this;
  3990. }
  3991. public function getDonneesPersonnelles(): ?bool
  3992. {
  3993. return $this->donneesPersonnelles;
  3994. }
  3995. public function setDonneesPersonnelles(?bool $donneesPersonnelles): User
  3996. {
  3997. $this->donneesPersonnelles = $donneesPersonnelles;
  3998. return $this;
  3999. }
  4000. /**
  4001. * @param PointTransactionType|string|null $type
  4002. * @param bool $sortByExpiration
  4003. *
  4004. * @return Collection|PointTransaction[]
  4005. * @throws Exception
  4006. */
  4007. public function getPointTransactions($type = null, bool $sortByExpiration = false): Collection
  4008. {
  4009. if (!$type && !$sortByExpiration) {
  4010. return $this->pointTransactions;
  4011. }
  4012. $points = clone $this->pointTransactions;
  4013. if ($type) {
  4014. $points = new ArrayCollection();
  4015. foreach ($this->getPointTransactions() as $pointTransaction) {
  4016. $pointTransactionType = $pointTransaction->getTransactionType();
  4017. if (!$pointTransactionType) {
  4018. continue;
  4019. }
  4020. if ($pointTransactionType === $type || $pointTransactionType->getSlug() === $type) {
  4021. $points->add($pointTransaction);
  4022. }
  4023. }
  4024. }
  4025. if ($sortByExpiration) {
  4026. $iterator = $points->getIterator();
  4027. $iterator->uasort(function ($a, $b) {
  4028. $AexpiredAt = $a->getExpiredAt();
  4029. $BexpiredAt = $b->getExpiredAt();
  4030. if ($AexpiredAt && $BexpiredAt) {
  4031. return ($AexpiredAt < $BexpiredAt) ? -1 : 1;
  4032. }
  4033. if (!$AexpiredAt) {
  4034. return 1;
  4035. }
  4036. return -1;
  4037. });
  4038. $points = new ArrayCollection(iterator_to_array($iterator));
  4039. }
  4040. return $points;
  4041. }
  4042. /**
  4043. * @param PointTransactionType|null $type
  4044. * @return float
  4045. * @throws Exception
  4046. */
  4047. public function getTotalPointTransactions(?PointTransactionType $type = null): float
  4048. {
  4049. $total = 0;
  4050. foreach ($this->getPointTransactions($type) as $pointTransaction) {
  4051. $total += $pointTransaction->getValue();
  4052. }
  4053. return $total;
  4054. }
  4055. /**
  4056. * @param PointTransaction $pointTransaction
  4057. * @return $this
  4058. */
  4059. public function addPointTransaction(PointTransaction $pointTransaction): User
  4060. {
  4061. if (!$this->pointTransactions->contains($pointTransaction)) {
  4062. $user = $pointTransaction->getUser();
  4063. if ($user) {
  4064. $user->removePointTransaction($pointTransaction);
  4065. }
  4066. $this->pointTransactions->add($pointTransaction);
  4067. $pointTransaction->setUser($this);
  4068. }
  4069. return $this;
  4070. }
  4071. public function removePointTransaction(PointTransaction $pointTransaction): User
  4072. {
  4073. if ($this->pointTransactions->removeElement($pointTransaction)) {
  4074. // set the owning side to null (unless already changed)
  4075. if ($pointTransaction->getUser() === $this) {
  4076. $pointTransaction->setUser(null);
  4077. }
  4078. }
  4079. return $this;
  4080. }
  4081. /**
  4082. * @return Collection|User[]
  4083. */
  4084. public function getInstallers(): Collection
  4085. {
  4086. return $this->installers;
  4087. }
  4088. public function addInstaller(User $installer): User
  4089. {
  4090. if (!$this->installers->contains($installer)) {
  4091. $this->installers[] = $installer;
  4092. $installer->setCommercial($this);
  4093. }
  4094. return $this;
  4095. }
  4096. public function removeInstaller(User $installer): User
  4097. {
  4098. if ($this->installers->removeElement($installer)) {
  4099. // set the owning side to null (unless already changed)
  4100. if ($installer->getCommercial() === $this) {
  4101. $installer->setCommercial(null);
  4102. }
  4103. }
  4104. return $this;
  4105. }
  4106. public function getCommercial(): ?User
  4107. {
  4108. return $this->commercial;
  4109. }
  4110. public function setCommercial(?User $commercial): User
  4111. {
  4112. $this->commercial = $commercial;
  4113. return $this;
  4114. }
  4115. /**
  4116. * @return Collection|User[]
  4117. */
  4118. public function getHeatingInstallers(): Collection
  4119. {
  4120. return $this->heatingInstallers;
  4121. }
  4122. public function addHeatingInstaller(User $heatingInstaller): User
  4123. {
  4124. if (!$this->heatingInstallers->contains($heatingInstaller)) {
  4125. $this->heatingInstallers[] = $heatingInstaller;
  4126. $heatingInstaller->setHeatingCommercial($this);
  4127. }
  4128. return $this;
  4129. }
  4130. public function removeHeatingInstaller(User $heatingInstaller): User
  4131. {
  4132. if ($this->heatingInstallers->removeElement($heatingInstaller)) {
  4133. // set the owning side to null (unless already changed)
  4134. if ($heatingInstaller->getHeatingCommercial() === $this) {
  4135. $heatingInstaller->setHeatingCommercial(null);
  4136. }
  4137. }
  4138. return $this;
  4139. }
  4140. public function getHeatingCommercial(): ?User
  4141. {
  4142. return $this->heatingCommercial;
  4143. }
  4144. public function setHeatingCommercial(?User $heatingCommercial): User
  4145. {
  4146. $this->heatingCommercial = $heatingCommercial;
  4147. return $this;
  4148. }
  4149. public function getAgency(): ?Agence
  4150. {
  4151. return $this->agency;
  4152. }
  4153. public function setAgency(?Agence $agency): User
  4154. {
  4155. $this->agency = $agency;
  4156. return $this;
  4157. }
  4158. public function getArchivedAt(): ?DateTimeInterface
  4159. {
  4160. return $this->archivedAt;
  4161. }
  4162. public function setArchivedAt(?DateTimeInterface $archivedAt): User
  4163. {
  4164. $this->archivedAt = $archivedAt;
  4165. return $this;
  4166. }
  4167. public function getNewsletter(): ?bool
  4168. {
  4169. return $this->newsletter;
  4170. }
  4171. public function setNewsletter(bool $newsletter): User
  4172. {
  4173. $this->newsletter = $newsletter;
  4174. return $this;
  4175. }
  4176. public function getCompanySiret(): ?string
  4177. {
  4178. return $this->companySiret;
  4179. }
  4180. public function setCompanySiret(?string $companySiret): User
  4181. {
  4182. $this->companySiret = $companySiret;
  4183. return $this;
  4184. }
  4185. /**
  4186. * @return Collection|UserBusinessResult[]|int
  4187. * @var bool $getPrevious highlight non null
  4188. * @var bool $sum retourne un integer avec la somme des résultats
  4189. * @var int|null $highlight highlight spécifique
  4190. * @var bool $getCurrent highlight à null
  4191. */
  4192. public function getUserBusinessResults(
  4193. bool $getCurrent = false,
  4194. bool $getPrevious = false,
  4195. bool $sum = false,
  4196. ?int $highlight = null
  4197. ) {
  4198. if (!$getCurrent && !$getPrevious && !$sum && !$highlight) {
  4199. return $this->userBusinessResults;
  4200. }
  4201. $userBusinessResults = $sum ? 0 : new ArrayCollection();
  4202. foreach ($this->userBusinessResults as $userBusinessResult) {
  4203. if ((!$getCurrent && !$getPrevious && !$highlight) || (($getCurrent && $userBusinessResult->getHighlight(
  4204. ) === null) || ($getPrevious && $userBusinessResult->getHighlight(
  4205. ) !== null) || ($highlight && $userBusinessResult->getHighlight() == $highlight))) {
  4206. $sum ? $userBusinessResults += $userBusinessResult->getSale() : $userBusinessResults->add(
  4207. $userBusinessResult
  4208. );
  4209. }
  4210. }
  4211. return $userBusinessResults;
  4212. }
  4213. public function getTotalUserBusinessResults(): int
  4214. {
  4215. $total = 0;
  4216. foreach ($this->userBusinessResults as $userBusinessResult) {
  4217. $total += $userBusinessResult->getSale();
  4218. }
  4219. return $total;
  4220. }
  4221. public function addUserBusinessResult(UserBusinessResult $userBusinessResult): User
  4222. {
  4223. if (!$this->userBusinessResults->contains($userBusinessResult)) {
  4224. $this->userBusinessResults->add($userBusinessResult);
  4225. $user = $userBusinessResult->getUser();
  4226. if ($user) {
  4227. $user->removeUserBusinessResult($userBusinessResult);
  4228. }
  4229. $userBusinessResult->setUser($this);
  4230. }
  4231. return $this;
  4232. }
  4233. public function removeUserBusinessResult(UserBusinessResult $userBusinessResult): User
  4234. {
  4235. if ($this->userBusinessResults->removeElement($userBusinessResult)) {
  4236. // set the owning side to null (unless already changed)
  4237. if ($userBusinessResult->getUser() === $this) {
  4238. $userBusinessResult->setUser(null);
  4239. }
  4240. }
  4241. return $this;
  4242. }
  4243. public function getExtension1(): ?string
  4244. {
  4245. return $this->extension1;
  4246. }
  4247. public function setExtension1(?string $extension1): User
  4248. {
  4249. $this->extension1 = $extension1;
  4250. return $this;
  4251. }
  4252. public function getExtension2(): ?string
  4253. {
  4254. return $this->extension2;
  4255. }
  4256. public function setExtension2(?string $extension2): User
  4257. {
  4258. $this->extension2 = $extension2;
  4259. return $this;
  4260. }
  4261. public function getWdg(): ?int
  4262. {
  4263. return $this->wdg;
  4264. }
  4265. public function setWdg(?int $wdg): User
  4266. {
  4267. $this->wdg = $wdg;
  4268. return $this;
  4269. }
  4270. public function getGladyUuid(): ?string
  4271. {
  4272. return $this->gladyUuid;
  4273. }
  4274. public function setGladyUuid(?string $gladyUuid): User
  4275. {
  4276. $this->gladyUuid = $gladyUuid;
  4277. return $this;
  4278. }
  4279. public function getCoverageArea(): ?CoverageArea
  4280. {
  4281. return $this->coverageArea;
  4282. }
  4283. public function setCoverageArea(?CoverageArea $coverageArea): User
  4284. {
  4285. $this->coverageArea = $coverageArea;
  4286. $coverageArea->setUser($this);
  4287. return $this;
  4288. }
  4289. /**
  4290. * @return Collection<int, Project>
  4291. */
  4292. public function getProjects(): Collection
  4293. {
  4294. return $this->projects;
  4295. }
  4296. public function addProject(Project $project): User
  4297. {
  4298. if (!$this->projects->contains($project)) {
  4299. $this->projects[] = $project;
  4300. $project->setReferent($this);
  4301. }
  4302. return $this;
  4303. }
  4304. public function removeProject(Project $project): User
  4305. {
  4306. if ($this->projects->removeElement($project)) {
  4307. // set the owning side to null (unless already changed)
  4308. if ($project->getReferent() === $this) {
  4309. $project->setReferent(null);
  4310. }
  4311. }
  4312. return $this;
  4313. }
  4314. public function getProgramme(): ?Programme
  4315. {
  4316. return $this->programme;
  4317. }
  4318. public function setProgramme(?Programme $programme): User
  4319. {
  4320. $this->programme = $programme;
  4321. return $this;
  4322. }
  4323. /**
  4324. * @return Collection<int, ServiceUser>
  4325. */
  4326. public function getServiceUsers(): Collection
  4327. {
  4328. return $this->serviceUsers;
  4329. }
  4330. public function addServiceUser(ServiceUser $serviceUser): User
  4331. {
  4332. if (!$this->serviceUsers->contains($serviceUser)) {
  4333. $this->serviceUsers[] = $serviceUser;
  4334. $serviceUser->setUser($this);
  4335. }
  4336. return $this;
  4337. }
  4338. public function removeServiceUser(ServiceUser $serviceUser): User
  4339. {
  4340. if ($this->serviceUsers->removeElement($serviceUser)) {
  4341. // set the owning side to null (unless already changed)
  4342. if ($serviceUser->getUser() === $this) {
  4343. $serviceUser->setUser(null);
  4344. }
  4345. }
  4346. return $this;
  4347. }
  4348. public function getSaleOrderValidation(): ?SaleOrderValidation
  4349. {
  4350. return $this->saleOrderValidation;
  4351. }
  4352. public function setSaleOrderValidation(?SaleOrderValidation $saleOrderValidation): User
  4353. {
  4354. $this->saleOrderValidation = $saleOrderValidation;
  4355. return $this;
  4356. }
  4357. /**
  4358. * @return Collection<int, Univers>
  4359. */
  4360. public function getUniverses(): Collection
  4361. {
  4362. return $this->universes;
  4363. }
  4364. public function addUnivers(Univers $univers): User
  4365. {
  4366. if (!$this->universes->contains($univers)) {
  4367. $this->universes[] = $univers;
  4368. $univers->addUser($this);
  4369. }
  4370. return $this;
  4371. }
  4372. public function removeUniverses(Univers $universes): User
  4373. {
  4374. if ($this->universes->removeElement($universes)) {
  4375. $universes->removeUser($this);
  4376. }
  4377. return $this;
  4378. }
  4379. public function getBillingPoint(): ?BillingPoint
  4380. {
  4381. return $this->billingPoint;
  4382. }
  4383. public function setBillingPoint(?BillingPoint $billingPoint): User
  4384. {
  4385. $this->billingPoint = $billingPoint;
  4386. return $this;
  4387. }
  4388. /**
  4389. * @return Collection<int, Score>
  4390. */
  4391. public function getScores(): Collection
  4392. {
  4393. return $this->scores;
  4394. }
  4395. public function addScore(Score $score): User
  4396. {
  4397. if (!$this->scores->contains($score)) {
  4398. $this->scores[] = $score;
  4399. $score->setUser($this);
  4400. }
  4401. return $this;
  4402. }
  4403. public function removeScore(Score $score): User
  4404. {
  4405. if ($this->scores->removeElement($score)) {
  4406. // set the owning side to null (unless already changed)
  4407. if ($score->getUser() === $this) {
  4408. $score->setUser(null);
  4409. }
  4410. }
  4411. return $this;
  4412. }
  4413. /**
  4414. * @return Collection<int, ScoreObjective>
  4415. */
  4416. public function getScoreObjectives(): Collection
  4417. {
  4418. return $this->scoreObjectives;
  4419. }
  4420. public function addScoreObjective(ScoreObjective $scoreObjective): User
  4421. {
  4422. if (!$this->scoreObjectives->contains($scoreObjective)) {
  4423. $this->scoreObjectives[] = $scoreObjective;
  4424. $scoreObjective->setUser($this);
  4425. }
  4426. return $this;
  4427. }
  4428. public function removeScoreObjective(ScoreObjective $scoreObjective): User
  4429. {
  4430. if ($this->scoreObjectives->removeElement($scoreObjective)) {
  4431. // set the owning side to null (unless already changed)
  4432. if ($scoreObjective->getUser() === $this) {
  4433. $scoreObjective->setUser(null);
  4434. }
  4435. }
  4436. return $this;
  4437. }
  4438. /**
  4439. * @return Collection<int, User>
  4440. */
  4441. public function getChildren(): Collection
  4442. {
  4443. return $this->children;
  4444. }
  4445. /**
  4446. * @param User|null $child
  4447. *
  4448. * @return $this
  4449. */
  4450. public function addChild(?User $child): User
  4451. {
  4452. if ($child && !$this->children->contains($child)) {
  4453. $this->children[] = $child;
  4454. $child->addParent($this);
  4455. }
  4456. return $this;
  4457. }
  4458. /**
  4459. * @param User|null $parent
  4460. *
  4461. * @return $this
  4462. */
  4463. public function addParent(?User $parent): User
  4464. {
  4465. if ($parent && !$this->parents->contains($parent)) {
  4466. $this->parents[] = $parent;
  4467. $parent->addChild($this);
  4468. }
  4469. return $this;
  4470. }
  4471. public function removeParent(User $parent): User
  4472. {
  4473. if ($this->parents->removeElement($parent)) {
  4474. $parent->removeChild($this);
  4475. $this->removeParent($parent);
  4476. }
  4477. return $this;
  4478. }
  4479. public function removeChild(User $child): User
  4480. {
  4481. $this->children->removeElement($child);
  4482. return $this;
  4483. }
  4484. /**
  4485. * @return Collection<int, Message>
  4486. */
  4487. public function getSenderMessages(): Collection
  4488. {
  4489. return $this->senderMessages;
  4490. }
  4491. public function addSenderMessage(Message $senderMessage): User
  4492. {
  4493. if (!$this->senderMessages->contains($senderMessage)) {
  4494. $this->senderMessages[] = $senderMessage;
  4495. $senderMessage->setSender($this);
  4496. }
  4497. return $this;
  4498. }
  4499. public function removeSenderMessage(Message $senderMessage): User
  4500. {
  4501. if ($this->senderMessages->removeElement($senderMessage)) {
  4502. // set the owning side to null (unless already changed)
  4503. if ($senderMessage->getSender() === $this) {
  4504. $senderMessage->setSender(null);
  4505. }
  4506. }
  4507. return $this;
  4508. }
  4509. /**
  4510. * @return Collection<int, Message>
  4511. */
  4512. public function getReceiverMessages(): Collection
  4513. {
  4514. return $this->receiverMessages;
  4515. }
  4516. public function addReceiverMessage(Message $receiverMessage): User
  4517. {
  4518. if (!$this->receiverMessages->contains($receiverMessage)) {
  4519. $this->receiverMessages[] = $receiverMessage;
  4520. $receiverMessage->setReceiver($this);
  4521. }
  4522. return $this;
  4523. }
  4524. public function removeReceiverMessage(Message $receiverMessage): User
  4525. {
  4526. if ($this->receiverMessages->removeElement($receiverMessage)) {
  4527. // set the owning side to null (unless already changed)
  4528. if ($receiverMessage->getReceiver() === $this) {
  4529. $receiverMessage->setReceiver(null);
  4530. }
  4531. }
  4532. return $this;
  4533. }
  4534. public function getRequestRegistration(): ?RequestRegistration
  4535. {
  4536. return $this->requestRegistration;
  4537. }
  4538. public function setRequestRegistration(RequestRegistration $requestRegistration): User
  4539. {
  4540. // set the owning side of the relation if necessary
  4541. if ($requestRegistration->getUser() !== $this) {
  4542. $requestRegistration->setUser($this);
  4543. }
  4544. $this->requestRegistration = $requestRegistration;
  4545. return $this;
  4546. }
  4547. /**
  4548. * @return Collection<int, RequestRegistration>
  4549. */
  4550. public function getRequestRegistrationsToValidate(): Collection
  4551. {
  4552. return $this->requestRegistrationsToValidate;
  4553. }
  4554. public function addRequestRegistrationsToValidate(RequestRegistration $requestRegistrationsToValidate): User
  4555. {
  4556. if (!$this->requestRegistrationsToValidate->contains($requestRegistrationsToValidate)) {
  4557. $this->requestRegistrationsToValidate[] = $requestRegistrationsToValidate;
  4558. $requestRegistrationsToValidate->setReferent($this);
  4559. }
  4560. return $this;
  4561. }
  4562. public function removeRequestRegistrationsToValidate(RequestRegistration $requestRegistrationsToValidate): User
  4563. {
  4564. if ($this->requestRegistrationsToValidate->removeElement($requestRegistrationsToValidate)) {
  4565. // set the owning side to null (unless already changed)
  4566. if ($requestRegistrationsToValidate->getReferent() === $this) {
  4567. $requestRegistrationsToValidate->setReferent(null);
  4568. }
  4569. }
  4570. return $this;
  4571. }
  4572. /**
  4573. * @return Collection<int, CustomProductOrder>
  4574. */
  4575. public function getCustomProductOrders(): Collection
  4576. {
  4577. return $this->customProductOrders;
  4578. }
  4579. public function addCustomProductOrder(CustomProductOrder $customProductOrder): User
  4580. {
  4581. if (!$this->customProductOrders->contains($customProductOrder)) {
  4582. $this->customProductOrders->add($customProductOrder);
  4583. $user = $customProductOrder->getUser();
  4584. if ($user) {
  4585. $user->removeCustomProductOrder($customProductOrder);
  4586. }
  4587. $customProductOrder->setUser($this);
  4588. }
  4589. return $this;
  4590. }
  4591. public function removeCustomProductOrder(CustomProductOrder $customProductOrder): User
  4592. {
  4593. if ($this->customProductOrders->removeElement($customProductOrder)) {
  4594. // set the owning side to null (unless already changed)
  4595. if ($customProductOrder->getUser() === $this) {
  4596. $customProductOrder->setUser(null);
  4597. }
  4598. }
  4599. return $this;
  4600. }
  4601. public function removeCustomProduct(CustomProduct $customProduct): User
  4602. {
  4603. if ($this->customProducts->removeElement($customProduct)) {
  4604. // set the owning side to null (unless already changed)
  4605. if ($customProduct->getCreatedBy() === $this) {
  4606. $customProduct->setCreatedBy(null);
  4607. }
  4608. }
  4609. return $this;
  4610. }
  4611. public function getSubscription()
  4612. {
  4613. return $this->subscription;
  4614. }
  4615. public function setSubscription(UserSubscription $subscription): User
  4616. {
  4617. // set the owning side of the relation if necessary
  4618. if ($subscription->getUser() !== $this) {
  4619. $subscription->setUser($this);
  4620. }
  4621. $this->subscription = $subscription;
  4622. return $this;
  4623. }
  4624. /**
  4625. * @return Collection<int, UserExtension>
  4626. */
  4627. public function getExtensions(): Collection
  4628. {
  4629. return $this->extensions;
  4630. }
  4631. public function removeExtension(UserExtension $extension): User
  4632. {
  4633. if ($this->extensions->removeElement($extension)) {
  4634. // set the owning side to null (unless already changed)
  4635. if ($extension->getUser() === $this) {
  4636. $extension->setUser(null);
  4637. }
  4638. }
  4639. return $this;
  4640. }
  4641. /**
  4642. * @return Collection<int, CustomProduct>
  4643. */
  4644. public function getCustomProducts(): Collection
  4645. {
  4646. return $this->customProducts;
  4647. }
  4648. public function addCustomProduct(CustomProduct $customProduct): User
  4649. {
  4650. if (!$this->customProducts->contains($customProduct)) {
  4651. $this->customProducts[] = $customProduct;
  4652. $customProduct->setCreatedBy($this);
  4653. }
  4654. return $this;
  4655. }
  4656. public function getCalculatedPoints(): ?string
  4657. {
  4658. return $this->calculatedPoints;
  4659. }
  4660. public function setCalculatedPoints(?string $calculatedPoints): User
  4661. {
  4662. $this->calculatedPoints = $calculatedPoints;
  4663. return $this;
  4664. }
  4665. public function getAvatar()
  4666. {
  4667. return $this->avatar;
  4668. }
  4669. public function setAvatar($avatar): User
  4670. {
  4671. $this->avatar = $avatar;
  4672. return $this;
  4673. }
  4674. public function getAvatarFile(): ?File
  4675. {
  4676. return $this->avatarFile;
  4677. }
  4678. /**
  4679. * @param File|UploadedFile|null $avatarFile
  4680. */
  4681. public function setAvatarFile(?File $avatarFile = null): void
  4682. {
  4683. $this->avatarFile = $avatarFile;
  4684. if (null !== $avatarFile) {
  4685. $this->updatedAt = new DateTime();
  4686. }
  4687. }
  4688. public function getLogo()
  4689. {
  4690. return $this->logo;
  4691. }
  4692. public function setLogo($logo): User
  4693. {
  4694. $this->logo = $logo;
  4695. return $this;
  4696. }
  4697. public function getLogoFile(): ?File
  4698. {
  4699. return $this->logoFile;
  4700. }
  4701. public function setLogoFile(?File $logoFile = null): User
  4702. {
  4703. $this->logoFile = $logoFile;
  4704. if (null !== $logoFile) {
  4705. $this->updatedAt = new DateTime();
  4706. }
  4707. return $this;
  4708. }
  4709. /**
  4710. * @return Collection<int, PointOfSale>
  4711. */
  4712. public function getManagedPointOfSales(): Collection
  4713. {
  4714. return $this->managedPointOfSales;
  4715. }
  4716. public function addManagedPointOfSale(PointOfSale $managedPointOfSale): User
  4717. {
  4718. if (!$this->managedPointOfSales->contains($managedPointOfSale)) {
  4719. $this->managedPointOfSales[] = $managedPointOfSale;
  4720. $managedPointOfSale->addManager($this);
  4721. }
  4722. return $this;
  4723. }
  4724. public function removeManagedPointOfSale(PointOfSale $managedPointOfSale): User
  4725. {
  4726. if ($this->managedPointOfSales->removeElement($managedPointOfSale)) {
  4727. $managedPointOfSale->removeManager($this);
  4728. }
  4729. return $this;
  4730. }
  4731. public function isManagerOfPointOfSale(?PointOfSale $pointOfSale = null): bool
  4732. {
  4733. if ($pointOfSale) {
  4734. return $this->managedPointOfSales->contains($pointOfSale);
  4735. }
  4736. return !$this->managedPointOfSales->isEmpty();
  4737. }
  4738. /**
  4739. * @return Collection<int, Parameter>
  4740. */
  4741. public function getRelatedParameters(): Collection
  4742. {
  4743. return $this->relatedParameters;
  4744. }
  4745. public function addRelatedParameter(Parameter $relatedParameter): User
  4746. {
  4747. if (!$this->relatedParameters->contains($relatedParameter)) {
  4748. $this->relatedParameters[] = $relatedParameter;
  4749. $relatedParameter->setUserRelated($this);
  4750. }
  4751. return $this;
  4752. }
  4753. public function removeRelatedParameter(Parameter $relatedParameter): User
  4754. {
  4755. if ($this->relatedParameters->removeElement($relatedParameter)) {
  4756. // set the owning side to null (unless already changed)
  4757. if ($relatedParameter->getUserRelated() === $this) {
  4758. $relatedParameter->setUserRelated(null);
  4759. }
  4760. }
  4761. return $this;
  4762. }
  4763. public function getCompanyLegalStatus(): ?string
  4764. {
  4765. return $this->companyLegalStatus;
  4766. }
  4767. public function setCompanyLegalStatus(?string $companyLegalStatus): User
  4768. {
  4769. $this->companyLegalStatus = $companyLegalStatus;
  4770. return $this;
  4771. }
  4772. /**
  4773. * @return Collection<int, PointOfSale>
  4774. */
  4775. public function getCreatedPointOfSales(): Collection
  4776. {
  4777. return $this->createdPointOfSales;
  4778. }
  4779. public function addCreatedPointOfSale(PointOfSale $createdPointOfSale): User
  4780. {
  4781. if (!$this->createdPointOfSales->contains($createdPointOfSale)) {
  4782. $this->createdPointOfSales[] = $createdPointOfSale;
  4783. $createdPointOfSale->setCreatedBy($this);
  4784. }
  4785. return $this;
  4786. }
  4787. public function removeCreatedPointOfSale(PointOfSale $createdPointOfSale): User
  4788. {
  4789. if ($this->createdPointOfSales->removeElement($createdPointOfSale)) {
  4790. // set the owning side to null (unless already changed)
  4791. if ($createdPointOfSale->getCreatedBy() === $this) {
  4792. $createdPointOfSale->setCreatedBy(null);
  4793. }
  4794. }
  4795. return $this;
  4796. }
  4797. /**
  4798. * Serializer\VirtualProperty()
  4799. * @Serializer\SerializedName("count_created_point_of_sales")
  4800. *
  4801. * @return int
  4802. * @Expose()
  4803. * @Groups ({"export_user_datatable", "export_admin_datatable", "user"})
  4804. */
  4805. public function countCreatedPointOfSales(): int
  4806. {
  4807. return $this->createdPointOfSales->count();
  4808. }
  4809. public function getOwnerObjectiveTargets(): Collection
  4810. {
  4811. return $this->ownerObjectiveTargets;
  4812. }
  4813. public function addOwnerObjectiveTarget(ObjectiveTarget $ownerObjectiveTarget): User
  4814. {
  4815. if (!$this->ownerObjectiveTargets->contains($ownerObjectiveTarget)) {
  4816. $this->ownerObjectiveTargets[] = $ownerObjectiveTarget;
  4817. $ownerObjectiveTarget->setOwner($this);
  4818. }
  4819. return $this;
  4820. }
  4821. public function removeOwnerObjectiveTarget(ObjectiveTarget $ownerObjectiveTarget): User
  4822. {
  4823. if ($this->ownerObjectiveTargets->removeElement($ownerObjectiveTarget)) {
  4824. // set the owning side to null (unless already changed)
  4825. if ($ownerObjectiveTarget->getOwner() === $this) {
  4826. $ownerObjectiveTarget->setOwner(null);
  4827. }
  4828. }
  4829. return $this;
  4830. }
  4831. /**
  4832. * @return Collection<int, ObjectiveTarget>
  4833. */
  4834. public function getObjectiveTargets(): Collection
  4835. {
  4836. return $this->objectiveTargets;
  4837. }
  4838. public function addObjectiveTarget(ObjectiveTarget $objectiveTarget): self
  4839. {
  4840. if (!$this->objectiveTargets->contains($objectiveTarget)) {
  4841. $this->objectiveTargets[] = $objectiveTarget;
  4842. }
  4843. return $this;
  4844. }
  4845. public function removeObjectiveTarget(ObjectiveTarget $objectiveTarget): self
  4846. {
  4847. $this->objectiveTargets->removeElement($objectiveTarget);
  4848. return $this;
  4849. }
  4850. public function getFonction(): ?string
  4851. {
  4852. return $this->fonction;
  4853. }
  4854. public function setFonction(?string $fonction): User
  4855. {
  4856. $this->fonction = $fonction;
  4857. return $this;
  4858. }
  4859. public function getResponsableRegate(): ?Regate
  4860. {
  4861. return $this->responsableRegate;
  4862. }
  4863. public function setResponsableRegate(?Regate $responsableRegate): User
  4864. {
  4865. $previousRegate = $this->responsableRegate;
  4866. $this->responsableRegate = $responsableRegate;
  4867. $this->setCanOrder(
  4868. $responsableRegate !== null && $this->getEmail() !== null && !$this->isFakeUser()
  4869. );
  4870. if ($previousRegate !== null && $previousRegate !== $responsableRegate
  4871. && $previousRegate->getResponsable() === $this) {
  4872. $previousRegate->setResponsable(null);
  4873. }
  4874. if ($responsableRegate !== null && $responsableRegate->getResponsable() !== $this) {
  4875. $responsableRegate->setResponsable($this);
  4876. }
  4877. return $this;
  4878. }
  4879. public function getRegistrationDocument(): ?string
  4880. {
  4881. return $this->registrationDocument;
  4882. }
  4883. public function setRegistrationDocument(?string $registrationDocument): User
  4884. {
  4885. $this->registrationDocument = $registrationDocument;
  4886. return $this;
  4887. }
  4888. public function getRegistrationDocumentFile(): ?File
  4889. {
  4890. return $this->registrationDocumentFile;
  4891. }
  4892. public function setRegistrationDocumentFile(?File $registrationDocumentFile = null): User
  4893. {
  4894. $this->registrationDocumentFile = $registrationDocumentFile;
  4895. if (null !== $registrationDocumentFile) {
  4896. $this->updatedAt = new DateTime();
  4897. }
  4898. return $this;
  4899. }
  4900. public function getIdeaBoxAnswers(): ArrayCollection
  4901. {
  4902. return $this->ideaBoxAnswers;
  4903. }
  4904. public function setIdeaBoxAnswers(ArrayCollection $ideaBoxAnswers): void
  4905. {
  4906. $this->ideaBoxAnswers = $ideaBoxAnswers;
  4907. }
  4908. public function getIdeaBoxRatings(): Collection
  4909. {
  4910. return $this->ideaBoxRatings;
  4911. }
  4912. public function addIdeaBoxRating(IdeaBoxRating $ideaBoxRating): User
  4913. {
  4914. if (!$this->ideaBoxRatings->contains($ideaBoxRating)) {
  4915. $this->ideaBoxRatings[] = $ideaBoxRating;
  4916. $ideaBoxRating->setUser($this);
  4917. }
  4918. return $this;
  4919. }
  4920. public function removeIdeaBoxRating(IdeaBoxRating $ideaBoxRating): User
  4921. {
  4922. if ($this->ideaBoxRatings->removeElement($ideaBoxRating)) {
  4923. // set the owning side to null (unless already changed)
  4924. if ($ideaBoxRating->getUser() === $this) {
  4925. $ideaBoxRating->setUser(null);
  4926. }
  4927. }
  4928. return $this;
  4929. }
  4930. public function getIdeaBoxRecipients(): Collection
  4931. {
  4932. return $this->ideaBoxRecipients;
  4933. }
  4934. public function addIdeaBoxRecipient(IdeaBoxRecipient $ideaBoxRecipient): User
  4935. {
  4936. if (!$this->ideaBoxRecipients->contains($ideaBoxRecipient)) {
  4937. $this->ideaBoxRecipients[] = $ideaBoxRecipient;
  4938. $ideaBoxRecipient->setUser($this);
  4939. }
  4940. return $this;
  4941. }
  4942. public function removeIdeaBoxRecipient(IdeaBoxRecipient $ideaBoxRecipient): User
  4943. {
  4944. if ($this->ideaBoxRecipients->removeElement($ideaBoxRecipient)) {
  4945. // set the owning side to null (unless already changed)
  4946. if ($ideaBoxRecipient->getUser() === $this) {
  4947. $ideaBoxRecipient->setUser(null);
  4948. }
  4949. }
  4950. return $this;
  4951. }
  4952. public function getOldStatus(): ?string
  4953. {
  4954. return $this->oldStatus;
  4955. }
  4956. public function setOldStatus(?string $oldStatus): User
  4957. {
  4958. $this->oldStatus = $oldStatus;
  4959. return $this;
  4960. }
  4961. public function getDisabledAt(): ?DateTimeInterface
  4962. {
  4963. return $this->disabledAt;
  4964. }
  4965. public function setDisabledAt(?DateTimeInterface $disabledAt): User
  4966. {
  4967. $this->disabledAt = $disabledAt;
  4968. return $this;
  4969. }
  4970. public function getArchiveReason(): ?string
  4971. {
  4972. return $this->archiveReason;
  4973. }
  4974. public function setArchiveReason(?string $archiveReason): User
  4975. {
  4976. $this->archiveReason = $archiveReason;
  4977. return $this;
  4978. }
  4979. public function getUnsubscribeReason(): ?string
  4980. {
  4981. return $this->unsubscribeReason;
  4982. }
  4983. public function setUnsubscribeReason(?string $unsubscribeReason): User
  4984. {
  4985. $this->unsubscribeReason = $unsubscribeReason;
  4986. return $this;
  4987. }
  4988. /**
  4989. * @return Collection<int, ActionLog>
  4990. */
  4991. public function getActionLogs(): Collection
  4992. {
  4993. return $this->actionLogs;
  4994. }
  4995. public function addActionLog(ActionLog $ActionLog): User
  4996. {
  4997. if (!$this->actionLogs->contains($ActionLog)) {
  4998. $this->actionLogs[] = $ActionLog;
  4999. $ActionLog->setUser($this);
  5000. }
  5001. return $this;
  5002. }
  5003. public function removeActionLog(ActionLog $ActionLog): User
  5004. {
  5005. if ($this->actionLogs->removeElement($ActionLog)) {
  5006. // set the owning side to null (unless already changed)
  5007. if ($ActionLog->getUser() === $this) {
  5008. $ActionLog->setUser(null);
  5009. }
  5010. }
  5011. return $this;
  5012. }
  5013. public function getFailedAttempts(): int
  5014. {
  5015. return $this->failedAttempts;
  5016. }
  5017. public function setFailedAttempts(int $failedAttempts): User
  5018. {
  5019. $this->failedAttempts = $failedAttempts;
  5020. return $this;
  5021. }
  5022. public function getLastFailedAttempt()
  5023. {
  5024. return $this->lastFailedAttempt;
  5025. }
  5026. public function setLastFailedAttempt($lastFailedAttempt): User
  5027. {
  5028. $this->lastFailedAttempt = $lastFailedAttempt;
  5029. return $this;
  5030. }
  5031. public function getPasswordUpdatedAt(): ?DateTimeInterface
  5032. {
  5033. return $this->passwordUpdatedAt;
  5034. }
  5035. public function setPasswordUpdatedAt(?DateTimeInterface $passwordUpdatedAt): User
  5036. {
  5037. $this->passwordUpdatedAt = $passwordUpdatedAt;
  5038. return $this;
  5039. }
  5040. public function getBirthPlace(): ?string
  5041. {
  5042. return $this->birthPlace;
  5043. }
  5044. public function setBirthPlace(?string $birthPlace): User
  5045. {
  5046. $this->birthPlace = $birthPlace;
  5047. return $this;
  5048. }
  5049. public function getQuizUserAnswers()
  5050. {
  5051. return $this->quizUserAnswers;
  5052. }
  5053. public function setQuizUserAnswers($quizUserAnswers): void
  5054. {
  5055. $this->quizUserAnswers = $quizUserAnswers;
  5056. }
  5057. public function getPasswordHistories(): Collection
  5058. {
  5059. return $this->passwordHistories;
  5060. }
  5061. public function addPasswordHistory(PasswordHistory $passwordHistory): User
  5062. {
  5063. if (!$this->passwordHistories->contains($passwordHistory)) {
  5064. $this->passwordHistories[] = $passwordHistory;
  5065. $passwordHistory->setUser($this);
  5066. }
  5067. return $this;
  5068. }
  5069. public function removePasswordHistory(PasswordHistory $passwordHistory): User
  5070. {
  5071. if ($this->passwordHistories->removeElement($passwordHistory)) {
  5072. // set the owning side to null (unless already changed)
  5073. if ($passwordHistory->getUser() === $this) {
  5074. $passwordHistory->setUser(null);
  5075. }
  5076. }
  5077. return $this;
  5078. }
  5079. public function getLastActivity(): ?DateTimeInterface
  5080. {
  5081. return $this->lastActivity;
  5082. }
  5083. public function setLastActivity(?DateTimeInterface $lastActivity): User
  5084. {
  5085. $this->lastActivity = $lastActivity;
  5086. return $this;
  5087. }
  5088. public function getUserFavorites(): ArrayCollection
  5089. {
  5090. return $this->userFavorites;
  5091. }
  5092. public function setUserFavorites(ArrayCollection $userFavorites): User
  5093. {
  5094. $this->userFavorites = $userFavorites;
  5095. return $this;
  5096. }
  5097. /**
  5098. * Serializer\VirtualProperty()
  5099. * @SerializedName("count_current_highlight_sale_result")
  5100. *
  5101. * @return int
  5102. * @Expose()
  5103. * @Groups ({
  5104. * "default",
  5105. * "user:count_current_highlight_sale_result",
  5106. * "user:list", "user:item", "user:post", "cdp", "user","email", "user_citroentf",
  5107. * "export_order_datatable",
  5108. * "user_bussiness_result",
  5109. * })
  5110. */
  5111. public function getCurrentHighlightSaleResult(): int
  5112. {
  5113. $ubr = $this->userBusinessResults->filter(function (UserBusinessResult $ubr) {
  5114. return $ubr->getHighlight() === null;
  5115. });
  5116. $result = 0;
  5117. /** @var UserBusinessResult $item */
  5118. foreach ($ubr as $item) {
  5119. $result += $item->getSale();
  5120. }
  5121. return $result;
  5122. }
  5123. public function getAccountId(): ?string
  5124. {
  5125. return $this->accountId;
  5126. }
  5127. public function setAccountId(?string $accountId): self
  5128. {
  5129. $this->accountId = $accountId;
  5130. return $this;
  5131. }
  5132. public function getUniqueSlugConstraint(): ?string
  5133. {
  5134. return $this->uniqueSlugConstraint;
  5135. }
  5136. public function setUniqueSlugConstraint(?string $uniqueSlugConstraint): self
  5137. {
  5138. $this->uniqueSlugConstraint = $uniqueSlugConstraint;
  5139. return $this;
  5140. }
  5141. public function isFakeUser(): bool
  5142. {
  5143. return !str_contains($this->getEmail(), '@');
  5144. }
  5145. public function isMainUser(): bool
  5146. {
  5147. return $this === $this->mainAccountUser;
  5148. }
  5149. /**
  5150. * @return Collection<int, BoosterProductResult>
  5151. */
  5152. public function getBoosterProductResults(): Collection
  5153. {
  5154. return $this->boosterProductResults;
  5155. }
  5156. public function addBoosterProductResult(BoosterProductResult $boosterProductResult): self
  5157. {
  5158. if (!$this->boosterProductResults->contains($boosterProductResult)) {
  5159. $this->boosterProductResults[] = $boosterProductResult;
  5160. $boosterProductResult->setUser($this);
  5161. }
  5162. return $this;
  5163. }
  5164. public function removeBoosterProductResult(BoosterProductResult $boosterProductResult): self
  5165. {
  5166. if ($this->boosterProductResults->removeElement($boosterProductResult)) {
  5167. // set the owning side to null (unless already changed)
  5168. if ($boosterProductResult->getUser() === $this) {
  5169. $boosterProductResult->setUser(null);
  5170. }
  5171. }
  5172. return $this;
  5173. }
  5174. /**
  5175. * @return Collection<int, PushSubscription>
  5176. */
  5177. public function getPushSubscriptions(): Collection
  5178. {
  5179. return $this->pushSubscriptions;
  5180. }
  5181. public function addPushSubscription(PushSubscription $pushSubscription): self
  5182. {
  5183. if (!$this->pushSubscriptions->contains($pushSubscription)) {
  5184. $this->pushSubscriptions[] = $pushSubscription;
  5185. $pushSubscription->setUser($this);
  5186. }
  5187. return $this;
  5188. }
  5189. public function removePushSubscription(PushSubscription $pushSubscription): self
  5190. {
  5191. if ($this->pushSubscriptions->removeElement($pushSubscription)) {
  5192. // set the owning side to null (unless already changed)
  5193. if ($pushSubscription->getUser() === $this) {
  5194. $pushSubscription->setUser(null);
  5195. }
  5196. }
  5197. return $this;
  5198. }
  5199. /**
  5200. * @param bool $getLevel
  5201. *
  5202. * @return bool|int
  5203. * @throws DateInvalidOperationException
  5204. */
  5205. public function isActive(bool $getLevel = false)
  5206. {
  5207. $status = $this->getStatus();
  5208. if (!$getLevel && $this->isFakeUser()) {
  5209. return false;
  5210. }
  5211. $inactiveStatus = [
  5212. self::STATUS_ARCHIVED,
  5213. self::STATUS_DELETED,
  5214. self::STATUS_UNSUBSCRIBED,
  5215. self::STATUS_REGISTER_PENDING,
  5216. self::STATUS_DISABLED,
  5217. self::STATUS_ADMIN_PENDING
  5218. ];
  5219. if (!$getLevel && in_array($status, $inactiveStatus)) {
  5220. return false;
  5221. }
  5222. $twoYears = (new DateTime())->sub(new DateInterval('P2Y'));
  5223. $cguStatus = [self::STATUS_CGU_PENDING, self::STATUS_CGU_DECLINED];
  5224. if (!$getLevel && in_array($status, $cguStatus) && (!$this->lastLogin || $twoYears > $this->lastLogin)) {
  5225. return false;
  5226. }
  5227. if ($getLevel) {
  5228. $oneYear = (new DateTime())->sub(new DateInterval('P1Y'));
  5229. $sixMonths = (new DateTime())->sub(new DateInterval('P6M'));
  5230. $lvl = 15;
  5231. if ($this->isFakeUser()) {
  5232. $lvl = 0;
  5233. } // si l'utilisateur possède un email, son score sera au moins de 1
  5234. else {
  5235. switch ($status) {
  5236. case self::STATUS_DELETED:
  5237. $lvl -= 11;
  5238. break;
  5239. case self::STATUS_ARCHIVED:
  5240. $lvl -= 10;
  5241. break;
  5242. case self::STATUS_DISABLED:
  5243. case self::STATUS_UNSUBSCRIBED:
  5244. $lvl -= 9;
  5245. break;
  5246. case self::STATUS_REGISTER_PENDING:
  5247. $lvl -= 8;
  5248. break;
  5249. case self::STATUS_CGU_DECLINED:
  5250. $lvl -= 7;
  5251. break;
  5252. case self::STATUS_CGU_PENDING:
  5253. $lvl -= 6;
  5254. break;
  5255. case self::STATUS_ENABLED:
  5256. break;
  5257. default:
  5258. $lvl -= 5;
  5259. }
  5260. if (!$this->lastLogin || $twoYears > $this->lastLogin) {
  5261. $lvl -= 3;
  5262. } elseif ($oneYear > $this->lastLogin) {
  5263. $lvl -= 2;
  5264. } elseif ($sixMonths > $this->lastLogin) {
  5265. $lvl -= 1;
  5266. }
  5267. }
  5268. return $lvl;
  5269. }
  5270. return true;
  5271. }
  5272. /** Jeton chiffré ; utiliser OidcTokenStorage pour obtenir la valeur déchiffrée. */
  5273. #[Ignore]
  5274. public function getOidcAccessToken(): ?string
  5275. {
  5276. return $this->oidcAccessToken;
  5277. }
  5278. public function setOidcAccessToken(?string $oidcAccessToken): self
  5279. {
  5280. $this->oidcAccessToken = $oidcAccessToken;
  5281. return $this;
  5282. }
  5283. /** Jeton chiffré ; utiliser OidcTokenStorage pour obtenir la valeur déchiffrée. */
  5284. #[Ignore]
  5285. public function getOidcRefreshToken(): ?string
  5286. {
  5287. return $this->oidcRefreshToken;
  5288. }
  5289. public function setOidcRefreshToken(?string $oidcRefreshToken): self
  5290. {
  5291. $this->oidcRefreshToken = $oidcRefreshToken;
  5292. return $this;
  5293. }
  5294. #[Ignore]
  5295. public function getOidcTokenExpiresAt(): ?DateTimeImmutable
  5296. {
  5297. return $this->oidcTokenExpiresAt;
  5298. }
  5299. public function setOidcTokenExpiresAt(?DateTimeImmutable $oidcTokenExpiresAt): self
  5300. {
  5301. $this->oidcTokenExpiresAt = $oidcTokenExpiresAt;
  5302. return $this;
  5303. }
  5304. #[Ignore]
  5305. public function getOidcTokenConfiguration(): ?string
  5306. {
  5307. return $this->oidcTokenConfiguration;
  5308. }
  5309. public function setOidcTokenConfiguration(?string $oidcTokenConfiguration): self
  5310. {
  5311. $this->oidcTokenConfiguration = $oidcTokenConfiguration;
  5312. return $this;
  5313. }
  5314. #[Ignore]
  5315. public function getOidcApiUsername(): ?string
  5316. {
  5317. return $this->oidcApiUsername;
  5318. }
  5319. public function setOidcApiUsername(?string $oidcApiUsername): self
  5320. {
  5321. $this->oidcApiUsername = $oidcApiUsername;
  5322. return $this;
  5323. }
  5324. public function getAzureId(): ?string
  5325. {
  5326. return $this->azureId;
  5327. }
  5328. public function setAzureId(?string $azureId): self
  5329. {
  5330. $this->azureId = $azureId;
  5331. return $this;
  5332. }
  5333. /**
  5334. * @return Collection<int, AzureGroup>
  5335. */
  5336. public function getAzureGroups(): Collection
  5337. {
  5338. return $this->azureGroups;
  5339. }
  5340. public function addAzureGroup(AzureGroup $azureGroup): self
  5341. {
  5342. if (!$this->azureGroups->contains($azureGroup)) {
  5343. $this->azureGroups[] = $azureGroup;
  5344. $azureGroup->addMember($this);
  5345. }
  5346. return $this;
  5347. }
  5348. public function removeAzureGroup(AzureGroup $azureGroup): self
  5349. {
  5350. if ($this->azureGroups->removeElement($azureGroup)) {
  5351. $azureGroup->removeMember($this);
  5352. }
  5353. return $this;
  5354. }
  5355. public function getActivatedBy(): ?self
  5356. {
  5357. return $this->activatedBy;
  5358. }
  5359. public function setActivatedBy(?self $activatedBy): self
  5360. {
  5361. $this->activatedBy = $activatedBy;
  5362. return $this;
  5363. }
  5364. /**
  5365. * @return Collection<int, QuotaProductUser>
  5366. */
  5367. public function getQuotaProductUsers(): Collection
  5368. {
  5369. return $this->quotaProductUsers;
  5370. }
  5371. public function addQuotaProductUser(QuotaProductUser $quotaProductUser): self
  5372. {
  5373. if (!$this->quotaProductUsers->contains($quotaProductUser)) {
  5374. $this->quotaProductUsers[] = $quotaProductUser;
  5375. $quotaProductUser->setUser($this);
  5376. }
  5377. return $this;
  5378. }
  5379. public function removeQuotaProductUser(QuotaProductUser $quotaProductUser): self
  5380. {
  5381. if ($this->quotaProductUsers->removeElement($quotaProductUser)) {
  5382. // set the owning side to null (unless already changed)
  5383. if ($quotaProductUser->getUser() === $this) {
  5384. $quotaProductUser->setUser(null);
  5385. }
  5386. }
  5387. return $this;
  5388. }
  5389. /**
  5390. * @return Collection<int, QuotasProductFree>
  5391. */
  5392. public function getQuotaProductFrees(): Collection
  5393. {
  5394. return $this->quotaProductFrees;
  5395. }
  5396. public function addQuotaProductFree(QuotasProductFree $quotaProductFree): self
  5397. {
  5398. if (!$this->quotaProductFrees->contains($quotaProductFree)) {
  5399. $this->quotaProductFrees->add($quotaProductFree);
  5400. $quotaProductFree->addUser($this);
  5401. }
  5402. return $this;
  5403. }
  5404. public function removeQuotaProductFree(QuotasProductFree $quotaProductFree): self
  5405. {
  5406. if ($this->quotaProductFrees->removeElement($quotaProductFree)) {
  5407. $quotaProductFree->removeUser($this);
  5408. }
  5409. return $this;
  5410. }
  5411. /**
  5412. * @return Collection<int, RankingScore>
  5413. */
  5414. public function getRankingScores(): Collection
  5415. {
  5416. return $this->rankingScores;
  5417. }
  5418. public function addRankingScore(RankingScore $rankingScore): self
  5419. {
  5420. if (!$this->rankingScores->contains($rankingScore)) {
  5421. $this->rankingScores->add($rankingScore);
  5422. $user = $rankingScore->getUser();
  5423. if ($user) {
  5424. $user->removeRankingScore($rankingScore);
  5425. }
  5426. $rankingScore->setUser($this);
  5427. }
  5428. return $this;
  5429. }
  5430. public function removeRankingScore(RankingScore $rankingScore): self
  5431. {
  5432. if ($this->rankingScores->removeElement($rankingScore)) {
  5433. // set the owning side to null (unless already changed)
  5434. if ($rankingScore->getUser() === $this) {
  5435. $rankingScore->setUser(null);
  5436. }
  5437. }
  5438. return $this;
  5439. }
  5440. /**
  5441. * @return Collection<int, ObjectiveTargetScore>
  5442. */
  5443. public function getObjectiveTargetScores(): Collection
  5444. {
  5445. return $this->objectiveTargetScores;
  5446. }
  5447. public function addObjectiveTargetScore(ObjectiveTargetScore $objectiveTargetScore): self
  5448. {
  5449. if (!$this->objectiveTargetScores->contains($objectiveTargetScore)) {
  5450. $this->objectiveTargetScores->add($objectiveTargetScore);
  5451. $objectiveTargetScore->setUser($this);
  5452. }
  5453. return $this;
  5454. }
  5455. public function removeObjectiveTargetScore(ObjectiveTargetScore $objectiveTargetScore): self
  5456. {
  5457. if ($this->objectiveTargetScores->removeElement($objectiveTargetScore)) {
  5458. // set the owning side to null (unless already changed)
  5459. if ($objectiveTargetScore->getUser() === $this) {
  5460. $objectiveTargetScore->setUser(null);
  5461. }
  5462. }
  5463. return $this;
  5464. }
  5465. public function getEmailUnsubscribeReason(): ?string
  5466. {
  5467. return $this->emailUnsubscribeReason;
  5468. }
  5469. public function setEmailUnsubscribeReason(?string $emailUnsubscribeReason): User
  5470. {
  5471. $this->emailUnsubscribeReason = $emailUnsubscribeReason;
  5472. return $this;
  5473. }
  5474. public function getEmailUnsubscribedAt(): ?DateTimeInterface
  5475. {
  5476. return $this->emailUnsubscribedAt;
  5477. }
  5478. public function setEmailUnsubscribedAt(?DateTimeInterface $emailUnsubscribedAt): User
  5479. {
  5480. $this->emailUnsubscribedAt = $emailUnsubscribedAt;
  5481. return $this;
  5482. }
  5483. /**
  5484. * @throws Exception
  5485. */
  5486. public function hasOrder(): bool
  5487. {
  5488. return $this->getPointTransactions(PointTransactionType::ORDER)->count() > 0;
  5489. }
  5490. public static function createFromArray(array $data): self
  5491. {
  5492. $user = new self();
  5493. $user->setEmail($data['email'] ?? null);
  5494. $user->setCivility($data['civility'] ?? null);
  5495. $user->setFirstName($data['firstName'] ?? null);
  5496. $user->setLastName($data['lastName'] ?? null);
  5497. $user->setPhone($data['phone'] ?? null);
  5498. $user->setMobile($data['mobile'] ?? null);
  5499. $user->setCreatedAt(new DateTime());
  5500. $user->setPassword(password_hash($data['password'] ?? '', PASSWORD_DEFAULT));
  5501. $user->setRoles($data['password'] ?? ['ROLE_USER']);
  5502. return $user;
  5503. }
  5504. }