From: Marcel Werk Date: Wed, 8 Jun 2016 13:18:20 +0000 (+0200) Subject: Added links to other (language) versions of an article X-Git-Tag: 3.0.0_Beta_1~1481 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=30ac765c7cd66621f581040fa52d97a451f6f51f;p=GitHub%2FWoltLab%2FWCF.git Added links to other (language) versions of an article --- diff --git a/com.woltlab.wcf/templates/article.tpl b/com.woltlab.wcf/templates/article.tpl index df85e5a4f6..87a693b356 100644 --- a/com.woltlab.wcf/templates/article.tpl +++ b/com.woltlab.wcf/templates/article.tpl @@ -48,6 +48,16 @@ {/capture} +{capture assign='headContent'} + {if $article->isMultilingual} + {foreach from=$article->getLanguageLinks() item='langArticleContent'} + {if $langArticleContent->getLanguage()} + + {/if} + {/foreach} + {/if} +{/capture} + {include file='header'} {if $articleContent->getImage()} @@ -85,6 +95,14 @@ + {if $article->isMultilingual} + {foreach from=$article->getLanguageLinks() item='langArticleContent'} + {if $langArticleContent->getLanguage() && $langArticleContent->languageID != $articleContent->languageID} + {$langArticleContent->getLanguage()->languageName} + {/if} + {/foreach} + {/if} + {if ENABLE_SHARE_BUTTONS}

{lang}wcf.message.share{/lang}

diff --git a/wcfsetup/install/files/lib/data/article/Article.class.php b/wcfsetup/install/files/lib/data/article/Article.class.php index f2a3f392c0..d3988d1282 100644 --- a/wcfsetup/install/files/lib/data/article/Article.class.php +++ b/wcfsetup/install/files/lib/data/article/Article.class.php @@ -48,6 +48,12 @@ class Article extends DatabaseObject implements ILinkableObject { */ public $articleContent; + /** + * language links + * @var ArticleContent[] + */ + public $languageLinks; + /** * article's category * @var ArticleCategory @@ -205,6 +211,27 @@ class Article extends DatabaseObject implements ILinkableObject { return $this->articleContent; } + /** + * Returns the article's language links. + * + * @return ArticleContent[] + */ + public function getLanguageLinks() { + if ($this->languageLinks === null) { + $this->languageLinks = []; + $sql = "SELECT articleContentID, title, languageID + FROM wcf" . WCF_N . "_article_content + WHERE articleID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute([$this->articleID]); + while ($row = $statement->fetchArray()) { + $this->languageLinks[($row['languageID'] ?: 0)] = new ArticleContent(null, $row); + } + } + + return $this->languageLinks; + } + /** * Returns the category of the article. * diff --git a/wcfsetup/install/files/lib/data/article/content/ArticleContent.class.php b/wcfsetup/install/files/lib/data/article/content/ArticleContent.class.php index 126d88ddc1..ac4d51457f 100644 --- a/wcfsetup/install/files/lib/data/article/content/ArticleContent.class.php +++ b/wcfsetup/install/files/lib/data/article/content/ArticleContent.class.php @@ -3,7 +3,9 @@ namespace wcf\data\article\content; use wcf\data\article\Article; use wcf\data\DatabaseObject; use wcf\data\ILinkableObject; +use wcf\data\language\Language; use wcf\system\html\output\HtmlOutputProcessor; +use wcf\system\language\LanguageFactory; use wcf\system\message\embedded\object\MessageEmbeddedObjectManager; use wcf\system\request\IRouteController; use wcf\system\request\LinkHandler; @@ -88,6 +90,19 @@ class ArticleContent extends DatabaseObject implements ILinkableObject, IRouteCo return $this->article; } + /** + * Returns the language of this article content as language object. + * + * @return Language|null + */ + public function getLanguage() { + if ($this->languageID) { + return LanguageFactory::getInstance()->getLanguage($this->languageID); + } + + return null; + } + public static function getArticleContent($articleID, $languageID) { if ($languageID !== null) { $sql = "SELECT *