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