HosipLan

Untitled

Oct 16th, 2014
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. namespace App\FrontModule\Presenters;
  4.  
  5. use Nette,
  6.     Nette\Mail\Message,
  7.     Nette\Mail\SendmailMailer;
  8.  
  9. use \App\Presenters\BasePresenter as BasePresenter;
  10.  
  11. /**
  12.  * Emailing presenters.
  13.  */
  14. class EmailingPresenter extends BasePresenter
  15. {
  16.  
  17.     /** @var Nette\Database\Context */
  18.     private $database;
  19.  
  20.     private $templateFactory;
  21.  
  22.     private $mailer;
  23.  
  24.  
  25.  
  26.     public function __construct(Nette\Database\Context $database, Nette\Application\UI\ITemplateFactory $templateFactory, Nette\Mail\IMailer $mailer)
  27.     {
  28.         $this->database = $database;
  29.     $this->templateFactory = $templateFactory;
  30.     $this->mailer = $mailer;
  31.     }
  32.    
  33.    
  34.     /**
  35.      * Send email
  36.      */
  37.     public function actionSendTodayOrders($key)
  38.     {
  39.         if ($key !== 1983) {
  40.             $this->error('Nepovoleny pristup');
  41.         }
  42.  
  43.         if (!$order = $this->database->table('orders')->get(11)) {
  44.             $this->error('Order not found'); // vyhodit chybu, kdyz nenajde objednavku
  45.         }
  46.  
  47.         // setup template
  48.         $emailTemplate = $this->templateFactory->createTemplate($this);
  49.  
  50.         // set variables
  51.         $emailTemplate->locale  = $this->locale;
  52.         $emailTemplate->order   = $order;
  53.         // tohle neni potreba, translator muzes pouzit klidne rovnou i v sablone
  54.         // $emailTemplate->day = $this->translator->translate('template.delivery.days.day_1');
  55.         $emailTemplate->total   = 500;
  56.  
  57.         // set template file
  58.         $emailTemplate->setFile(__DIR__ . '/../templates/Emailing/sendTodayOrders.latte');
  59.  
  60.         // setup email
  61.         $mail = new Message();
  62.         $mail->setFrom('[email protected]')
  63.             ->addTo('[email protected]')
  64.             ->setSubject($this->translator->translate('email.title.confirmation'))
  65.             ->setHtmlBody($emailTemplate);
  66.  
  67.         // send email
  68.         $this->mailer->send($mail);
  69.  
  70.         $this->terminate();
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment