3 namespace CoreFramework\Mailer;
5 // Load framework stuff
6 use CoreFramework\Generic\FrameworkInterface;
9 * A general mailer class for all other mailers
11 * @author Roland Haeder <webmaster@shipsimu.org>
13 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
14 * @license GNU GPL 3.0 or any newer version
15 * @link http://www.shipsimu.org
17 * This program is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation, either version 3 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 class BaseMailer extends BaseFrameworkSystem {
34 private $templateName = '';
37 * Protected constructor
39 * @param $className Name of the class
42 protected function __construct ($className) {
43 // Call parent constructor
44 parent::__construct($className);
48 * Loads a text or HTML template depending on configuration into the template engine
50 * @param $templateName Name of the template we shall load
53 protected final function loadTemplate ($templateName) {
55 $this->setTemplateName($templateName);
57 // Get configuration entry
58 $templatePrefix = $this->getConfigInstance()->getConfigEntry('email_tpl_' . $templateName);
60 // Load this email template
61 $this->getTemplateInstance()->loadEmailTemplate($templatePrefix . '_' . $templateName);
65 * Adds a user class to the recipient list for current template
67 * @param $userInstance An instance of a user class
70 public function addRecipientByUserInstance (ManageableMember $userInstance) {
72 $templateName = $this->getTemplateName();
74 // Is the list initialized?
75 $this->pushValueToGenericArrayKey('recipients', $templateName, 'recipients', $userInstance);
79 * Adds a template variable (just the name) to the recipient list in given section of current template
81 * @param $section Section can be 'config' or "value" currently
82 * @param $variableName Template variable name to add
85 private final function addTemplateVariable ($section, $variableName) {
87 $templateName = $this->getTemplateName();
89 // Generate full section name
90 $sectionName = $section . '_vars';
92 // Is the list initialized?
93 $this->setGenericArrayElement('recipients', $templateName, $sectionName, $variableName, 'OK');
97 * Adds a config template variable to the recipient list of current template
99 * @param $variableName Template variable name to add
102 public final function addConfigTemplateVariable ($variableName) {
103 $this->addTemplateVariable('config', $variableName);
107 * Adds a 'value' template variable to the recipient list of current template
109 * @param $variableName Template variable name to add
112 public final function addValueTemplateVariable ($variableName) {
113 $this->addTemplateVariable('value', $variableName);
117 * Adds a value instance for a given variable name. It should be set!
119 * @param $variableName Template variable we want to assign a value instance
120 * @param $valueInstance An object instance which can provide "field values"
123 public final function addValueInstance ($variableName, FrameworkInterface $valueInstance) {
124 $this->setGenericArrayElement('recipients', $this->getTemplateName(), 'values', $variableName, $valueInstance);
128 * Protected setter for template name
130 * @param $templateName Name of email template
133 public final function setTemplateName ($templateName) {
134 $this->templateName = (string) $templateName;
138 * Protected getter for template name
140 * @return $templateName Name of email template
142 protected final function getTemplateName () {
143 return $this->templateName;
147 * Setter for subject line
149 * @param $subjectLine Subject line to set
152 public final function setSubjectLine ($subjectLine) {
153 $this->setGenericArrayElement('recipients', $this->getTemplateName(), 'generic', 'subject', $subjectLine);
157 * Getter for subject line or null if not found
159 * @return $subjectLine Subject line to set
161 public final function getSubjectLine () {
162 // Default subject is null
166 $templateName = $this->getTemplateName();
168 // Does the subject line exist?
169 if ((!empty($templateName)) && ($this->isGenericArrayElementSet('recipients', $templateName, 'generic', 'subject'))) {
171 $subjectLine = $this->getGenericArrayElement('recipients', $templateName, 'generic', 'subject');
179 * Use subject line provided by the (XML) template otherwise a subject line must be set
183 public function useSubjectFromTemplate () {
184 // Set the subject line
185 $this->setSubjectLine('{?subject?}');
189 * Getter for recipient list array
191 * @return $recipientList Array with reciepients
193 public final function getRecipientList () {
194 return $this->getGenericArray('recipients');