/** * @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(); }
/** * @param array $paths * @param string $templateNamePrefix * @param string $suffix * @return string */ public function render(array $paths, $templateNamePrefix = NULL, $suffix = '.hbs') { foreach ($paths as $path) { $templates = \TYPO3\Flow\Utility\Files::readDirectoryRecursively($path, $suffix); foreach ($templates as $template) { if (substr($template, 0, strlen($path) + 10) === $path . '/Resources') { $templateName = str_replace(array($path . '/Resources/', $suffix), '', $template); $this->handlebarTemplates[$this->getPrefixedResourceTemplateName($templateName, $templateNamePrefix)] = $template; } elseif (substr($template, 0, strlen($path) + 9) === $path . '/Partials') { $templateName = str_replace(array($path . '/Partials/', $suffix), '', $template); $this->handlebarTemplates['_' . $this->getPrefixedResourceTemplateName($templateName, $templateNamePrefix)] = $template; } else { $templateName = str_replace(array($path . '/', $suffix, '/'), array('', '', '_'), $template); $this->handlebarTemplates[$this->getPrefixedTemplateName($templateName, $templateNamePrefix)] = $template; } } } foreach ($this->handlebarTemplates as $templateName => $template) { $handlebarView = new \TYPO3\Fluid\View\StandaloneView(); $handlebarView->setFormat('html'); $handlebarView->setTemplateSource(\TYPO3\Flow\Utility\Files::getFileContents($template)); $assignHelpers = \TYPO3\Flow\Reflection\ObjectAccess::getPropertyPath($this->settings, 'handlebar.view.assignHelpers.' . $templateName); if (is_array($assignHelpers)) { foreach ($assignHelpers as $variable => $helper) { if (!isset($helper['class']) || !isset($helper['method'])) { continue; } $helperInstance = $this->objectManager->get($helper['class']); $value = call_user_func_array(array($helperInstance, $helper['method']), isset($helper['arguments']) ? $helper['arguments'] : array()); $handlebarView->assign($variable, $value); } } $this->handlebarTemplates[$templateName] = sprintf('<script type="text/x-handlebars" data-template-name="%s">%s</script>', $templateName, $handlebarView->render()); } return implode('', $this->handlebarTemplates); }