]> git.mxchange.org Git - core.git/blob - inc/classes/main/mailer/debug/class_DebugMailer.php
Copyright year updated, converted double->single quotes
[core.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@shipsimu.org>
7  * @version             0.0.0
8  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2013 Core Developer Team
9  * @license             GNU GPL 3.0 or any newer version
10  * @link                http://www.shipsimu.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
36         /**
37          * Creates an instance of this mailer class
38          *
39          * @param       $templateInstance               A template instance
40          * @param       $applicationInstance    An application helper class
41          * @param       $templateName                   Name of email template to set
42          * @return      $mailerInstance                 An instance of this mailer class
43          */
44         public static final function createDebugMailer (CompileableTemplate $templateInstance, ManageableApplication $applicationInstance, $templateName) {
45                 // Get a new instance
46                 $mailerInstance = new DebugMailer();
47
48                 // Set template instance
49                 $mailerInstance->setTemplateInstance($templateInstance);
50
51                 // Set application instance
52                 $mailerInstance->setApplicationInstance($applicationInstance);
53
54                 // Set template name
55                 $mailerInstance->setTemplateName('resend_link');
56
57                 // Return the instance
58                 return $mailerInstance;
59         }
60
61         /**
62          * Deliver email to the recipient(s)
63          *
64          * @return      void
65          * @throws      InvalidInterfaceException       If the recipient instance does not implement ManageableMember
66          */
67         public function deliverEmail () {
68                 // Get template instance
69                 $templateInstance = $this->getTemplateInstance();
70
71                 // "Deliver" all emails
72                 foreach ($this->getRecipientList() as $templateName => $recipientList) {
73                         // Walk through all recipients and "sent", or better print, it out
74                         foreach ($recipientList['recipients'] as $recipientInstance) {
75                                 // The recipient should be a user instance, right?
76                                 if (!$recipientInstance instanceof ManageableMember) {
77                                         // Invalid entry found!
78                                         throw new InvalidInterfaceException(array($this, 'ManageableMember'), self::EXCEPTION_REQUIRED_INTERFACE_MISSING);
79                                 }
80
81                                 // User class found, so entry is valid, first load the template
82                                 $this->loadTemplate($templateName);
83
84                                 // Set subject line
85                                 $templateInstance->assignVariable('subject', $this->getSubjectLine());
86
87                                 // Walk through all variables, first config to assign them
88                                 foreach ($recipientList['config_vars'] as $variable => $dummy) {
89                                         // Load the config value and set it
90                                         $templateInstance->assignConfigVariable($variable);
91                                 } // END - if
92
93                                 // Now do the same with the values but ask the "value instance" instead!
94                                 foreach ($recipientList['value_vars'] as $variable => $dummy) {
95                                         // Is the value instance there?
96                                         if (!isset($recipientList['values'][$variable])) {
97                                                 // Throw exception
98                                                 throw new NullPointerException ($this, self::EXCEPTION_IS_NULL_POINTER);
99                                         } // END - if
100
101                                         // Get the field from the value instance
102                                         $fieldValue = $recipientList['values'][$variable]->getField($variable);
103
104                                         // Set it in template engine
105                                         $templateInstance->assignVariable($variable, $fieldValue);
106                                 }
107
108                                 // Render the content
109                                 $templateInstance->renderXmlContent();
110
111                                 // Get responce instance
112                                 $responseInstance = $this->getApplicationInstance()->getResponseInstance();
113
114                                 // Transfer the data to the response
115                                 $this->getTemplateInstance()->transferToResponse($responseInstance);
116                         } // END - foreach
117                 } // END - foreach
118         }
119
120         /**
121          * Send notification to the admin
122          *
123          * @return      void
124          * @todo        0% done
125          */
126         public function sendAdminNotification () {
127                 // Unfinished work
128         }
129
130         /**
131          * Invokes the mail delivery process which will prepare the output of the message in a code template
132          *
133          * @return      void
134          */
135         public function invokeMailDelivery () {
136                 // Get template instance
137                 $templateInstance = $this->getTemplateInstance();
138
139                 // Get the compiled message and set it as new template variable
140                 $message = $templateInstance->getCompiledData();
141                 $templateInstance->assignVariable('message', $message);
142
143                 // Load the code template
144                 $templateInstance->loadCodeTemplate('mail_debug');
145
146                 // Compile the template
147                 $templateInstance->compileTemplate();
148
149                 // Assign this template with variable
150                 $templateInstance->assignTemplateWithVariable('mail_debug', 'content');
151
152                 // Load header template
153                 $templateInstance->loadCodeTemplate('header');
154
155                 // Compile and assign it with a variable
156                 $templateInstance->compileTemplate();
157                 $templateInstance->assignTemplateWithVariable('header', 'header');
158
159                 // Load footer template
160                 $templateInstance->loadCodeTemplate('footer');
161
162                 // Compile and assign it with a variable
163                 $templateInstance->compileTemplate();
164                 $templateInstance->assignTemplateWithVariable('footer', 'footer');
165
166                 // Load the master template
167                 $templateInstance->loadCodeTemplate($this->getApplicationInstance()->buildMasterTemplateName());
168
169                 // Then compile it again
170                 $templateInstance->compileVariables();
171         }
172 }
173
174 // [EOF]
175 ?>