Debug mailer finished and debug messages removed:
[shipsimu.git] / inc / classes / main / mailer / debug / class_DebugMailer.php
1 <?php
2 /**
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.
5  *
6  * @author              Roland Haeder <webmaster@ship-simu.org>
7  * @version             0.0.0
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
11  *
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.
16  *
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.
21  *
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/>.
24  */
25 class DebugMailer extends BaseMailer implements DeliverableMail {
26         /**
27          * Protected constructor
28          *
29          * @return      void
30          */
31         protected function __construct () {
32                 // Call parent constructor
33                 parent::__construct(__CLASS__);
34
35                 // Set part description
36                 $this->setObjectDescription("A mailer for debugging purposes");
37
38                 // Create unique ID number
39                 $this->generateUniqueId();
40         }
41
42         /**
43          * Creates an instance of this mailer class
44          *
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
49          */
50         public final static function createDebugMailer (CompileableTemplate $templateInstance, ManageableApplication $appInstance, $templateName) {
51                 // Get a new instance
52                 $mailerInstance = new DebugMailer();
53
54                 // Set template instance
55                 $mailerInstance->setTemplateInstance($templateInstance);
56
57                 // Set application instance
58                 $mailerInstance->setApplicationInstance($appInstance);
59
60                 // Set template name
61                 $mailerInstance->setTemplateName('resend_link');
62
63                 // Return the instance
64                 return $mailerInstance;
65         }
66
67         /**
68          * Deliver email to the recipient(s)
69          *
70          * @return      void
71          */
72         public function deliverEmail () {
73                 // Get template instance
74                 $templateInstance = $this->getTemplateInstance();
75
76                 // "Deliver" all emails
77                 foreach ($this->getRecipientList() as $templateName => $recipientList) {
78                         // Walk through all recipients and "sent", or better print, it out
79                         foreach ($recipientList['recipients'] as $recipientInstance) {
80                                 // The recipient should be a user instance, right?
81                                 if ($recipientInstance instanceof ManageableUser) {
82                                         // User class found, so entry is valid, first load the template
83                                         $this->loadTemplate($templateName);
84
85                                         // Set subject line
86                                         $templateInstance->assignVariable('subject', $this->getSubjectLine());
87
88                                         // Walk through all variables, first config to assign them
89                                         foreach ($recipientList['config_vars'] as $variable=>$dummy) {
90                                                 // Load the config value and set it
91                                                 $templateInstance->assignConfigVariable($variable);
92                                         } // END - if
93
94                                         // Now do the same with the values but ask the "value instance" instead!
95                                         foreach ($recipientList['value_vars'] as $variable=>$dummy) {
96                                                 // Is the value instance there?
97                                                 if (!isset($recipientList['values'][$variable])) {
98                                                         // Throw exception
99                                                         throw new NullPointerException ($this, self::EXCEPTION_IS_NULL_POINTER);
100                                                 } // END - if
101
102                                                 // Get the field from the value instance
103                                                 $fieldValue = $recipientList['values'][$variable]->getField($variable);
104
105                                                 // Set it in the template engine
106                                                 $templateInstance->assignVariable($variable, $fieldValue);
107                                         }
108
109                                         // Render the content
110                                         $templateInstance->renderXmlContent();
111
112                                         // Get responce instance
113                                         $responseInstance = $this->getApplicationInstance()->getResponseInstance();
114
115                                         // Transfer the data to the response
116                                         $this->getTemplateInstance()->transferToResponse($responseInstance);
117                                 } else {
118                                         // Invalid entry found!
119                                         $this->partialStub("Handling of invalid recipient entries not yet finished.");
120                                 }
121                         } // END - foreach
122                 } // END - foreach
123         }
124
125         /**
126          * Send notification to the admin
127          *
128          * @return      void
129          * @todo        0% done
130          */
131         public function sendAdminNotification () {
132                 // Unfinished work
133         }
134
135         /**
136          * Invokes the mail delivery process which will prepare the output of the message in a code template
137          *
138          * @return      void
139          */
140         public function invokeMailDelivery () {
141                 // Get template instance
142                 $templateInstance = $this->getTemplateInstance();
143
144                 // Get the compiled message and set it as new template variable
145                 $message = $templateInstance->getCompiledData();
146                 $templateInstance->assignVariable('message', $message);
147
148                 // Load the code template
149                 $templateInstance->loadCodeTemplate('mail_debug');
150
151                 // Compile the template
152                 $templateInstance->compileTemplate();
153
154                 // Assign this template with variable
155                 $templateInstance->assignTemplateWithVariable('mail_debug', 'content');
156
157                 // Load header template
158                 $templateInstance->loadCodeTemplate('header');
159
160                 // Compile and assign it with a variable
161                 $templateInstance->compileTemplate();
162                 $templateInstance->assignTemplateWithVariable('header', 'header');
163
164                 // Load footer template
165                 $templateInstance->loadCodeTemplate('footer');
166
167                 // Compile and assign it with a variable
168                 $templateInstance->compileTemplate();
169                 $templateInstance->assignTemplateWithVariable('footer', 'footer');
170
171                 // Load the master template
172                 $templateInstance->loadCodeTemplate($this->getApplicationInstance()->getMasterTemplate());
173
174                 // Then compile it again
175                 $templateInstance->compileVariables();
176         }
177 }
178
179 // [EOF]
180 ?>