]> git.mxchange.org Git - shipsimu.git/blobdiff - inc/classes/main/mailer/class_BaseMailer.php
DebugMailer classes extended, again some minor fixes:
[shipsimu.git] / inc / classes / main / mailer / class_BaseMailer.php
index cec249de4918871967b38c663e7e8f1ab9c01768..3ffe1c0853a45605485fe362debf22218759192e 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 class BaseMailer extends BaseFrameworkSystem {
+       /**
+        * Iterateable list of recipients
+        */
+       private $recipientList = array();
+
+       /**
+        * Template name
+        */
+       private $templateName = "";
+
        /**
         * Protected constructor
         *
@@ -36,6 +46,104 @@ class BaseMailer extends BaseFrameworkSystem {
                $this->removeNumberFormaters();
                $this->removeSystemArray();
        }
+
+       /**
+        * Loads a text or HTML template depending on configuration into the template engine
+        *
+        * @param       $templateName   Name of the template we shall load
+        * @return      void
+        */
+       public function loadTemplate ($templateName) {
+               // Set template name
+               $this->setTemplateName($templateName);
+
+               // Get configuration entry
+               $templatePrefix = $this->getConfigInstance()->readConfig('email_tpl_' . $templateName);
+
+               // Load this email template
+               $this->getTemplateInstance()->loadEmailTemplate($templatePrefix . '_' . $templateName);
+       }
+
+       /**
+        * Adds a user class to the recipient list for current template
+        *
+        * @param       $userInstance   An instance of a user class
+        * @return      void
+        */
+       public function addRecipientByUserInstance (ManageableUser $userInstance) {
+               // Get template name
+               $templateName = $this->getTemplateName();
+
+               // Is the list initialized?
+               if (!isset($this->recipientList[$templateName]['recipients'])) {
+                       // Then initialize it here
+                       $this->recipientList[$templateName]['recipients'] = new FrameworkArrayObject("FakedRecipientList");
+               } // END - if
+
+               // Add it as a recipient
+               $this->recipientList[$templateName]['recipients']->append($userInstance);
+       }
+
+       /**
+        * Protected setter for template name
+        *
+        * @param       $templateName   Name of email template
+        * @return      void
+        */
+       protected final function setTemplateName ($templateName) {
+               $this->templateName = (string) $templateName;
+       }
+
+       /**
+        * Protected getter for template name
+        *
+        * @return      $templateName   Name of email template
+        */
+       protected final function getTemplateName () {
+               return $this->templateName;
+       }
+
+       /**
+        * Setter for subject line
+        *
+        * @param       $subjectLine    Subject line to set
+        * @return      void
+        */
+       public final function setSubjectLine ($subjectLine) {
+               $this->recipientList[$this->getTemplateName()]['subject'] = (string) $subjectLine;
+       }
+
+       /**
+        * Getter for subject line or null if not found
+        *
+        * @return      $subjectLine    Subject line to set
+        */
+       public final function getSubjectLine () {
+               // Default subject is null
+               $subjectLine = null;
+
+               // Get template name
+               $templateName = $this->getTemplateName();
+
+               // Does the subject line exist?
+               if ((!empty($templateName)) && (isset($this->recipientList[$templateName]['subject']))) {
+                       // Then use it
+                       $subjectLine = $this->recipientList[$templateName]['subject'];
+               } // END - if
+
+               // Return it
+               return $subjectLine;
+       }
+
+       /**
+        * Use subject line provided by the (XML) template otherwise a subject line must be set
+        *
+        * @return      void
+        */
+       public function useSubjectFromTemplate () {
+               // Set the subject line
+               $this->setSubjectLine("{?subject?}");
+       }
 }
 
 // [EOF]