3 * A mailer class for debugging purposes only. This class will print the
4 * prepared mail out and will not send it to the recipient.
6 * @author Roland Haeder <webmaster@ship-simu.org>
8 * @copyright Copyright (c) 2007, 2008 Roland Haeder, this is free software
9 * @license GNU GPL 3.0 or any newer version
10 * @link http://www.ship-simu.org
12 * This program is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 class DebugMailer extends BaseMailer implements DeliverableMail {
27 * Protected constructor
31 protected function __construct () {
32 // Call parent constructor
33 parent::__construct(__CLASS__);
35 // Set part description
36 $this->setObjectDescription("A mailer for debugging purposes");
38 // Create unique ID number
39 $this->generateUniqueId();
43 * Creates an instance of this mailer class
45 * @param $templateInstance A template instance
46 * @param $appInstance An application helper class
47 * @param $templateName Name of email template to set
48 * @return $mailerInstance An instance of this mailer class
50 public final static function createDebugMailer (CompileableTemplate $templateInstance, ManageableApplication $appInstance, $templateName) {
52 $mailerInstance = new DebugMailer();
54 // Set template instance
55 $mailerInstance->setTemplateInstance($templateInstance);
57 // Set application instance
58 $mailerInstance->setApplicationInstance($appInstance);
61 $mailerInstance->setTemplateName('resend_link');
63 // Return the instance
64 return $mailerInstance;
68 * Deliver email to the recipient(s)
71 * @throws InvalidInterfaceException If the recipient instance does not implement ManageableMember
73 public function deliverEmail () {
74 // Get template instance
75 $templateInstance = $this->getTemplateInstance();
77 // "Deliver" all emails
78 foreach ($this->getRecipientList() as $templateName => $recipientList) {
79 // Walk through all recipients and "sent", or better print, it out
80 foreach ($recipientList['recipients'] as $recipientInstance) {
81 // The recipient should be a user instance, right?
82 if (!$recipientInstance instanceof ManageableMember) {
83 // Invalid entry found!
84 throw new InvalidInterfaceException(array($this, 'ManageableMember'), self::EXCEPTION_REQUIRED_INTERFACE_MISSING);
87 // User class found, so entry is valid, first load the template
88 $this->loadTemplate($templateName);
91 $templateInstance->assignVariable('subject', $this->getSubjectLine());
93 // Walk through all variables, first config to assign them
94 foreach ($recipientList['config_vars'] as $variable=>$dummy) {
95 // Load the config value and set it
96 $templateInstance->assignConfigVariable($variable);
99 // Now do the same with the values but ask the "value instance" instead!
100 foreach ($recipientList['value_vars'] as $variable=>$dummy) {
101 // Is the value instance there?
102 if (!isset($recipientList['values'][$variable])) {
104 throw new NullPointerException ($this, self::EXCEPTION_IS_NULL_POINTER);
107 // Get the field from the value instance
108 $fieldValue = $recipientList['values'][$variable]->getField($variable);
110 // Set it in the template engine
111 $templateInstance->assignVariable($variable, $fieldValue);
114 // Render the content
115 $templateInstance->renderXmlContent();
117 // Get responce instance
118 $responseInstance = $this->getApplicationInstance()->getResponseInstance();
120 // Transfer the data to the response
121 $this->getTemplateInstance()->transferToResponse($responseInstance);
127 * Send notification to the admin
132 public function sendAdminNotification () {
137 * Invokes the mail delivery process which will prepare the output of the message in a code template
141 public function invokeMailDelivery () {
142 // Get template instance
143 $templateInstance = $this->getTemplateInstance();
145 // Get the compiled message and set it as new template variable
146 $message = $templateInstance->getCompiledData();
147 $templateInstance->assignVariable('message', $message);
149 // Load the code template
150 $templateInstance->loadCodeTemplate('mail_debug');
152 // Compile the template
153 $templateInstance->compileTemplate();
155 // Assign this template with variable
156 $templateInstance->assignTemplateWithVariable('mail_debug', 'content');
158 // Load header template
159 $templateInstance->loadCodeTemplate('header');
161 // Compile and assign it with a variable
162 $templateInstance->compileTemplate();
163 $templateInstance->assignTemplateWithVariable('header', 'header');
165 // Load footer template
166 $templateInstance->loadCodeTemplate('footer');
168 // Compile and assign it with a variable
169 $templateInstance->compileTemplate();
170 $templateInstance->assignTemplateWithVariable('footer', 'footer');
172 // Load the master template
173 $templateInstance->loadCodeTemplate($this->getApplicationInstance()->getMasterTemplate());
175 // Then compile it again
176 $templateInstance->compileVariables();