/** * Executes this finisher * @see AbstractFinisher::execute() * * @return void * @throws \TYPO3\Flow\Mvc\Exception\StopActionException(); */ protected function executeInternal() { /** @var \TYPO3\Form\Core\Runtime\FormRuntime $formRuntime */ $formRuntime = $this->finisherContext->getFormRuntime(); $formValueArray = $formRuntime->getFormState()->getFormValues(); if ($formRuntime->getRequest()->getParentRequest()->getControllerActionName() == 'edit') { // we need to update the template /** @var \GIB\GradingTool\Domain\Model\Template $template */ $template = $this->templateRepository->findByIdentifier($formRuntime->getRequest()->getParentRequest()->getArgument('template')['__identity']); $template->setTemplateIdentifier($formValueArray['templateIdentifier']); $template->setContent(serialize($formValueArray)); //$project->setLastUpdated(new \TYPO3\Flow\Utility\Now); $this->templateRepository->update($template); // add a flash message $message = new \TYPO3\Flow\Error\Message('The template "%s" was successfully edited.', \TYPO3\Flow\Error\Message::SEVERITY_OK, array($template->getTemplateIdentifier())); $this->flashMessageContainer->addMessage($message); } else { // we need to add a new template /** @var \GIB\GradingTool\Domain\Model\Template $template */ $template = new \GIB\GradingTool\Domain\Model\Template(); $template->setTemplateIdentifier($formValueArray['templateIdentifier']); // serialize all form content and store it $template->setContent(serialize($formValueArray)); //$project->setCreated(new \TYPO3\Flow\Utility\Now); $this->templateRepository->add($template); // add a flash message $message = new \TYPO3\Flow\Error\Message('The template "%s" was successfully created.', \TYPO3\Flow\Error\Message::SEVERITY_OK, array($formValueArray['templateIdentifier'])); $this->flashMessageContainer->addMessage($message); } $this->persistenceManager->persistAll(); // redirect to dashboard $formRuntime = $this->finisherContext->getFormRuntime(); $request = $formRuntime->getRequest()->getMainRequest(); $uriBuilder = new \TYPO3\Flow\Mvc\Routing\UriBuilder(); $uriBuilder->setRequest($request); $uriBuilder->reset(); $uri = $uriBuilder->uriFor('list', NULL, 'Template'); $response = $formRuntime->getResponse(); $mainResponse = $response; while ($response = $response->getParentResponse()) { $mainResponse = $response; } $mainResponse->setStatus(303); $mainResponse->setHeader('Location', (string) $uri); throw new \TYPO3\Flow\Mvc\Exception\StopActionException(); }
/** * Returns the templateIdentifier of a template in the laguage of a project if available, * fall back to default language if not available * * @param string $templateIdentifier * @param \GIB\GradingTool\Domain\Model\Project $project * @return string */ public function getTemplateIdentifierOverlay($templateIdentifier, \GIB\GradingTool\Domain\Model\Project $project) { $availableLanguages = $this->settings['languages']; $defaultLangage = $this->settings['defaultLanguage']; $projectLanguage = $project->getLanguage(); if ($projectLanguage === $defaultLangage) { // the language for the default template has no suffix, therefore return the unchanged templateIdentifier return $templateIdentifier; } if (array_key_exists($projectLanguage, $availableLanguages)) { // language is available, so we try to overlay if (count($this->templateRepository->findByTemplateIdentifier($templateIdentifier . ucfirst($projectLanguage)))) { // localized template was found, so we use it return $templateIdentifier . ucfirst($projectLanguage); } else { // localized template was not found, we fall back to default language return $templateIdentifier; } } }
/** * @param $templateIdentifier * @param \GIB\GradingTool\Domain\Model\Project $project * @param \GIB\GradingTool\Domain\Model\ProjectManager $projectManager * @param string $recipientName * @param string $recipientEmail * @param string $additionalContent * @param array $attachements * @return bool|void */ public function sendNotificationMail($templateIdentifier, \GIB\GradingTool\Domain\Model\Project $project, \GIB\GradingTool\Domain\Model\ProjectManager $projectManager = NULL, $recipientName = '', $recipientEmail = '', $additionalContent = '', $attachements = array()) { if ($this->settings['email']['activateNotifications'] === FALSE) { return TRUE; } /** @var \GIB\GradingTool\Domain\Model\Template $template */ $template = $this->templateRepository->findOneByTemplateIdentifier($templateIdentifier); $templateContentArray = unserialize($template->getContent()); // some kind of wrapper of all e-mail templates containing the HTML structure and styles $beforeContent = Files::getFileContents($this->settings['email']['beforeContentTemplate']); $afterContent = Files::getFileContents($this->settings['email']['afterContentTemplate']); /** @var \TYPO3\Fluid\View\StandaloneView $emailView */ $emailView = new \TYPO3\Fluid\View\StandaloneView(); $emailView->setTemplateSource('<f:format.raw>' . $beforeContent . $templateContentArray['content'] . $afterContent . '</f:format.raw>'); $emailView->setPartialRootPath(FLOW_PATH_PACKAGES . 'Application/GIB.GradingTool/Resources/Private/Partials'); $emailView->setFormat('html'); $emailView->assignMultiple(array('beforeContent' => $beforeContent, 'afterContent' => $afterContent, 'project' => $project, 'projectManager' => $projectManager, 'dataSheetContent' => $project->getDataSheetContentArray(), 'additionalContent' => $additionalContent)); $emailBody = $emailView->render(); /** @var \TYPO3\SwiftMailer\Message $email */ $email = new Message(); $email->setFrom(array($templateContentArray['senderEmail'] => $templateContentArray['senderName'])); // the recipient e-mail can be overridden by method arguments if (!empty($recipientEmail)) { $email->setTo(array((string) $recipientEmail => (string) $recipientName)); // in this case, send a bcc to the GIB team $email->setBcc(array($templateContentArray['senderEmail'] => $templateContentArray['senderName'])); } else { $email->setTo(array($templateContentArray['recipientEmail'] => $templateContentArray['recipientName'])); } if (!empty($attachements)) { foreach ($attachements as $attachement) { $email->attach(\Swift_Attachment::fromPath($attachement['source'])->setFilename($attachement['fileName'])); } } $email->setSubject($templateContentArray['subject']); $email->setBody($emailBody, 'text/html'); $email->send(); }
/** * List action */ public function listAction() { $templates = $this->templateRepository->findAll(); $this->view->assignMultiple(array('currentAction' => $this->request->getControllerActionName(), 'templates' => $templates)); }