]> git.mxchange.org Git - shipsimu.git/commitdiff
DebugMailer classes extended, again some minor fixes:
authorRoland Häder <roland@mxchange.org>
Sat, 28 Jun 2008 19:28:09 +0000 (19:28 +0000)
committerRoland Häder <roland@mxchange.org>
Sat, 28 Jun 2008 19:28:09 +0000 (19:28 +0000)
- New methods added to interface DeliverableMail
- Minor fixes to MemoryCache (really minor)
- Base mailer now holds some generic methods which are specified in above
  interface
- DebugMailer class with stubs
- Mail templates shall now be in own XML format

inc/classes/interfaces/mailer/class_DeliverableMail.php
inc/classes/main/cache/class_MemoryCache.php
inc/classes/main/commands/web/class_WebResendLinkCommand.php
inc/classes/main/mailer/class_
inc/classes/main/mailer/class_BaseMailer.php
inc/classes/main/mailer/debug/class_DebugMailer.php

index e9f9e2b494bba8c705721d104c3e221da18165db..34a55086a2b57e7fa5f774e029da3eb1a88a0caa 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 interface DeliverableMail extends FrameworkInterface {
+       /**
+        * Loads a text or HTML template depending on configuration into the template engine
+        *
+        * @param       $templateName   Name of the template we shall load
+        * @return      void
+        */
+       function loadTemplate ($templateName);
+
+       /**
+        * Adds a user class to the recipient list for current template
+        *
+        * @param       $userInstance   An instance of a user class
+        * @return      void
+        */
+       function addRecipientByUserInstance (ManageableUser $userInstance);
+
+       /**
+        * Use subject line provided by the (XML) template otherwise a subject line must be set
+        *
+        * @return      void
+        */
+       function useSubjectFromTemplate ();
+
+       /**
+        * Deliver email to the recipient(s)
+        *
+        * @return      void
+        */
+       function deliverEmail();
+
+       /**
+        * Send notification to the admin
+        *
+        * @return      void
+        */
+       function sendAdminNotification();
 }
 
 //
index 9d52a2179d13af3fed80a1c774a6d9613bd259f6..50929bae492bfa718b4edf737d96862a2f72adcc 100644 (file)
@@ -101,7 +101,7 @@ class MemoryCache extends BaseFrameworkSystem implements Cacheable {
         * @param       $offset         The offset we shall set
         * @return      $data           Data to store in the cache
         */
-       public final function offsetget ($offset) {
+       public final function offsetGet ($offset) {
                // Default is offset not found
                $data = null;
 
index c08066adc45a5e36c1ef9fe8a23162b9b6c94289..138c44da3a865742d84bd2e6387490556aa5406a 100644 (file)
@@ -69,6 +69,15 @@ class WebResendLinkCommand extends BaseCommand implements Commandable {
                // Get template instance
                $templateInstance = $responseInstance->getTemplateInstance();
 
+               // Get an application instance
+               $appInstance = $this->getResolverInstance()->getApplicationInstance();
+
+               // Assign the application data with the template engine
+               $templateInstance->assignApplicationData($appInstance);
+
+               // Assign base URL
+               $templateInstance->assignConfigVariable('base_url');
+
                // Get a mailer class
                $mailerInstance = ObjectFactory::createObjectByConfiguredName('mailer_class', array($templateInstance));
 
@@ -81,11 +90,14 @@ class WebResendLinkCommand extends BaseCommand implements Commandable {
                // Add the recipient
                $mailerInstance->addRecipientByUserInstance($userInstance);
 
-               // Set subject line from template
-               $mailerInstance->setSubjectFromTemplate();
+               // Use subject line from template
+               $mailerInstance->useSubjectFromTemplate();
 
                // Send the email out
                $mailerInstance->deliverEmail();
+
+               // Send out notification to admin (depends on settings)
+               $mailerInstance->sendAdminNotification();
        }
 
        /**
index 5b7e9c557a5c0ff2bb830deef6e09a0500988fbd..5baea6fe6ed8423317c04eae31226cda93c55884 100644 (file)
@@ -50,6 +50,24 @@ class ???Mailer extends BaseMailer implements DeliverableMail {
                // Return the instance
                return $mailerInstance;
        }
+
+       /**
+        * Deliver email to the recipient(s)
+        *
+        * @return      void
+        */
+       public function deliverEmail() {
+               $this->partialStub("You have to implement this method.");
+       }
+
+       /**
+        * Send notification to the admin
+        *
+        * @return      void
+        */
+       public function sendAdminNotification() {
+               $this->partialStub("You have to implement this method.");
+       }
 }
 
 // [EOF]
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]
index 62c592049898c26113d479a5e45351ec0b6591af..f5f1174b3aa737d650c879d11c634dd3c20ee915 100644 (file)
@@ -55,6 +55,24 @@ class DebugMailer extends BaseMailer implements DeliverableMail {
                // Return the instance
                return $mailerInstance;
        }
+
+       /**
+        * Deliver email to the recipient(s)
+        *
+        * @return      void
+        */
+       public function deliverEmail () {
+               $this->partialStub();
+       }
+
+       /**
+        * Send notification to the admin
+        *
+        * @return      void
+        */
+       public function sendAdminNotification () {
+               $this->partialStub();
+       }
 }
 
 // [EOF]