3 * A general mailer class for all other mailers
5 * @author Roland Haeder <webmaster@shipsimu.org>
7 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Core Developer Team
8 * @license GNU GPL 3.0 or any newer version
9 * @link http://www.shipsimu.org
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 class BaseMailer extends BaseFrameworkSystem {
28 private $templateName = '';
31 * Protected constructor
33 * @param $className Name of the class
36 protected function __construct ($className) {
37 // Call parent constructor
38 parent::__construct($className);
42 * Loads a text or HTML template depending on configuration into the template engine
44 * @param $templateName Name of the template we shall load
47 protected final function loadTemplate ($templateName) {
49 $this->setTemplateName($templateName);
51 // Get configuration entry
52 $templatePrefix = $this->getConfigInstance()->getConfigEntry('email_tpl_' . $templateName);
54 // Load this email template
55 $this->getTemplateInstance()->loadEmailTemplate($templatePrefix . '_' . $templateName);
59 * Adds a user class to the recipient list for current template
61 * @param $userInstance An instance of a user class
64 public function addRecipientByUserInstance (ManageableMember $userInstance) {
66 $templateName = $this->getTemplateName();
68 // Is the list initialized?
69 $this->pushValueToGenericArrayKey('recipients', $templateName, 'recipients', $userInstance);
73 * Adds a template variable (just the name) to the recipient list in given section of current template
75 * @param $section Section can be 'config' or "value" currently
76 * @param $variableName Template variable name to add
79 private final function addTemplateVariable ($section, $variableName) {
81 $templateName = $this->getTemplateName();
83 // Generate full section name
84 $sectionName = $section . '_vars';
86 // Is the list initialized?
87 $this->setGenericArrayElement('recipients', $templateName, $sectionName, $variableName, 'OK');
91 * Adds a config template variable to the recipient list of current template
93 * @param $variableName Template variable name to add
96 public final function addConfigTemplateVariable ($variableName) {
97 $this->addTemplateVariable('config', $variableName);
101 * Adds a 'value' template variable to the recipient list of current template
103 * @param $variableName Template variable name to add
106 public final function addValueTemplateVariable ($variableName) {
107 $this->addTemplateVariable('value', $variableName);
111 * Adds a value instance for a given variable name. It should be set!
113 * @param $variableName Template variable we want to assign a value instance
114 * @param $valueInstance An object instance which can provide "field values"
117 public final function addValueInstance ($variableName, FrameworkInterface $valueInstance) {
118 $this->setGenericArrayElement('recipients', $this->getTemplateName(), 'values', $variableName, $valueInstance);
122 * Protected setter for template name
124 * @param $templateName Name of email template
127 public final function setTemplateName ($templateName) {
128 $this->templateName = (string) $templateName;
132 * Protected getter for template name
134 * @return $templateName Name of email template
136 protected final function getTemplateName () {
137 return $this->templateName;
141 * Setter for subject line
143 * @param $subjectLine Subject line to set
146 public final function setSubjectLine ($subjectLine) {
147 $this->setGenericArrayElement('recipients', $this->getTemplateName(), 'generic', 'subject', $subjectLine);
151 * Getter for subject line or null if not found
153 * @return $subjectLine Subject line to set
155 public final function getSubjectLine () {
156 // Default subject is null
160 $templateName = $this->getTemplateName();
162 // Does the subject line exist?
163 if ((!empty($templateName)) && ($this->isGenericArrayElementSet('recipients', $templateName, 'generic', 'subject'))) {
165 $subjectLine = $this->getGenericArrayElement('recipients', $templateName, 'generic', 'subject');
173 * Use subject line provided by the (XML) template otherwise a subject line must be set
177 public function useSubjectFromTemplate () {
178 // Set the subject line
179 $this->setSubjectLine('{?subject?}');
183 * Getter for recipient list array
185 * @return $recipientList Array with reciepients
187 public final function getRecipientList () {
188 return $this->getGenericArray('recipients');