| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- declare(strict_types=1);
- namespace Meramo\Begriffmgt\Controller;
- use Meramo\Begriffmgt\Domain\Model\Category;
- use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
- use Meramo\Begriffmgt\Domain\Repository\TermRepository;
- use Meramo\Begriffmgt\Domain\Model\Term;
- use Meramo\Begriffmgt\Domain\Repository\CategoryRepository;
- use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
- class DashboardController extends ActionController
- {
- protected $termRepository;
- protected $categoryRepository;
- public function __construct(TermRepository $termRepository, CategoryRepository $categoryRepository) {
- $this->termRepository = $termRepository;
- $this->categoryRepository = $categoryRepository;
- }
- public function indexAction(): void
- {
- $terms = $this->termRepository->findAll();
- $categories = $this->categoryRepository->findAll();
- $this->view->assignMultiple([
- 'terms' => $terms,
- 'categories' => $categories,
- ]);
- }
- public function newAction(): void {
- }
- public function listAction(): void {
- $terms = $this->termRepository->findAll();
- $this->view->assign('terms', $terms);
- }
- public function createAction(string $termList, string $categoryTitle): void {
- $terms = array_map('trim', explode(',', $termList));
- $category = $this->createCategoryAction($categoryTitle);
- $categoryObj = $this->categoryRepository->findByUid($category);
- foreach ($terms as $term) {
- $termObj = new Term();
- $termObj->setTerm($term);
- $termObj->setCategory($categoryObj);
- $this->termRepository->add($termObj);
- }
- $this->redirect('index');
- }
- public function createCategoryAction(string $title) {
- $category = new Category();
- $category->setTitle($title);
- $this->categoryRepository->add($category);
- $this->objectManager->get(PersistenceManager::class)->persistAll();
- return $category->getUid();
- }
- }
|