Added missing 'lookup' implentations
authorMarcel Werk <burntime@woltlab.com>
Thu, 7 Jul 2016 15:45:07 +0000 (17:45 +0200)
committerMarcel Werk <burntime@woltlab.com>
Thu, 7 Jul 2016 15:45:36 +0000 (17:45 +0200)
wcfsetup/install/files/lib/system/page/handler/ArticlePageHandler.class.php
wcfsetup/install/files/lib/system/page/handler/CategoryArticleListPageHandler.class.php

index 066d3eb143354e5a8cc0203835b0a32432ddee3f..9b724768148f97b52353dd32bdefedcb2a5a9207 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 namespace wcf\system\page\handler;
+use wcf\data\article\ViewableArticleList;
 use wcf\data\page\Page;
 use wcf\data\user\online\UserOnline;
 use wcf\system\cache\runtime\ViewableArticleRuntimeCache;
@@ -43,8 +44,25 @@ class ArticlePageHandler extends AbstractLookupPageHandler implements IOnlineLoc
         * @inheritDoc
         */
        public function lookup($searchString) {
-               // @todo
-               return [];
+               $articleList = new ViewableArticleList();
+               $articleList->sqlSelects = "(SELECT title FROM wcf".WCF_N."_article_content WHERE articleID = article.articleID AND (languageID IS NULL OR languageID = ".WCF::getLanguage()->languageID.") LIMIT 1) AS title";
+               $articleList->getConditionBuilder()->add('article.articleID IN (SELECT articleID FROM wcf'.WCF_N.'_article_content WHERE title LIKE ?)', ['%' . $searchString . '%']);
+               $articleList->sqlLimit = 10;
+               $articleList->sqlOrderBy = 'title';
+               $articleList->readObjects();
+               
+               $results = [];
+               foreach ($articleList->getObjects() as $article) {
+                       $results[] = [
+                               'description' => $article->getFormattedTeaser(),
+                               'image' => ($article->getImage() ? $article->getImage()->getElementTag(48) : ''),
+                               'link' => $article->getLink(),
+                               'objectID' => $article->articleID,
+                               'title' => $article->getTitle()
+                       ];
+               }
+               
+               return $results;
        }
        
        /**
index 1bf04e96f328ff7d4f64ee33747eb00a531e6858..c6ed7ee4814748acf54c2cb0a8e4961e50f5522e 100644 (file)
@@ -1,8 +1,10 @@
 <?php
 namespace wcf\system\page\handler;
 use wcf\data\article\category\ArticleCategory;
+use wcf\data\object\type\ObjectTypeCache;
 use wcf\data\page\Page;
 use wcf\data\user\online\UserOnline;
+use wcf\system\database\util\PreparedStatementConditionBuilder;
 use wcf\system\request\LinkHandler;
 use wcf\system\WCF;
 
@@ -47,8 +49,36 @@ class CategoryArticleListPageHandler extends AbstractLookupPageHandler implement
         * @inheritDoc
         */
        public function lookup($searchString) {
-               // @todo
-               return [];
+               $conditionBuilder = new PreparedStatementConditionBuilder();
+               $conditionBuilder->add('category.objectTypeID = ?', [ObjectTypeCache::getInstance()->getObjectTypeIDByName('com.woltlab.wcf.category', 'com.woltlab.wcf.article.category')]);
+               $conditionBuilder->add('(category.title LIKE ? OR language_item.languageItemValue LIKE ?)', ['%' . $searchString . '%', '%' . $searchString . '%']);
+               $sql = "SELECT          DISTINCT categoryID
+                       FROM            wcf".WCF_N."_category category
+                       LEFT JOIN       wcf".WCF_N."_language_item language_item
+                       ON              (language_item.languageItem = category.title)
+                       ".$conditionBuilder;
+               $statement = WCF::getDB()->prepareStatement($sql, 10);
+               $statement->execute($conditionBuilder->getParameters());
+               $results = [];
+               while ($categoryID = $statement->fetchColumn()) {
+                       $category = ArticleCategory::getCategory($categoryID);
+                       
+                       // build hierarchy
+                       $description = '';
+                       foreach ($category->getParentCategories() as $parentCategory) {
+                               $description .= $parentCategory->getTitle() . ' &raquo; ';
+                       }
+                       
+                       $results[] = [
+                               'description' => $description,
+                               'image' => 'fa-folder-open-o',
+                               'link' => $category->getLink(),
+                               'objectID' => $categoryID,
+                               'title' => $category->getTitle()
+                       ];
+               }
+               
+               return $results;
        }
        
        /**