3 namespace Org\Mxchange\CoreFramework\Mailer;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
7 use Org\Mxchange\CoreFramework\Manager\Login\ManageableMember;
8 use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
11 * A general mailer class for all other mailers
13 * @author Roland Haeder <webmaster@shipsimu.org>
15 <<<<<<< HEAD:framework/main/classes/mailer/class_BaseMailer.php
16 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
18 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2016 Core Developer Team
19 >>>>>>> Some updates::inc/main/classes/mailer/class_BaseMailer.php
20 * @license GNU GPL 3.0 or any newer version
21 * @link http://www.shipsimu.org
23 * This program is free software: you can redistribute it and/or modify
24 * it under the terms of the GNU General Public License as published by
25 * the Free Software Foundation, either version 3 of the License, or
26 * (at your option) any later version.
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
33 * You should have received a copy of the GNU General Public License
34 * along with this program. If not, see <http://www.gnu.org/licenses/>.
36 abstract class BaseMailer extends BaseFrameworkSystem {
40 private $templateName = '';
43 * Protected constructor
45 * @param $className Name of the class
48 protected function __construct ($className) {
49 // Call parent constructor
50 parent::__construct($className);
54 * Loads a text or HTML template depending on configuration into the template engine
56 * @param $templateName Name of the template we shall load
59 protected final function loadTemplate ($templateName) {
61 $this->setTemplateName($templateName);
63 // Get configuration entry
64 $templatePrefix = $this->getConfigInstance()->getConfigEntry('email_tpl_' . $templateName);
66 // Load this email template
67 $this->getTemplateInstance()->loadEmailTemplate($templatePrefix . '_' . $templateName);
71 * Adds a user class to the recipient list for current template
73 * @param $userInstance An instance of a user class
76 public function addRecipientByUserInstance (ManageableMember $userInstance) {
78 $templateName = $this->getTemplateName();
80 // Is the list initialized?
81 $this->pushValueToGenericArrayKey('recipients', $templateName, 'recipients', $userInstance);
85 * Adds a template variable (just the name) to the recipient list in given section of current template
87 * @param $section Section can be 'config' or "value" currently
88 * @param $variableName Template variable name to add
91 private final function addTemplateVariable ($section, $variableName) {
93 $templateName = $this->getTemplateName();
95 // Generate full section name
96 $sectionName = $section . '_vars';
98 // Is the list initialized?
99 $this->setGenericArrayElement('recipients', $templateName, $sectionName, $variableName, 'OK');
103 * Adds a config template variable to the recipient list of current template
105 * @param $variableName Template variable name to add
108 public final function addConfigTemplateVariable ($variableName) {
109 $this->addTemplateVariable('config', $variableName);
113 * Adds a 'value' template variable to the recipient list of current template
115 * @param $variableName Template variable name to add
118 public final function addValueTemplateVariable ($variableName) {
119 $this->addTemplateVariable('value', $variableName);
123 * Adds a value instance for a given variable name. It should be set!
125 * @param $variableName Template variable we want to assign a value instance
126 * @param $valueInstance An object instance which can provide "field values"
129 public final function addValueInstance ($variableName, FrameworkInterface $valueInstance) {
130 $this->setGenericArrayElement('recipients', $this->getTemplateName(), 'values', $variableName, $valueInstance);
134 * Protected setter for template name
136 * @param $templateName Name of email template
139 public final function setTemplateName ($templateName) {
140 $this->templateName = (string) $templateName;
144 * Protected getter for template name
146 * @return $templateName Name of email template
148 protected final function getTemplateName () {
149 return $this->templateName;
153 * Setter for subject line
155 * @param $subjectLine Subject line to set
158 public final function setSubjectLine ($subjectLine) {
159 $this->setGenericArrayElement('recipients', $this->getTemplateName(), 'generic', 'subject', $subjectLine);
163 * Getter for subject line or null if not found
165 * @return $subjectLine Subject line to set
167 public final function getSubjectLine () {
168 // Default subject is null
172 $templateName = $this->getTemplateName();
174 // Does the subject line exist?
175 if ((!empty($templateName)) && ($this->isGenericArrayElementSet('recipients', $templateName, 'generic', 'subject'))) {
177 $subjectLine = $this->getGenericArrayElement('recipients', $templateName, 'generic', 'subject');
185 * Use subject line provided by the (XML) template otherwise a subject line must be set
189 public function useSubjectFromTemplate () {
190 // Set the subject line
191 $this->setSubjectLine('{?subject?}');
195 * Getter for recipient list array
197 * @return $recipientList Array with reciepients
199 public final function getRecipientList () {
200 return $this->getGenericArray('recipients');