Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
sg_mail
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TYPO3
sg_mail
Commits
7ab9999a
Commit
7ab9999a
authored
8 years ago
by
Torsten Oppermann
Browse files
Options
Downloads
Patches
Plain Diff
[TASK] Refactoring Mailcontroller for new db logic
parent
82153d5e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Classes/Controller/MailController.php
+104
-36
104 additions, 36 deletions
Classes/Controller/MailController.php
with
104 additions
and
36 deletions
Classes/Controller/MailController.php
+
104
−
36
View file @
7ab9999a
...
...
@@ -26,6 +26,8 @@ namespace SGalinski\SgMail\Controller;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use
SGalinski\SgMail\Domain\Model\Template
;
use
SGalinski\SgMail\Domain\Repository\TemplateRepository
;
use
SGalinski\SgMail\Service\MailTemplateService
;
use
TYPO3\CMS\Core\Messaging\FlashMessage
;
use
TYPO3\CMS\Core\Utility\GeneralUtility
;
...
...
@@ -44,6 +46,12 @@ class MailController extends ActionController {
*/
protected
$languageRepository
=
NULL
;
/**
* @var \SGalinski\SgMail\Domain\Repository\TemplateRepository
* @inject
*/
protected
$templateRepository
=
NULL
;
/**
* Show template Selection and enable content input + mail preview
*
...
...
@@ -72,10 +80,6 @@ class MailController extends ActionController {
$languages
[]
=
$language
->
getLocale
();
}
foreach
(
$languages
as
$currentLanguage
)
{
$this
->
writeLanguageFile
(
$currentLanguage
,
$templatePath
);
}
$this
->
view
->
assign
(
'languages'
,
$languages
);
$this
->
view
->
assign
(
'templates'
,
MailTemplateService
::
getRegisterArray
());
...
...
@@ -83,7 +87,6 @@ class MailController extends ActionController {
&&
!
isset
(
$selectedLanguageLeft
)
&&
!
isset
(
$selectedLanguageRight
)
)
{
$selectedTemplateArray
=
$registerArray
[
$selectedExtension
][
$selectedTemplate
];
$this
->
view
->
assign
(
'selectedTemplate'
,
$selectedTemplateArray
);
...
...
@@ -116,48 +119,72 @@ class MailController extends ActionController {
$this
->
view
->
assign
(
'selectedTemplateKey'
,
$selectedTemplateKey
);
$this
->
view
->
assign
(
'selectedExtensionKey'
,
$selectedExtensionKey
);
/** @var /SGalinski/SgMail/Domain/Model/Template $result */
$templateLeft
=
$this
->
templateRepository
->
findTemplate
(
$selectedExtensionKey
,
$selectedTemplateKey
,
$selectedLanguageLeft
)
->
getFirst
();
$this
->
view
->
assign
(
'contentLeft'
,
file_get_contents
(
$templatePath
.
$selectedLanguageLeft
.
'.sg_mail.locallang.html'
)
$templateLeft
!==
NULL
?
$templateLeft
->
getContent
()
:
''
);
$this
->
view
->
assign
(
'subjectLeft'
,
$templateLeft
!==
NULL
?
$templateLeft
->
getSubject
()
:
''
);
/** @var /SGalinski/SgMail/Domain/Model/Template $result */
$templateRight
=
$this
->
templateRepository
->
findTemplate
(
$selectedExtensionKey
,
$selectedTemplateKey
,
$selectedLanguageRight
)
->
getFirst
();
$this
->
view
->
assign
(
'contentRight'
,
file_get_contents
(
$templatePath
.
$selectedLanguageRight
.
'.sg_mail.locallang.html'
)
$templateRight
!==
NULL
?
$templateRight
->
getContent
()
:
''
);
$this
->
view
->
assign
(
'subjectRight'
,
$templateRight
!==
NULL
?
$templateRight
->
getSubject
()
:
''
);
}
else
{
$this
->
view
->
assign
(
'selectedLanguageLeft'
,
'en'
);
/** @var /SGalinski/SgMail/Domain/Model/Template $result */
$templateLeft
=
$this
->
templateRepository
->
findTemplate
(
$firstEntry
,
$secondLevelFirstEntry
,
'en'
)
->
getFirst
();
$this
->
view
->
assign
(
'contentLeft'
,
file_get_contents
(
$templatePath
.
'en.sg_mail.locallang.html'
)
'contentLeft'
,
$templateLeft
!==
NULL
?
$templateLeft
->
getContent
()
:
''
);
$this
->
view
->
assign
(
'selectedLanguageRight'
,
'en'
);
$this
->
view
->
assign
(
'contentRight'
,
file_get_contents
(
$templatePath
.
'en.sg_mail.locallang.html'
)
'subjectLeft'
,
$templateLeft
!==
NULL
?
$templateLeft
->
getSubject
()
:
''
);
}
}
/**
*
* creates a language File for this Template
*
* @param string $language
* @param string $path
*/
private
function
writeLanguageFile
(
$language
,
$path
)
{
$currentLangFile
=
$path
.
$language
.
'.sg_mail.locallang.html'
;
/** @var /SGalinski/SgMail/Domain/Model/Template $result */
$templateRight
=
$this
->
templateRepository
->
findTemplate
(
$firstEntry
,
$secondLevelFirstEntry
,
'en'
)
->
getFirst
();
if
(
file_exists
(
$currentLangFile
))
{
return
;
}
$this
->
view
->
assign
(
'contentRight'
,
$templateRight
!==
NULL
?
$templateRight
->
getContent
()
:
''
);
$langFileContent
=
'Auto Generated for Language: '
.
$language
;
file_put_contents
(
$currentLangFile
,
$langFileContent
);
$this
->
view
->
assign
(
'subjectRight'
,
$templateRight
!==
NULL
?
$templateRight
->
getSubject
()
:
''
);
}
}
/**
* Save content (left & right)
* if left & right is the same language, the right content will apply
* if left & right is the same language, the right content will apply
only if its another language
*
* @param string $contentLeft
* @param string $contentRight
...
...
@@ -165,19 +192,20 @@ class MailController extends ActionController {
* @param string $selectedTemplate
* @param string $selectedLanguageLeft
* @param string $selectedLanguageRight
* @param string $subjectLeft
* @param string $subjectRight
*/
public
function
saveAction
(
$contentLeft
=
NULL
,
$contentRight
=
NULL
,
$selectedExtension
=
NULL
,
$selectedTemplate
=
NULL
,
$selectedLanguageLeft
=
NULL
,
$selectedLanguageRight
=
NULL
$selectedLanguageLeft
=
NULL
,
$selectedLanguageRight
=
NULL
,
$subjectLeft
=
NULL
,
$subjectRight
=
NULL
)
{
$this
->
saveTemplate
(
$selectedExtension
,
$selectedTemplate
,
$selectedLanguageLeft
,
$contentLeft
,
$subjectLeft
);
$templatePath
=
$this
->
getTemplatePath
(
$selectedExtension
,
$selectedTemplate
);
$filename
=
$templatePath
.
$selectedLanguageLeft
.
'.sg_mail.locallang.html'
;
file_put_contents
(
$filename
,
$contentLeft
);
$filename
=
$templatePath
.
$selectedLanguageRight
.
'.sg_mail.locallang.html'
;
file_put_contents
(
$filename
,
$contentRight
);
if
(
$selectedLanguageLeft
!==
$selectedLanguageRight
)
{
$this
->
saveTemplate
(
$selectedExtension
,
$selectedTemplate
,
$selectedLanguageRight
,
$contentRight
,
$subjectRight
);
}
$message
=
LocalizationUtility
::
translate
(
'backend.success'
,
'sg_mail'
);
$this
->
addFlashMessage
(
$message
,
''
,
FlashMessage
::
OK
);
...
...
@@ -186,6 +214,46 @@ class MailController extends ActionController {
$this
->
redirect
(
'index'
,
NULL
,
NULL
,
$arguments
);
}
/**
* Save or update the template in the DB, depending if it already exists or not
*
* @param string $selectedExtension
* @param string $selectedTemplate
* @param string $selectedLanguage
* @param string $selectedContent
* @param string $selectedSubject
* @return Template $template
*/
private
function
saveTemplate
(
$selectedExtension
,
$selectedTemplate
,
$selectedLanguage
,
$selectedContent
,
$selectedSubject
)
{
/** @var Template $template */
$template
=
$this
->
templateRepository
->
findTemplate
(
$selectedExtension
,
$selectedTemplate
,
$selectedLanguage
)
->
getFirst
();
$templateAlreadyExists
=
TRUE
;
$objectManager
=
GeneralUtility
::
makeInstance
(
ObjectManager
::
class
);
if
(
$template
===
NULL
)
{
$templateAlreadyExists
=
FALSE
;
$template
=
$objectManager
->
get
(
Template
::
class
);
}
$template
->
setExtensionKey
(
$selectedExtension
);
$template
->
setTemplateName
(
$selectedTemplate
);
$template
->
setLanguage
(
$selectedLanguage
);
$template
->
setContent
(
$selectedContent
);
$template
->
setSubject
(
$selectedSubject
);
if
(
$templateAlreadyExists
)
{
$this
->
templateRepository
->
update
(
$template
);
}
else
{
$this
->
templateRepository
->
add
(
$template
);
}
return
$template
;
}
/**
* Returns the Path for this Template
*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment