TermController.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace Meramo\Begriffmgt\Controller;
  3. use Meramo\Begriffmgt\Domain\Model\Term;
  4. use Meramo\Begriffmgt\Domain\Repository\TermRepository;
  5. use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
  6. class TermController extends ActionController
  7. {
  8. public function __construct(
  9. TermRepository $termRepository
  10. ) {
  11. $this->termRepository = $termRepository;
  12. }
  13. public function createAction($terms, $categoryObj, $typeObj, $urlObj): void {
  14. foreach ($terms as $term) {
  15. if($term !== '' && !($this->termRepository->findByTitle($term))) {
  16. $termObj = new Term();
  17. $termObj->setTerm($term);
  18. $termObj->setCategory($categoryObj);
  19. $termObj->setType($typeObj);
  20. $termObj->setUrl($urlObj);
  21. $this->termRepository->add($termObj);
  22. }
  23. elseif ($term !== '' && $this->termRepository->findByTitle($term)) {
  24. $termObj = $this->termRepository->findByUid(($this->termRepository->findByTitle($term))['uid']);
  25. $termObj->setCategory($categoryObj);
  26. $termObj->setType($typeObj);
  27. $termObj->setUrl($urlObj);
  28. $this->termRepository->update($termObj);
  29. }
  30. }
  31. }
  32. public function deleteAction(int $termId): void {
  33. $term = $this->termRepository->findByUid($termId);
  34. if ($term) {
  35. $this->termRepository->remove($term);
  36. }
  37. }
  38. }