Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TYPO3 v10.4 LTS compatibility #7

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 39 additions & 35 deletions Classes/Controller/ModuleController.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<?php

namespace Bithost\PowermailFastexport\Controller;

use Bithost\PowermailFastexport\Domain\Repository\AnswerRepository;
use Bithost\PowermailFastexport\Domain\Repository\MailRepository;
use Bithost\PowermailFastexport\Exporter\CsvExporter;
use Bithost\PowermailFastexport\Exporter\XlsExporter;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use In2code\Powermail\Utility\StringUtility;
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;

/***
*
Expand Down Expand Up @@ -42,68 +46,44 @@ class ModuleController extends \In2code\Powermail\Controller\ModuleController
*
* @return String
*/
public function exportXlsAction() {
public function exportXlsAction(): void
{

$mails = $this->getMailsAsArray();
/** @var \Bithost\PowermailFastexport\Exporter\XlsExporter $xlsExporter */
$xlsExporter = GeneralUtility::makeInstance('Bithost\\PowermailFastexport\\Exporter\\XlsExporter', $this->objectManager);
$xlsExporter = GeneralUtility::makeInstance(XlsExporter::class, $this->objectManager, new RenderingContext());
$fieldUids = GeneralUtility::trimExplode(
',',
StringUtility::conditionalVariable($this->piVars['export']['fields'], ''),
TRUE
true
);
$fileName = StringUtility::conditionalVariable($this->settings['export']['filenameXls'], 'export.xls');

header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: inline; filename="' . $fileName . '"');
header('Pragma: no-cache');

return $xlsExporter->export($mails, $fieldUids);
}

/**
* Export Action for CSV Files
*
* @return String
*/
public function exportCsvAction() {

$mails = $this->getMailsAsArray();
/** @var \Bithost\PowermailFastexport\Exporter\CsvExporter $csvExporter */
$csvExporter = GeneralUtility::makeInstance('Bithost\\PowermailFastexport\\Exporter\\CsvExporter', $this->objectManager);
$fieldUids = GeneralUtility::trimExplode(
',',
StringUtility::conditionalVariable($this->piVars['export']['fields'], ''),
TRUE
);
$fileName = StringUtility::conditionalVariable($this->settings['export']['filenameCsv'], 'export.csv');

header('Content-Type: text/x-csv');
header('Content-Disposition: attachment; filename="' . $fileName . '"');
header('Pragma: no-cache');

return $csvExporter->export($mails, $fieldUids);
$this->response->appendContent($xlsExporter->export($mails, $fieldUids));
}

/**
* get all mails as array
*
* @return array
*/
private function getMailsAsArray() {
if(!empty($this->settings['maxExecutionTime']))
{
private function getMailsAsArray()
{
if (!empty($this->settings['maxExecutionTime'])) {
ini_set('max_execution_time', (int)$this->settings['maxExecutionTime']);
}
if(!empty($this->settings['memoryLimit']))
{
if (!empty($this->settings['memoryLimit'])) {
ini_set('memory_limit', $this->settings['memoryLimit']);
}

/** @var MailRepository $mailRepository */
$mailRepository = $this->objectManager->get(MailRepository::class);
$dbMails = $mailRepository->findAllInPidRaw($this->id, $this->settings, $this->piVars);
$mails = array();
$mails = [];

foreach ($dbMails as $mail) {
$mails[$mail['uid']] = $mail;
Expand All @@ -115,12 +95,36 @@ private function getMailsAsArray() {

foreach ($answers as $answer) {
if (!is_array($mails[$answer['mail']]['answers'])) {
$mails[$answer['mail']]['answers'] = array();
$mails[$answer['mail']]['answers'] = [];
}
$mails[$answer['mail']]['answers'][$answer['uid']] = $answer;
}

return $mails;
}

/**
* Export Action for CSV Files
*
* @return String
*/
public function exportCsvAction(): void
{
$mails = $this->getMailsAsArray();
/** @var \Bithost\PowermailFastexport\Exporter\CsvExporter $csvExporter */
$csvExporter = GeneralUtility::makeInstance(CsvExporter::class, $this->objectManager, new RenderingContext());
$fieldUids = GeneralUtility::trimExplode(
',',
StringUtility::conditionalVariable($this->piVars['export']['fields'], ''),
true
);
$fileName = StringUtility::conditionalVariable($this->settings['export']['filenameCsv'], 'export.csv');

header('Content-Type: text/x-csv');
header('Content-Disposition: attachment; filename="' . $fileName . '"');
header('Pragma: no-cache');

$this->response->appendContent($csvExporter->export($mails, $fieldUids));
}

}
4 changes: 3 additions & 1 deletion Classes/Domain/Repository/AnswerRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Bithost\PowermailFastexport\Domain\Repository;

use In2code\Powermail\Domain\Model\Answer;

/***
*
* This file is part of the "Powermail FastExport" Extension for TYPO3 CMS.
Expand Down Expand Up @@ -38,7 +40,7 @@ class AnswerRepository extends \In2code\Powermail\Domain\Repository\AnswerReposi
public function __construct(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
{
parent::__construct($objectManager);
$this->objectType = 'In2code\\Powermail\\Domain\\Model\\Answer';
$this->objectType = Answer::class;
}

public function findByMailUidsRaw(array $mailUids) {
Expand Down
3 changes: 2 additions & 1 deletion Classes/Domain/Repository/MailRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Bithost\PowermailFastexport\Domain\Repository;

use In2code\Powermail\Domain\Model\Mail;
use TYPO3\CMS\Extbase\Persistence\Generic\QueryResult;

/***
Expand Down Expand Up @@ -40,7 +41,7 @@ class MailRepository extends \In2code\Powermail\Domain\Repository\MailRepository
public function __construct(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
{
parent::__construct($objectManager);
$this->objectType = 'In2code\\Powermail\\Domain\\Model\\Mail';
$this->objectType = Mail::class;
}

/**
Expand Down
94 changes: 44 additions & 50 deletions Classes/Exporter/AbstractExporter.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
<?php
namespace Bithost\PowermailFastexport\Exporter;

use Bithost\PowermailFastexport\MockViewHelpers\Condition\IsArrayViewHelper;
use Bithost\PowermailFastexport\MockViewHelpers\Condition\IsDateTimeVariableInVariableViewHelper;
use Bithost\PowermailFastexport\MockViewHelpers\Condition\IsNumberViewHelper;
use Bithost\PowermailFastexport\MockViewHelpers\Format\DateViewHelper;
use Bithost\PowermailFastexport\MockViewHelpers\Getter\GetFieldLabelFromUidViewHelper;
use Bithost\PowermailFastexport\MockViewHelpers\Getter\GetPageNameFromUidViewHelper;
use Bithost\PowermailFastexport\MockViewHelpers\Misc\VariableInVariableViewHelper;
use Bithost\PowermailFastexport\MockViewHelpers\String\UnderscoredToLowerCamelCaseViewHelper;
use In2code\Powermail\Domain\Model\Answer;
use In2code\Powermail\Utility\ArrayUtility;
use In2code\Powermail\ViewHelpers\Condition\IsDateTimeVariableInVariableViewHelper;
use In2code\Powermail\ViewHelpers\Getter\GetFieldLabelFromUidViewHelper;
use In2code\Powermail\ViewHelpers\Getter\GetPageNameFromUidViewHelper;
use In2code\Powermail\ViewHelpers\Misc\VariableInVariableViewHelper;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TYPO3\CMS\Fluid\ViewHelpers\Format\DateViewHelper;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContext;

/***
*
Expand Down Expand Up @@ -43,16 +41,6 @@

abstract class AbstractExporter
{
/**
* @var IsNumberViewHelper
*/
protected $isNumber = null;

/**
* @var IsArrayViewHelper
*/
protected $isArray = null;

/**
* @var IsDateTimeVariableInVariableViewHelper
*/
Expand All @@ -73,11 +61,6 @@ abstract class AbstractExporter
*/
protected $getPageNameFromUid = null;

/**
* @var UnderscoredToLowerCamelCaseViewHelper
*/
protected $underscoredToLowerCamelCase = null;

/**
* @var VariableInVariableViewHelper
*/
Expand All @@ -88,20 +71,23 @@ abstract class AbstractExporter
*/
protected $objectManager = null;

/**
* @var RenderingContext
*/
protected $renderingContext = null;

/**
* @param ObjectManager $objectManager
*/
public function __construct(ObjectManager $objectManager)
public function __construct(ObjectManager $objectManager, RenderingContext $renderingContext)
Copy link
Member

Choose a reason for hiding this comment

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

Is the RenderingContext ever used? If it does not serve any purpose, it would be great if you could remove it.

{
$this->objectManager = $objectManager;
$this->isNumber = GeneralUtility::makeInstance('Bithost\\PowermailFastexport\\MockViewHelpers\\Condition\\IsNumberViewHelper');
$this->isArray = GeneralUtility::makeInstance('Bithost\\PowermailFastexport\\MockViewHelpers\\Condition\\IsArrayViewHelper');
$this->isDateTimeVariableInVariable = GeneralUtility::makeInstance('Bithost\\PowermailFastexport\\MockViewHelpers\\Condition\\IsDateTimeVariableInVariableViewHelper');
$this->date = GeneralUtility::makeInstance('Bithost\\PowermailFastexport\\MockViewHelpers\\Format\\DateViewHelper');
$this->getFieldLabelFromUid = $this->objectManager->get('Bithost\\PowermailFastexport\\MockViewHelpers\\Getter\\GetFieldLabelFromUidViewHelper');
$this->getPageNamerFromUid = $this->objectManager->get('Bithost\\PowermailFastexport\\MockViewHelpers\\Getter\\GetPageNameFromUidViewHelper');
$this->underscoredToLowerCamelCase = GeneralUtility::makeInstance('Bithost\\PowermailFastexport\\MockViewHelpers\\String\\UnderscoredToLowerCamelCaseViewHelper');
$this->variableInVariable = GeneralUtility::makeInstance('Bithost\\PowermailFastexport\\MockViewHelpers\\Misc\\VariableInVariableViewHelper');
$this->renderingContext = $renderingContext;
$this->isDateTimeVariableInVariable = GeneralUtility::makeInstance(IsDateTimeVariableInVariableViewHelper::class);
$this->date = GeneralUtility::makeInstance(DateViewHelper::class);
$this->getFieldLabelFromUid = $this->objectManager->get(GetFieldLabelFromUidViewHelper::class);
$this->getPageNamerFromUid = $this->objectManager->get(GetPageNameFromUidViewHelper::class);
$this->variableInVariable = GeneralUtility::makeInstance(VariableInVariableViewHelper::class);
}

/**
Expand Down Expand Up @@ -131,13 +117,13 @@ protected function renderRecordFieldContent(array &$mail, $fieldUid)
{
$result = '';

if ($this->isNumber->render($fieldUid)) {
if (is_numeric($fieldUid)) {
if (is_array($mail['answers'])) {
foreach ($mail['answers'] as $answer) {
$answer['value'] = $this->getValue($answer);
/** @var Answer $answer */
if (isset($answer['field']) && $fieldUid == $answer['field']) {
if ($this->isArray->render($answer['value'])) {
if (isset($answer['field']) && (int)$fieldUid === (int)$answer['field']) {
if (is_array($answer['value'])) {
$i = 0;
$length = count($answer['value']);
foreach ($answer['value'] as $singleValue) {
Expand All @@ -156,31 +142,39 @@ protected function renderRecordFieldContent(array &$mail, $fieldUid)
}
}
} else {
if ($this->isDateTimeVariableInVariable->render($mail, $fieldUid)) {
if ($fieldUid == 'crdate') {
$result .= $this->date->render($this->variableInVariable->render($mail, $fieldUid), 'd.m.Y H:i:s');
$this->isDateTimeVariableInVariable->setArguments(['obj' => $mail, 'prop' => $fieldUid]);
if ($this->isDateTimeVariableInVariable->render()) {
$this->variableInVariable->setArguments(['obj' => $mail, 'prop' => $fieldUid]);
if ($fieldUid === 'crdate') {
$this->date->setArguments(['date' => $this->variableInVariable->render(), 'format' => 'd.m.Y H:i:s']);
$result .= $this->date->render();
$result .= $this->translate('Clock');
} else {
if ($fieldUid == 'time') {
$result .= $this->date->render($this->variableInVariable->render($mail, $fieldUid), '%M:%S');
if ($fieldUid === 'time') {
$this->date->setArguments(['date' => $this->variableInVariable->render(), 'format' => '%M:%S']);
$result .= $this->date->render();
} else {
$result .= $this->date->render($this->variableInVariable->render($mail, $fieldUid), 'H:i:s');
$this->date->setArguments(['date' => $this->variableInVariable->render(), 'format' => 'H:i:s']);
$result .= $this->date->render();
}
}
} else {
if ($fieldUid == 'marketing_page_funnel') {
if ($this->isArray->render($this->variableInVariable->render($mail, $fieldUid))) {
if ($fieldUid === 'marketing_page_funnel') {
$this->variableInVariable->setArguments(['obj' => $mail, 'prop' => $fieldUid]);
if (is_array($this->variableInVariable->render())) {
$i = 0;
$length = count($this->variableInVariable->render($mail, $fieldUid));
foreach ($this->variableInVariable->render($mail, $fieldUid) as $pid) {
$result .= $this->getPageNameFromUid->render($pid);
$length = count($this->variableInVariable->render());
foreach ($this->variableInVariable->render() as $pid) {
$this->getPageNameFromUid->setArguments(['uid' => $pid]);
$result .= $this->getPageNameFromUid->render();
if ($i !== $length - 1) {
$result .= '&gt;';
}
}
}
} else {
$result .= $this->variableInVariable->render($mail, $fieldUid);
$this->variableInVariable->setArguments(['obj' => $mail, 'prop' => $fieldUid]);
$result .= $this->variableInVariable->render();
}
}
}
Expand All @@ -194,14 +188,14 @@ protected function getValue($answer) {
// if serialized, change to array
if (ArrayUtility::isJsonArray($value)) {
// only if type multivalue or upload
if ($answer['value_type'] == 1 || $answer['value_type'] == 3) {
if ($answer['value_type'] === 1 || $answer['value_type'] === 3) {
$value = json_decode($value, TRUE);
}
}

// if multitext or upload force array
if (($answer['value_type'] == 1 || $answer['value_type'] == 3) && !is_array($value)) {
$value = (empty($value) ? array() : array(strval($value)));
if (($answer['value_type'] === 1 || $answer['value_type'] === 3) && !is_array($value)) {
$value = (empty($value) ? array() : array((string)$value));
}

return $value;
Expand Down
9 changes: 6 additions & 3 deletions Classes/Exporter/CsvExporter.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace Bithost\PowermailFastexport\Exporter;

use TYPO3\CMS\Core\Utility\GeneralUtility;

/***
*
* This file is part of the "Powermail FastExport" Extension for TYPO3 CMS.
Expand Down Expand Up @@ -82,10 +84,11 @@ protected function renderHeader(array $fieldUids)
$data = array();

foreach ($fieldUids as $fieldUid) {
if ($this->isNumber->render($fieldUid)) {
$data[] = $this->getFieldLabelFromUid->render($fieldUid);
if (is_numeric($fieldUid)) {
$this->getFieldLabelFromUid->setArguments(['uid' => (int)$fieldUid]);
$data[] = $this->getFieldLabelFromUid->render();
} else {
$data[] = $this->translate('\\In2code\\Powermail\\Domain\\Model\\Mail.' . $this->underscoredToLowerCamelCase->render($fieldUid));
$data[] = $this->translate('\\In2code\\Powermail\\Domain\\Model\\Mail.' . GeneralUtility::underscoredToLowerCamelCase($fieldUid));
}
}

Expand Down
9 changes: 6 additions & 3 deletions Classes/Exporter/XlsExporter.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace Bithost\PowermailFastexport\Exporter;

use TYPO3\CMS\Core\Utility\GeneralUtility;

/***
*
* This file is part of the "Powermail FastExport" Extension for TYPO3 CMS.
Expand Down Expand Up @@ -109,10 +111,11 @@ protected function renderHeader(array $fieldUids)
foreach ($fieldUids as $fieldUid) {
$result .= '<th>';

if ($this->isNumber->render($fieldUid)) {
$result .= $this->getFieldLabelFromUid->render($fieldUid);
if (is_numeric($fieldUid)) {
$this->getFieldLabelFromUid->setArguments(['uid' => (int)$fieldUid]);
$result .= $this->getFieldLabelFromUid->render();
} else {
$result .= $this->translate('\\In2code\\Powermail\\Domain\\Model\\Mail.' . $this->underscoredToLowerCamelCase->render($fieldUid));
$result .= $this->translate('\\In2code\\Powermail\\Domain\\Model\\Mail.' . GeneralUtility::underscoredToLowerCamelCase($fieldUid));
}

$result .= '</th>';
Expand Down
Loading