Skip to content

Commit

Permalink
Merge branch 'release/5.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
yannick-gafner committed Dec 7, 2023
2 parents 60942b2 + 7cb6eb8 commit 115b5f6
Show file tree
Hide file tree
Showing 24 changed files with 435 additions and 309 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
.idea
167 changes: 124 additions & 43 deletions Classes/Controller/FormEntryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,27 @@
use Frappant\FrpFormAnswers\Domain\Model\FormEntryDemand;
use Frappant\FrpFormAnswers\Domain\Repository\FormEntryRepository;
use Frappant\FrpFormAnswers\Utility\FormAnswersUtility;
use Frappant\FrpFormAnswers\View\FormEntry\ExportCsv;
use Frappant\FrpFormAnswers\View\FormEntry\ExportXls;
use Frappant\FrpFormAnswers\View\FormEntry\ExportXml;
use JetBrains\PhpStorm\NoReturn;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Backend\Template\Components\Menu\Menu;
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
use TYPO3\CMS\Core\Http\StreamFactory;
use TYPO3\CMS\Core\Http\Stream;
use TYPO3\CMS\Core\Http\Response;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException;
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;

Expand Down Expand Up @@ -67,6 +75,16 @@ class FormEntryController extends ActionController
*/
protected PageRepository $pageRepository;

/**
* @var PersistenceManager $persistenceManager
*/
protected PersistenceManager $persistenceManager;

/**
* @var string $filename
*/
protected string $filename = '';

/**
* @var integer
*/
Expand All @@ -86,17 +104,17 @@ public function __construct(
FormAnswersUtility $formAnswersUtility,
FormEntryRepository $formEntryRepository,
DataExporter $dataExporter,
PageRepository $pageRepository
PageRepository $pageRepository,
PersistenceManager $persistenceManager
) {
$this->moduleTemplateFactory = $moduleTemplateFactory;
$this->iconFactory = $iconFactory;
$this->formAnswersUtility = $formAnswersUtility;
$this->formEntryRepository = $formEntryRepository;
$this->dataExporter = $dataExporter;
$this->pageRepository = $pageRepository;

$this->pid = (int)GeneralUtility::_GP('id');

$this->pid = $_GET['id'];
$this->persistenceManager = $persistenceManager;
}

/**
Expand All @@ -112,8 +130,8 @@ public function listAction(): ResponseInterface
$this->view->assign('subPagesWithFormEntries', $this->pageRepository->getMenuForPages(array_keys($pageIds)));
$this->view->assign('formEntriesStatus', $pageIds);
}
$this->view->assign('pid', (int)GeneralUtility::_GP('id'));
$this->view->assign('formNames', $this->formAnswersUtility->getAllFormNames());
$this->view->assign('pid', $this->pid);
$this->view->assign('formNames', $this->formAnswersUtility->getAllFormNames([$this->pid]));
$this->view->assign('settings', $this->settings);

$moduleTemplate = $this->moduleTemplateFactory->create($this->request);
Expand Down Expand Up @@ -154,7 +172,7 @@ public function prepareRemoveAction(): ResponseInterface
->from('tx_frpformanswers_domain_model_formentry')
->where($queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($this->pid, \PDO::PARAM_INT)))
->andWhere($queryBuilder->expr()->eq('deleted', $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT)))
->execute()->fetchFirstColumn();
->executeQuery()->fetchFirstColumn();
//DebuggerUtility::var_dump($count);
$this->view->assign('count', $count[0]);

Expand All @@ -168,9 +186,35 @@ public function prepareRemoveAction(): ResponseInterface
}

/**
* action remove, Remove form entries which are marked as deleted
* action mark single entry as deleted
*
* @return void
* @throws IllegalObjectTypeException
*/
public function removeEntryAction(): \Psr\Http\Message\ResponseInterface
{
$arguments = $this->request->getArguments();
$uid = $arguments['uid'];
$pid = $arguments['pid'];
$entry = $this->formEntryRepository->findByUid($uid);

$this->formEntryRepository->remove($entry);
$this->persistenceManager->persistAll();

$this->addFlashMessage(
'Deleted entry with uid: ' . $uid,
'Entry deleted',
\TYPO3\CMS\Core\Type\ContextualFeedbackSeverity::OK,
true
);

return $this->redirect('list', null, null, ['id' => $pid]);
}

/**
* action remove, Remove form entries which are marked as deleted
*
* @return ResponseInterface
*/
public function removeAction()
{
Expand All @@ -184,10 +228,10 @@ public function removeAction()
$this->addFlashMessage(
LocalizationUtility::translate('LLL:EXT:frp_form_answers/Resources/Private/Language/de.locallang_be.xlf:flashmessage.removeEntries.body', null, [$this->pid]),
LocalizationUtility::translate('LLL:EXT:frp_form_answers/Resources/Private/Language/de.locallang_be.xlf:flashmessage.removeEntries.title'),
\TYPO3\CMS\Core\Messaging\FlashMessage::OK,
\TYPO3\CMS\Core\Type\ContextualFeedbackSeverity::OK,
true);

$this->redirect('list');
return $this->redirect('list', null, null, ['id' => $this->pid]);
}

