| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace Meramo\Begriffmgt\Controller;
- use Meramo\Begriffmgt\Domain\Model\Term;
- use Meramo\Begriffmgt\Domain\Repository\TermRepository;
- use TYPO3\CMS\Core\Messaging\FlashMessage;
- use TYPO3\CMS\Core\Utility\GeneralUtility;
- use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
- class TermController extends ActionController
- {
- public function __construct(
- TermRepository $termRepository
- ) {
- $this->termRepository = $termRepository;
- }
- public function createAction($terms, $categoryObj, $typeObj, $urlObj): void {
- $objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
- $flashMessageService = $objectManager->get('TYPO3\\CMS\\Core\\Messaging\\FlashMessageService');
- $messageQueue = $flashMessageService->getMessageQueueByIdentifier('begriffmgt');
- foreach ($terms as $term) {
- if($term !== '' && !($this->termRepository->findByTitle($term))) {
- $termObj = new Term();
- $termObj->setTerm($term);
- $termObj->setCategory($categoryObj);
- $termObj->setType($typeObj);
- $termObj->setUrl($urlObj);
- $this->termRepository->add($termObj);
- }
- elseif ($term !== '' && $this->termRepository->findByTitle($term)) {
- $termObj = $this->termRepository->findByUid(($this->termRepository->findByTitle($term))['uid']);
- $termObj->setCategory($categoryObj);
- $termObj->setType($typeObj);
- $termObj->setUrl($urlObj);
- $this->termRepository->update($termObj);
- $flashMessage = GeneralUtility::makeInstance(
- FlashMessage::class,
- 'Begriff ' . $term . ' wurde aktualisiert. Begriff war bereits vorhanden. Bitte Liste prüfen!',
- 'Update', // the header of the flash message
- FlashMessage::OK, // the severity of the flash message
- TRUE // whether the flash message should be stored in the session (to survive redirects)
- );
- $messageQueue->addMessage($flashMessage);
- }
- }
- }
- public function deleteAction(int $termId): void {
- $term = $this->termRepository->findByUid($termId);
- if ($term) {
- $this->termRepository->remove($term);
- }
- }
- }
|