src/Entity/SmsSpotHitCampaign.php line 19

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