3 namespace Org\Mxchange\CoreFramework\Mailer;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
7 use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
8 use Org\Mxchange\CoreFramework\Manager\Login\ManageableMember;
9 use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
12 * A general mailer class for all other mailers
14 * @author Roland Haeder <webmaster@shipsimu.org>
16 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
17 * @license GNU GPL 3.0 or any newer version
18 * @link http://www.shipsimu.org
20 * This program is free software: you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation, either version 3 of the License, or
23 * (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program. If not, see <http://www.gnu.org/licenses/>.
33 abstract class BaseMailer extends BaseFrameworkSystem {
37 private $templateName = '';
40 * Protected constructor
42 * @param $className Name of the class
45 protected function __construct ($className) {
46 // Call parent constructor
47 parent::__construct($className);
51 * Loads a text or HTML template depending on configuration into the template engine
53 * @param $templateName Name of the template we shall load
56 protected final function loadTemplate ($templateName) {
58 $this->setTemplateName($templateName);
60 // Get configuration entry
61 $templatePrefix = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('email_tpl_' . $templateName);
63 // Load this email template
64 $this->getTemplateInstance()->loadEmailTemplate($templatePrefix . '_' . $templateName);
68 * Adds a user class to the recipient list for current template
70 * @param $userInstance An instance of a user class
73 public function addRecipientByUserInstance (ManageableMember $userInstance) {
75 $templateName = $this->getTemplateName();
77 // Is the list initialized?
78 $this->pushValueToGenericArrayKey('recipients', $templateName, 'recipients', $userInstance);
82 * Adds a template variable (just the name) to the recipient list in given section of current template
84 * @param $section Section can be 'config' or "value" currently
85 * @param $variableName Template variable name to add
88 private final function addTemplateVariable ($section, $variableName) {
90 $templateName = $this->getTemplateName();
92 // Generate full section name
93 $sectionName = $section . '_vars';
95 // Is the list initialized?
96 $this->setGenericArrayElement('recipients', $templateName, $sectionName, $variableName, 'OK');
100 * Adds a config template variable to the recipient list of current template
102 * @param $variableName Template variable name to add
105 public final function addConfigTemplateVariable ($variableName) {
106 $this->addTemplateVariable('config', $variableName);
110 * Adds a 'value' template variable to the recipient list of current template
112 * @param $variableName Template variable name to add
115 public final function addValueTemplateVariable ($variableName) {
116 $this->addTemplateVariable('value', $variableName);
120 * Adds a value instance for a given variable name. It should be set!
122 * @param $variableName Template variable we want to assign a value instance
123 * @param $valueInstance An object instance which can provide "field values"
126 public final function addValueInstance ($variableName, FrameworkInterface $valueInstance) {
127 $this->setGenericArrayElement('recipients', $this->getTemplateName(), 'values', $variableName, $valueInstance);
131 * Protected setter for template name
133 * @param $templateName Name of email template
136 public final function setTemplateName ($templateName) {
137 $this->templateName = (string) $templateName;
141 * Protected getter for template name
143 * @return $templateName Name of email template
145 protected final function getTemplateName () {
146 return $this->templateName;
150 * Setter for subject line
152 * @param $subjectLine Subject line to set
155 public final function setSubjectLine ($subjectLine) {
156 $this->setGenericArrayElement('recipients', $this->getTemplateName(), 'generic', 'subject', $subjectLine);
160 * Getter for subject line or null if not found
162 * @return $subjectLine Subject line to set
164 public final function getSubjectLine () {
165 // Default subject is null
169 $templateName = $this->getTemplateName();
171 // Does the subject line exist?
172 if ((!empty($templateName)) && ($this->isGenericArrayElementSet('recipients', $templateName, 'generic', 'subject'))) {
174 $subjectLine = $this->getGenericArrayElement('recipients', $templateName, 'generic', 'subject');
182 * Use subject line provided by the (XML) template otherwise a subject line must be set
186 public function useSubjectFromTemplate () {
187 // Set the subject line
188 $this->setSubjectLine('{?subject?}');
192 * Getter for recipient list array
194 * @return $recipientList Array with reciepients
196 public final function getRecipientList () {
197 return $this->getGenericArray('recipients');