Skip to content

Commit

Permalink
Version 4.0.0 beta 8
Browse files Browse the repository at this point in the history
  • Loading branch information
bihor committed Jun 28, 2023
1 parent 66655fb commit 966801b
Show file tree
Hide file tree
Showing 11 changed files with 310 additions and 70 deletions.
78 changes: 71 additions & 7 deletions Classes/Controller/ParticipantController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
use TYPO3\CMS\Core\Pagination\ArrayPaginator;
use TYPO3\CMS\Core\Pagination\SimplePagination;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;

/***
*
Expand All @@ -24,6 +28,10 @@
*/
class ParticipantController extends ActionController
{
protected int $id;

protected ModuleTemplate $moduleTemplate;

/**
* participantRepository
*
Expand All @@ -41,13 +49,24 @@ public function injectParticipantRepository(\Fixpunkt\FpMasterquiz\Domain\Reposi
$this->participantRepository = $participantRepository;
}

public function __construct(
protected readonly ModuleTemplateFactory $moduleTemplateFactory,
) {
}

public function initializeAction()
{
$this->id = (int)($this->request->getQueryParams()['id'] ?? 0);
$this->moduleTemplate = $this->moduleTemplateFactory->create($this->request);
}

/**
* action list
*
* @param int $currentPage
* @return void
* @return ResponseInterface
*/
public function listAction(int $currentPage = 1)
public function listAction(int $currentPage = 1): ResponseInterface
{
$pid = (int)GeneralUtility::_GP('id');
$qid = $this->request->hasArgument('quiz') ? intval($this->request->getArgument('quiz')) : 0;
Expand All @@ -70,15 +89,17 @@ public function listAction(int $currentPage = 1)
$this->view->assign('paginator', $participantPaginator);
$this->view->assign('pagination', $participantPagination);
$this->view->assign('pages', range(1, $participantPagination->getLastPageNumber()));
$this->addDocHeaderDropDown('list');
return $this->defaultRendering();
}

/**
* action detail
*
* @param \Fixpunkt\FpMasterquiz\Domain\Model\Participant $participant
* @return void
* @return ResponseInterface
*/
public function detailAction(\Fixpunkt\FpMasterquiz\Domain\Model\Participant $participant)
public function detailAction(\Fixpunkt\FpMasterquiz\Domain\Model\Participant $participant): ResponseInterface
{
foreach ($participant->getSelections() as $selection) {
if ($selection->getQuestion()->getQmode() == 8) {
Expand All @@ -97,20 +118,63 @@ public function detailAction(\Fixpunkt\FpMasterquiz\Domain\Model\Participant $pa
}
}
$this->view->assign('participant', $participant);
$this->addDocHeaderDropDown('list');
return $this->defaultRendering();
}

/**
* action delete
*
* @param \Fixpunkt\FpMasterquiz\Domain\Model\Participant $participant
* @return void
* @return ResponseInterface
*/
public function deleteAction(\Fixpunkt\FpMasterquiz\Domain\Model\Participant $participant)
public function deleteAction(\Fixpunkt\FpMasterquiz\Domain\Model\Participant $participant): ResponseInterface
{
if ($participant->getUid() > 0) {
$this->addFlashMessage($participant->getName() . ' deleted.', '', AbstractMessage::WARNING);
$this->participantRepository->remove($participant);
}
$this->redirect('list');
return $this->responseFactory->createResponse(307)
->withHeader('Location', $this->uriBuilder->reset()->uriFor('list'));
}

/*
* Fürs Backend-Modul
*/
protected function getLanguageService(): LanguageService
{
return $GLOBALS['LANG'];
}

protected function defaultRendering(): ResponseInterface
{
$this->moduleTemplate->setContent($this->view->render());
return $this->htmlResponse($this->moduleTemplate->renderContent());
}

protected function addDocHeaderDropDown(string $currentAction): void
{
$languageService = $this->getLanguageService();
$actionMenu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
$actionMenu->setIdentifier('masterquizSelector');
$actions = ['Quiz,index', 'Participant,list'];
foreach ($actions as $controller_action_string) {
$controller_action_array = explode(",", $controller_action_string);
$actionMenu->addMenuItem(
$actionMenu->makeMenuItem()
->setTitle($languageService->sL(
'LLL:EXT:fp_masterquiz/Resources/Private/Language/locallang_mod1.xlf:index.' .
strtolower($controller_action_array[0])
))
->setHref($this->getModuleUri($controller_action_array[0], $controller_action_array[1]))
->setActive($currentAction === $controller_action_array[1])
);
}
$this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($actionMenu);
}

protected function getModuleUri(string $controller = null, string $action = null): string
{
return $this->uriBuilder->reset()->uriFor($action, null, $controller, 'mod1');
}
}
64 changes: 62 additions & 2 deletions Classes/Controller/QuestionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;

/***
*
Expand All @@ -21,6 +25,10 @@
*/
class QuestionController extends ActionController
{
protected int $id;

protected ModuleTemplate $moduleTemplate;

/**
* questionRepository
*
Expand All @@ -38,14 +46,25 @@ public function injectQuestionRepository(\Fixpunkt\FpMasterquiz\Domain\Repositor
$this->questionRepository = $questionRepository;
}

public function __construct(
protected readonly ModuleTemplateFactory $moduleTemplateFactory,
) {
}

public function initializeAction()
{
$this->id = (int)($this->request->getQueryParams()['id'] ?? 0);
$this->moduleTemplate = $this->moduleTemplateFactory->create($this->request);
}

/**
* action move
*
* @param \Fixpunkt\FpMasterquiz\Domain\Model\Quiz $quiz
* @param \Fixpunkt\FpMasterquiz\Domain\Model\Question $question
* @return void
* @return ResponseInterface
*/
public function moveAction(\Fixpunkt\FpMasterquiz\Domain\Model\Quiz $quiz, \Fixpunkt\FpMasterquiz\Domain\Model\Question $question = NULL)
public function moveAction(\Fixpunkt\FpMasterquiz\Domain\Model\Quiz $quiz, \Fixpunkt\FpMasterquiz\Domain\Model\Question $question = NULL): ResponseInterface
{
$pid = (int)GeneralUtility::_GP('id');
if ($question) {
Expand All @@ -55,6 +74,47 @@ public function moveAction(\Fixpunkt\FpMasterquiz\Domain\Model\Quiz $quiz, \Fixp
$this->view->assign('question', $question);
$this->view->assign('questions', $questions);
$this->view->assign('quiz', $quiz);
$this->addDocHeaderDropDown('index');
return $this->defaultRendering();
}

/*
* Fürs Backend-Modul
*/
protected function getLanguageService(): LanguageService
{
return $GLOBALS['LANG'];
}

protected function defaultRendering(): ResponseInterface
{
$this->moduleTemplate->setContent($this->view->render());
return $this->htmlResponse($this->moduleTemplate->renderContent());
}

protected function addDocHeaderDropDown(string $currentAction): void
{
$languageService = $this->getLanguageService();
$actionMenu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
$actionMenu->setIdentifier('masterquizSelector');
$actions = ['Quiz,index', 'Participant,list'];
foreach ($actions as $controller_action_string) {
$controller_action_array = explode(",", $controller_action_string);
$actionMenu->addMenuItem(
$actionMenu->makeMenuItem()
->setTitle($languageService->sL(
'LLL:EXT:fp_masterquiz/Resources/Private/Language/locallang_mod1.xlf:index.' .
strtolower($controller_action_array[0])
))
->setHref($this->getModuleUri($controller_action_array[0], $controller_action_array[1]))
->setActive($currentAction === $controller_action_array[1])
);
}
$this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($actionMenu);
}

protected function getModuleUri(string $controller = null, string $action = null): string
{
return $this->uriBuilder->reset()->uriFor($action, null, $controller, 'mod1');
}
}
Loading

0 comments on commit 966801b

Please sign in to comment.