DashboardController.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. declare(strict_types=1);
  3. namespace Meramo\Begriffmgt\Controller;
  4. use Meramo\Begriffmgt\Domain\Repository\TypeRepository;
  5. use Meramo\Begriffmgt\Domain\Repository\UrlRepository;
  6. use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
  7. use Meramo\Begriffmgt\Domain\Repository\TermRepository;
  8. use Meramo\Begriffmgt\Domain\Repository\CategoryRepository;
  9. use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
  10. class DashboardController extends ActionController
  11. {
  12. protected $termRepository;
  13. protected $termController;
  14. protected $categoryRepository;
  15. protected $categoryController;
  16. protected $typeRepository;
  17. protected $typeController;
  18. protected $urlRepository;
  19. protected $urlController;
  20. public function __construct(
  21. TermRepository $termRepository,
  22. CategoryRepository $categoryRepository,
  23. CategoryController $categoryController,
  24. TypeRepository $typeRepository,
  25. TypeController $typeController,
  26. UrlRepository $urlRepository,
  27. UrlController $urlController,
  28. TermController $termController
  29. ) {
  30. $this->termRepository = $termRepository;
  31. $this->categoryRepository = $categoryRepository;
  32. $this->categoryController = $categoryController;
  33. $this->termController = $termController;
  34. $this->typeRepository = $typeRepository;
  35. $this->typeController = $typeController;
  36. $this->urlRepository = $urlRepository;
  37. $this->urlController = $urlController;
  38. }
  39. public function indexAction(): void
  40. {
  41. $terms = $this->termRepository->findAllOrderedByTerm();
  42. $categories = $this->categoryRepository->findAllOrderedByTitle();
  43. $types = $this->typeRepository->findAllOrderedByTitle();
  44. $urls = $this->urlRepository->findAllOrderedByTitle();
  45. $this->view->assignMultiple([
  46. 'terms' => $terms,
  47. 'categories' => $categories,
  48. 'types' => $types,
  49. 'urls' => $urls
  50. ]);
  51. }
  52. public function newAction(): void {
  53. }
  54. public function listAction(): void {
  55. $terms = $this->termRepository->findAll();
  56. $this->view->assign('terms', $terms);
  57. }
  58. public function createAction(string $termList, string $categoryTitle, string $typeTitle, string $urlTitle): void {
  59. $terms = array_map('trim', explode(';', $termList));
  60. $category = $this->categoryController->createAction($categoryTitle);
  61. $categoryObj = $this->categoryRepository->findByUid($category);
  62. $type = $this->typeController->createAction($typeTitle);
  63. $typeObj = $this->typeRepository->findByUid($type);
  64. $url = $this->urlController->createAction($urlTitle);
  65. $urlObj = $this->urlRepository->findByUid($url);
  66. $this->termController->createAction($terms, $categoryObj, $typeObj, $urlObj);
  67. $request = $this->request;
  68. if ($request) {
  69. // Called by a form action - in this case the data is persisted to the db 'automatically'
  70. $this->redirect('index');
  71. } else {
  72. // Called by another controller
  73. $persistenceManager = $this->objectManager->get(PersistenceManager::class);
  74. $persistenceManager->persistAll();
  75. }
  76. }
  77. public function deleteTermAction(int $termId): void {
  78. $this->termController->deleteAction($termId);
  79. $this->redirect('index');
  80. }
  81. }