/**
Expand All @@ -201,7 +245,7 @@ public function prepareExportAction(): ResponseInterface

$this->formEntryDemand = $demandObject;
$this->view->assign('formEntryDemand', $demandObject);
$this->view->assign('formHashes', $this->formAnswersUtility->getAllFormHashes());
$this->view->assign('formHashes', $this->formAnswersUtility->getAllFormHashes($this->pid));

$moduleTemplate = $this->moduleTemplateFactory->create($this->request);

Expand All @@ -216,43 +260,32 @@ public function initializeExportAction(){

$args = $this->request->getArguments();
$format = $args['format'];
$filename = $args['formEntryDemand']['fileName'];
// $this->filename = $args['formEntryDemand']['formName'];

$charset = (strlen($args['formEntryDemand']['charset']) > 0 ? $args['formEntryDemand']['charset'] : 'iso-8859-1');

switch ($format){
case 'Csv':
$filename = (strlen($filename) > 0 ? $filename.'.csv' : 'export.csv');

$this->filename = (strlen($this->filename) > 0 ? $this->filename.'.csv' : 'export.csv');
$this->setRequestHeader('Content-Type', 'application/force-download');
$this->setRequestHeader('Content-Type', 'text/csv');
$this->setRequestHeader('Content-Disposition', "attachment;filename=$filename");
$this->setRequestHeader('Content-Disposition', "attachment;filename=$this->filename");
$this->setRequestHeader('Content-Transfer-Encoding', 'binary');
$this->setRequestHeader('Content-Type', "application/download; charset=$charset");

$this->defaultViewObjectName = \Frappant\FrpFormAnswers\View\FormEntry\ExportCsv::class;

break;
case 'Xls':
$filename = (strlen($filename) > 0 ? $filename.'.xlsx' : 'export.xlsx');

$this->filename = (strlen($this->filename) > 0 ? $this->filename.'.xlsx' : 'export.xlsx');
$this->setRequestHeader('Content-Type', 'application/force-download');
$this->setRequestHeader('Content-Disposition', "attachment;filename=$filename");
$this->setRequestHeader('Content-Disposition', "attachment;filename=$this->filename");
$this->setRequestHeader('Content-Type', "application/download; charset=$charset");

$this->defaultViewObjectName = \Frappant\FrpFormAnswers\View\FormEntry\ExportXls::class;

break;
case 'Xml':
$filename = (strlen($filename) > 0 ? $filename.'.xml' : 'export.xml');

$this->filename = (strlen($this->filename) > 0 ? $this->filename.'.xml' : 'export.xml');
$this->setRequestHeader('Content-Type', 'application/force-download');
$this->setRequestHeader('Content-Type', 'application/xml');
$this->setRequestHeader('Content-Disposition', "attachment;filename=$filename");
$this->setRequestHeader('Content-Disposition', "attachment;filename=$this->filename");
$this->setRequestHeader('Content-Transfer-Encoding', 'binary');
$this->setRequestHeader('Content-Type', "application/download; charset=$charset");

$this->defaultViewObjectName = \Frappant\FrpFormAnswers\View\FormEntry\ExportXml::class;

break;
}
}
Expand All @@ -261,40 +294,88 @@ public function initializeExportAction(){
* export Action
*
* @param FormEntryDemand $formEntryDemand
* @return responseInterface A Downloadable file
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException
*/
public function exportAction(\Frappant\FrpFormAnswers\Domain\Model\FormEntryDemand $formEntryDemand = null): ResponseInterface
public function exportAction(\Frappant\FrpFormAnswers\Domain\Model\FormEntryDemand $formEntryDemand = null)
{

$format = $this->request->getArguments()['format'];
$formEntryDemand->setAllPids($this->request->getArguments()['allPids']);
$pid = $_GET['id'];

if($formEntryDemand) {
$formEntries = $this->formEntryRepository->findbyDemand($formEntryDemand);
$formEntries = $this->formEntryRepository->findbyDemand($formEntryDemand, $pid);
if (count($formEntries) === 0) {
$this->addFlashMessage('No entries found with your criteria',
'No Entries found',
FlashMessage::WARNING,
\TYPO3\CMS\Core\Type\ContextualFeedbackSeverity::WARNING,
true
);
$this->redirect('list');
return $this->redirect('list', null, null, ['id' => $this->pid]);
}
} else {
$this->addFlashMessage('No Demand set',
'No Demand found',
FlashMessage::ERROR,
\TYPO3\CMS\Core\Type\ContextualFeedbackSeverity::ERROR,
true
);
$this->redirect('list');
return $this->redirect('list', null, null, ['id' => $this->pid]);
}

$extensionConfiguration = $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['frp_formanswers'] ?? null;
$exportData = $this->dataExporter->getExport($formEntries, $formEntryDemand, $extensionConfiguration['useSubmitUid']['value'] ?? false);

$this->formEntryRepository->setFormsToExported($formEntries);

$this->view->assign('rows', $exportData);
$this->view->assign('formEntryDemand', $formEntryDemand);

return $this->generateDownloadResponse($this->view->render());
$exporter = Null;
switch ($format) {
case 'Csv':
$exporter = new ExportCsv();
break;
case 'Xls':
$exporter = new ExportXls();
break;
case 'Xml':
$exporter = new ExportXml();
break;
}



$exporter->assign('rows', $exportData);
$exporter->assign('formEntryDemand', $formEntryDemand);

// Get the content as a string
$content = $exporter->render();

// Prepare a PSR-7 Response
$stream = new Stream('php://memory', 'rw');
$stream->write($content);

switch ($format) {
case 'Csv':
$response = new Response($stream, 200, [
'Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'Content-Disposition' => 'attachment; filename="export.csv"',
]);
break;
case 'Xls':
$response = new Response($stream, 200, [
'Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'Content-Disposition' => 'attachment; filename="export.xlsx"',
]);
break;
case 'Xml':
$response = new Response($stream, 200, [
'Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'Content-Disposition' => 'attachment; filename="export.xml"',
]);
break;
}

return $response;
}

