Skip to content

Commit

Permalink
[TASK] Refactoring Utility Folder
Browse files Browse the repository at this point in the history
Split files in utility folder into service and utility classes
  • Loading branch information
einpraegsam committed Aug 2, 2015
1 parent 3fa4fe7 commit a688fb4
Show file tree
Hide file tree
Showing 65 changed files with 594 additions and 499 deletions.
12 changes: 6 additions & 6 deletions Classes/Command/TaskCommandController.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace In2code\Powermail\Command;

use In2code\Powermail\Utility\BasicFileFunctions;
use In2code\Powermail\Utility\BasicFileUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\CommandController;

Expand Down Expand Up @@ -93,22 +93,22 @@ public function exportCommand(
$storageFolder = 'typo3temp/tx_powermail/',
$fileName = NULL
) {
/** @var \In2code\Powermail\Utility\Export $export */
$export = $this->objectManager->get(
/** @var \In2code\Powermail\Utility\ExportService $exportService */
$exportService = $this->objectManager->get(
'In2code\Powermail\Utility\Export',
$this->mailRepository->findAllInPid($pageUid, array(), $this->getFilterVariables($period)),
$format,
array('domain' => $domain)
);
$export
$exportService
->setReceiverEmails($receiverEmails)
->setSenderEmails($senderEmail)
->setSubject($subject)
->setFieldList($fieldList)
->setAddAttachment($attachment)
->setStorageFolder($storageFolder)
->setFileName($fileName);
return $export->send();
return $exportService->send();
}

/**
Expand All @@ -122,7 +122,7 @@ public function exportCommand(
*/
public function cleanUnusedUploadsCommand($uploadPath = 'uploads/tx_powermail/') {
$usedUploads = $this->getUsedUploads();
$allUploads = BasicFileFunctions::getFilesFromRelativePath($uploadPath);
$allUploads = BasicFileUtility::getFilesFromRelativePath($uploadPath);
$removeCounter = 0;
foreach ($allUploads as $upload) {
if (!in_array($upload, $usedUploads)) {
Expand Down
10 changes: 5 additions & 5 deletions Classes/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use In2code\Powermail\Utility\Div;
use In2code\Powermail\Utility\BasicFileFunctions;
use In2code\Powermail\Utility\DivUtility;
use In2code\Powermail\Utility\BasicFileUtility;
use In2code\Powermail\Domain\Model\Mail;

/***************************************************************
Expand Down Expand Up @@ -109,7 +109,7 @@ abstract class AbstractController extends ActionController {
/**
* Instance for Misc Functions
*
* @var \In2code\Powermail\Utility\Div
* @var \In2code\Powermail\Utility\DivUtility
* @inject
*/
protected $div;
Expand Down Expand Up @@ -231,11 +231,11 @@ protected function reformatParamsForAction() {
$propertyMappingConfiguration->allowCreationForSubProperty('answers.' . $i);
$propertyMappingConfiguration->allowModificationForSubProperty('answers.' . $i);

$valueType = Div::getDataTypeFromFieldType(
$valueType = DivUtility::getDataTypeFromFieldType(
$this->div->getFieldTypeFromMarker($marker, $arguments['mail']['form'])
);
if ($valueType === 3 && is_array($value)) {
$value = BasicFileFunctions::getUniqueNamesForFileUploads($value, $this->settings, FALSE);
$value = BasicFileUtility::getUniqueNamesForFileUploads($value, $this->settings, FALSE);
}
if (is_array($value)) {
if (empty($value)) {
Expand Down
50 changes: 26 additions & 24 deletions Classes/Controller/FormController.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<?php
namespace In2code\Powermail\Controller;

use In2code\Powermail\Utility\SessionUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TYPO3\CMS\Core\Utility\DebugUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Core\Messaging\AbstractMessage;
use In2code\Powermail\Utility\BasicFileFunctions;
use In2code\Powermail\Utility\Div;
use In2code\Powermail\Utility\BasicFileUtility;
use In2code\Powermail\Utility\DivUtility;
use In2code\Powermail\Domain\Model\Mail;
use In2code\Powermail\Utility\Configuration;
use In2code\Powermail\Utility\ConfigurationUtility;

/***************************************************************
* Copyright notice
Expand Down Expand Up @@ -45,10 +46,10 @@
class FormController extends AbstractController {

/**
* @var \In2code\Powermail\Utility\SendMail
* @var \In2code\Powermail\Domain\Service\SendMailService
* @inject
*/
protected $sendMail;
protected $sendMailService;

/**
* action show form for creating new mails
Expand All @@ -61,7 +62,7 @@ public function formAction() {
}
$forms = $this->formRepository->findByUids($this->settings['main']['form']);
$this->signalSlotDispatcher->dispatch(__CLASS__, __FUNCTION__ . 'BeforeRenderView', array($forms, $this));
Div::saveFormStartInSession($forms, $this->settings);
SessionUtility::saveFormStartInSession($forms, $this->settings);

$this->assignForAll();
$this->view->assignMultiple(
Expand Down Expand Up @@ -99,8 +100,9 @@ public function initializeCreateAction() {
* @return void
*/
public function createAction(Mail $mail, $hash = NULL) {
BasicFileFunctions::fileUpload($this->settings['misc']['file']['folder'], $this->settings['misc']['file']['extension'], $mail);
$this->signalSlotDispatcher->dispatch(__CLASS__, __FUNCTION__ . 'BeforeRenderView', array($mail, $hash, $this));
BasicFileUtility::fileUpload($this->settings['misc']['file']['folder'], $this->settings['misc']['file']['extension'], $mail);
SessionUtility::saveSessionValuesAfterSubmit($mail);

if ($this->settings['debug']['variables']) {
GeneralUtility::devLog('Variables', $this->extensionName, 0, $_REQUEST);
Expand Down Expand Up @@ -152,7 +154,7 @@ public function initializeConfirmationAction() {
* @return void
*/
public function confirmationAction(Mail $mail) {
BasicFileFunctions::fileUpload($this->settings['misc']['file']['folder'], $this->settings['misc']['file']['extension'], $mail);
BasicFileUtility::fileUpload($this->settings['misc']['file']['folder'], $this->settings['misc']['file']['extension'], $mail);
$this->signalSlotDispatcher->dispatch(__CLASS__, __FUNCTION__ . 'BeforeRenderView', array($mail, $this));
$this->showThx($mail);
}
Expand Down Expand Up @@ -181,7 +183,7 @@ protected function sendMailPreflight(Mail $mail, $hash = NULL) {
* @return void
*/
protected function sendReceiverMail(Mail $mail, $hash = NULL) {
$receiverString = div::fluidParseString(
$receiverString = DivUtility::fluidParseString(
$this->settings['receiver']['email'],
$this->div->getVariablesWithMarkersFromMail($mail)
);
Expand Down Expand Up @@ -210,7 +212,7 @@ protected function sendReceiverMail(Mail $mail, $hash = NULL) {
$this->div->overwriteValueFromTypoScript($email['receiverName'], $this->conf['receiver.']['overwrite.'], 'name');
$this->div->overwriteValueFromTypoScript($email['senderName'], $this->conf['receiver.']['overwrite.'], 'senderName');
$this->div->overwriteValueFromTypoScript($email['senderEmail'], $this->conf['receiver.']['overwrite.'], 'senderEmail');
$sent = $this->sendMail->sendTemplateEmail($email, $mail, $this->settings, 'receiver');
$sent = $this->sendMailService->sendTemplateEmail($email, $mail, $this->settings, 'receiver');

if (!$sent) {
$this->addFlashMessage(
Expand Down Expand Up @@ -244,7 +246,7 @@ protected function sendSenderMail(Mail $mail) {
$this->div->overwriteValueFromTypoScript($email['receiverName'], $this->conf['sender.']['overwrite.'], 'name');
$this->div->overwriteValueFromTypoScript($email['senderName'], $this->conf['sender.']['overwrite.'], 'senderName');
$this->div->overwriteValueFromTypoScript($email['senderEmail'], $this->conf['sender.']['overwrite.'], 'senderEmail');
$this->sendMail->sendTemplateEmail($email, $mail, $this->settings, 'sender');
$this->sendMailService->sendTemplateEmail($email, $mail, $this->settings, 'sender');
}

/**
Expand All @@ -264,15 +266,15 @@ protected function sendConfirmationMail(Mail &$mail) {
'rteBody' => '',
'format' => $this->settings['sender']['mailformat'],
'variables' => array(
'hash' => Div::createOptinHash($mail),
'hash' => DivUtility::createOptinHash($mail),
'mail' => $mail
)
);
$this->div->overwriteValueFromTypoScript($email['receiverName'], $this->conf['optin.']['overwrite.'], 'name');
$this->div->overwriteValueFromTypoScript($email['receiverEmail'], $this->conf['optin.']['overwrite.'], 'email');
$this->div->overwriteValueFromTypoScript($email['senderName'], $this->conf['optin.']['overwrite.'], 'senderName');
$this->div->overwriteValueFromTypoScript($email['senderEmail'], $this->conf['optin.']['overwrite.'], 'senderEmail');
$this->sendMail->sendTemplateEmail($email, $mail, $this->settings, 'optin');
$this->sendMailService->sendTemplateEmail($email, $mail, $this->settings, 'optin');
}

/**
Expand All @@ -286,7 +288,7 @@ protected function showThx(Mail $mail) {

// assign
$this->view->assign('mail', $mail);
$this->view->assign('marketingInfos', Div::getMarketingInfos());
$this->view->assign('marketingInfos', SessionUtility::getMarketingInfos());
$this->view->assign('messageClass', $this->messageClass);
$this->view->assign('powermail_rte', $this->settings['thx']['body']);

Expand Down Expand Up @@ -324,16 +326,16 @@ protected function redirectToTarget() {
* @return void
*/
protected function saveMail(Mail &$mail = NULL) {
$marketingInfos = Div::getMarketingInfos();
$marketingInfos = SessionUtility::getMarketingInfos();
$mail
->setPid(Div::getStoragePage($this->settings['main']['pid']))
->setPid(DivUtility::getStoragePage($this->settings['main']['pid']))
->setSenderMail($this->div->getSenderMailFromArguments($mail))
->setSenderName($this->div->getSenderNameFromArguments($mail))
->setSubject($this->settings['receiver']['subject'])
->setReceiverMail($this->settings['receiver']['email'])
->setBody(DebugUtility::viewArray($this->div->getVariablesWithMarkersFromMail($mail)))
->setSpamFactor($GLOBALS['TSFE']->fe_user->getKey('ses', 'powermail_spamfactor'))
->setTime((time() - Div::getFormStartFromSession($mail->getForm()->getUid(), $this->settings)))
->setTime((time() - SessionUtility::getFormStartFromSession($mail->getForm()->getUid(), $this->settings)))
->setUserAgent(GeneralUtility::getIndpEnv('HTTP_USER_AGENT'))
->setMarketingRefererDomain($marketingInfos['refererDomain'])
->setMarketingReferer($marketingInfos['referer'])
Expand All @@ -344,17 +346,17 @@ protected function saveMail(Mail &$mail = NULL) {
->setMarketingPageFunnel($marketingInfos['pageFunnel']);
if ((int) $GLOBALS['TSFE']->fe_user->user['uid'] > 0) {
$mail->setFeuser(
$this->userRepository->findByUid(Div::getPropertyFromLoggedInFeUser('uid'))
$this->userRepository->findByUid(DivUtility::getPropertyFromLoggedInFeUser('uid'))
);
}
if (!Configuration::isDisableIpLogActive()) {
if (!ConfigurationUtility::isDisableIpLogActive()) {
$mail->setSenderIp(GeneralUtility::getIndpEnv('REMOTE_ADDR'));
}
if ($this->settings['main']['optin'] || $this->settings['db']['hidden']) {
$mail->setHidden(TRUE);
}
foreach ($mail->getAnswers() as $answer) {
$answer->setPid(Div::getStoragePage($this->settings['main']['pid']));
$answer->setPid(DivUtility::getStoragePage($this->settings['main']['pid']));
}
$this->mailRepository->add($mail);
$this->persistenceManager->persistAll();
Expand All @@ -371,7 +373,7 @@ public function optinConfirmAction($mail, $hash) {
$this->signalSlotDispatcher->dispatch(__CLASS__, __FUNCTION__ . 'BeforeRenderView', array($mail, $hash, $this));
$mail = $this->mailRepository->findByUid($mail);

if ($mail !== NULL && Div::checkOptinHash($hash, $mail)) {
if ($mail !== NULL && DivUtility::checkOptinHash($hash, $mail)) {
if ($mail->getHidden()) {
$mail->setHidden(FALSE);
$this->mailRepository->update($mail);
Expand All @@ -392,7 +394,7 @@ public function optinConfirmAction($mail, $hash) {
* @return void
*/
public function marketingAction($referer = NULL, $language = 0, $pid = 0, $mobileDevice = 0) {
Div::storeMarketingInformation($referer, $language, $pid, $mobileDevice);
SessionUtility::storeMarketingInformation($referer, $language, $pid, $mobileDevice);
}

/**
Expand All @@ -406,7 +408,7 @@ public function initializeObject() {
ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT
);
$this->conf = $typoScriptSetup['plugin.']['tx_powermail.']['settings.']['setup.'];
Div::mergeTypoScript2FlexForm($this->settings);
ConfigurationUtility::mergeTypoScript2FlexForm($this->settings);

$this->signalSlotDispatcher->dispatch(__CLASS__, __FUNCTION__ . 'Settings', array($this));

Expand Down Expand Up @@ -475,6 +477,6 @@ protected function isMailPersistActive($hash) {
* @return bool
*/
protected function isSendMailActive(Mail $mail, $hash) {
return empty($this->settings['main']['optin']) || (!empty($this->settings['main']['optin']) && Div::checkOptinHash($hash, $mail));
return empty($this->settings['main']['optin']) || (!empty($this->settings['main']['optin']) && DivUtility::checkOptinHash($hash, $mail));
}
}
27 changes: 14 additions & 13 deletions Classes/Controller/ModuleController.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php
namespace In2code\Powermail\Controller;

use In2code\Powermail\Domain\Service\FormConverterService;
use In2code\Powermail\Utility\DivUtility;
use In2code\Powermail\Utility\ReportingUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use In2code\Powermail\Utility\Div;
use In2code\Powermail\Utility\Reporting;

/***************************************************************
* Copyright notice
Expand Down Expand Up @@ -55,7 +56,7 @@ public function dispatchAction($forwardToAction = 'list') {
*/
public function listAction() {
$formUids = $this->mailRepository->findGroupedFormUidsToGivenPageUid($this->id);
$firstFormUid = Div::conditionalVariable($this->piVars['filter']['form'], key($formUids));
$firstFormUid = DivUtility::conditionalVariable($this->piVars['filter']['form'], key($formUids));
$this->view->assignMultiple(
array(
'mails' => $this->mailRepository->findAllInPid($this->id, $this->settings, $this->piVars),
Expand All @@ -80,13 +81,13 @@ public function exportXlsAction() {
'mails' => $this->mailRepository->findAllInPid($this->id, $this->settings, $this->piVars),
'fieldUids' => GeneralUtility::trimExplode(
',',
Div::conditionalVariable($this->piVars['export']['fields'], ''),
DivUtility::conditionalVariable($this->piVars['export']['fields'], ''),
TRUE
)
)
);

$fileName = Div::conditionalVariable($this->settings['export']['filenameXls'], 'export.xls');
$fileName = DivUtility::conditionalVariable($this->settings['export']['filenameXls'], 'export.xls');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: inline; filename="' . $fileName . '"');
header('Pragma: no-cache');
Expand All @@ -103,13 +104,13 @@ public function exportCsvAction() {
'mails' => $this->mailRepository->findAllInPid($this->id, $this->settings, $this->piVars),
'fieldUids' => GeneralUtility::trimExplode(
',',
Div::conditionalVariable($this->piVars['export']['fields'], ''),
DivUtility::conditionalVariable($this->piVars['export']['fields'], ''),
TRUE
)
)
);

$fileName = Div::conditionalVariable($this->settings['export']['filenameCsv'], 'export.csv');
$fileName = DivUtility::conditionalVariable($this->settings['export']['filenameCsv'], 'export.csv');
header('Content-Type: text/x-csv');
header('Content-Disposition: attachment; filename="' . $fileName . '"');
header('Pragma: no-cache');
Expand Down Expand Up @@ -143,7 +144,7 @@ public function reportingBeAction($subaction = NULL) {
public function reportingFormBeAction() {
$mails = $this->mailRepository->findAllInPid($this->id, $this->settings, $this->piVars);
$firstMail = $this->mailRepository->findFirstInPid($this->id);
$groupedAnswers = Reporting::getGroupedAnswersFromMails($mails);
$groupedAnswers = ReportingUtility::getGroupedAnswersFromMails($mails);

$this->view->assignMultiple(
array(
Expand All @@ -166,7 +167,7 @@ public function reportingFormBeAction() {
public function reportingMarketingBeAction() {
$mails = $this->mailRepository->findAllInPid($this->id, $this->settings, $this->piVars);
$firstMail = $this->mailRepository->findFirstInPid($this->id);
$groupedMarketingStuff = Reporting::getGroupedMarketingPropertiesFromMails($mails);
$groupedMarketingStuff = ReportingUtility::getGroupedMarketingPropertiesFromMails($mails);

$this->view->assignMultiple(
array(
Expand Down Expand Up @@ -289,9 +290,9 @@ public function converterUpdateBeAction($converter) {
$this->formRepository->findOldFieldsetsAndFieldsToTtContentRecord($form['uid']);
$formCounter++;
}
/** @var \In2code\Powermail\Utility\FormConverter $formConverter */
$formConverter = $this->objectManager->get('In2code\Powermail\Utility\FormConverter');
$result = $formConverter->createNewFromOldForms($oldFormsWithFieldsetsAndFields, $converter);
/** @var FormConverterService $formConverterService */
$formConverterService = $this->objectManager->get('In2code\Powermail\Domain\Service\FormConverterService');
$result = $formConverterService->createNewFromOldForms($oldFormsWithFieldsetsAndFields, $converter);
$this->view->assign('result', $result);
$this->view->assign('converter', $converter);
}
Expand Down Expand Up @@ -382,7 +383,7 @@ public function fixFilledMarkersInLocalizedFieldsAction() {
* @return void
*/
protected function checkAdminPermissions() {
if (!Div::isBackendAdmin()) {
if (!DivUtility::isBackendAdmin()) {
$this->controllerContext = $this->buildControllerContext();
$this->forward('toolsBe');
}
Expand Down
Loading

0 comments on commit a688fb4

Please sign in to comment.