SHOW:
|
|
- or go back to the newest paste.
| 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 | - | |
| 19 | + | |
| 20 | - | public function __construct(Nette\Database\Context $database) |
| 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 | - | if ($key == 1983) {
|
| 31 | + | |
| 32 | - | $order = $this->database->table('orders')->get(11);
|
| 32 | + | |
| 33 | - | |
| 33 | + | |
| 34 | - | // setup template |
| 34 | + | |
| 35 | - | $emailTemplate = clone $this->template; |
| 35 | + | |
| 36 | - | |
| 36 | + | |
| 37 | - | // set variables |
| 37 | + | |
| 38 | - | $emailTemplate->locale = $this->locale; |
| 38 | + | |
| 39 | - | $emailTemplate->order = $order; |
| 39 | + | if ($key !== 1983) {
|
| 40 | - | $emailTemplate->day = $this->translator->translate('template.delivery.days.day_1');
|
| 40 | + | $this->error('Nepovoleny pristup');
|
| 41 | - | $emailTemplate->total = 500; |
| 41 | + | |
| 42 | - | |
| 42 | + | |
| 43 | - | // set template file |
| 43 | + | if (!$order = $this->database->table('orders')->get(11)) {
|
| 44 | - | $emailTemplate->setFile(APP_DIR.DIRECTORY_SEPARATOR.'FrontModule'.DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR.'Emailing'.DIRECTORY_SEPARATOR.'sendTodayOrders.latte'); |
| 44 | + | $this->error('Order not found'); // vyhodit chybu, kdyz nenajde objednavku
|
| 45 | - | |
| 45 | + | |
| 46 | - | |
| 46 | + | |
| 47 | - | // setup email |
| 47 | + | // setup template |
| 48 | - | $mail = new Message(); |
| 48 | + | $emailTemplate = $this->templateFactory->createTemplate($this); |
| 49 | - | $mail->setFrom('[email protected]')
|
| 49 | + | |
| 50 | - | ->addTo('[email protected]')
|
| 50 | + | // set variables |
| 51 | - | ->setSubject($this->translator->translate('email.title.confirmation'))
|
| 51 | + | $emailTemplate->locale = $this->locale; |
| 52 | - | ->setHtmlBody($emailTemplate); |
| 52 | + | $emailTemplate->order = $order; |
| 53 | - | |
| 53 | + | // tohle neni potreba, translator muzes pouzit klidne rovnou i v sablone |
| 54 | - | // send email |
| 54 | + | // $emailTemplate->day = $this->translator->translate('template.delivery.days.day_1');
|
| 55 | - | $mailer = new SendmailMailer(); |
| 55 | + | $emailTemplate->total = 500; |
| 56 | - | $mailer->send($mail); |
| 56 | + | |
| 57 | // set template file | |
| 58 | - | |
| 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 | } |