/**
Expand Down Expand Up @@ -336,10 +417,10 @@ public function deleteFormnameAction($formName = ''){
$this->addFlashMessage(
LocalizationUtility::translate('LLL:EXT:frp_form_answers/Resources/Private/Language/de.locallang_be.xlf:flashmessage.deleteFormName.body', 'frp_form_answers', [$formName, $this->pid]),
LocalizationUtility::translate('LLL:EXT:frp_form_answers/Resources/Private/Language/de.locallang_be.xlf:flashmessage.deleteFormName.title'),
\TYPO3\CMS\Core\Messaging\FlashMessage::OK,
\TYPO3\CMS\Core\Type\ContextualFeedbackSeverity::OK,
true);
}
$this->redirect('list');
return $this->redirect('list', null, null, ['id' => $this->pid]);
}

/**
Expand Down
34 changes: 7 additions & 27 deletions Classes/Domain/Finishers/SaveFormToDatabaseFinisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@

use Frappant\FrpFormAnswers\Event\ManipulateFormValuesEvent;
use Frappant\FrpFormAnswers\Domain\Model\FormEntry;
use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException;
use TYPO3\CMS\Core\EventDispatcher\EventDispatcher;
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
use TYPO3\CMS\Form\Domain\Finishers;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
use TYPO3\CMS\Extbase\SignalSlot\Dispatcher;
use TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher;
use TYPO3\CMS\Form\Domain\Finishers\Exception\FinisherException;
use TYPO3\CMS\Form\Domain\Model\FormElements\FormElementInterface;
use Frappant\FrpFormAnswers\Domain\Repository\FormEntryRepository;
use Psr\EventDispatcher\EventDispatcherInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class SaveFormToDatabaseFinisher extends AbstractFinisher
{
Expand All @@ -26,20 +22,6 @@ class SaveFormToDatabaseFinisher extends AbstractFinisher
*/
protected $formEntryRepository = null;

/**
* signalSlotDispatcher
*
* @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
*/
protected $signalSlotDispatcher = null;

/**
* @param \TYPO3\CMS\Extbase\SignalSlot\Dispatcher $dispatcher
*/
public function injectDispatcher(Dispatcher $dispatcher) {
$this->signalSlotDispatcher = $dispatcher;
}

protected EventDispatcherInterface $eventDispatcher;

public function injectEventDispatcherInterface(EventDispatcherInterface $eventDispatcher) {
Expand Down Expand Up @@ -68,6 +50,7 @@ public function injectPersistenceManager(PersistenceManager $persistenceManager)

/**
* Executes this finisher
* @throws AspectNotFoundException
* @see AbstractFinisher::execute()
*/
protected function executeInternal()
Expand All @@ -82,12 +65,6 @@ protected function executeInternal()
// Default Value is new Form
$lastFormUid = 1;

/**
* Provide a Signal to manipulate $values before saving
* @deprecated since v4 will be removed in v5
*/
$this->signalSlotDispatcher->dispatch(__CLASS__, 'preInsertSignal', array(&$values));

/**
* Dispatch an Event to manipulate $values (Use this instead of preInsertSignal above)
*/
Expand All @@ -98,7 +75,10 @@ protected function executeInternal()
$this->formEntry->setAnswers($values);

$this->formEntry->setForm($identifier);
$this->formEntry->setPid($GLOBALS['TSFE']->id);


$pageId = $this->finisherContext->getFormRuntime()->getRequest()->getAttributes()['routing']['pageId'];
$this->formEntry->setPid($pageId);

$lastForm = $this->formEntryRepository->getLastFormAnswerByIdentifyer($identifier);

Expand Down
Loading

0 comments on commit 115b5f6

Please sign in to comment.