src/Entity/Vs/Vs.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Vs;
  3. use App\Util\UrlSlug;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use IntlDateFormatter as SystemIntlDateFormatter;
  6. use Ramsey\Uuid\Uuid;
  7. use Symfony\Component\Filesystem\Filesystem;
  8. use Symfony\Component\Finder\Finder;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  11. #[ORM\HasLifecycleCallbacks]
  12. #[ORM\Entity]
  13. #[ORM\Table(name: 'vs')]
  14. class Vs
  15. {
  16. public const int MAX_WIDTH_VSIMAGE = 1024;
  17. #[ORM\Column(name: 'id', type: 'integer')]
  18. #[ORM\Id]
  19. #[ORM\GeneratedValue(strategy: 'AUTO')]
  20. private ?int $id = null;
  21. #[ORM\Column(name: 'uuid', type: 'string', length: 36)]
  22. private string $uuid;
  23. #[ORM\Column(name: 'titel', type: 'string', length: 200, unique: false, nullable: true)]
  24. #[Assert\NotBlank]
  25. private ?string $titel = null;
  26. #[ORM\Column(name: 'adresse', type: 'string', length: 200, nullable: true)]
  27. private ?string $adresse = null;
  28. #[ORM\ManyToOne(targetEntity: VsRegion::class, inversedBy: 'vss')]
  29. private ?VsRegion $region = null;
  30. #[ORM\ManyToOne(targetEntity: VsRubrik::class, inversedBy: 'vss')]
  31. #[Assert\NotBlank]
  32. private ?VsRubrik $rubrik = null;
  33. #[ORM\ManyToOne(targetEntity: VsStatus::class, inversedBy: 'vss')]
  34. private ?VsStatus $status = null;
  35. #[ORM\ManyToOne(targetEntity: VsAbo::class, inversedBy: 'vss')]
  36. #[Assert\NotBlank]
  37. private ?VsAbo $abo = null;
  38. /**
  39. * HINWEIS:
  40. * Assert/Validierung erfolgt unten über Validation Callback
  41. */
  42. #[ORM\ManyToOne(targetEntity: VsTyp::class, inversedBy: 'vss')]
  43. private ?VsTyp $typ = null;
  44. #[ORM\Column(name: 'beschreibung', type: 'text', length: 300, unique: false, nullable: true)]
  45. private ?string $beschreibung = null;
  46. #[ORM\Column(name: 'beginnzeit', type: 'time', nullable: true)]
  47. #[Assert\NotBlank]
  48. private ?\DateTimeInterface $beginnzeit = null;
  49. #[ORM\ManyToOne(targetEntity: VsBeginnAuswahl::class, inversedBy: 'vss')]
  50. private ?VsBeginnAuswahl $beginn_auswahl = null;
  51. #[ORM\Column(name: 'endzeit', type: 'time', nullable: true)]
  52. #[Assert\NotBlank]
  53. private ?\DateTimeInterface $endzeit = null;
  54. #[ORM\Column(name: 'startdatum', type: 'date', length: 20, unique: false, nullable: true)]
  55. #[Assert\NotBlank]
  56. private ?\DateTimeInterface $startdatum = null;
  57. #[ORM\Column(name: 'enddatum', type: 'date', length: 20, unique: false, nullable: true)]
  58. #[Assert\NotBlank(groups: ['dauerveranstaltung', 'ohnefixdatum'])]
  59. #[Assert\GreaterThan(propertyPath: 'startdatum', message: "Datum ungültig, dies muss ein Datum nach dem 'von Datum' sein!", groups: ['dauerveranstaltung', 'ohnefixdatum'])]
  60. private ?\DateTimeInterface $enddatum = null;
  61. #[ORM\Column(name: 'url', type: 'string', length: 200, unique: false, nullable: true)]
  62. #[Assert\Url(protocols: ['http', 'https'])]
  63. private ?string $url = null;
  64. #[ORM\Column(name: 'videolink', type: 'string', length: 250, unique: false, nullable: true)]
  65. #[Assert\Regex(
  66. pattern: '#^(https://www\.youtube\.com/watch\?v=[a-zA-Z0-9_-]+|https://vimeo\.com/\d+)$#',
  67. message: 'Ungültige URL. Erlaubte URL Format Beispiel: YouTube-Format: https://www.youtube.com/watch?v=ZtqOylLqyCU | Vimeo Format: https://vimeo.com/253989945'
  68. )]
  69. private ?string $videolink = null;
  70. #[ORM\Column(name: 'googlemaps', type: 'string', length: 600, unique: false, nullable: true)]
  71. #[Assert\Regex(
  72. pattern:"#^<iframe src=\"https://www.google.com/maps/embed.*></iframe>$#",
  73. message:"Der 'Karten einbett-Code' ist ungültig"
  74. )]
  75. private ?string $googlemaps = null;
  76. #[ORM\Column(name: 'ticketsbestellen', type: 'string', length: 200, unique: false, nullable: true)]
  77. #[Assert\Url(protocols: ['http', 'https'])]
  78. private ?string $ticketsbestellen = null;
  79. #[ORM\Column(name: 'export_uristier', type: 'boolean', length: 4, unique: false, nullable: true)]
  80. private bool $export_uristier;
  81. #[ORM\Column(name: 'export_uw', type: 'boolean', length: 4, unique: false, nullable: true)]
  82. private bool $export_uw;
  83. #[ORM\Column(name: 'export_1_enddatum', type: 'datetime', length: 8, unique: false, nullable: true)]
  84. private ?\DateTimeInterface $export_1_enddatum = null;
  85. #[ORM\Column(name: 'kveranstalter', type: 'string', length: 100, unique: false, nullable: true)]
  86. private ?string $kveranstalter = null;
  87. #[ORM\Column(name: 'kname', type: 'string', length: 100, unique: false, nullable: true)]
  88. #[Assert\NotBlank(groups: ['kundendaten'])]
  89. private ?string $kname = null;
  90. #[ORM\Column(name: 'kvorname', type: 'string', length: 100, unique: false, nullable: true)]
  91. #[Assert\NotBlank(groups: ['kundendaten'])]
  92. private ?string $kvorname = null;
  93. #[ORM\Column(name: 'kstrasse', type: 'string', length: 200, unique: false, nullable: true)]
  94. #[Assert\NotBlank(groups: ['kundendaten'])]
  95. private ?string $kstrasse = null;
  96. #[ORM\Column(name: 'kplz', type: 'string', length: 5, unique: false, nullable: true)]
  97. #[Assert\NotBlank(groups: ['kundendaten'])]
  98. private ?string $kplz = null;
  99. #[ORM\Column(name: 'kort', type: 'string', length: 200, unique: false, nullable: true)]
  100. #[Assert\NotBlank(groups: ['kundendaten'])]
  101. private ?string $kort = null;
  102. #[ORM\Column(name: 'ktel', type: 'string', length: 200, unique: false, nullable: true)]
  103. #[Assert\NotBlank(groups: ['kundendaten'])]
  104. private ?string $ktel = null;
  105. #[ORM\Column(name: 'kemail', type: 'string', length: 200, unique: false, nullable: true)]
  106. #[Assert\NotBlank(groups: ['kundendaten'])]
  107. #[Assert\Email(message: "Diese E-mail '{{ value }}' ist nicht gültig.", groups: ['kundendaten'])]
  108. private ?string $kemail = null;
  109. #[ORM\Column(name: 'kkontaktieren', type: 'boolean', length: 4, unique: false, nullable: true)]
  110. private bool $kkontaktieren = false;
  111. #[ORM\Column(name: 'kbemerkung', type: 'text', length: 200, unique: false, nullable: true)]
  112. private ?string $kbemerkung = null;
  113. #[ORM\Column(name: 'lastupdate', type: 'datetime', length: 10, unique: false, nullable: true)]
  114. private \DateTimeInterface $lastupdate;
  115. #[ORM\Column(name: 'vs_image', type: 'json', nullable: true)]
  116. private ?array $vsImage = [];
  117. public function __construct()
  118. {
  119. $this->uuid = self::generateNewUuid();
  120. $this->setLastupdate();
  121. }
  122. public static function generateNewUuid(): string
  123. {
  124. return Uuid::uuid4()->toString();
  125. }
  126. public function getId(): ?int
  127. {
  128. return $this->id;
  129. }
  130. public function getUuid(): string
  131. {
  132. return $this->uuid;
  133. }
  134. public function setUuid($uuid): void
  135. {
  136. $this->uuid = $uuid;
  137. }
  138. public function getTitel(): ?string
  139. {
  140. return $this->titel;
  141. }
  142. public function setTitel(?string $titel): static
  143. {
  144. $this->titel = $titel;
  145. return $this;
  146. }
  147. public function getSlug(): array|string|null
  148. {
  149. return UrlSlug::fromString($this->titel);
  150. }
  151. public function getAdresse(): ?string
  152. {
  153. return $this->adresse;
  154. }
  155. public function setAdresse(?string $adresse): static
  156. {
  157. $this->adresse = $adresse;
  158. return $this;
  159. }
  160. public function getBeschreibung(): ?string
  161. {
  162. return $this->beschreibung;
  163. }
  164. public function setBeschreibung(?string $beschreibung): static
  165. {
  166. $this->beschreibung = $beschreibung;
  167. return $this;
  168. }
  169. public function getBeginnzeit(): ?\DateTimeInterface
  170. {
  171. return $this->beginnzeit;
  172. }
  173. public function setBeginnzeit(?\DateTimeInterface$beginnzeit): static
  174. {
  175. $this->beginnzeit = $beginnzeit;
  176. return $this;
  177. }
  178. public function getEndzeit(): ?\DateTimeInterface
  179. {
  180. return $this->endzeit;
  181. }
  182. public function setEndzeit(?\DateTimeInterface $endzeit): static
  183. {
  184. $this->endzeit = $endzeit;
  185. return $this;
  186. }
  187. public function getStartdatum(): ?\DateTimeInterface
  188. {
  189. return $this->startdatum;
  190. }
  191. public function setStartdatum(?\DateTimeInterface $startdatum): static
  192. {
  193. $this->startdatum = $startdatum;
  194. return $this;
  195. }
  196. public function getEnddatum(): ?\DateTimeInterface
  197. {
  198. return $this->enddatum;
  199. }
  200. public function setEnddatum(?\DateTimeInterface $enddatum): static
  201. {
  202. $this->enddatum = $enddatum;
  203. return $this;
  204. }
  205. public function getUrl(bool $useLinktextFormat = false): ?string
  206. {
  207. $url = $this->url;
  208. if ($useLinktextFormat) {
  209. $url = str_replace(['https://', 'http://'], '', $url);
  210. }
  211. return $url;
  212. }
  213. public function setUrl(?string $url): static
  214. {
  215. $this->url = $url;
  216. return $this;
  217. }
  218. public function getVideolink(): ?string
  219. {
  220. return $this->videolink;
  221. }
  222. public function setVideolink(?string $videolink): static
  223. {
  224. $this->videolink = $videolink;
  225. return $this;
  226. }
  227. public function getGooglemaps(): ?string
  228. {
  229. return $this->googlemaps;
  230. }
  231. public function setGooglemaps(?string $googlemaps): void
  232. {
  233. $this->googlemaps = $googlemaps;
  234. }
  235. public function getTicketsbestellen(): ?string
  236. {
  237. return $this->ticketsbestellen;
  238. }
  239. public function setTicketsbestellen(?string $ticketsbestellen): static
  240. {
  241. $this->ticketsbestellen = $ticketsbestellen;
  242. return $this;
  243. }
  244. public function getExportUristier(): bool
  245. {
  246. return $this->export_uristier;
  247. }
  248. public function setExportUristier(bool $exportUristier): static
  249. {
  250. $this->export_uristier = $exportUristier;
  251. return $this;
  252. }
  253. public function getExportUw(): bool
  254. {
  255. return $this->export_uw;
  256. }
  257. public function setExportUw(bool $export_uw): static
  258. {
  259. $this->export_uw = $export_uw;
  260. return $this;
  261. }
  262. public function getRegion(): ?VsRegion
  263. {
  264. return $this->region;
  265. }
  266. public function setRegion(?VsRegion $region): static
  267. {
  268. $this->region = $region;
  269. return $this;
  270. }
  271. public function getRubrik(): ?VsRubrik
  272. {
  273. return $this->rubrik;
  274. }
  275. public function setRubrik(?VsRubrik $rubrik): static
  276. {
  277. $this->rubrik = $rubrik;
  278. return $this;
  279. }
  280. public function getStatus(): ?VsStatus
  281. {
  282. return $this->status;
  283. }
  284. public function setStatus(?VsStatus $status): static
  285. {
  286. $this->status = $status;
  287. return $this;
  288. }
  289. public function getAbo(): ?VsAbo
  290. {
  291. return $this->abo;
  292. }
  293. public function setAbo(?VsAbo $abo): static
  294. {
  295. $this->abo = $abo;
  296. return $this;
  297. }
  298. public function getTyp(): ?VsTyp
  299. {
  300. return $this->typ;
  301. }
  302. public function setTyp(?VsTyp $typ): static
  303. {
  304. $this->typ = $typ;
  305. return $this;
  306. }
  307. public function getBeginnAuswahl(): ?VsBeginnAuswahl
  308. {
  309. return $this->beginn_auswahl;
  310. }
  311. public function setBeginnAuswahl(?VsBeginnAuswahl $beginn_auswahl): static
  312. {
  313. $this->beginn_auswahl = $beginn_auswahl;
  314. return $this;
  315. }
  316. public function getExport1Enddatum(): ?\DateTimeInterface
  317. {
  318. return $this->export_1_enddatum;
  319. }
  320. public function setExport1Enddatum(?\DateTimeInterface $export_1_enddatum): static
  321. {
  322. $this->export_1_enddatum = $export_1_enddatum;
  323. return $this;
  324. }
  325. public function getKveranstalter(): ?string
  326. {
  327. return $this->kveranstalter;
  328. }
  329. public function setKveranstalter(?string $kveranstalter): static
  330. {
  331. $this->kveranstalter = $kveranstalter;
  332. return $this;
  333. }
  334. public function getKname(): ?string
  335. {
  336. return $this->kname;
  337. }
  338. public function setKname(?string $kname): static
  339. {
  340. $this->kname = $kname;
  341. return $this;
  342. }
  343. public function getKvorname(): ?string
  344. {
  345. return $this->kvorname;
  346. }
  347. public function setKvorname(?string $kvorname): static
  348. {
  349. $this->kvorname = $kvorname;
  350. return $this;
  351. }
  352. public function getKstrasse(): ?string
  353. {
  354. return $this->kstrasse;
  355. }
  356. public function setKstrasse(?string $kstrasse): static
  357. {
  358. $this->kstrasse = $kstrasse;
  359. return $this;
  360. }
  361. public function getKplz(): ?string
  362. {
  363. return $this->kplz;
  364. }
  365. public function setKplz(?string $kplz): static
  366. {
  367. $this->kplz = $kplz;
  368. return $this;
  369. }
  370. public function getKort(): ?string
  371. {
  372. return $this->kort;
  373. }
  374. public function setKort(?string $kort): static
  375. {
  376. $this->kort = $kort;
  377. return $this;
  378. }
  379. public function getKtel(): ?string
  380. {
  381. return $this->ktel;
  382. }
  383. public function setKtel(?string $ktel): static
  384. {
  385. $this->ktel = $ktel;
  386. return $this;
  387. }
  388. public function getKemail(): ?string
  389. {
  390. return $this->kemail;
  391. }
  392. public function setKemail(?string $kemail): static
  393. {
  394. $this->kemail = $kemail;
  395. return $this;
  396. }
  397. public function isKkontaktieren(): bool
  398. {
  399. return $this->kkontaktieren;
  400. }
  401. public function setKkontaktieren(bool $kkontaktieren): static
  402. {
  403. $this->kkontaktieren = $kkontaktieren;
  404. return $this;
  405. }
  406. public function getKbemerkung(): ?string
  407. {
  408. return $this->kbemerkung;
  409. }
  410. public function setKbemerkung(?string $kbemerkung): static
  411. {
  412. $this->kbemerkung = $kbemerkung;
  413. return $this;
  414. }
  415. public function getLastupdate(): \DateTimeInterface
  416. {
  417. return $this->lastupdate;
  418. }
  419. public function setVsImage(string $filename, ?string $alt = '', ?string $caption = ''): void
  420. {
  421. $vsImage = VsImage::createNonExistImage();
  422. if ($filename) {
  423. $vsImage = VsImage::create($filename, $alt, $caption);
  424. }
  425. $this->vsImage['filename'] = $vsImage->getFilename();
  426. $this->vsImage['alt'] = $vsImage->getAlt();
  427. $this->vsImage['caption'] = $vsImage->getCaption();
  428. }
  429. public function getVsImage(): VsImage
  430. {
  431. if ($this->vsImage && array_key_exists('filename', $this->vsImage)) {
  432. $fileName = $this->vsImage['filename'];
  433. $alt = array_key_exists('alt', $this->vsImage) ? $this->vsImage['alt'] : '';
  434. $caption = array_key_exists('caption', $this->vsImage) ? $this->vsImage['caption'] : '';
  435. return VsImage::create($fileName, $alt, $caption, $this->baseObjectServerDirPath(), $this->baseObjectWebDirPath());
  436. }
  437. return VsImage::createNonExistImage();
  438. }
  439. public static function baseObjectServerDirPathStatic($uuid): string
  440. {
  441. return __DIR__.'/../../../var/data/public/vs/images/'.substr((string) $uuid, 0, 2).'/'.$uuid;
  442. }
  443. public function baseObjectServerDirPath(): string
  444. {
  445. return self::baseObjectServerDirPathStatic($this->uuid);
  446. }
  447. public static function baseObjectWebDirPathStatic($uuid): string
  448. {
  449. return '/data/vs/images/'.substr((string) $uuid, 0, 2).'/'.$uuid;
  450. }
  451. public function baseObjectWebDirPath(): string
  452. {
  453. return self::baseObjectWebDirPathStatic($this->uuid);
  454. }
  455. //---- Helper Function
  456. public function getVideolinkYouTubeId(): string
  457. {
  458. if (!$this->getVideolink() || !str_contains($this->getVideolink(), 'www.youtube.com')) {
  459. return '';
  460. }
  461. // in der Annahme, das URL im folgenden Format abgelegt ist:
  462. // https://www.youtube.com/watch?v=ZtqOylLqyCU
  463. return explode('v=', $this->getVideolink())[1];
  464. }
  465. public function getVideolinkVimeoId(): string
  466. {
  467. if (!$this->getVideolink() || !str_contains($this->getVideolink(), 'vimeo.com')) {
  468. return '';
  469. }
  470. return trim(parse_url($this->getVideolink(), PHP_URL_PATH), '/');
  471. }
  472. public function formatZeit(): string
  473. {
  474. // Zeit Formatierung
  475. $zeit = '';
  476. $beginnAuswahlPrefix = $this->getBeginnAuswahl() ? $this->getBeginnAuswahl().' ' : '';
  477. $beginnzeit = $this->getBeginnzeit() ? $this->getBeginnzeit()->format('G.i') : '';
  478. $endZeit = $this->getEndzeit() ? $this->getEndzeit()->format('G.i') : '';
  479. if ($beginnzeit && $endZeit) {
  480. $zeit = $beginnAuswahlPrefix.$beginnzeit.'–'.$endZeit.' Uhr';
  481. } elseif ($beginnzeit) {
  482. $zeit = $beginnAuswahlPrefix.$beginnzeit.' Uhr';
  483. } elseif ($endZeit) {
  484. $zeit = 'Bis '.lcfirst($beginnAuswahlPrefix).$endZeit.' Uhr';
  485. }
  486. return $zeit;
  487. }
  488. public function formatStartEndDatumUndZeit(): string
  489. {
  490. // Zeit Formatierung
  491. $datumZeit = $this->formatZeit();
  492. if (!$this->getTyp()) {
  493. return $datumZeit;
  494. }
  495. if ($this->getTyp()->isEinzelveranstaltung()) {
  496. if ($datumZeit) {
  497. $datumZeit = ', '.lcfirst((string) $datumZeit);
  498. }
  499. $datumZeit = SystemIntlDateFormatter::formatObject($this->getStartdatum(), 'EEEE, d. MMMM').$datumZeit;
  500. }
  501. // wenn Dauerveranstaltung, dann anstatt Zeit, nur Von Bis Datum ausgeben
  502. if ($this->getTyp()->isDauerveranstaltung()) {
  503. $startDatFormat = 'd.';
  504. // Falls Monat/Jahr Kombination unterschiedlich, Monat auch in Startdatum ausgeben
  505. // Bsp: "Vom 1. bis 30. Juni", oder "Vom 1. Januar bis 31. Dezember,"
  506. // Evtl. noch Jahr Ausgabe Optimierung nötig!
  507. if ($this->getStartdatum()->format('mY') != $this->getEnddatum()->format('mY')) {
  508. $startDatFormat = 'd. MMMM';
  509. }
  510. $datumZeit = 'Vom '.SystemIntlDateFormatter::formatObject($this->getStartdatum(), $startDatFormat).' bis '.SystemIntlDateFormatter::formatObject($this->getEnddatum(), 'd. MMMM');
  511. } elseif ($this->getTyp()->isOhneFixdatum()) {
  512. // Alles zurücksetzen, da hier weder Datum noch Uhrzeit genutzt werden
  513. $datumZeit = '';
  514. }
  515. // Zeit
  516. return $datumZeit;
  517. }
  518. public function formatStartEndDatum(): false|string
  519. {
  520. $datum = '';
  521. if (!$this->getTyp()) {
  522. return $datum;
  523. }
  524. if ($this->getTyp()->isEinzelveranstaltung()) {
  525. $datum = SystemIntlDateFormatter::formatObject($this->getStartdatum(), 'EEEE, d. MMMM');
  526. }
  527. // wenn Dauerveranstaltung, dann anstatt Zeit, nur Vom-Bis Datum ausgeben
  528. if ($this->getTyp()->isDauerveranstaltung()) {
  529. $startDatFormat = 'd.';
  530. // Falls Monat/Jahr Kombination unterschiedlich, Monat auch in Startdatum ausgeben
  531. // Bsp: "Vom 1. bis 30. Juni, " oder "Vom 1. Januar bis 31. Dezember, "
  532. // Evtl. noch Jahr Ausgabe Optimierung nötig!
  533. if ($this->getStartdatum()->format('mY') != $this->getEnddatum()->format('mY')) {
  534. $startDatFormat = 'd. MMMM';
  535. }
  536. $datum = 'Vom '.SystemIntlDateFormatter::formatObject($this->getStartdatum(), $startDatFormat).' bis '.SystemIntlDateFormatter::formatObject($this->getEnddatum(), 'd. MMMM');
  537. }
  538. // Zeit
  539. return $datum;
  540. }
  541. #[ORM\PostRemove]
  542. public function removeFiles(): void
  543. {
  544. $fs = new Filesystem();
  545. $fs->remove($this->baseObjectServerDirPath());
  546. }
  547. #[ORM\PostPersist]
  548. #[ORM\PostUpdate]
  549. public function removeUnusedFiles(): void
  550. {
  551. $serverPath = $this->baseObjectServerDirPath();
  552. // Auflistung aller effektiv benötigter Filenamen dieses Objects, damit diese erhalten bleiben
  553. $usedFiles_ = [];
  554. if ($this->getVsImage()->getFilename()) {
  555. $usedFiles_[] = $this->getVsImage()->getFilename();
  556. $usedFiles_[] = $this->getVsImage()->getFilenameThumb();
  557. }
  558. // Ende
  559. // Lösche alle Files aus dem Objektverzeichnis, welche nicht im Objekt vorhanden sind
  560. $fs = new Filesystem();
  561. if ($fs->exists($serverPath)) {
  562. $finder = new Finder();
  563. $finder->files()->in($serverPath);
  564. foreach ($finder as $file) {
  565. if (!in_array($file->getFilename(), $usedFiles_)) {
  566. $fs->remove($file->getRealPath());
  567. }
  568. }
  569. }
  570. // Ende
  571. }
  572. // Diese Funktionen wird vor dem definitiven Speichern aufgerufen
  573. #[Assert\Callback]
  574. public function validate(ExecutionContextInterface $context): void
  575. {
  576. // Feld Typ nur darf "null" sein, wenn Feld Status "nicht zugewiesen" besitzt
  577. if (!$this->getTyp() && ($this->getStatus() && !$this->getStatus()->isNichtZugewiesen())) {
  578. $context->buildViolation('Typ muss gesetzt sein, da Status ungleich "Nicht zugewiesen"!')
  579. ->atPath('typ')
  580. ->addViolation();
  581. }
  582. // Max Length Titel und Beschreibung checken
  583. if ($this->getAbo()) {
  584. $maxLengthTitel = $this->getAbo()->getMaxLengthVsTitel() ?: null;
  585. $maxLengthBeschreibung = $this->getAbo()->getMaxLengthVsBeschreibung();
  586. if ($maxLengthTitel !== null && mb_strlen($this->getTitel()) > $maxLengthTitel) {
  587. $context->buildViolation('Zu viele Zeichen verwendet, max. Zeichenlänge = '.$maxLengthTitel)
  588. ->atPath('titel')
  589. ->addViolation();
  590. }
  591. if ($maxLengthBeschreibung !== null && mb_strlen($this->getBeschreibung()) > $maxLengthBeschreibung) {
  592. $context->buildViolation('Zu viele Zeichen verwendet, max. Zeichenlänge = '.$maxLengthBeschreibung)
  593. ->atPath('beschreibung')
  594. ->addViolation();
  595. }
  596. }
  597. }
  598. #[ORM\PrePersist]
  599. #[ORM\PreUpdate]
  600. public function setLastupdate(): void
  601. {
  602. $this->lastupdate = new \DateTime();
  603. }
  604. #[ORM\PrePersist]
  605. #[ORM\PreUpdate]
  606. public function calculateExport1Enddatum(): void
  607. {
  608. if (!$this->getTyp()) {
  609. return;
  610. }
  611. // Nur eine Dauerveranstaltung soll dieses Feld belegt haben
  612. if (!$this->getTyp()->isDauerveranstaltung()) {
  613. $this->setExport1Enddatum(null);
  614. return;
  615. }
  616. if ($this->getEnddatum() && !$this->getExport1Enddatum()) {
  617. $this->setExport1Enddatum($this->getEnddatum());
  618. }
  619. }
  620. #[ORM\PrePersist]
  621. #[ORM\PreUpdate]
  622. public function cleanUnusedFields(): void
  623. {
  624. // End Datum
  625. if ($this->getTyp() && $this->getTyp()->isEinzelveranstaltung()) {
  626. $this->setEnddatum(null);
  627. }
  628. // Begin/Endzeit
  629. if ($this->getTyp() && !$this->getTyp()->isEinzelveranstaltung()) {
  630. $this->setBeginnAuswahl(null);
  631. $this->setBeginnzeit(null);
  632. $this->setEndzeit(null);
  633. }
  634. // Bild
  635. if (!$this->getAbo()->isPremium()) {
  636. $this->setVsImage('');
  637. }
  638. }
  639. }