Overview

Namespaces

  • GLFramework
    • Cache
    • Controller
    • DaMa
      • Manipulators
    • Database
    • HTTP
    • Mail
    • Middleware
    • Model
    • Module
    • Tests
    • Upload
    • Utils
  • None

Classes

  • GLFramework\Bootstrap
  • GLFramework\Cache\Cache
  • GLFramework\Cache\MemcachedCache
  • GLFramework\Cache\MemoryCache
  • GLFramework\Controller
  • GLFramework\Controller\AdminController
  • GLFramework\Controller\APIController
  • GLFramework\Controller\AuthController
  • GLFramework\Controller\ErrorController
  • GLFramework\Controller\ExceptionController
  • GLFramework\DaMa\Association
  • GLFramework\DaMa\DataManipulation
  • GLFramework\DaMa\Manipulator
  • GLFramework\DaMa\Manipulators\CSVManipulator
  • GLFramework\DaMa\Manipulators\ManipulatorCore
  • GLFramework\DaMa\Manipulators\XLSManipulator
  • GLFramework\DaMa\Manipulators\XLSXManipulator
  • GLFramework\Database\Connection
  • GLFramework\Database\MySQLConnection
  • GLFramework\DatabaseManager
  • GLFramework\DBStructure
  • GLFramework\Events
  • GLFramework\Filesystem
  • GLFramework\HTTP\API
  • GLFramework\Log
  • GLFramework\Mail
  • GLFramework\Mail\Mail
  • GLFramework\Mail\MailSystem
  • GLFramework\Mail\PHPMailer
  • GLFramework\MailView
  • GLFramework\Middleware\APIAuthorizationMiddleware
  • GLFramework\Middleware\ControllerMiddleware
  • GLFramework\Model
  • GLFramework\Model\Page
  • GLFramework\Model\User
  • GLFramework\Model\UserPage
  • GLFramework\ModelResult
  • GLFramework\Module\Module
  • GLFramework\Module\ModuleManager
  • GLFramework\Request
  • GLFramework\Response
  • GLFramework\Tests\DatabaseTestCase
  • GLFramework\Tests\TestCase
  • GLFramework\Upload\Upload
  • GLFramework\Upload\Uploads
  • GLFramework\Utils\DataTablesManager
  • GLFramework\Versions
  • GLFramework\View

Interfaces

  • GLFramework\Middleware

Functions

  • array_merge_recursive_ex
  • e
  • file_get_php_classes
  • fix_date
  • fix_date_format
  • fix_decimal
  • fix_url
  • get
  • get_php_classes
  • http_response_code
  • instance_method
  • is_module_enabled
  • now
  • post
  • print_array
  • print_brief_debug
  • print_debug
  • random_str
  • reArrayFiles
  • reArrayPost
  • today
  • Overview
  • Namespace
  • Class
  1: <?php
  2: /**
  3:  * Created by PhpStorm.
  4:  * User: manus
  5:  * Date: 15/1/16
  6:  * Time: 20:27
  7:  */
  8: 
  9: namespace GLFramework;
 10: 
 11: use TijsVerkoyen\CssToInlineStyles\CssToInlineStyles;
 12: 
 13: class Mail
 14: {
 15: 
 16:     private static $mailer;
 17:     private function getCss($cssFiles = array())
 18:     {
 19:         $css = "";
 20:         foreach($cssFiles as $file)
 21:         {
 22:             if(file_exists($file)) $css .= file_get_contents($file) . "\n";
 23:         }
 24:     }
 25: 
 26:     /**
 27:      * Genera una vista del email compatible con clientes de correo
 28:      * @param $controller
 29:      * @param $template
 30:      * @param $data
 31:      * @return string
 32:      * @throws \TijsVerkoyen\CssToInlineStyles\Exception
 33:      */
 34:     public function render($controller, $template, $data)
 35:     {
 36:         $view = new View($controller);
 37:         $css = array();
 38:         $html = $view->mail($template, $data, $css);
 39:         $cssToInlineStyles = new CssToInlineStyles();
 40:         $cssToInlineStyles->setCSS($this->getCss($css));
 41:         $cssToInlineStyles->setHTML($html);
 42:         return $cssToInlineStyles->convert();
 43:     }
 44: 
 45:     /**
 46:      * @return Mail\MailSystem.php
 47:      */
 48:     private function getMailSystem()
 49:     {
 50:         $config = Bootstrap::getSingleton()->getConfig();
 51:         if(isset($config['mail']))
 52:         {
 53:             if(isset($config['mail']['mailsystem']))
 54:             {
 55:                 $system = $config['mail']['mailsystem'];
 56:                 $class = "GLPlanning/Mail/$system";
 57:                 if(class_exists($class)) return new $class($config);
 58:             }
 59:         }
 60:         return new Mail\Mail($config);
 61:     }
 62: 
 63:     /**
 64:      * Este transporte se genera mediante la configuración
 65:      * @return \Swift_Transport
 66:      */
 67:     public function getTransport()
 68:     {
 69:         if(!self::$mailer)
 70:         {
 71:             self::$mailer = $this->getMailSystem()->getTransport();
 72:             Events::fire('onMailTransport', array( 'transport' => self::$mailer ));
 73:         }
 74:         return self::$mailer;
 75:     }
 76: 
 77:     /**
 78:      * Envia el email a los contactos pasados a $to
 79:      * @param $to
 80:      * @param $subject
 81:      * @param $message
 82:      * @param array $attachments Use the array key to set the attachment file name in the email
 83:      *
 84:      */
 85:     public function send($to, $subject, $message, $attachments = array())
 86:     {
 87:         $config = Bootstrap::getSingleton()->getConfig();
 88:         $mailsystem = $this->getMailSystem();
 89:         $transport = $mailsystem->getTransport();
 90:         Events::fire('onEmail', array( 'emails' => $to, 'subject' => $subject, 'message' => $message, 'transport' => $transport));
 91: 
 92:         $mail = new \Swift_Message($subject, $message, "text/html", "UTF-8");
 93:         $mail->setFrom($config['mail']['from']['email'], $config['mail']['from']['title']);
 94:         $mail->setTo($to);
 95:         foreach ($attachments as $key => $attachment)
 96:         {
 97:             $atta = \Swift_Attachment::fromPath($attachment);
 98:             if(!is_int($key)) $atta->setFilename($key);
 99:             $mail->attach($atta);
100:         }
101: 
102:         return $transport->send($mail);
103: 
104:     }
105: }
API documentation generated by ApiGen