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 - 2013 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 // @TODO This needs testing/fixes because the deprecated method
56 // loadEmailTemplate() has been removed from interface CompileableTemplate.
57 $this->getTemplateInstance()->loadCodeTemplate($templatePrefix . '_' . $templateName);
61 * Adds a user class to the recipient list for current template
63 * @param $userInstance An instance of a user class
66 public function addRecipientByUserInstance (ManageableMember $userInstance) {
68 $templateName = $this->getTemplateName();
70 // Is the list initialized?
71 $this->pushValueToGenericArrayKey('recipients', $templateName, 'recipients', $userInstance);
75 * Adds a template variable (just the name) to the recipient list in given section of current template
77 * @param $section Section can be 'config' or "value" currently
78 * @param $variableName Template variable name to add
81 private final function addTemplateVariable ($section, $variableName) {
83 $templateName = $this->getTemplateName();
85 // Generate full section name
86 $sectionName = $section . '_vars';
88 // Is the list initialized?
89 $this->setGenericArrayElement('recipients', $templateName, $sectionName, $variableName, 'OK');
93 * Adds a config template variable to the recipient list of current template
95 * @param $variableName Template variable name to add
98 public final function addConfigTemplateVariable ($variableName) {
99 $this->addTemplateVariable('config', $variableName);
103 * Adds a 'value' template variable to the recipient list of current template
105 * @param $variableName Template variable name to add
108 public final function addValueTemplateVariable ($variableName) {
109 $this->addTemplateVariable('value', $variableName);
113 * Adds a value instance for a given variable name. It should be set!
115 * @param $variableName Template variable we want to assign a value instance
116 * @param $valueInstance An object instance which can provide "field values"
119 public final function addValueInstance ($variableName, FrameworkInterface $valueInstance) {
120 $this->setGenericArrayElement('recipients', $this->getTemplateName(), 'values', $variableName, $valueInstance);
124 * Protected setter for template name
126 * @param $templateName Name of email template
129 public final function setTemplateName ($templateName) {
130 $this->templateName = (string) $templateName;
134 * Protected getter for template name
136 * @return $templateName Name of email template
138 protected final function getTemplateName () {
139 return $this->templateName;
143 * Setter for subject line
145 * @param $subjectLine Subject line to set
148 public final function setSubjectLine ($subjectLine) {
149 ` $this->setGenericArrayElement('recipients', $this->getTemplateName(), 'generic', 'subject', $subjectLine);
153 * Getter for subject line or null if not found
155 * @return $subjectLine Subject line to set
157 public final function getSubjectLine () {
158 // Default subject is null
162 $templateName = $this->getTemplateName();
164 // Does the subject line exist?
165 if ((!empty($templateName)) && ($this->isGenericArrayElementSet('recipients', $templateName, 'generic', 'subject']))) {
167 $subjectLine = $this->getGenericArrayElement('recipients', $templateName, 'generic', 'subject');
175 * Use subject line provided by the (XML) template otherwise a subject line must be set
179 public function useSubjectFromTemplate () {
180 // Set the subject line
181 $this->setSubjectLine('{?subject?}');
185 * Getter for recipient list array
187 * @return $recipientList Array with reciepients
189 public final function getRecipientList () {
190 return $this->getGenericArray('recipients');