Skip to content

Commit

Permalink
[BUGFIX] corrected some v11 bugs according to issue #53
Browse files Browse the repository at this point in the history
thanks to @AstCommodore
  • Loading branch information
Jonas Hirschi committed Aug 17, 2022
1 parent 731af22 commit 4f88ab7
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 40 deletions.
52 changes: 34 additions & 18 deletions Classes/Controller/FormEntryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
Expand Down Expand Up @@ -61,31 +62,46 @@ class FormEntryController extends ActionController
*/
protected DataExporter $dataExporter;

/**
* @var PageRepository $pageRepository
*/
protected PageRepository $pageRepository;

/**
* @var integer
*/
protected $pid;

/**
* http headers to send with filedownload request @see exportAction
*
*
* @var array
*/
protected $requestHeaders = [];


public function __construct(
ModuleTemplateFactory $moduleTemplateFactory,
IconFactory $iconFactory,
FormAnswersUtility $formAnswersUtility,
FormEntryRepository $formEntryRepository,
DataExporter $dataExporter
DataExporter $dataExporter,
PageRepository $pageRepository
) {
$this->moduleTemplateFactory = $moduleTemplateFactory;
$this->iconFactory = $iconFactory;
$this->formAnswersUtility = $formAnswersUtility;
$this->formEntryRepository = $formEntryRepository;
$this->dataExporter = $dataExporter;
$this->pageRepository = $pageRepository;

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

}

/**
* action list, Show saved form entries from database
*
*
* @return ResponseInterface
*/
public function listAction(): ResponseInterface
Expand All @@ -101,7 +117,7 @@ public function listAction(): ResponseInterface
$this->view->assign('settings', $this->settings);

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

$this->createMenu($moduleTemplate);
$this->createButtons($moduleTemplate);

Expand All @@ -118,7 +134,7 @@ public function listAction(): ResponseInterface
public function showAction(\Frappant\FrpFormAnswers\Domain\Model\FormEntry $formEntry): ResponseInterface
{
$this->view->assign('formEntry', $formEntry);

$moduleTemplate = $this->moduleTemplateFactory->create($this->request);
$moduleTemplate->setContent($this->view->render());
return $this->htmlResponse($moduleTemplate->renderContent());
Expand All @@ -136,14 +152,14 @@ public function prepareRemoveAction(): ResponseInterface

$count = $queryBuilder->count('*')
->from('tx_frpformanswers_domain_model_formentry')
->where($queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter(\Frappant\FrpFormAnswers\Utility\BackendUtility::getCurrentPid(), \PDO::PARAM_INT)))
->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();
//DebuggerUtility::var_dump($count);
$this->view->assign('count', $count[0]);

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

$this->createMenu($moduleTemplate);
$this->createButtons($moduleTemplate);

Expand All @@ -161,12 +177,12 @@ public function removeAction()
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_frpformanswers_domain_model_formentry');

$queryBuilder->delete('tx_frpformanswers_domain_model_formentry')
->where($queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter(\Frappant\FrpFormAnswers\Utility\BackendUtility::getCurrentPid(), \PDO::PARAM_INT)))
->where($queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($this->pid, \PDO::PARAM_INT)))
->andWhere($queryBuilder->expr()->eq('deleted', $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT)))
->execute();

$this->addFlashMessage(
LocalizationUtility::translate('LLL:EXT:frp_form_answers/Resources/Private/Language/de.locallang_be.xlf:flashmessage.removeEntries.body', null, [\Frappant\FrpFormAnswers\Utility\BackendUtility::getCurrentPid()]),
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,
true);
Expand All @@ -176,7 +192,7 @@ public function removeAction()

/**
* action prepareExport
*
*
* @return ResponseInterface
*/
public function prepareExportAction(): ResponseInterface
Expand All @@ -188,7 +204,7 @@ public function prepareExportAction(): ResponseInterface
$this->view->assign('formHashes', $this->formAnswersUtility->getAllFormHashes());

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

$this->createMenu($moduleTemplate);
$this->createButtons($moduleTemplate);

Expand Down Expand Up @@ -236,14 +252,14 @@ public function initializeExportAction(){
$this->setRequestHeader('Content-Type', "application/download; charset=$charset");

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

break;
}
}

