QueueController.php 4.68 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
namespace SGalinski\SgMail\Controller;

/***************************************************************
 *  Copyright notice
 *
 *  (c) sgalinski Internet Services (https://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!
 ***************************************************************/
27
use SGalinski\SgMail\Service\BackendService;
28
use SGalinski\SgMail\Service\MailTemplateService;
29
30
31
32
33
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Backend\Template\Components\DocHeaderComponent;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
34
use TYPO3\CMS\Core\Messaging\FlashMessage;
35
use TYPO3\CMS\Core\Utility\GeneralUtility;
36
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
37
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
38
39
40
41
42

/**
 * Controller for the mail templating service module
 */
class QueueController extends ActionController {
43
44
45
46
47
48
49
	/**
	 * DocHeaderComponent
	 *
	 * @var DocHeaderComponent
	 */
	protected $docHeaderComponent;

50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
	/**
	 * @var \SGalinski\SgMail\Domain\Repository\MailRepository
	 * @inject
	 */
	protected $mailRepository;

	/**
	 * @var \SGalinski\SgMail\Session\PhpSession
	 */
	protected $session;

	/**
	 * @param string $selectedTemplate
	 * @param string $selectedExtension
	 */
	public function indexAction($selectedTemplate = NULL, $selectedExtension = NULL) {
66
67
		$registerArray = MailTemplateService::getRegisterArray();

68
		if ($selectedTemplate === NULL || $selectedTemplate === '') {
69
70
71
			$selectedExtension = key($registerArray);
			$selectedTemplate = key($registerArray[$selectedExtension]);
		}
72

73
74
		$pageUid = BackendService::getSiteRoot((int) GeneralUtility::_GP('id'));
		$siteRootId = BackendService::getSiteRoot($pageUid);
75
76
77
		$queue = $this->mailRepository->findAllEntries($selectedExtension, $selectedTemplate, $siteRootId);

		// create doc header component
78
79
80
81
82
83
84
		$pageInfo = BackendUtility::readPageAccess($pageUid, $GLOBALS['BE_USER']->getPagePermsClause(1));
		$this->docHeaderComponent = GeneralUtility::makeInstance(DocHeaderComponent::class);

		$this->docHeaderComponent->setMetaInformation($pageInfo);
		$this->makeButtons();
		$this->view->assign('docHeader', $this->docHeaderComponent->docHeaderContent());

85
		$this->view->assign('selectedTemplateKey', $selectedTemplate);
86
		$this->view->assign('selectedExtensionKey', $selectedExtension);
87
		$this->view->assign('templates', $registerArray);
88
		$this->view->assign('queue', $queue);
89
90
		$this->view->assign('mode', 'queue');
	}
91
92
93
94
95

	/**
	 * send or resend a mail in the queue
	 *
	 * @param int $uid
96
97
	 * @param string $selectedExtension
	 * @param string $selectedTemplate
98
	 */
99
	public function sendMailAction($uid, $selectedExtension, $selectedTemplate) {
100
101
102
		$mailService = new MailTemplateService();
		$mailService->sendMailFromQueue($uid);

103
		$message = LocalizationUtility::translate('backend.success_mail_queue', 'sg_mail');
104
105
106
107
		$this->addFlashMessage($message, '', FlashMessage::OK);
		$arguments = $this->request->getArguments();
		$this->redirect('index', NULL, NULL, $arguments);
	}
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139

	/**
	 * create buttons for the backend module header
	 */
	private function makeButtons() {
		/** @var ButtonBar $buttonBar */
		$buttonBar = $this->docHeaderComponent->getButtonBar();

		/** @var IconFactory $iconFactory */
		$iconFactory = GeneralUtility::makeInstance(IconFactory::class);

		// Refresh
		$refreshButton = $buttonBar->makeLinkButton()
			->setHref(GeneralUtility::getIndpEnv('REQUEST_URI'))
			->setTitle(LocalizationUtility::translate('LLL:EXT:lang/locallang_core.xlf:labels.reload', ''))
			->setIcon($iconFactory->getIcon('actions-refresh', Icon::SIZE_SMALL));
		$buttonBar->addButton($refreshButton, ButtonBar::BUTTON_POSITION_RIGHT);

		// shortcut button
		$shortcutButton = $buttonBar->makeShortcutButton()
			->setModuleName($this->request->getPluginName())
			->setGetVariables(
				[
					'id',
					'M'
				]
			)
			->setSetVariables([]);

		$buttonBar->addButton($shortcutButton, ButtonBar::BUTTON_POSITION_RIGHT);
		$this->docHeaderComponent->getButtonBar();
	}
140
}