]> git.mxchange.org Git - core.git/blob - framework/main/classes/mailer/class_BaseMailer.php
Some updates:
[core.git] / framework / main / classes / mailer / class_BaseMailer.php
1 <?php
2 // Own namespace
3 namespace Org\Mxchange\CoreFramework\Mailer;
4
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
7 use Org\Mxchange\CoreFramework\Manager\Login\ManageableMember;
8 use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
9
10 /**
11  * A general mailer class for all other mailers
12  *
13  * @author              Roland Haeder <webmaster@shipsimu.org>
14  * @version             0.0.0
15 <<<<<<< HEAD:framework/main/classes/mailer/class_BaseMailer.php
16  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
17 =======
18  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2016 Core Developer Team
19 >>>>>>> Some updates::inc/main/classes/mailer/class_BaseMailer.php
20  * @license             GNU GPL 3.0 or any newer version
21  * @link                http://www.shipsimu.org
22  *
23  * This program is free software: you can redistribute it and/or modify
24  * it under the terms of the GNU General Public License as published by
25  * the Free Software Foundation, either version 3 of the License, or
26  * (at your option) any later version.
27  *
28  * This program is distributed in the hope that it will be useful,
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31  * GNU General Public License for more details.
32  *
33  * You should have received a copy of the GNU General Public License
34  * along with this program. If not, see <http://www.gnu.org/licenses/>.
35  */
36 abstract class BaseMailer extends BaseFrameworkSystem {
37         /**
38          * Template name
39          */
40         private $templateName = '';
41
42         /**
43          * Protected constructor
44          *
45          * @param       $className      Name of the class
46          * @return      void
47          */
48         protected function __construct ($className) {
49                 // Call parent constructor
50                 parent::__construct($className);
51         }
52
53         /**
54          * Loads a text or HTML template depending on configuration into the template engine
55          *
56          * @param       $templateName   Name of the template we shall load
57          * @return      void
58          */
59         protected final function loadTemplate ($templateName) {
60                 // Set template name
61                 $this->setTemplateName($templateName);
62
63                 // Get configuration entry
64                 $templatePrefix = $this->getConfigInstance()->getConfigEntry('email_tpl_' . $templateName);
65
66                 // Load this email template
67                 $this->getTemplateInstance()->loadEmailTemplate($templatePrefix . '_' . $templateName);
68         }
69
70         /**
71          * Adds a user class to the recipient list for current template
72          *
73          * @param       $userInstance   An instance of a user class
74          * @return      void
75          */
76         public function addRecipientByUserInstance (ManageableMember $userInstance) {
77                 // Get template name
78                 $templateName = $this->getTemplateName();
79
80                 // Is the list initialized?
81                 $this->pushValueToGenericArrayKey('recipients', $templateName, 'recipients', $userInstance);
82         }
83
84         /**
85          * Adds a template variable (just the name) to the recipient list in given section of current template
86          *
87          * @param       $section                Section can be 'config' or "value" currently
88          * @param       $variableName   Template variable name to add
89          * @return      void
90          */
91         private final function addTemplateVariable ($section, $variableName) {
92                 // Get template name
93                 $templateName = $this->getTemplateName();
94
95                 // Generate full section name
96                 $sectionName = $section . '_vars';
97
98                 // Is the list initialized?
99                 $this->setGenericArrayElement('recipients', $templateName, $sectionName, $variableName, 'OK');
100         }
101
102         /**
103          * Adds a config template variable to the recipient list of current template
104          *
105          * @param       $variableName   Template variable name to add
106          * @return      void
107          */
108         public final function addConfigTemplateVariable ($variableName) {
109                 $this->addTemplateVariable('config', $variableName);
110         }
111
112         /**
113          * Adds a 'value' template variable to the recipient list of current template
114          *
115          * @param       $variableName   Template variable name to add
116          * @return      void
117          */
118         public final function addValueTemplateVariable ($variableName) {
119                 $this->addTemplateVariable('value', $variableName);
120         }
121
122         /**
123          * Adds a value instance for a given variable name. It should be set!
124          *
125          * @param       $variableName   Template variable we want to assign a value instance
126          * @param       $valueInstance  An object instance which can provide "field values"
127          * @return      void
128          */
129         public final function addValueInstance ($variableName, FrameworkInterface $valueInstance) {
130                 $this->setGenericArrayElement('recipients', $this->getTemplateName(), 'values', $variableName, $valueInstance);
131         }
132
133         /**
134          * Protected setter for template name
135          *
136          * @param       $templateName   Name of email template
137          * @return      void
138          */
139         public final function setTemplateName ($templateName) {
140                 $this->templateName = (string) $templateName;
141         }
142
143         /**
144          * Protected getter for template name
145          *
146          * @return      $templateName   Name of email template
147          */
148         protected final function getTemplateName () {
149                 return $this->templateName;
150         }
151
152         /**
153          * Setter for subject line
154          *
155          * @param       $subjectLine    Subject line to set
156          * @return      void
157          */
158         public final function setSubjectLine ($subjectLine) {
159                 $this->setGenericArrayElement('recipients', $this->getTemplateName(), 'generic', 'subject', $subjectLine);
160         }
161
162         /**
163          * Getter for subject line or null if not found
164          *
165          * @return      $subjectLine    Subject line to set
166          */
167         public final function getSubjectLine () {
168                 // Default subject is null
169                 $subjectLine = NULL;
170
171                 // Get template name
172                 $templateName = $this->getTemplateName();
173
174                 // Does the subject line exist?
175                 if ((!empty($templateName)) && ($this->isGenericArrayElementSet('recipients', $templateName, 'generic', 'subject'))) {
176                         // Then use it
177                         $subjectLine = $this->getGenericArrayElement('recipients', $templateName, 'generic', 'subject');
178                 } // END - if
179
180                 // Return it
181                 return $subjectLine;
182         }
183
184         /**
185          * Use subject line provided by the (XML) template otherwise a subject line must be set
186          *
187          * @return      void
188          */
189         public function useSubjectFromTemplate () {
190                 // Set the subject line
191                 $this->setSubjectLine('{?subject?}');
192         }
193
194         /**
195          * Getter for recipient list array
196          *
197          * @return      $recipientList  Array with reciepients
198          */
199         public final function getRecipientList () {
200                 return $this->getGenericArray('recipients');
201         }
202
203 }