private function switchTemplateByMessagesType(ITemplate $template)
 {
     switch ($this->messagesHandler->getMessagesType()) {
         case SentMessage::RECEIVED:
             $template->setFile(__DIR__ . '/templates/receivedMessagesTable.latte');
             break;
         case SentMessage::SENT:
             $template->setFile(__DIR__ . '/templates/sentMessagesTable.latte');
             break;
     }
 }
 /**
  * @param Nette\Application\UI\ITemplate $template
  */
 public function configure(Nette\Application\UI\ITemplate $template)
 {
     if (!$template instanceof Nette\Bridges\ApplicationLatte\Template) {
         return;
     }
     $latte = $template->getLatte();
     if ($this->translator) {
         $template->setTranslator($this->translator);
     }
     foreach ($this->providers as $name => $provider) {
         $latte->addProvider($name, $provider);
     }
     foreach ($this->filters as $name => $filter) {
         $template->addFilter($name, $filter);
     }
     $template->setParameters($this->parameters);
 }
Пример #3
0
 public function setTemplateFile(ITemplate $template, Control $control)
 {
     $renderMode = $control instanceof IRenderMode ? $control->getRenderMode() : IRenderMode::DEFAULT_RENDER_MODE;
     $renderMode = $renderMode === IRenderMode::DEFAULT_RENDER_MODE ? ITemplateLocator::DEFAULT_COMPONENT_RENDER_MODE : $renderMode;
     $files = $this->templateLocator->formatComponentTemplateFiles($control, $renderMode);
     foreach ($files as $file) {
         if (is_file($file)) {
             $template->setFile($file);
             break;
         }
     }
     if (!$template->getFile()) {
         $file = preg_replace('#^.*([/\\\\].{1,70})\\z#U', "…\$1", reset($files));
         $file = strtr($file, '/', DIRECTORY_SEPARATOR);
         throw new FileNotFoundException("Control template not found. Missing template '{$file}'.");
     }
 }
Пример #4
0
 /**
  * @return ITemplate
  */
 public final function getTemplate()
 {
     if ($this->template === NULL) {
         $value = $this->createTemplate();
         if (!$value instanceof ITemplate && $value !== NULL) {
             $class2 = get_class($value);
             $class = get_class($this);
             throw new Nette\UnexpectedValueException("Object returned by {$class}::createTemplate() must be instance of Nette\\Application\\UI\\ITemplate, '{$class2}' given.");
         }
         $this->template = $value;
         $this->template->form = $this->template->_form = $this;
         $this->template->setFile($this->templateFile ?: dirname($this->reflection->getFileName()) . '/' . $this->reflection->getShortName() . '.latte');
     }
     return $this->template;
 }
Пример #5
0
 /**
  * Render latte template to string and send (and/or log) mail
  * @return void
  */
 public function send()
 {
     /**
      * Set template variables
      */
     $this->setTemplateVariables();
     /**
      * Set body/html body
      */
     try {
         $this->template->setFile($this->getTemplateFile());
         if (version_compare(Latte\Engine::VERSION, '2.4.0', '>=')) {
             $this->template->getLatte()->addProvider('uiControl', $this->linkGenerator);
         } else {
             $this->template->_control = $this->linkGenerator;
         }
         $this->message->setHtmlBody((string) $this->template, $this->mail_images_base_path);
     } catch (MailingException $e) {
         /**
          * If mail template was set and not found, bubble exception up
          */
         if ($this->template_file) {
             throw $e;
         }
         /**
          * Otherwise just suppose that user has set message body via ::setBody
          */
     }
     /**
      * In case mail sending in on, send message
      */
     if ($this->config === self::CONFIG_BOTH || $this->config === self::CONFIG_SEND) {
         $this->mailer->send($this->message);
     }
     /**
      * In case mail logging is turned on, log message
      */
     if ($this->config === self::CONFIG_LOG || $this->config === self::CONFIG_BOTH) {
         $this->logger->log($this->log_type, $this->message);
     }
 }
Пример #6
0
 /**
  * Render latte template to string and send (and/or log) mail
  * @return void
  */
 public function send()
 {
     /**
      * Set template variables
      */
     $this->setTemplateVariables();
     /**
      * Set body/html body
      */
     try {
         $this->template->setFile($this->getTemplateFile());
         $this->message->setHtmlBody((string) $this->template, $this->mail_images_base_path);
     } catch (MailException $e) {
         /**
          * If mail template was set and not found, bubble exception up
          */
         if ($this->template_file) {
             throw $e;
         }
         /**
          * Otherwise just suppose that user has set message body via ::setBody
          */
     }
     /**
      * In case mail sending in on, send message
      */
     if ($this->config === self::CONFIG_BOTH || $this->config === self::CONFIG_SEND) {
         $this->mailer->send($this->message);
     }
     /**
      * In case mail logging is turned on, log message
      */
     if ($this->config === self::CONFIG_LOG || $this->config === self::CONFIG_BOTH) {
         $this->logger->log($this->log_type, $this->message);
     }
 }
Пример #7
0
 /**
  * Generates the invoice to the defined template.
  *
  * @param ITemplate $template
  * @return void
  */
 private function generate(ITemplate $template)
 {
     $template->setFile($this->templatePath);
     $template->registerHelper('round', function ($value, $precision = 2) {
         return number_format(round($value, $precision), $precision, ',', '');
     });
     $template->title = $this->data->getTitle();
     $template->id = $this->data->getId();
     $template->items = $this->data->getItems();
     $this->generateSupplier($template);
     $this->generateCustomer($template);
     $this->generateDates($template);
     $this->generateSymbols($template);
     $this->generateFinalValues($template);
 }
Пример #8
0
 /**
  * @return string
  */
 public function getResultHtml()
 {
     return $this->template->__toString();
 }
Пример #9
0
 /**
  * @param  ITemplate  $html
  * @param  string     $wwwDir
  * @return Nette\Mailer\Message
  */
 public function create(ITemplate $html, $wwwDir = NULL)
 {
     $html->setFile(__DIR__ . '/templates/message.latte');
     Assert::same($wwwDir, $html->wwwDir);
     return (new \Nette\Mail\Message())->setHtmlBody($html->__toString(1), $wwwDir)->addTo('*****@*****.**');
 }
Пример #10
0
 /**
  * @param \Nette\Application\UI\ITemplate $template
  */
 protected function prepareTemplate(ITemplate $template)
 {
     $template->setTranslator($this->translator);
     $this->registerHelperLoader($template, $this->helperLoader);
 }