/**
* export Action
*
*
* @param FormEntryDemand $formEntryDemand
* @return responseInterface A Downloadable file
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
Expand Down Expand Up @@ -277,13 +293,13 @@ public function exportAction(\Frappant\FrpFormAnswers\Domain\Model\FormEntryDema

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

return $this->generateDownloadResponse($this->view->render());
}

/**
* Prepare the download request
*
*
* @param string File Contents wich would be downloaded
* @return ResponseInterface http response with http headers and file contents
*/
Expand Down Expand Up @@ -314,11 +330,11 @@ public function deleteFormnameAction($formName = ''){
$queryBuilder->update(
'tx_frpformanswers_domain_model_formentry',
[ 'deleted' => 1 ], // set
[ 'form' => $formName, 'pid' => \Frappant\FrpFormAnswers\Utility\BackendUtility::getCurrentPid()]
[ 'form' => $formName, 'pid' => $this->pid]
);

$this->addFlashMessage(
LocalizationUtility::translate('LLL:EXT:frp_form_answers/Resources/Private/Language/de.locallang_be.xlf:flashmessage.deleteFormName.body', 'frp_form_answers', [$formName, \Frappant\FrpFormAnswers\Utility\BackendUtility::getCurrentPid()]),
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,
true);
Expand Down
8 changes: 8 additions & 0 deletions Classes/Domain/Finishers/SaveFormToDatabaseFinisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Frappant\FrpFormAnswers\Event\ManipulateFormValuesEvent;
use Frappant\FrpFormAnswers\Domain\Model\FormEntry;
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;
Expand Down Expand Up @@ -59,6 +60,12 @@ public function injectFormEntry(FormEntry $formEntry) {
$this->formEntry = $formEntry;
}

protected PersistenceManager $persistenceManager;

public function injectPersistenceManager(PersistenceManager $persistenceManager) {
$this->persistenceManager = $persistenceManager;
}

/**
* Executes this finisher
* @see AbstractFinisher::execute()
Expand Down Expand Up @@ -103,6 +110,7 @@ protected function executeInternal()
$this->formEntry->setSubmitUid($lastFormUid);

$this->formEntryRepository->add($this->formEntry);
$this->persistenceManager->persistAll();
}

/**
Expand Down
16 changes: 0 additions & 16 deletions Classes/Domain/Repository/FormEntryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,6 @@ public function setRespectStoragePage($bool)
$this->setDefaultQuerySettings($querySettings);
}


/**
* Adds an object to this repository
*
* @param object $object The object to add
* @throws IllegalObjectTypeException
*/
public function add($object)
{
if (!$object instanceof $this->objectType) {
throw new IllegalObjectTypeException('The object given to add() was not of the type (' . $this->objectType . ') this repository manages.', 1248363335);
}
$this->persistenceManager->add($object);
$this->persistenceManager->persistAll();
}

/**
* Finds all FormEntries given by conf Array
* @param \Frappant\FrpFormAnswers\Domain\Model\FormEntryDemand $formEntryDemand
Expand Down
13 changes: 11 additions & 2 deletions Classes/Utility/FormAnswersUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,19 @@ public function prepareFormAnswersArray()
// Get all Pids with a formEntry list
foreach ($startPointPids as $pageId) {
foreach ($this->formEntryRepository->findAllInPidAndRootline($pageId) as $formEntry) {
$pageIds[$formEntry->getPid()][$formEntry->getForm()]['tot'] += 1;
if($pageIds[$formEntry->getPid()][$formEntry->getForm()]['tot']) {
$pageIds[$formEntry->getPid()][$formEntry->getForm()]['tot'] += 1;
} else {
$pageIds[$formEntry->getPid()][$formEntry->getForm()]['tot'] = 1;
}

if (!$formEntry->isExported()) {
$pageIds[$formEntry->getPid()][$formEntry->getForm()]['new'] += 1;
if($pageIds[$formEntry->getPid()][$formEntry->getForm()]['new']) {
$pageIds[$formEntry->getPid()][$formEntry->getForm()]['new'] += 1;
} else {
$pageIds[$formEntry->getPid()][$formEntry->getForm()]['new'] = 1;
}

}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Resources/Private/Backend/Templates/FormEntry/List.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ <h1>
</f:link.action>
</div>
</f:form>
<f:be.tableList tableName="tx_frpformanswers_domain_model_formentry" filter="{formName}" enableControlPanels="true"
fieldList="{0:'uid', 1: 'crdate'}" storagePid="{pid}" clickTitleMode="edit"/>
<f:be.tableList tableName="tx_frpformanswers_domain_model_formentry" filter="{formName}" enableClickMenu="true" enableControlPanels="true"
fieldList="{0:'uid', 1: 'form', 2: 'crdate', 3: 'exported'}" storagePid="{pid}" clickTitleMode="edit"/>
</f:for>

<f:if condition="{subPagesWithFormEntries}">
Expand Down
4 changes: 2 additions & 2 deletions Resources/Private/Language/de.locallang_be.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</trans-unit>
<trans-unit id="tx_frpformanswers_backend_templates_formentry_show.delete">
<source>Delete entries</source>
<target>Eingaben löschen</target>
<target>Einträge löschen</target>
</trans-unit>
<trans-unit id="flashmessage.deleteFormName.header">
<source>Entries deleted</source>
Expand Down Expand Up @@ -141,7 +141,7 @@
</trans-unit>
<trans-unit id="tx_frpformanswers_backend_templates_formentry_list.nothingsaved">
<source>No saved formEntries</source>
<target>Keine gespeicherten formEinträge</target>
<target>Keine gespeicherten Einträge</target>
</trans-unit>
</body>
</file>
Expand Down

1 comment on commit 4f88ab7

@frpuser
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

close #52; close #53;

Please sign in to comment.