Skip to content
Snippets Groups Projects
Commit b9ce9634 authored by Torsten Oppermann's avatar Torsten Oppermann
Browse files

[TASK] Remembering language selections

parent c4b1229b
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,7 @@ namespace SGalinski\SgMail\Controller;
use SGalinski\SgMail\Domain\Model\Template;
use SGalinski\SgMail\Service\MailTemplateService;
use SGalinski\SgMail\Session\PhpSession;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
......@@ -51,6 +52,11 @@ class MailController extends ActionController {
*/
protected $templateRepository = NULL;
/**
* @var \SGalinski\Lfeditor\Session\PhpSession
*/
protected $session;
/**
* Show template Selection and enable content input + mail preview
*
......@@ -66,6 +72,11 @@ class MailController extends ActionController {
$selectedLanguageRight = NULL, $selectedExtensionKey = NULL, $selectedTemplateKey = NULL
) {
if (!($this->session instanceof PhpSession)) {
$this->session = $this->objectManager->get('SGalinski\SgMail\Session\PhpSession');
$this->session->setSessionKey('sg_mail_controller_session');
}
$registerArray = MailTemplateService::getRegisterArray();
reset(MailTemplateService::getRegisterArray());
$firstEntry = key(MailTemplateService::getRegisterArray());
......@@ -86,9 +97,20 @@ class MailController extends ActionController {
) {
$selectedTemplateArray = $registerArray[$selectedExtension][$selectedTemplate];
// get last selected languages
!isset($selectedLanguageLeft) ? $selectedLanguageLeft = $this->session->getDataByKey(
'selectedLanguageLeft'
) : NULL;
!isset($selectedLanguageRight) ? $selectedLanguageRight = $this->session->getDataByKey(
'selectedLanguageRight'
) : NULL;
$this->view->assign('selectedTemplate', $selectedTemplateArray);
$this->view->assign('selectedTemplateKey', $selectedTemplate);
$this->view->assign('selectedExtensionKey', $selectedExtension);
$this->view->assign('selectedLanguageLeft', $selectedLanguageLeft);
$this->view->assign('selectedLanguageRight', $selectedLanguageRight);
} elseif (!isset($selectedLanguageLeft) && !isset($selectedLanguageRight)) {
......@@ -98,16 +120,38 @@ class MailController extends ActionController {
);
}
$this->view->assign('selectedLanguageLeft', $this->settings['templateDefaultLanguage']);
$this->view->assign('selectedLanguageRight', $this->settings['templateDefaultLanguage']);
// get last selected languages
!isset($selectedLanguageLeft) ? $selectedLanguageLeft = $this->session->getDataByKey(
'selectedLanguageLeft'
) : NULL;
!isset($selectedLanguageRight) ? $selectedLanguageRight = $this->session->getDataByKey(
'selectedLanguageRight'
) : NULL;
$this->view->assign('selectedLanguageLeft', $selectedLanguageLeft);
$this->view->assign('selectedLanguageRight', $selectedLanguageRight);
$this->view->assign('selectedTemplateKey', $secondLevelFirstEntry);
$this->view->assign('selectedExtensionKey', $firstEntry);
}
if (isset($selectedTemplate) && isset($selectedExtension)) {
!isset($selectedLanguageLeft) ? $selectedLanguageLeft = 'en' : NULL;
!isset($selectedLanguageRight) ? $selectedLanguageRight = 'en' : NULL;
isset($selectedLanguageLeft) ? $this->session->setDataByKey(
'selectedLanguageLeft', $selectedLanguageLeft
) : NULL;
isset($selectedLanguageRight) ? $this->session->setDataByKey(
'selectedLanguageRight', $selectedLanguageRight
) : NULL;
// get last selected languages
!isset($selectedLanguageLeft) ? $selectedLanguageLeft = $this->session->getDataByKey(
'selectedLanguageLeft'
) : NULL;
!isset($selectedLanguageRight) ? $selectedLanguageRight = $this->session->getDataByKey(
'$selectedLanguageRight'
) : NULL;
$this->view->assign('selectedLanguageLeft', $selectedLanguageLeft);
$this->view->assign('selectedLanguageRight', $selectedLanguageRight);
......@@ -289,9 +333,12 @@ class MailController extends ActionController {
* @param string $selectedExtensionKey
* @param string $selectedLanguageLeft
* @param string $selectedLanguageRight
* @param string $contentRight
* @param string $contentLeft
*/
public function sendTestMailAction(
$emailAddress, $selectedExtensionKey, $selectedTemplateKey, $selectedLanguageLeft, $selectedLanguageRight
$emailAddress, $selectedExtensionKey, $selectedTemplateKey, $selectedLanguageLeft, $selectedLanguageRight,
$contentRight, $contentLeft
) {
if (!filter_var($this->settings['mail']['test']['from'], FILTER_VALIDATE_EMAIL)) {
......
<?php
namespace SGalinski\SgMail\Session;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (http://www.sgalinski.de)
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Core\SingletonInterface;
/**
* PHP Session handler
*/
class PhpSession implements SingletonInterface {
/**
* @var string
*/
protected $sessionKey;
/**
* Constructor
*/
public function __construct() {
session_start();
$this->sessionKey = uniqid();
}
/**
* @param string $sessionKey
* @return void
*/
public function setSessionKey($sessionKey) {
$this->sessionKey = $sessionKey;
}
/**
* Returns the current session key
*
* @return string
*/
public function getSessionKey() {
return $this->sessionKey;
}
/**
* Exchanges the complete session data
*
* @param mixed $data
* @return void
*/
public function exchangeData($data) {
$this->destroy();
$_SESSION[$this->sessionKey] = $data;
}
/**
* Returns the complete session data
*
* @return mixed
*/
public function getData() {
return $_SESSION[$this->sessionKey];
}
/**
* Sets data inside the session below the given key
*
* @param string $key
* @param mixed $data
* @return void
*/
public function setDataByKey($key, $data) {
$_SESSION[$this->sessionKey][$key] = $data;
}
/**
* Returns data of the session defined by the given key
*
* @param string $key
* @return mixed
*/
public function getDataByKey($key) {
return $_SESSION[$this->sessionKey][$key];
}
/**
* Removes data defined by the given key.
*
* @param string $key
* @return void
*/
public function unsetDataByKey($key) {
unset($_SESSION[$this->sessionKey][$key]);
}
/**
* Removes all session data
*
* @return void
*/
public function destroy() {
unset($_SESSION[$this->sessionKey]);
}
}
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment