DashboardController.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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, $categoryTitle, $typeTitle, string $urlTitle): void {
  59. $terms = array_map('trim', explode(';', $termList));
  60. if($categoryTitle){
  61. $category = $this->categoryController->createAction($categoryTitle);
  62. $categoryObj = $this->categoryRepository->findByUid($category);
  63. }
  64. if($typeTitle){
  65. $type = $this->typeController->createAction($typeTitle);
  66. $typeObj = $this->typeRepository->findByUid($type);
  67. }
  68. $url = $this->urlController->createAction($urlTitle);
  69. $urlObj = $this->urlRepository->findByUid($url);
  70. $this->termController->createAction($terms, $categoryObj, $typeObj, $urlObj);
  71. $request = $this->request;
  72. if ($request) {
  73. // Called by a form action - in this case the data is persisted to the db 'automatically'
  74. $this->redirect('index');
  75. } else {
  76. // Called by another controller
  77. $persistenceManager = $this->objectManager->get(PersistenceManager::class);
  78. $persistenceManager->persistAll();
  79. }
  80. }
  81. public function deleteTermAction(int $termId): void {
  82. $this->termController->deleteAction($termId);
  83. $this->redirect('index');
  84. }
  85. }