commentsUtil = $commentsUtil; $this->contextManager = $contextManager; } public function setComment(Comment $comment): self { $this->comment = $comment; return $this; } public static function getPlaceholders() { $placeholders = [ 'KOMENTAR' => [ 'text' => 'Komentář', ], 'ODKAZ' => [ 'text' => 'Odkaz', ], ]; return [self::$type => $placeholders] + (parent::getPlaceholders() ?? []); } public function replacePlaceholdersItem($placeholder) { switch ($placeholder) { case 'KOMENTAR': $smarty = createSmarty(false, true); $smarty->assign('comment', $this->comment); $smarty->assign('simpleComment', static::$simpleComment); return $smarty->fetch('email/email_comment.tpl'); case 'ODKAZ': if ($this->comment->getIdProduct()) { return path('products', [ 'id' => $this->comment->getIdProduct(), 'name' => StringUtil::slugify($this->getObjectTitle()), ], Router::ABSOLUTE_URL); } return path('kupshop_content_articles_article_1', [ 'IDa' => $this->comment->getIdArticle(), 'slug' => StringUtil::slugify($this->getObjectTitle()), ], Router::ABSOLUTE_URL); } return parent::replacePlaceholdersItem($placeholder); } public function testEmail(): array { $comment = $this->getDummyComment(); $this->setComment($comment); return $this->contextManager->activateContexts([LanguageContext::class => $comment->getIdLanguage()], function () { return parent::testEmail(); }); } protected function getObjectTitle(): string { if ($this->comment->getIdProduct()) { $title = sqlQueryBuilder()->select('p.title') ->from('products', 'p') ->where(Operator::equals(['p.id' => $this->comment->getIdProduct()])) ->andWhere(Translation::coalesceTranslatedFields(ProductsTranslation::class)) ->execute()->fetchColumn(); } else { $title = sqlQueryBuilder()->select('a.title') ->from('articles', 'a') ->where(Operator::equals(['a.id' => $this->comment->getIdArticle()])) ->andWhere(Translation::coalesceTranslatedFields(ArticlesTranslation::class)) ->execute()->fetchColumn(); } return $title ? $title : ''; } private function getDummyComment(): Comment { $comment1 = (new Comment()) ->setId(1) ->setIdLanguage('cs') ->setIdParent(null) ->setIdProduct((int) returnSQLResult('SELECT MAX(id) FROM products')) ->setIdUser((int) returnSQLResult('SELECT MAX(id) FROM users')) ->setContent('Testovaci komentar') ->setStatus(Comment::STATUS_CONFIRMED) ->setDateAdd('2020-07-16 12:00:00'); $comment2 = clone $comment1; $comment2->setId(2) ->setIdParent(1) ->setParent($comment1); $comment1->setChildren([$comment2]); return $comment2; } }