src/Entity/Abo/AboBestellung.php line 5

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Abo;
  3. class AboBestellung
  4. {
  5. public const string TYP_PRINT_ABO = 'PRINT_ABO';
  6. public const string TYP_EPAPER_ABO = 'EPAPER_ABO';
  7. public const string TYP_KOMBI_ABO = 'KOMBI_ABO';
  8. public const string TYP_ADD_EPAPER_ABO = 'ADD_EPAPER_ABO';
  9. public const string GLOB_ORDER_SEND_MSG = "Vielen Dank für Ihre Bestellung.\nNach der Bearbeitung erhalten Sie eine entsprechende Rückmeldung per E-Mail.";
  10. private static array $textData = [
  11. self::TYP_PRINT_ABO => ['titel' => 'Print-Abo bestellen', 'order_send_msg' => self::GLOB_ORDER_SEND_MSG],
  12. self::TYP_EPAPER_ABO => ['titel' => 'E-Paper-Abo bestellen', 'order_send_msg' => self::GLOB_ORDER_SEND_MSG],
  13. self::TYP_KOMBI_ABO => ['titel' => 'Standard-Abo bestellen', 'order_send_msg' => self::GLOB_ORDER_SEND_MSG],
  14. self::TYP_ADD_EPAPER_ABO => ['titel' => 'E-Paper zum laufenden Abo hinzufügen', 'order_send_msg' => self::GLOB_ORDER_SEND_MSG],
  15. ];
  16. // Formular Felder
  17. public $aboOption;
  18. public $vorname;
  19. public $nachname;
  20. public $firma;
  21. public $strasse;
  22. public $plz;
  23. public $ort;
  24. public $land = 'Schweiz';
  25. public $telefon;
  26. public $email;
  27. public $mitteilung;
  28. public $useRechnungsKontakt;
  29. public $rechnungVorname;
  30. public $rechnungNachname;
  31. public $rechnungFirma;
  32. public $rechnungStrasse;
  33. public $rechnungPlz;
  34. public $rechnungOrt;
  35. public $rechnungLand = 'Schweiz';
  36. public $emailEpaperLogin;
  37. protected function __construct(
  38. private $typeId,
  39. private readonly array $aboOptions,
  40. private $useEpaperLoginFields = false
  41. )
  42. {
  43. $this->aboOption = $this->aboOptions ? $this->aboOptions[0] : []; // die options stammen vom externen content, damit diese variabel bearbeitet werden können
  44. }
  45. public static function newPrintAbo(array $aboOptions): AboBestellung
  46. {
  47. return new self(self::TYP_PRINT_ABO, $aboOptions);
  48. }
  49. public static function newEPaperAbo(array $aboOptions): AboBestellung
  50. {
  51. return new self(self::TYP_EPAPER_ABO, $aboOptions, true);
  52. }
  53. public static function newKombiAbo(array $aboOptions): AboBestellung
  54. {
  55. return new self(self::TYP_KOMBI_ABO, $aboOptions, true);
  56. }
  57. public static function newAddEPaperAbo(array $aboOptions): AboBestellung
  58. {
  59. return new self(self::TYP_ADD_EPAPER_ABO, $aboOptions, true);
  60. }
  61. public function formAboOptions(): array
  62. {
  63. return array_combine($this->aboOptions, $this->aboOptions);
  64. }
  65. /**
  66. * Hilfsfunktion um die gespeicherten Options aus dem Content Textfeld in ein Array umzuwandeln.
  67. */
  68. public static function transformTextconfigToOptionsArray($optionString): array
  69. {
  70. $options = [];
  71. $data = explode("\n", (string) $optionString);
  72. foreach ($data as $option) {
  73. $option = trim($option);
  74. if (mb_strlen($option) > 0) {
  75. $options[] = $option;
  76. }
  77. }
  78. return $options;
  79. }
  80. public function titel(): string
  81. {
  82. return self::$textData[$this->typeId]['titel'];
  83. }
  84. public function orderTitel(): string
  85. {
  86. return $this->titel();
  87. }
  88. public function orderSendMessage(): string
  89. {
  90. return self::$textData[$this->typeId]['order_send_msg'];
  91. }
  92. public function useEpaperLoginFields(): bool
  93. {
  94. return (bool) $this->useEpaperLoginFields;
  95. }
  96. /**
  97. * Zusammenfassung Bestellung für Mailbody.
  98. */
  99. public function mailBodyBestellung(): string
  100. {
  101. $body = '<br>
  102. Neue <b>"'.$this->titel().'"</b> Bestellung vom '.date('d.m.Y H:i').' ab www.urnerwochenblatt.ch<br>'
  103. ;
  104. if ($this->aboOption) {
  105. $body .= '<br>
  106. <br>
  107. <b>Abo-Option</b><br>'
  108. .$this->aboOption.'<br>'
  109. ;
  110. }
  111. $body .= '<br>
  112. <table>
  113. <tr>
  114. <td colspan="2"><br><b>Ihre Angaben/Zahlungsadresse</b><br></td>
  115. </tr>
  116. <tr>
  117. <td>Vor-/Nachname</td><td>'.$this->vorname.' '.$this->nachname.'</td>
  118. </tr>
  119. <tr>
  120. <td>Firma</td><td>'.$this->firma.'</td>
  121. </tr>
  122. <tr>
  123. <td>Strasse</td><td>'.$this->strasse.'</td>
  124. </tr>
  125. <tr>
  126. <td>PLZ/Ort</td><td>'.$this->plz.' '.$this->ort.'</td>
  127. </tr>
  128. <tr>
  129. <td>Land</td><td>'.$this->land.'</td>
  130. </tr>
  131. <tr>
  132. <td>Telefon</td><td>'.$this->telefon.'</td>
  133. </tr>
  134. <tr>
  135. <td>E-Mail</td><td>'.$this->email.'</td>
  136. </tr>
  137. </table>'
  138. ;
  139. // Dies ist die Lieferadresse im Formular abweichende Lieferadresse
  140. if ($this->useRechnungsKontakt) {
  141. $body .= '<br>
  142. <table>
  143. <tr>
  144. <td colspan="2"><br><b>Lieferadresse</b><br></td>
  145. </tr>
  146. <tr>
  147. <td>Vor-/Nachname</td><td>'.$this->rechnungVorname.' '.$this->rechnungNachname.'</td>
  148. </tr>
  149. <tr>
  150. <td>Firma</td><td>'.$this->rechnungFirma.'</td>
  151. </tr>
  152. <tr>
  153. <td>Strasse</td><td>'.$this->rechnungStrasse.'</td>
  154. </tr>
  155. <tr>
  156. <td>PLZ/Ort</td><td>'.$this->rechnungPlz.' '.$this->rechnungOrt.'</td>
  157. </tr>
  158. <tr>
  159. <td>Land</td><td>'.$this->rechnungLand.'</td>
  160. </tr>
  161. </table>'
  162. ;
  163. }
  164. if ($this->emailEpaperLogin) {
  165. $body .= '<br><br>
  166. <b>E-Paper Login</b><br>'
  167. .$this->emailEpaperLogin.'<br>';
  168. }
  169. if ($this->mitteilung) {
  170. $body .= '<br><br>
  171. <b>Mitteilung</b><br>'
  172. .str_replace("\n", '<br>', strip_tags((string) $this->mitteilung)).'<br>';
  173. }
  174. return $body;
  175. }
  176. public function mailSubjectBestellung(): string
  177. {
  178. return 'Neue Bestellung: '.$this->titel();
  179. }
  180. }