3 namespace CoreFramework\Mailer;
5 // Import framework stuff
6 use CoreFramework\Generic\FrameworkInterface;
7 use CoreFramework\Manager\Login\ManageableMember;
8 use CoreFramework\Object\BaseFrameworkSystem;
11 * A general mailer class for all other mailers
13 * @author Roland Haeder <webmaster@shipsimu.org>
15 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
16 * @license GNU GPL 3.0 or any newer version
17 * @link http://www.shipsimu.org
19 * This program is free software: you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation, either version 3 of the License, or
22 * (at your option) any later version.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
32 class BaseMailer extends BaseFrameworkSystem {
36 private $templateName = '';
39 * Protected constructor
41 * @param $className Name of the class
44 protected function __construct ($className) {
45 // Call parent constructor
46 parent::__construct($className);
50 * Loads a text or HTML template depending on configuration into the template engine
52 * @param $templateName Name of the template we shall load
55 protected final function loadTemplate ($templateName) {
57 $this->setTemplateName($templateName);
59 // Get configuration entry
60 $templatePrefix = $this->getConfigInstance()->getConfigEntry('email_tpl_' . $templateName);
62 // Load this email template
63 $this->getTemplateInstance()->loadEmailTemplate($templatePrefix . '_' . $templateName);
67 * Adds a user class to the recipient list for current template
69 * @param $userInstance An instance of a user class
72 public function addRecipientByUserInstance (ManageableMember $userInstance) {
74 $templateName = $this->getTemplateName();
76 // Is the list initialized?
77 $this->pushValueToGenericArrayKey('recipients', $templateName, 'recipients', $userInstance);
81 * Adds a template variable (just the name) to the recipient list in given section of current template
83 * @param $section Section can be 'config' or "value" currently
84 * @param $variableName Template variable name to add
87 private final function addTemplateVariable ($section, $variableName) {
89 $templateName = $this->getTemplateName();
91 // Generate full section name
92 $sectionName = $section . '_vars';
94 // Is the list initialized?
95 $this->setGenericArrayElement('recipients', $templateName, $sectionName, $variableName, 'OK');
99 * Adds a config template variable to the recipient list of current template
101 * @param $variableName Template variable name to add
104 public final function addConfigTemplateVariable ($variableName) {
105 $this->addTemplateVariable('config', $variableName);
109 * Adds a 'value' template variable to the recipient list of current template
111 * @param $variableName Template variable name to add
114 public final function addValueTemplateVariable ($variableName) {
115 $this->addTemplateVariable('value', $variableName);
119 * Adds a value instance for a given variable name. It should be set!
121 * @param $variableName Template variable we want to assign a value instance
122 * @param $valueInstance An object instance which can provide "field values"
125 public final function addValueInstance ($variableName, FrameworkInterface $valueInstance) {
126 $this->setGenericArrayElement('recipients', $this->getTemplateName(), 'values', $variableName, $valueInstance);
130 * Protected setter for template name
132 * @param $templateName Name of email template
135 public final function setTemplateName ($templateName) {
136 $this->templateName = (string) $templateName;
140 * Protected getter for template name
142 * @return $templateName Name of email template
144 protected final function getTemplateName () {
145 return $this->templateName;
149 * Setter for subject line
151 * @param $subjectLine Subject line to set
154 public final function setSubjectLine ($subjectLine) {
155 $this->setGenericArrayElement('recipients', $this->getTemplateName(), 'generic', 'subject', $subjectLine);
159 * Getter for subject line or null if not found
161 * @return $subjectLine Subject line to set
163 public final function getSubjectLine () {
164 // Default subject is null
168 $templateName = $this->getTemplateName();
170 // Does the subject line exist?
171 if ((!empty($templateName)) && ($this->isGenericArrayElementSet('recipients', $templateName, 'generic', 'subject'))) {
173 $subjectLine = $this->getGenericArrayElement('recipients', $templateName, 'generic', 'subject');
181 * Use subject line provided by the (XML) template otherwise a subject line must be set
185 public function useSubjectFromTemplate () {
186 // Set the subject line
187 $this->setSubjectLine('{?subject?}');
191 * Getter for recipient list array
193 * @return $recipientList Array with reciepients
195 public final function getRecipientList () {
196 return $this->getGenericArray('recipients');