3 namespace CoreFramework\Mailer;
5 // Import framework stuff
6 use CoreFramework\Object\BaseFrameworkSystem;
7 use CoreFramework\Generic\FrameworkInterface;
10 * A general mailer class for all other mailers
12 * @author Roland Haeder <webmaster@shipsimu.org>
14 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
15 * @license GNU GPL 3.0 or any newer version
16 * @link http://www.shipsimu.org
18 * This program is free software: you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation, either version 3 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 class BaseMailer extends BaseFrameworkSystem {
35 private $templateName = '';
38 * Protected constructor
40 * @param $className Name of the class
43 protected function __construct ($className) {
44 // Call parent constructor
45 parent::__construct($className);
49 * Loads a text or HTML template depending on configuration into the template engine
51 * @param $templateName Name of the template we shall load
54 protected final function loadTemplate ($templateName) {
56 $this->setTemplateName($templateName);
58 // Get configuration entry
59 $templatePrefix = $this->getConfigInstance()->getConfigEntry('email_tpl_' . $templateName);
61 // Load this email template
62 $this->getTemplateInstance()->loadEmailTemplate($templatePrefix . '_' . $templateName);
66 * Adds a user class to the recipient list for current template
68 * @param $userInstance An instance of a user class
71 public function addRecipientByUserInstance (ManageableMember $userInstance) {
73 $templateName = $this->getTemplateName();
75 // Is the list initialized?
76 $this->pushValueToGenericArrayKey('recipients', $templateName, 'recipients', $userInstance);
80 * Adds a template variable (just the name) to the recipient list in given section of current template
82 * @param $section Section can be 'config' or "value" currently
83 * @param $variableName Template variable name to add
86 private final function addTemplateVariable ($section, $variableName) {
88 $templateName = $this->getTemplateName();
90 // Generate full section name
91 $sectionName = $section . '_vars';
93 // Is the list initialized?
94 $this->setGenericArrayElement('recipients', $templateName, $sectionName, $variableName, 'OK');
98 * Adds a config template variable to the recipient list of current template
100 * @param $variableName Template variable name to add
103 public final function addConfigTemplateVariable ($variableName) {
104 $this->addTemplateVariable('config', $variableName);
108 * Adds a 'value' template variable to the recipient list of current template
110 * @param $variableName Template variable name to add
113 public final function addValueTemplateVariable ($variableName) {
114 $this->addTemplateVariable('value', $variableName);
118 * Adds a value instance for a given variable name. It should be set!
120 * @param $variableName Template variable we want to assign a value instance
121 * @param $valueInstance An object instance which can provide "field values"
124 public final function addValueInstance ($variableName, FrameworkInterface $valueInstance) {
125 $this->setGenericArrayElement('recipients', $this->getTemplateName(), 'values', $variableName, $valueInstance);
129 * Protected setter for template name
131 * @param $templateName Name of email template
134 public final function setTemplateName ($templateName) {
135 $this->templateName = (string) $templateName;
139 * Protected getter for template name
141 * @return $templateName Name of email template
143 protected final function getTemplateName () {
144 return $this->templateName;
148 * Setter for subject line
150 * @param $subjectLine Subject line to set
153 public final function setSubjectLine ($subjectLine) {
154 $this->setGenericArrayElement('recipients', $this->getTemplateName(), 'generic', 'subject', $subjectLine);
158 * Getter for subject line or null if not found
160 * @return $subjectLine Subject line to set
162 public final function getSubjectLine () {
163 // Default subject is null
167 $templateName = $this->getTemplateName();
169 // Does the subject line exist?
170 if ((!empty($templateName)) && ($this->isGenericArrayElementSet('recipients', $templateName, 'generic', 'subject'))) {
172 $subjectLine = $this->getGenericArrayElement('recipients', $templateName, 'generic', 'subject');
180 * Use subject line provided by the (XML) template otherwise a subject line must be set
184 public function useSubjectFromTemplate () {
185 // Set the subject line
186 $this->setSubjectLine('{?subject?}');
190 * Getter for recipient list array
192 * @return $recipientList Array with reciepients
194 public final function getRecipientList () {
195 return $this->getGenericArray('recipients');