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) $this->addStop();
  302. return $this;
  303. }
  304. /**
  305. * @return $this
  306. */
  307. public function addStop(): SmsSpotHitCampaign
  308. {
  309. if(strpos($this->message, 'STOP au 36200') === false) $this->message .= ' \n STOP au 36200';
  310. return $this;
  311. }
  312. /**
  313. * @return $this
  314. */
  315. public function removeStop(): SmsSpotHitCampaign
  316. {
  317. $this->message = trim(str_replace('\n STOP au 36200', '', $this->message));
  318. return $this;
  319. }
  320. /**
  321. * @param bool $useType
  322. *
  323. * @return array|string[]|string
  324. */
  325. public function getDestinataires(bool $useType = false)
  326. {
  327. $type = $this->getDestinatairesType();
  328. if(!$useType || $type === self::DESTINATAIRE_TYPE_DATAS) return $this->destinataires;
  329. if(!$type || $type === self::DESTINATAIRE_TYPE_GROUPE) return implode(",", $this->destinataires);
  330. return [];
  331. }
  332. /**
  333. * @return int
  334. */
  335. public function getNbDestinataires(): int
  336. {
  337. return count($this->getDestinataires());
  338. }
  339. /**
  340. * @return int
  341. */
  342. public function getNbUsersList(): int
  343. {
  344. return $this->contactList ? $this->contactList->getUsers()->count() : 0;
  345. }
  346. /**
  347. * @param array $destinataires
  348. *
  349. * @return $this
  350. */
  351. public function setDestinataires(array $destinataires, bool $throwException = true): SmsSpotHitCampaign
  352. {
  353. if($this->destinatairesType === self::DESTINATAIRE_TYPE_ALL)
  354. {
  355. if(!empty($destinataires) && $throwException) throw new InvalidArgumentException("Si le type est '" . self::DESTINATAIRE_TYPE_ALL . "', il n'y a pas de destinataires à renseigner");
  356. $this->destinataires = [];
  357. }
  358. else
  359. {
  360. foreach($destinataires as $key => $val)
  361. {
  362. if($this->destinatairesType === self::DESTINATAIRE_TYPE_DATAS)
  363. {
  364. $numero = $key;
  365. $datas = $val;
  366. if(!is_array($val))
  367. {
  368. 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");
  369. $numero = $val;
  370. $datas = [];
  371. }
  372. }
  373. // groupe ou null
  374. else
  375. {
  376. $numero = $val;
  377. $datas = null;
  378. if(is_array($val))
  379. {
  380. 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");
  381. $numero = $key;
  382. }
  383. }
  384. $this->addDestinataire($numero, $datas, $throwException);
  385. }
  386. }
  387. return $this;
  388. }
  389. /**
  390. * @param string $numero ou groupe
  391. * @param array|null $datas à utiliser seulement si le type de destinataire est "datas"
  392. * @param bool $throwException
  393. *
  394. * @return $this
  395. */
  396. public function addDestinataire(string $numero, ?array $datas = null, bool $throwException = true): SmsSpotHitCampaign
  397. {
  398. $baseNumero = $numero;
  399. switch($this->destinatairesType)
  400. {
  401. case self::DESTINATAIRE_TYPE_DATAS:
  402. if($datas === null)
  403. {
  404. if($throwException) throw new InvalidArgumentException("Si le type est '" . self::DESTINATAIRE_TYPE_DATAS . "', datas doit être un tableau de variables ou vide");
  405. $datas = [];
  406. }
  407. break;
  408. case self::DESTINATAIRE_TYPE_ALL:
  409. if($throwException) throw new InvalidArgumentException("Si le type est '" . self::DESTINATAIRE_TYPE_ALL . "', il est impossible de rajouter des destinataires");
  410. return $this;
  411. default:
  412. if($datas !== null)
  413. {
  414. if($throwException) throw new InvalidArgumentException("Si le type n'est pas '" . self::DESTINATAIRE_TYPE_DATAS . "', datas doit être null");
  415. $datas = null;
  416. }
  417. }
  418. if($this->destinatairesType !== self::DESTINATAIRE_TYPE_GROUPE)
  419. {
  420. if(!$numero = $this->checkMobile($numero))
  421. {
  422. if($throwException) throw new InvalidArgumentException("Le numero '$baseNumero' est invalide");
  423. return $this;
  424. }
  425. }
  426. if(!$datas)
  427. {
  428. if(!in_array($numero, $this->destinataires)) $this->destinataires[] = $numero;
  429. }
  430. else
  431. {
  432. if(!isset($this->destinataires[$numero])) $this->destinataires[$numero] = $datas;
  433. }
  434. return $this;
  435. }
  436. /**
  437. * @param string|null $numero
  438. *
  439. * @return string|false
  440. */
  441. static function checkMobile(?string $numero)
  442. {
  443. if(!$numero) return false;
  444. $numero = trim($numero);
  445. $numero = preg_replace('/[^0-9+]/', '', $numero);
  446. if(!preg_match('/\+[1-9]\d{10,14}/', $numero))
  447. {
  448. $numero = str_replace('+', '', $numero);
  449. while(substr($numero, 0, 1) === '0')
  450. {
  451. $numero = substr($numero, 1, strlen($numero) - 1);
  452. }
  453. $numero = '+33' . $numero;
  454. }
  455. if(!preg_match('/\+[1-9]\d{10,14}/', $numero)) return false;
  456. //validation mobile FR
  457. if(substr($numero, 0, 3) === '+33' && (strlen($numero) !== 12 || (substr($numero, 0, 4) !== '+336' && substr($numero, 0, 4) !== '+337')))
  458. {
  459. return false;
  460. }
  461. return $numero;
  462. }
  463. /**
  464. * @param string $numero
  465. *
  466. * @return $this
  467. */
  468. public function removeDestinataire(string $numero): SmsSpotHitCampaign
  469. {
  470. $numero = $this->checkMobile($numero);
  471. if(!$numero) return $this;
  472. if($this->getDestinatairesType() === self::DESTINATAIRE_TYPE_DATAS)
  473. {
  474. unset($this->destinataires[$numero]);
  475. }
  476. else
  477. {
  478. $key = array_search($numero, $this->destinataires);
  479. unset($this->destinataires[$key]);
  480. }
  481. return $this;
  482. }
  483. /**
  484. * @return string|null
  485. */
  486. public function getExpediteur(): ?string
  487. {
  488. return $this->expediteur;
  489. }
  490. /**
  491. * @param string|null $expediteur
  492. *
  493. * @return $this
  494. */
  495. public function setExpediteur(?string $expediteur): SmsSpotHitCampaign
  496. {
  497. $this->expediteur = $expediteur;
  498. return $this;
  499. }
  500. /**
  501. * @return bool
  502. */
  503. public function isSmslong(): bool
  504. {
  505. return $this->smslong;
  506. }
  507. /**
  508. * @param bool $smslong
  509. *
  510. * @return $this
  511. */
  512. public function setSmslong(bool $smslong): SmsSpotHitCampaign
  513. {
  514. $this->smslong = $smslong;
  515. return $this;
  516. }
  517. /**
  518. * @return int|null
  519. */
  520. public function getSmslongnbr(): ?int
  521. {
  522. return $this->smslongnbr;
  523. }
  524. /**
  525. * @param int|null $smslongnbr
  526. *
  527. * @return $this
  528. */
  529. public function setSmslongnbr(?int $smslongnbr): SmsSpotHitCampaign
  530. {
  531. $this->smslongnbr = $smslongnbr;
  532. return $this;
  533. }
  534. /**
  535. * @return bool
  536. */
  537. public function isTronque(): bool
  538. {
  539. return $this->tronque;
  540. }
  541. /**
  542. * @param bool $tronque
  543. *
  544. * @return $this
  545. */
  546. public function setTronque(bool $tronque): SmsSpotHitCampaign
  547. {
  548. $this->tronque = $tronque;
  549. return $this;
  550. }
  551. /**
  552. * @return string|null
  553. */
  554. public function getEncodage(): ?string
  555. {
  556. return $this->encodage;
  557. }
  558. /**
  559. * @param string|null $encodage
  560. *
  561. * @return $this
  562. */
  563. public function setEncodage(?string $encodage): SmsSpotHitCampaign
  564. {
  565. $this->encodage = $encodage;
  566. return $this;
  567. }
  568. /**
  569. * @return string|null
  570. */
  571. public function getNom(): ?string
  572. {
  573. return $this->nom;
  574. }
  575. /**
  576. * @param string|null $nom
  577. *
  578. * @return $this
  579. */
  580. public function setNom(?string $nom): SmsSpotHitCampaign
  581. {
  582. $this->nom = $nom;
  583. return $this;
  584. }
  585. /**
  586. * @return string|null
  587. */
  588. public function getDestinatairesType(): ?string
  589. {
  590. return $this->destinatairesType;
  591. }
  592. /**
  593. * Le contenu de "destinataires" actuel doit être adapté en fonction du type, en principe il faut définir le type avant "destinataires"
  594. *
  595. * @param string|null $destinatairesType
  596. *
  597. * @return $this
  598. */
  599. public function setDestinatairesType(?string $destinatairesType): SmsSpotHitCampaign
  600. {
  601. if($destinatairesType !== $this->destinatairesType && !empty($this->destinataires))
  602. {
  603. $destinataires = [];
  604. if($destinatairesType === self::DESTINATAIRE_TYPE_ALL) $this->destinataires = [];
  605. if(($destinatairesType === self::DESTINATAIRE_TYPE_GROUPE || !$destinatairesType) && $this->destinatairesType === self::DESTINATAIRE_TYPE_DATAS)
  606. {
  607. foreach($this->destinataires as $numOrGroup => $datas)
  608. {
  609. $destinataires[] = $numOrGroup;
  610. }
  611. $this->destinataires = $destinataires;
  612. }
  613. if($destinatairesType === self::DESTINATAIRE_TYPE_DATAS)
  614. {
  615. foreach($this->destinataires as $numOrGroup)
  616. {
  617. $destinataires[$numOrGroup] = [];
  618. }
  619. $this->destinataires = $destinataires;
  620. }
  621. }
  622. $this->destinatairesType = $destinatairesType;
  623. return $this;
  624. }
  625. /**
  626. * @return string|null
  627. */
  628. public function getUrl(): ?string
  629. {
  630. return $this->url;
  631. }
  632. /**
  633. * @param string|null $url
  634. *
  635. * @return $this
  636. */
  637. public function setUrl(?string $url): SmsSpotHitCampaign
  638. {
  639. $this->url = $url;
  640. return $this;
  641. }
  642. /**
  643. * @return array|int[]|null
  644. */
  645. public function getCreneaux(): ?array
  646. {
  647. return $this->creneaux;
  648. }
  649. /**
  650. * @param array|null $creneaux
  651. *
  652. * @return $this
  653. */
  654. public function setCreneaux(?array $creneaux): SmsSpotHitCampaign
  655. {
  656. $this->creneaux = $creneaux;
  657. return $this;
  658. }
  659. /**
  660. * @return int|null
  661. */
  662. public function getCreneauxHeure(): ?int
  663. {
  664. return $this->creneauxHeure;
  665. }
  666. /**
  667. * @param int|null $creneauxHeure
  668. *
  669. * @return $this
  670. */
  671. public function setCreneauxHeure(?int $creneauxHeure): SmsSpotHitCampaign
  672. {
  673. $this->creneauxHeure = $creneauxHeure;
  674. return $this;
  675. }
  676. /**
  677. * @return int|null
  678. */
  679. public function getJours(): ?int
  680. {
  681. return $this->jours;
  682. }
  683. /**
  684. * @param int|null $jours
  685. *
  686. * @return $this
  687. */
  688. public function setJours(?int $jours): SmsSpotHitCampaign
  689. {
  690. $this->jours = $jours;
  691. return $this;
  692. }
  693. /**
  694. * @return string|null
  695. */
  696. public function getTimezone(): ?string
  697. {
  698. return $this->timezone;
  699. }
  700. /**
  701. * @param string|null $timezone
  702. *
  703. * @return $this
  704. */
  705. public function setTimezone(?string $timezone): SmsSpotHitCampaign
  706. {
  707. $this->timezone = $timezone;
  708. return $this;
  709. }
  710. /**
  711. * @return DateTime|null
  712. */
  713. public function getDate(): ?DateTime
  714. {
  715. return $this->date;
  716. }
  717. /**
  718. * @param DateTime|null $date
  719. *
  720. * @return $this
  721. */
  722. public function setDate(?DateTime $date): SmsSpotHitCampaign
  723. {
  724. $this->date = $date;
  725. return $this;
  726. }
  727. /**
  728. * @return DateTime|null
  729. */
  730. public function getDateDebut(): ?DateTime
  731. {
  732. return $this->dateDebut;
  733. }
  734. /**
  735. * @param DateTime|null $dateDebut
  736. *
  737. * @return $this
  738. */
  739. public function setDateDebut(?DateTime $dateDebut): SmsSpotHitCampaign
  740. {
  741. $this->dateDebut = $dateDebut;
  742. return $this;
  743. }
  744. /**
  745. * @return DateTime|null
  746. */
  747. public function getDateFin(): ?DateTime
  748. {
  749. return $this->dateFin;
  750. }
  751. /**
  752. * @param DateTime|null $dateFin
  753. *
  754. * @return $this
  755. */
  756. public function setDateFin(?DateTime $dateFin): SmsSpotHitCampaign
  757. {
  758. $this->dateFin = $dateFin;
  759. return $this;
  760. }
  761. /**
  762. * @return int|null
  763. */
  764. public function getIdSpotHit(): ?int
  765. {
  766. return $this->idSpotHit;
  767. }
  768. /**
  769. * @param int|null $idSpotHit
  770. *
  771. * @return $this
  772. */
  773. public function setIdSpotHit(?int $idSpotHit): SmsSpotHitCampaign
  774. {
  775. $this->idSpotHit = $idSpotHit;
  776. return $this;
  777. }
  778. /**
  779. * @return string
  780. */
  781. public function getProduit(): string
  782. {
  783. return SpotHitCampaignInterface::PRODUIT_SMS;
  784. }
  785. /**
  786. * @return ContactList|null
  787. */
  788. public function getContactList(): ?ContactList
  789. {
  790. return $this->contactList;
  791. }
  792. /**
  793. * @param ContactList|null $contactList
  794. *
  795. * @return $this
  796. */
  797. public function setContactList(?ContactList $contactList): SmsSpotHitCampaign
  798. {
  799. if($this->contactList === $contactList)
  800. {
  801. return $this;
  802. }
  803. if($this->contactList !== null)
  804. {
  805. $this->contactList->removeSmsSpotHitCampaign($this);
  806. }
  807. $this->contactList = $contactList;
  808. if($contactList !== null && !$contactList->getSmsSpotHitCampaigns()->contains($this))
  809. {
  810. $contactList->addSmsSpotHitCampaign($this);
  811. }
  812. return $this;
  813. }
  814. /**
  815. * @return string
  816. */
  817. public function getStatut(): string
  818. {
  819. return $this->statut;
  820. }
  821. /**
  822. * @param string $statut
  823. *
  824. * @return $this
  825. */
  826. public function setStatut(string $statut): SmsSpotHitCampaign
  827. {
  828. $this->statut = $statut;
  829. return $this;
  830. }
  831. /**
  832. * @return string|null
  833. */
  834. public function getErreur(): ?string
  835. {
  836. return $this->erreur;
  837. }
  838. /**
  839. * @param string|null $erreur
  840. *
  841. * @return $this
  842. */
  843. public function setErreur(?string $erreur): SmsSpotHitCampaign
  844. {
  845. $this->erreur = $erreur;
  846. return $this;
  847. }
  848. /**
  849. * @return array|string[]|string
  850. */
  851. public function getStats(bool $onlyDatas = false, bool $onlyLabels = false, bool $jsonEncode = false)
  852. {
  853. $array = $this->stats;
  854. if($onlyDatas)
  855. {
  856. $array = [];
  857. foreach($this->stats as $label => $data)
  858. {
  859. $array[] = $data;
  860. }
  861. }
  862. if($onlyLabels)
  863. {
  864. $array = [];
  865. foreach($this->stats as $label => $data)
  866. {
  867. $array[] = $label;
  868. }
  869. }
  870. return $jsonEncode ? json_encode($array) : $array;
  871. }
  872. /**
  873. * @param array $stats
  874. *
  875. * @return $this
  876. */
  877. public function setStats(array $stats): SmsSpotHitCampaign
  878. {
  879. $this->stats = $stats;
  880. return $this;
  881. }
  882. /**
  883. * @return bool
  884. */
  885. public function isEditable(): bool
  886. {
  887. return $this->statut === self::STATUT_EN_ATTENTE || $this->statut === self::STATUT_EN_PAUSE;
  888. }
  889. /**
  890. * @return bool
  891. */
  892. public function isEnvoyee(): bool
  893. {
  894. return $this->statut !== self::STATUT_EN_ERREUR && !$this->isEditable();
  895. }
  896. /**
  897. * @return bool
  898. */
  899. public function isTerminee(): bool
  900. {
  901. return $this->statut === self::STATUT_TERMINEE;
  902. }
  903. /**
  904. * @return bool
  905. */
  906. public function isErreur(): bool
  907. {
  908. return $this->statut === self::STATUT_EN_ERREUR;
  909. }
  910. /**
  911. * @return string
  912. */
  913. public function getCampaignType(): string
  914. {
  915. return $this->campaignType;
  916. }
  917. /**
  918. * @param string $campaignType
  919. *
  920. * @return $this
  921. */
  922. public function setCampaignType(string $campaignType): SmsSpotHitCampaign
  923. {
  924. $this->campaignType = $campaignType;
  925. return $this;
  926. }
  927. }