Add subtitle to acp search result issues
authorMatthias Schmidt <gravatronics@live.com>
Wed, 20 Aug 2014 14:55:37 +0000 (16:55 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Wed, 20 Aug 2014 14:55:37 +0000 (16:55 +0200)
This changes make it possible to distinguish items with the same name. The subtitle will only be displayed if search results with the same title are in the same list.

wcfsetup/install/files/acp/js/WCF.ACP.js
wcfsetup/install/files/lib/data/acp/search/provider/ACPSearchProviderAction.class.php
wcfsetup/install/files/lib/system/search/acp/ACPSearchResult.class.php
wcfsetup/install/files/lib/system/search/acp/MenuItemACPSearchResultProvider.class.php
wcfsetup/install/files/lib/system/search/acp/OptionACPSearchResultProvider.class.php
wcfsetup/install/files/lib/system/search/acp/UserGroupOptionACPSearchResultProvider.class.php
wcfsetup/install/files/style/dropdown.less
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 901fac06364c1f3461ced147e0889b45e32ea2f8..f31a9f0c27d1c10254de9c64b2f5237e4ea768a3 100644 (file)
@@ -1922,7 +1922,7 @@ WCF.ACP.Search = WCF.Search.Base.extend({
                for (var $i in resultList.items) {
                        var $item = resultList.items[$i];
                        
-                       $('<li><a href="' + $item.link + '">' + WCF.String.escapeHTML($item.title) + '</a></li>').appendTo(this._list);
+                       $('<li><a href="' + $item.link + '"><span>' + WCF.String.escapeHTML($item.title) + '</span>' + ($item.subtitle ? '<small>' + WCF.String.escapeHTML($item.subtitle) + '</small>' : '') + '</a></li>').appendTo(this._list);
                        
                        this._itemCount++;
                }
index 41ef14c52a89e206453529e28bc6a26f01d77a92..8a46dd3a4448deb3acec8c51b6e88b4af0848e5e 100644 (file)
@@ -39,10 +39,26 @@ class ACPSearchProviderAction extends AbstractDatabaseObjectAction implements IS
                        foreach ($resultList as $item) {
                                $items[] = array(
                                        'link' => $item->getLink(),
+                                       'subtitle' => $item->getSubtitle(),
                                        'title' => $item->getTitle()
                                );
                        }
                        
+                       foreach ($items as $key => &$item) {
+                               $double = false;
+                               foreach ($items as $key2 => $item2) {
+                                       if ($key != $key2 && $item['title'] == $item2['title']) {
+                                               $double = true;
+                                               break;
+                                       }
+                               }
+                               
+                               if (!$double) {
+                                       unset($item['subtitle']);
+                               }
+                       }
+                       unset($item);
+                       
                        $data[] = array(
                                'items' => $items,
                                'title' => $resultList->getTitle()
index 18bc6ae67abb02d4eda5a4df65a112812462b345..17fead893d62120c61efcbae6dde7c196996811f 100644 (file)
@@ -18,6 +18,12 @@ class ACPSearchResult {
         */
        protected $link = '';
        
+       /**
+        * item subtitle
+        * @var string
+        */
+       protected $subtitle = '';
+       
        /**
         * item title
         * @var string
@@ -29,10 +35,12 @@ class ACPSearchResult {
         * 
         * @param       string          $title
         * @param       string          $link
+        * @param       string          $subtitle
         */
-       public function __construct($title, $link) {
+       public function __construct($title, $link, $subtitle = '') {
                $this->title = $title;
                $this->link = $link;
+               $this->subtitle = $subtitle;
        }
        
        /**
@@ -53,6 +61,15 @@ class ACPSearchResult {
                return $this->title;
        }
        
+       /**
+        * Returns the item subtitle.
+        * 
+        * @return      string
+        */
+       public function getSubtitle() {
+               return $this->subtitle;
+       }
+       
        /**
         * @see \wcf\system\search\acp\ACPSearchResult::getTitle()
         */
index a0438ae5a447c021c184e8f4ebb8eb5b1fa301d0..87a2f1e7612f5e49ff9b616fee395653df8438f3 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 namespace wcf\system\search\acp;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
+use wcf\system\menu\acp\ACPMenu;
 use wcf\system\WCF;
 
 /**
@@ -65,7 +66,16 @@ class MenuItemACPSearchResultProvider extends AbstractACPSearchResultProvider im
                                continue;
                        }
                        
-                       $results[] = new ACPSearchResult($languageItems[$menuItem->menuItem], $menuItem->getLink());
+                       $parentMenuItem = $menuItem->parentMenuItem;
+                       $parentMenuItems = array();
+                       while ($parentMenuItem && isset(ACPMenu::getInstance()->menuItems[$parentMenuItem])) {
+                               array_unshift($parentMenuItems, $parentMenuItem);
+                               
+                               $parentMenuItem = ACPMenu::getInstance()->menuItemList[$parentMenuItem]->parentMenuItem;
+                       }
+                       $results[] = new ACPSearchResult($languageItems[$menuItem->menuItem], $menuItem->getLink(), WCF::getLanguage()->getDynamicVariable('wcf.acp.search.result.subtitle', array(
+                               'pieces' => $parentMenuItems
+                       )));
                }
                
                return $results;
index a8820ae18cbbcd69dc515ef0b8cd8e1bb783dd92..5e2076ca1e423d3b4a7b423b74697c6e2321d700 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 namespace wcf\system\search\acp;
+use wcf\system\cache\builder\OptionCacheBuilder;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
 use wcf\system\request\LinkHandler;
 use wcf\system\WCF;
@@ -60,6 +61,8 @@ class OptionACPSearchResultProvider extends AbstractCategorizedACPSearchResultPr
                $statement = WCF::getDB()->prepareStatement($sql); // don't use a limit here
                $statement->execute($conditions->getParameters());
                
+               $optionCategories = OptionCacheBuilder::getInstance()->getData(array(), 'categories');
+               
                while ($option = $statement->fetchObject('wcf\data\option\Option')) {
                        // category is not accessible
                        if (!$this->isValid($option->categoryName)) {
@@ -72,7 +75,17 @@ class OptionACPSearchResultProvider extends AbstractCategorizedACPSearchResultPr
                        }
                        
                        $link = LinkHandler::getInstance()->getLink('Option', array('id' => $this->getCategoryID($this->getTopCategory($option->categoryName)->parentCategoryName)), 'optionName='.$option->optionName.'#'.$this->getCategoryName($option->categoryName));
-                       $results[] = new ACPSearchResult($languageItems[$option->optionName], $link);
+                       $categoryName = $option->categoryName;
+                       $parentCategories = array();
+                       while (isset($optionCategories[$categoryName])) {
+                               array_unshift($parentCategories, 'wcf.acp.option.category.'.$optionCategories[$categoryName]->categoryName);
+                               
+                               $categoryName = $optionCategories[$categoryName]->parentCategoryName;
+                       }
+                       
+                       $results[] = new ACPSearchResult($languageItems[$option->optionName], $link, WCF::getLanguage()->getDynamicVariable('wcf.acp.search.result.subtitle', array(
+                               'pieces' => $parentCategories
+                       )));
                }
                
                return $results;
index 59ead1c296e569c71e5b5d42f5598d522e169b5c..e140978d6bb3f084fdf7107243d160fd336fb52e 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 namespace wcf\system\search\acp;
+use wcf\system\cache\builder\UserGroupOptionCacheBuilder;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
 use wcf\system\request\LinkHandler;
 use wcf\system\WCF;
@@ -62,6 +63,8 @@ class UserGroupOptionACPSearchResultProvider extends AbstractCategorizedACPSearc
                $statement = WCF::getDB()->prepareStatement($sql); // don't use a limit here
                $statement->execute($conditions->getParameters());
                
+               $optionCategories = UserGroupOptionCacheBuilder::getInstance()->getData(array(), 'categories');
+               
                while ($userGroupOption = $statement->fetchObject('wcf\data\user\group\option\UserGroupOption')) {
                        // category is not accessible
                        if (!$this->isValid($userGroupOption->categoryName)) {
@@ -74,7 +77,17 @@ class UserGroupOptionACPSearchResultProvider extends AbstractCategorizedACPSearc
                        }
                        
                        $link = LinkHandler::getInstance()->getLink('UserGroupOption', array('id' => $userGroupOption->optionID));
-                       $results[] = new ACPSearchResult($languageItems[$userGroupOption->optionName], $link);
+                       $categoryName = $userGroupOption->categoryName;
+                       $parentCategories = array();
+                       while (isset($optionCategories[$categoryName])) {
+                               array_unshift($parentCategories, 'wcf.acp.group.option.category.'.$optionCategories[$categoryName]->categoryName);
+                               
+                               $categoryName = $optionCategories[$categoryName]->parentCategoryName;
+                       }
+                       
+                       $results[] = new ACPSearchResult($languageItems[$userGroupOption->optionName], $link, WCF::getLanguage()->getDynamicVariable('wcf.acp.search.result.subtitle', array(
+                               'pieces' => $parentCategories
+                       )));
                }
                
                return $results;
index 8a4a369c60e5abf738ad4f1a33b8066b17f9de5f..fb190afd9e6048daa19ec8605c8b0101445d3cc0 100644 (file)
                        }
                }
                
+               > a > small {
+                       display: block;
+               }
+               
                > a + span.badge {
                        display: none;
                }
index 8c970f7495f11dc1f8b8c637bf117595cbbb55e8..0ecff6ca53c86f000ed6f7a83ac69dcb38f29462 100644 (file)
@@ -1233,6 +1233,7 @@ GmbH=Gesellschaft mit beschränkter Haftung]]></item>
                <item name="wcf.acp.search.provider.com.woltlab.wcf.package"><![CDATA[Pakete]]></item>
                <item name="wcf.acp.search.provider.com.woltlab.wcf.user"><![CDATA[Benutzer]]></item>
                <item name="wcf.acp.search.provider.com.woltlab.wcf.userGroupOption"><![CDATA[Berechtigungen]]></item>
+               <item name="wcf.acp.search.result.subtitle"><![CDATA[{implode from=$pieces item=piece glue=' » '}{$piece|language}{/implode}]]></item>
        </category>
        
        <category name="wcf.acp.stat">
index 9c72e94eb6d350a5860fecaf6c1d2611cd091bb7..95e91ebfdfd972a8b0122a38ec8c2b88133350cd 100644 (file)
@@ -1232,6 +1232,7 @@ GmbH=Gesellschaft mit beschränkter Haftung]]></item>
                <item name="wcf.acp.search.provider.com.woltlab.wcf.package"><![CDATA[Packages]]></item>
                <item name="wcf.acp.search.provider.com.woltlab.wcf.user"><![CDATA[Users]]></item>
                <item name="wcf.acp.search.provider.com.woltlab.wcf.userGroupOption"><![CDATA[Permissions]]></item>
+               <item name="wcf.acp.search.result.subtitle"><![CDATA[{implode from=$pieces item=piece glue=' » '}{$piece|language}{/implode}]]></item>
        </category>
        
        <category name="wcf.acp.stat">