src/Entity/SmsSpotHitCampaign.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Interfaces\SpotHitCampaignInterface;
  4. use App\Traits\DateTrait;
  5. use DateTime;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use InvalidArgumentException;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. /**
  11. * @ORM\Entity
  12. *
  13. * @ORM\Table(uniqueConstraints={
  14. * @ORM\UniqueConstraint(columns={"nom"})
  15. * })
  16. * @UniqueEntity(fields={"nom"})
  17. */
  18. class SmsSpotHitCampaign implements SpotHitCampaignInterface
  19. {
  20. use DateTrait;
  21. const DESTINATAIRE_TYPE_DATAS = 'datas';
  22. const DESTINATAIRE_TYPE_ALL = 'all';
  23. const DESTINATAIRE_TYPE_GROUPE = 'groupe';
  24. const CAMPAIGN_TYPE_COMMUNICATION = 'communication';
  25. const CAMPAIGN_TYPE_RESET_PASSWORD = 'reset_password';
  26. const CAMPAIGN_TYPE_WELCOME = 'welcome_sms';
  27. const CAMPAIGN_TYPE_ACCEPT_CGU_FIRST = 'accept_cgu_first';
  28. /**
  29. * @var int|null
  30. *
  31. * @ORM\Column(type="integer")
  32. * @ORM\Id
  33. * @ORM\GeneratedValue(strategy="AUTO")
  34. */
  35. protected ?int $id = null;
  36. /**
  37. * @var integer|null
  38. *
  39. * @ORM\Column(type="integer", nullable=true)
  40. *
  41. * @Assert\GreaterThanOrEqual(value = 1)
  42. * @Assert\Type(type="integer")
  43. */
  44. protected ?int $idSpotHit = null;
  45. /**
  46. * @var string
  47. *
  48. * @ORM\Column(type="string")
  49. *
  50. * @Assert\NotBlank(groups={"new", "Default"})
  51. * @Assert\Type(type="string", groups={"new", "Default"})
  52. *
  53. */
  54. protected string $message = '';
  55. /**
  56. * @var array|string[]
  57. *
  58. * @ORM\Column(type="json")
  59. *
  60. * @Assert\NotBlank
  61. */
  62. protected array $destinataires = [];
  63. /**
  64. * @var array|string[]
  65. *
  66. * @ORM\Column(type="json")
  67. */
  68. protected array $stats = [];
  69. /**
  70. * @var string|null
  71. *
  72. * Si vide, l'expéditeur du SMS sera un numéro court à 5 chiffres auxquels les destinataires peuvent répondre
  73. * L’expéditeur doit comporter un minimum de 3 caractères pour être personnalisé et ne doit pas commencer par plus de 3 chiffres consécutifs avant la première lettre.
  74. *
  75. * @ORM\Column(type="string", length=11, nullable=true)
  76. *
  77. * @Assert\Length(min=3, max=11)
  78. * @Assert\Regex("/^(?![0-9]{3})\w+$/")
  79. * @Assert\Type(type="string")
  80. */
  81. protected ?string $expediteur = null;
  82. /**
  83. * @var DateTime|null
  84. *
  85. * @ORM\Column(type="datetime", nullable=true)
  86. *
  87. * @Assert\Type(type="\DateTime")
  88. */
  89. protected ?DateTime $date = null;
  90. /**
  91. * @var boolean
  92. *
  93. * Si true, autorise l'envoi de SMS supérieur à 160 caractères
  94. *
  95. * @ORM\Column(type="boolean")
  96. * @Assert\Type(type="bool")
  97. */
  98. protected bool $smslong = true;
  99. /**
  100. * @var integer|null
  101. *
  102. * Permet de vérifier la taille du SMS long envoyé. Doit correspondre au nombre de caractères su sms, Si le compteur spothit indique un nombre différent, le message sera rejeté.
  103. *
  104. * @ORM\Column(type="integer", nullable=true)
  105. *
  106. * @Assert\GreaterThanOrEqual(value = 1)
  107. * @Assert\Type(type="integer")
  108. */
  109. protected ?int $smslongnbr = null;
  110. /**
  111. * @var boolean
  112. *
  113. * Si true, tronque automatiquement le message à 160 caractères.
  114. *
  115. * @ORM\Column(type="boolean")
  116. * @Assert\Type(type="bool")
  117. */
  118. protected bool $tronque = false;
  119. /**
  120. * @var string|null
  121. *
  122. * "auto" => UTF8, "ucs2" => unicode
  123. *
  124. * @ORM\Column(type="string", nullable=true)
  125. *
  126. * @Assert\Choice({"auto", "ucs2", null})
  127. * @Assert\Type(type="string")
  128. */
  129. protected ?string $encodage = null;
  130. /**
  131. * @var string|null
  132. *
  133. * nom de la campagne
  134. *
  135. * @ORM\Column(type="string", nullable=true)
  136. *
  137. * @Assert\Length(min=1, max=50, groups={"new", "Default"})
  138. * @Assert\Type(type="string", groups={"new", "Default"})
  139. */
  140. protected ?string $nom = null;
  141. /**
  142. * @var string|null
  143. *
  144. * "all" => sélection de tous les contacts du compte
  145. * "groupe" => sélection de tous les contacts des groupes fournis dans le champ « destinataires »
  146. * "datas" => permet d'ajouter des données personnalisées aux « destinataires » pour les utiliser dans votre message (exemple : "Bonjour {nom} {prenom}")
  147. * il faut que le champ « destinataires » soit un tableau de cette forme : ["+33600000001" => ["nom" => "Nom 1", "prenom" => "Prénom 1"], "+33600000002" => ["nom" => "Nom 2", "prenom" => "Prénom 2"] ...]
  148. *
  149. * @ORM\Column(type="string", nullable=true)
  150. *
  151. * @Assert\Choice({"all", "groupe", "datas", null})
  152. * @Assert\Type(type="string")
  153. */
  154. protected ?string $destinatairesType = null;
  155. /**
  156. * @var string|null
  157. *
  158. * Adresse URL de votre serveur pour la réception en "push" des statuts après l'envoi.
  159. * Vous devez déjà avoir une adresse paramétrée sur votre compte pour activer les retours "push".
  160. * Si ce paramètre est renseigné, cette URL sera appelée pour cet envoi sinon l'adresse du compte est utilisée.
  161. *
  162. * @ORM\Column(type="string", nullable=true)
  163. *
  164. * @Assert\Type(type="string")
  165. */
  166. protected ?string $url = null;
  167. /**
  168. * @var DateTime|null
  169. *
  170. * Obligatoire pour l'envoi échelonné
  171. *
  172. * @ORM\Column(type="datetime", nullable=true)
  173. *
  174. * @Assert\Type(type="\DateTime")
  175. */
  176. protected ?DateTime $dateDebut = null;
  177. /**
  178. * @var DateTime|null
  179. *
  180. * Obligatoire pour l'envoi échelonné
  181. *
  182. * @ORM\Column(type="datetime", nullable=true)
  183. *
  184. * @Assert\Type(type="\DateTime")
  185. */
  186. protected ?DateTime $dateFin = null;
  187. /**
  188. * @var array|int[]|null
  189. *
  190. * Obligatoire pour l'envoi échelonné
  191. * Heure(s) d'envois (du lundi au samedi de 8h00 à 22h00 hors jours fériés)
  192. * Tableau avec 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19
  193. * La campagne sera fractionnée proportionnellement aux nombres de créneaux entre le jour et l'heure de démarrage, et le jour et l'heure de fin souhaitée.
  194. *
  195. * @ORM\Column(type="json", nullable=true)
  196. *
  197. * @Assert\All({
  198. * @Assert\Type(type="int"),
  199. * })
  200. *
  201. * @Assert\NotBlank(allowNull=true)
  202. */
  203. protected ?array $creneaux = null;
  204. /**
  205. * @var integer|null
  206. *
  207. * Obligatoire pour l'envoi échelonné
  208. * 1,2,3,4 ou 6
  209. * Nombre d'envoi(s) par heure
  210. *
  211. * @ORM\Column(type="integer", nullable=true)
  212. *
  213. * @Assert\Choice({1, 2, 3, 4, 6})
  214. * @Assert\Type(type="integer")
  215. */
  216. protected ?int $creneauxHeure = null;
  217. /**
  218. * @var integer|null
  219. *
  220. * Obligatoire pour l'envoi échelonné
  221. * Tableau avec 1,2,3,4,5,6
  222. * Jours d'envoi (1 représentant lundi). Pas d'envoi le dimanche.
  223. *
  224. * @ORM\Column(type="integer", nullable=true)
  225. *
  226. * @Assert\Length(min=1, max=6)
  227. * @Assert\Type(type="integer")
  228. */
  229. protected ?int $jours = null;
  230. /**
  231. * @var string|null
  232. *
  233. * Fuseau horaire
  234. *
  235. * @ORM\Column(type="string", nullable=true)
  236. *
  237. * @Assert\Type(type="string")
  238. */
  239. protected ?string $timezone = null;
  240. /**
  241. * @var ContactList|null
  242. *
  243. * @ORM\ManyToOne(targetEntity="ContactList", inversedBy="smsSpotHitCampaigns")
  244. * @ORM\JoinColumn(nullable=true)
  245. *
  246. * @Assert\Valid(groups={"new", "Default"})
  247. * @Assert\Type(type="App\Entity\ContactList", groups={"new", "Default"})
  248. */
  249. protected ?ContactList $contactList = null;
  250. /**
  251. * @var string
  252. *
  253. * @ORM\Column(type="string", nullable=false)
  254. *
  255. * @Assert\Choice({"pending", "processing", "sent", "error", "break"})
  256. * @Assert\Type(type="string")
  257. */
  258. protected string $statut = self::STATUT_EN_ATTENTE;
  259. /**
  260. * @var string|null
  261. *
  262. * Si statut "en_erreur", il s'agit du message en question
  263. *
  264. * @ORM\Column(type="string", nullable=true)
  265. *
  266. * @Assert\Type(type="string")
  267. */
  268. protected ?string $erreur = null;
  269. /**
  270. * @var string
  271. *
  272. * Type de campagne (Campagne créée via inscription d'un user / reset password etc)
  273. *
  274. * @ORM\Column(type="string", nullable=false)
  275. * @Assert\Type(type="string")
  276. */
  277. protected string $campaignType = '';
  278. /**
  279. * @return int|null
  280. */
  281. public function getId(): ?int
  282. {
  283. return $this->id;
  284. }
  285. /**
  286. * @return string
  287. */
  288. public function getMessage(): string
  289. {
  290. return $this->message;
  291. }
  292. /**
  293. * @param string $message
  294. * @param bool $addStop
  295. *
  296. * @return $this
  297. */
  298. public function setMessage(string $message, bool $addStop = true): SmsSpotHitCampaign
  299. {
  300. $this->message = trim($message);
  301. if ($addStop) {
  302. $this->addStop();
  303. }
  304. return $this;
  305. }
  306. /**
  307. * @return $this
  308. */
  309. public function addStop(): SmsSpotHitCampaign
  310. {
  311. if (strpos($this->message, 'STOP au 36200') === false) {
  312. $this->message .= ' \n STOP au 36200';
  313. }
  314. return $this;
  315. }
  316. /**
  317. * @return $this
  318. */
  319. public function removeStop(): SmsSpotHitCampaign
  320. {
  321. $this->message = trim(str_replace('\n STOP au 36200', '', $this->message));
  322. return $this;
  323. }
  324. /**
  325. * @param bool $useType
  326. *
  327. * @return array|string[]|string
  328. */
  329. public function getDestinataires(bool $useType = false)
  330. {
  331. $type = $this->getDestinatairesType();
  332. if (!$useType || $type === self::DESTINATAIRE_TYPE_DATAS) {
  333. return $this->destinataires;
  334. }
  335. if (!$type || $type === self::DESTINATAIRE_TYPE_GROUPE) {
  336. return implode(",", $this->destinataires);
  337. }
  338. return [];
  339. }
  340. /**
  341. * @return int
  342. */
  343. public function getNbDestinataires(): int
  344. {
  345. return count($this->getDestinataires());
  346. }
  347. /**
  348. * @return int
  349. */
  350. public function getNbUsersList(): int
  351. {
  352. return $this->contactList ? $this->contactList->getUsers()->count() : 0;
  353. }
  354. /**
  355. * @param array $destinataires
  356. *
  357. * @return $this
  358. */
  359. public function setDestinataires(array $destinataires, bool $throwException = true): SmsSpotHitCampaign
  360. {
  361. if ($this->destinatairesType === self::DESTINATAIRE_TYPE_ALL) {
  362. if (!empty($destinataires) && $throwException) {
  363. throw new InvalidArgumentException(
  364. "Si le type est '" . self::DESTINATAIRE_TYPE_ALL . "', il n'y a pas de destinataires à renseigner"
  365. );
  366. }
  367. $this->destinataires = [];
  368. } else {
  369. foreach ($destinataires as $key => $val) {
  370. if ($this->destinatairesType === self::DESTINATAIRE_TYPE_DATAS) {
  371. $numero = $key;
  372. $datas = $val;
  373. if (!is_array($val)) {
  374. if ($throwException) {
  375. throw new InvalidArgumentException(
  376. "Si le type est '" . self::DESTINATAIRE_TYPE_DATAS . "', le tableau doit est multidimensionnel avec en clef le numero et en valeurs un tableau de datas"
  377. );
  378. }
  379. $numero = $val;
  380. $datas = [];
  381. }
  382. } // groupe ou null
  383. else {
  384. $numero = $val;
  385. $datas = null;
  386. if (is_array($val)) {
  387. if ($throwException) {
  388. throw new InvalidArgumentException(
  389. "Si le type n'est pas '" . self::DESTINATAIRE_TYPE_DATAS . "', le tableau doit seulement contenir des numeros ou des groupes"
  390. );
  391. }
  392. $numero = $key;
  393. }
  394. }
  395. $this->addDestinataire($numero, $datas, $throwException);
  396. }
  397. }
  398. return $this;
  399. }
  400. /**
  401. * @param string $numero ou groupe
  402. * @param array|null $datas à utiliser seulement si le type de destinataire est "datas"
  403. * @param bool $throwException
  404. *
  405. * @return $this
  406. */
  407. public function addDestinataire(
  408. string $numero,
  409. ?array $datas = null,
  410. bool $throwException = true
  411. ): SmsSpotHitCampaign {
  412. $baseNumero = $numero;
  413. switch ($this->destinatairesType) {
  414. case self::DESTINATAIRE_TYPE_DATAS:
  415. if ($datas === null) {
  416. if ($throwException) {
  417. throw new InvalidArgumentException(
  418. "Si le type est '" . self::DESTINATAIRE_TYPE_DATAS . "', datas doit être un tableau de variables ou vide"
  419. );
  420. }
  421. $datas = [];
  422. }
  423. break;
  424. case self::DESTINATAIRE_TYPE_ALL:
  425. if ($throwException) {
  426. throw new InvalidArgumentException(
  427. "Si le type est '" . self::DESTINATAIRE_TYPE_ALL . "', il est impossible de rajouter des destinataires"
  428. );
  429. }
  430. return $this;
  431. default:
  432. if ($datas !== null) {
  433. if ($throwException) {
  434. throw new InvalidArgumentException(
  435. "Si le type n'est pas '" . self::DESTINATAIRE_TYPE_DATAS . "', datas doit être null"
  436. );
  437. }
  438. $datas = null;
  439. }
  440. }
  441. if ($this->destinatairesType !== self::DESTINATAIRE_TYPE_GROUPE) {
  442. if (!$numero = $this->checkMobile($numero)) {
  443. if ($throwException) {
  444. throw new InvalidArgumentException("Le numero '$baseNumero' est invalide");
  445. }
  446. return $this;
  447. }
  448. }
  449. if (!$datas) {
  450. if (!in_array($numero, $this->destinataires)) {
  451. $this->destinataires[] = $numero;
  452. }
  453. } else {
  454. if (!isset($this->destinataires[$numero])) {
  455. $this->destinataires[$numero] = $datas;
  456. }
  457. }
  458. return $this;
  459. }
  460. /**
  461. * @param string|null $numero
  462. *
  463. * @return string|false
  464. */
  465. static function checkMobile(?string $numero)
  466. {
  467. if (!$numero) {
  468. return false;
  469. }
  470. $numero = trim($numero);
  471. $numero = preg_replace('/[^0-9+]/', '', $numero);
  472. if (!preg_match('/\+[1-9]\d{10,14}/', $numero)) {
  473. $numero = str_replace('+', '', $numero);
  474. while (substr($numero, 0, 1) === '0') {
  475. $numero = substr($numero, 1, strlen($numero) - 1);
  476. }
  477. $numero = '+33' . $numero;
  478. }
  479. if (!preg_match('/\+[1-9]\d{10,14}/', $numero)) {
  480. return false;
  481. }
  482. //validation mobile FR
  483. if (substr($numero, 0, 3) === '+33' && (strlen($numero) !== 12 || (substr($numero, 0, 4) !== '+336' && substr(
  484. $numero,
  485. 0,
  486. 4
  487. ) !== '+337'))) {
  488. return false;
  489. }
  490. return $numero;
  491. }
  492. /**
  493. * @param string $numero
  494. *
  495. * @return $this
  496. */
  497. public function removeDestinataire(string $numero): SmsSpotHitCampaign
  498. {
  499. $numero = $this->checkMobile($numero);
  500. if (!$numero) {
  501. return $this;
  502. }
  503. if ($this->getDestinatairesType() === self::DESTINATAIRE_TYPE_DATAS) {
  504. unset($this->destinataires[$numero]);
  505. } else {
  506. $key = array_search($numero, $this->destinataires);
  507. unset($this->destinataires[$key]);
  508. }
  509. return $this;
  510. }
  511. /**
  512. * @return string|null
  513. */
  514. public function getExpediteur(): ?string
  515. {
  516. return $this->expediteur;
  517. }
  518. /**
  519. * @param string|null $expediteur
  520. *
  521. * @return $this
  522. */
  523. public function setExpediteur(?string $expediteur): SmsSpotHitCampaign
  524. {
  525. $this->expediteur = $expediteur;
  526. return $this;
  527. }
  528. /**
  529. * @return bool
  530. */
  531. public function isSmslong(): bool
  532. {
  533. return $this->smslong;
  534. }
  535. /**
  536. * @param bool $smslong
  537. *
  538. * @return $this
  539. */
  540. public function setSmslong(bool $smslong): SmsSpotHitCampaign
  541. {
  542. $this->smslong = $smslong;
  543. return $this;
  544. }
  545. /**
  546. * @return int|null
  547. */
  548. public function getSmslongnbr(): ?int
  549. {
  550. return $this->smslongnbr;
  551. }
  552. /**
  553. * @param int|null $smslongnbr
  554. *
  555. * @return $this
  556. */
  557. public function setSmslongnbr(?int $smslongnbr): SmsSpotHitCampaign
  558. {
  559. $this->smslongnbr = $smslongnbr;
  560. return $this;
  561. }
  562. /**
  563. * @return bool
  564. */
  565. public function isTronque(): bool
  566. {
  567. return $this->tronque;
  568. }
  569. /**
  570. * @param bool $tronque
  571. *
  572. * @return $this
  573. */
  574. public function setTronque(bool $tronque): SmsSpotHitCampaign
  575. {
  576. $this->tronque = $tronque;
  577. return $this;
  578. }
  579. /**
  580. * @return string|null
  581. */
  582. public function getEncodage(): ?string
  583. {
  584. return $this->encodage;
  585. }
  586. /**
  587. * @param string|null $encodage
  588. *
  589. * @return $this
  590. */
  591. public function setEncodage(?string $encodage): SmsSpotHitCampaign
  592. {
  593. $this->encodage = $encodage;
  594. return $this;
  595. }
  596. /**
  597. * @return string|null
  598. */
  599. public function getNom(): ?string
  600. {
  601. return $this->nom;
  602. }
  603. /**
  604. * @param string|null $nom
  605. *
  606. * @return $this
  607. */
  608. public function setNom(?string $nom): SmsSpotHitCampaign
  609. {
  610. $this->nom = $nom;
  611. return $this;
  612. }
  613. /**
  614. * @return string|null
  615. */
  616. public function getDestinatairesType(): ?string
  617. {
  618. return $this->destinatairesType;
  619. }
  620. /**
  621. * Le contenu de "destinataires" actuel doit être adapté en fonction du type, en principe il faut définir le type avant "destinataires"
  622. *
  623. * @param string|null $destinatairesType
  624. *
  625. * @return $this
  626. */
  627. public function setDestinatairesType(?string $destinatairesType): SmsSpotHitCampaign
  628. {
  629. if ($destinatairesType !== $this->destinatairesType && !empty($this->destinataires)) {
  630. $destinataires = [];
  631. if ($destinatairesType === self::DESTINATAIRE_TYPE_ALL) {
  632. $this->destinataires = [];
  633. }
  634. if (($destinatairesType === self::DESTINATAIRE_TYPE_GROUPE || !$destinatairesType) && $this->destinatairesType === self::DESTINATAIRE_TYPE_DATAS) {
  635. foreach ($this->destinataires as $numOrGroup => $datas) {
  636. $destinataires[] = $numOrGroup;
  637. }
  638. $this->destinataires = $destinataires;
  639. }
  640. if ($destinatairesType === self::DESTINATAIRE_TYPE_DATAS) {
  641. foreach ($this->destinataires as $numOrGroup) {
  642. $destinataires[$numOrGroup] = [];
  643. }
  644. $this->destinataires = $destinataires;
  645. }
  646. }
  647. $this->destinatairesType = $destinatairesType;
  648. return $this;
  649. }
  650. /**
  651. * @return string|null
  652. */
  653. public function getUrl(): ?string
  654. {
  655. return $this->url;
  656. }
  657. /**
  658. * @param string|null $url
  659. *
  660. * @return $this
  661. */
  662. public function setUrl(?string $url): SmsSpotHitCampaign
  663. {
  664. $this->url = $url;
  665. return $this;
  666. }
  667. /**
  668. * @return array|int[]|null
  669. */
  670. public function getCreneaux(): ?array
  671. {
  672. return $this->creneaux;
  673. }
  674. /**
  675. * @param array|null $creneaux
  676. *
  677. * @return $this
  678. */
  679. public function setCreneaux(?array $creneaux): SmsSpotHitCampaign
  680. {
  681. $this->creneaux = $creneaux;
  682. return $this;
  683. }
  684. /**
  685. * @return int|null
  686. */
  687. public function getCreneauxHeure(): ?int
  688. {
  689. return $this->creneauxHeure;
  690. }
  691. /**
  692. * @param int|null $creneauxHeure
  693. *
  694. * @return $this
  695. */
  696. public function setCreneauxHeure(?int $creneauxHeure): SmsSpotHitCampaign
  697. {
  698. $this->creneauxHeure = $creneauxHeure;
  699. return $this;
  700. }
  701. /**
  702. * @return int|null
  703. */
  704. public function getJours(): ?int
  705. {
  706. return $this->jours;
  707. }
  708. /**
  709. * @param int|null $jours
  710. *
  711. * @return $this
  712. */
  713. public function setJours(?int $jours): SmsSpotHitCampaign
  714. {
  715. $this->jours = $jours;
  716. return $this;
  717. }
  718. /**
  719. * @return string|null
  720. */
  721. public function getTimezone(): ?string
  722. {
  723. return $this->timezone;
  724. }
  725. /**
  726. * @param string|null $timezone
  727. *
  728. * @return $this
  729. */
  730. public function setTimezone(?string $timezone): SmsSpotHitCampaign
  731. {
  732. $this->timezone = $timezone;
  733. return $this;
  734. }
  735. /**
  736. * @return DateTime|null
  737. */
  738. public function getDate(): ?DateTime
  739. {
  740. return $this->date;
  741. }
  742. /**
  743. * @param DateTime|null $date
  744. *
  745. * @return $this
  746. */
  747. public function setDate(?DateTime $date): SmsSpotHitCampaign
  748. {
  749. $this->date = $date;
  750. return $this;
  751. }
  752. /**
  753. * @return DateTime|null
  754. */
  755. public function getDateDebut(): ?DateTime
  756. {
  757. return $this->dateDebut;
  758. }
  759. /**
  760. * @param DateTime|null $dateDebut
  761. *
  762. * @return $this
  763. */
  764. public function setDateDebut(?DateTime $dateDebut): SmsSpotHitCampaign
  765. {
  766. $this->dateDebut = $dateDebut;
  767. return $this;
  768. }
  769. /**
  770. * @return DateTime|null
  771. */
  772. public function getDateFin(): ?DateTime
  773. {
  774. return $this->dateFin;
  775. }
  776. /**
  777. * @param DateTime|null $dateFin
  778. *
  779. * @return $this
  780. */
  781. public function setDateFin(?DateTime $dateFin): SmsSpotHitCampaign
  782. {
  783. $this->dateFin = $dateFin;
  784. return $this;
  785. }
  786. /**
  787. * @return int|null
  788. */
  789. public function getIdSpotHit(): ?int
  790. {
  791. return $this->idSpotHit;
  792. }
  793. /**
  794. * @param int|null $idSpotHit
  795. *
  796. * @return $this
  797. */
  798. public function setIdSpotHit(?int $idSpotHit): SmsSpotHitCampaign
  799. {
  800. $this->idSpotHit = $idSpotHit;
  801. return $this;
  802. }
  803. /**
  804. * @return string
  805. */
  806. public function getProduit(): string
  807. {
  808. return SpotHitCampaignInterface::PRODUIT_SMS;
  809. }
  810. /**
  811. * @return ContactList|null
  812. */
  813. public function getContactList(): ?ContactList
  814. {
  815. return $this->contactList;
  816. }
  817. /**
  818. * @param ContactList|null $contactList
  819. *
  820. * @return $this
  821. */
  822. public function setContactList(?ContactList $contactList): SmsSpotHitCampaign
  823. {
  824. if ($this->contactList === $contactList) {
  825. return $this;
  826. }
  827. if ($this->contactList !== null) {
  828. $this->contactList->removeSmsSpotHitCampaign($this);
  829. }
  830. $this->contactList = $contactList;
  831. if ($contactList !== null && !$contactList->getSmsSpotHitCampaigns()->contains($this)) {
  832. $contactList->addSmsSpotHitCampaign($this);
  833. }
  834. return $this;
  835. }
  836. /**
  837. * @return string
  838. */
  839. public function getStatut(): string
  840. {
  841. return $this->statut;
  842. }
  843. /**
  844. * @param string $statut
  845. *
  846. * @return $this
  847. */
  848. public function setStatut(string $statut): SmsSpotHitCampaign
  849. {
  850. $this->statut = $statut;
  851. return $this;
  852. }
  853. /**
  854. * @return string|null
  855. */
  856. public function getErreur(): ?string
  857. {
  858. return $this->erreur;
  859. }
  860. /**
  861. * @param string|null $erreur
  862. *
  863. * @return $this
  864. */
  865. public function setErreur(?string $erreur): SmsSpotHitCampaign
  866. {
  867. $this->erreur = $erreur;
  868. return $this;
  869. }
  870. /**
  871. * @return array|string[]|string
  872. */
  873. public function getStats(bool $onlyDatas = false, bool $onlyLabels = false, bool $jsonEncode = false)
  874. {
  875. $array = $this->stats;
  876. if ($onlyDatas) {
  877. $array = [];
  878. foreach ($this->stats as $label => $data) {
  879. $array[] = $data;
  880. }
  881. }
  882. if ($onlyLabels) {
  883. $array = [];
  884. foreach ($this->stats as $label => $data) {
  885. $array[] = $label;
  886. }
  887. }
  888. return $jsonEncode ? json_encode($array) : $array;
  889. }
  890. /**
  891. * @param array $stats
  892. *
  893. * @return $this
  894. */
  895. public function setStats(array $stats): SmsSpotHitCampaign
  896. {
  897. $this->stats = $stats;
  898. return $this;
  899. }
  900. /**
  901. * @return bool
  902. */
  903. public function isEditable(): bool
  904. {
  905. return $this->statut === self::STATUT_EN_ATTENTE || $this->statut === self::STATUT_EN_PAUSE;
  906. }
  907. /**
  908. * @return bool
  909. */
  910. public function isEnvoyee(): bool
  911. {
  912. return $this->statut !== self::STATUT_EN_ERREUR && !$this->isEditable();
  913. }
  914. /**
  915. * @return bool
  916. */
  917. public function isTerminee(): bool
  918. {
  919. return $this->statut === self::STATUT_TERMINEE;
  920. }
  921. /**
  922. * @return bool
  923. */
  924. public function isErreur(): bool
  925. {
  926. return $this->statut === self::STATUT_EN_ERREUR;
  927. }
  928. /**
  929. * @return string
  930. */
  931. public function getCampaignType(): string
  932. {
  933. return $this->campaignType;
  934. }
  935. /**
  936. * @param string $campaignType
  937. *
  938. * @return $this
  939. */
  940. public function setCampaignType(string $campaignType): SmsSpotHitCampaign
  941. {
  942. $this->campaignType = $campaignType;
  943. return $this;
  944. }
  945. }