3 * A general mailer class for all other mailers
5 * @author Roland Haeder <webmaster@ship-simu.org>
7 * @copyright Copyright (c) 2007, 2008 Roland Haeder, this is free software
8 * @license GNU GPL 3.0 or any newer version
9 * @link http://www.ship-simu.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 {
26 * Iterateable list of recipients
28 private $recipientList = array();
33 private $templateName = "";
36 * Protected constructor
38 * @param $className Name of the class
41 protected function __construct ($className) {
42 // Call parent constructor
43 parent::__construct($className);
46 $this->removeNumberFormaters();
47 $this->removeSystemArray();
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 public function loadTemplate ($templateName) {
58 $this->setTemplateName($templateName);
60 // Get configuration entry
61 $templatePrefix = $this->getConfigInstance()->readConfig('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 (ManageableUser $userInstance) {
75 $templateName = $this->getTemplateName();
77 // Is the list initialized?
78 if (!isset($this->recipientList[$templateName]['recipients'])) {
79 // Then initialize it here
80 $this->recipientList[$templateName]['recipients'] = new FrameworkArrayObject("FakedRecipientList");
83 // Add it as a recipient
84 $this->recipientList[$templateName]['recipients']->append($userInstance);
88 * Protected setter for template name
90 * @param $templateName Name of email template
93 protected final function setTemplateName ($templateName) {
94 $this->templateName = (string) $templateName;
98 * Protected getter for template name
100 * @return $templateName Name of email template
102 protected final function getTemplateName () {
103 return $this->templateName;
107 * Setter for subject line
109 * @param $subjectLine Subject line to set
112 public final function setSubjectLine ($subjectLine) {
113 $this->recipientList[$this->getTemplateName()]['subject'] = (string) $subjectLine;
117 * Getter for subject line or null if not found
119 * @return $subjectLine Subject line to set
121 public final function getSubjectLine () {
122 // Default subject is null
126 $templateName = $this->getTemplateName();
128 // Does the subject line exist?
129 if ((!empty($templateName)) && (isset($this->recipientList[$templateName]['subject']))) {
131 $subjectLine = $this->recipientList[$templateName]['subject'];
139 * Use subject line provided by the (XML) template otherwise a subject line must be set
143 public function useSubjectFromTemplate () {
144 // Set the subject line
145 $this->setSubjectLine("{?subject?}");