From: Joshua Rüsweg Date: Sun, 23 Jul 2017 19:02:19 +0000 (+0200) Subject: Add trophy page X-Git-Tag: 3.1.0_Alpha_1~197 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=e91846e9f062d864ec95c47d212c4da512260e6d;p=GitHub%2FWoltLab%2FWCF.git Add trophy page See #2315 --- diff --git a/com.woltlab.wcf/page.xml b/com.woltlab.wcf/page.xml index 42540f272b..dc21e67eb3 100644 --- a/com.woltlab.wcf/page.xml +++ b/com.woltlab.wcf/page.xml @@ -560,9 +560,24 @@ system wcf\page\TrophyListPage + wcf\system\page\handler\TrophyListPageHandler Trophäen Trophies com.woltlab.wcf.MembersList + 1 + user.profile.trophy.canSeeTrophies + module_trophy + 1 + + + system + wcf\page\TrophyPage + wcf\system\page\handler\TrophyPageHandler + Trophäe + Trophy + com.woltlab.wcf.TrophyList + 1 + 1 user.profile.trophy.canSeeTrophies module_trophy 1 diff --git a/com.woltlab.wcf/templates/trophy.tpl b/com.woltlab.wcf/templates/trophy.tpl new file mode 100644 index 0000000000..00053600fd --- /dev/null +++ b/com.woltlab.wcf/templates/trophy.tpl @@ -0,0 +1,71 @@ +{capture assign='pageTitle'}{$trophy->getTitle()}{if $pageNo > 1} - {lang}wcf.page.pageNo{/lang}{/if}{/capture} + +{capture assign='headContent'} + {if $pageNo < $pages} + + {/if} + {if $pageNo > 1} + + {/if} +{/capture} + +{capture assign='contentHeader'} +
+
+ {@$trophy->renderTrophy(64)} +
+ +
+

{$trophy->getTitle()}

+ +
+
+{/capture} + +{include file='header'} + +{hascontent} +
+ {content} + {pages print=true assign='pagesLinks' controller='Trophy' object=$trophy link="pageNo=%d"} + {/content} +
+{/hascontent} + +{if $objects|count} +
    + {foreach from=$objects item=userTrophy} +
  1. +
    {@$userTrophy->getUserProfile()->getAvatar()->getImageTag(64)}
    + +
    +

    {@$userTrophy->getUserProfile()->getAnchorTag()}

    + {@$userTrophy->getDescription()} - {@$userTrophy->time|time} +
    +
  2. + {/foreach} +
+{else} +

{lang}wcf.global.noItems{/lang}

+{/if} + +
+ {hascontent} +
+ {content}{@$pagesLinks}{/content} +
+ {/hascontent} + + {hascontent} + + {/hascontent} +
+ +{include file='footer'} \ No newline at end of file diff --git a/wcfsetup/install/files/lib/page/TrophyListPage.class.php b/wcfsetup/install/files/lib/page/TrophyListPage.class.php index a60d379de1..c097febf22 100644 --- a/wcfsetup/install/files/lib/page/TrophyListPage.class.php +++ b/wcfsetup/install/files/lib/page/TrophyListPage.class.php @@ -70,19 +70,6 @@ class TrophyListPage extends MultipleLinkPage { if (isset($_REQUEST['id'])) $this->categoryID = intval($_REQUEST['id']); - // read category id, if no categoryID is selected - if ($this->categoryID == 0) { - $categories = TrophyCategoryCache::getInstance()->getEnabledCategories(); - - if (count($categories)) { - $category = reset($categories); - $this->categoryID = $category->getObjectID(); - } - else { - throw new IllegalLinkException(); - } - } - $this->category = TrophyCategoryCache::getInstance()->getCategoryByID($this->categoryID); if ($this->category === null) { @@ -110,16 +97,14 @@ class TrophyListPage extends MultipleLinkPage { public function assignVariables() { parent::assignVariables(); - if (!isset($_REQUEST['id'])) { - WCF::getTPL()->assign([ - 'canonicalURL' => $this->category->getLink() - ]); - } - WCF::getTPL()->assign([ 'category' => $this->category, 'categoryID' => $this->categoryID, 'categories' => TrophyCategoryCache::getInstance()->getEnabledCategories() ]); + + if (count($this->objectList) === 0) { + @header('HTTP/1.0 404 Not Found'); + } } } diff --git a/wcfsetup/install/files/lib/page/TrophyPage.class.php b/wcfsetup/install/files/lib/page/TrophyPage.class.php new file mode 100644 index 0000000000..bacca17432 --- /dev/null +++ b/wcfsetup/install/files/lib/page/TrophyPage.class.php @@ -0,0 +1,148 @@ + + * @package WoltLabSuite\Core\Page + * @since 3.1 + * + * @property UserTrophyList $objectList + */ +class TrophyPage extends MultipleLinkPage { + /** + * @inheritDoc + */ + public $neededModules = ['MODULE_TROPHY']; + + /** + * @inheritDoc + */ + public $neededPermissions = ['user.profile.trophy.canSeeTrophies']; + + /** + * @inheritDoc + */ + public $itemsPerPage = 30; + + /** + * @inheritDoc + */ + public $objectListClassName = UserTrophyList::class; + + /** + * @inheritDoc + */ + public $sortField = 'time'; + + /** + * @inheritDoc + */ + public $sortOrder = 'DESC'; + + /** + * the trophy id + * @var int + */ + public $trophyID = 0; + + /** + * The trophy instance + * @var Trophy + */ + public $trophy; + + public function readData() { + parent::readData(); + + PageLocationManager::getInstance()->addParentLocation('com.woltlab.wcf.TrophyList', $this->trophy->getCategory()->getObjectID(), $this->trophy->getCategory()); + } + + /** + * @inheritDoc + */ + public function readParameters() { + parent::readParameters(); + + if (isset($_REQUEST['id'])) $this->trophyID = intval($_REQUEST['id']); + + $this->trophy = TrophyCache::getInstance()->getTrophyByID($this->trophyID); + if ($this->trophy === null) { + throw new IllegalLinkException(); + } + + if ($this->trophy->isDisabled()) { + throw new PermissionDeniedException(); + } + } + + /** + * @inheritDoc + */ + public function readObjects() { + parent::readObjects(); + + $userIDs = []; + /** @var UserTrophy $trophy */ + foreach ($this->objectList->getObjects() as $trophy) { + $userIDs[] = $trophy->userID; + } + + UserProfileRuntimeCache::getInstance()->cacheObjectIDs(array_unique($userIDs)); + } + + /** + * @inheritDoc + */ + protected function initObjectList() { + parent::initObjectList(); + + $this->objectList->getConditionBuilder()->add('user_trophy.trophyID = ?', [$this->trophy->getObjectID()]); + + if (!WCF::getUser()->userID) { + $this->objectList->getConditionBuilder()->add('user_trophy.userID IN (SELECT userID FROM wcf'. WCF_N .'_user_option_value WHERE userOption'. UserOptionCacheBuilder::getInstance()->getData()['options']['canViewTrophies']->optionID .' = 0)'); + } + else if (!WCF::getSession()->getPermission('admin.general.canViewPrivateUserOptions')) { + $conditionBuilder = new PreparedStatementConditionBuilder(false, 'OR'); + $conditionBuilder->add('user_trophy.userID IN (SELECT userID FROM wcf'. WCF_N .'_user_option_value WHERE (userOption'. UserOptionCacheBuilder::getInstance()->getData()['options']['canViewTrophies']->optionID .' = 0 OR userOption'. UserOptionCacheBuilder::getInstance()->getData()['options']['canViewTrophies']->optionID .' = 1))'); + + $friendshipConditionBuilder = new PreparedStatementConditionBuilder(false); + $friendshipConditionBuilder->add('user_trophy.userID IN (SELECT userID FROM wcf'. WCF_N .'_user_option_value WHERE userOption'. UserOptionCacheBuilder::getInstance()->getData()['options']['canViewTrophies']->optionID .' = 2)'); + $friendshipConditionBuilder->add('user_trophy.userID IN (SELECT userID FROM wcf'. WCF_N .'_user_follow WHERE followUserID = ?)', [WCF::getUser()->userID]); + $conditionBuilder->add('(' . $friendshipConditionBuilder . ')', $friendshipConditionBuilder->getParameters()); + $conditionBuilder->add('user_trophy.userID = ?', [WCF::getUser()->userID]); + + $this->objectList->getConditionBuilder()->add('('. $conditionBuilder .')', $conditionBuilder->getParameters()); + } + } + + /** + * @inheritDoc + */ + public function assignVariables() { + parent::assignVariables(); + + WCF::getTPL()->assign([ + 'trophy' => $this->trophy, + 'trophyID' => $this->trophyID + ]); + + if (count($this->objectList) === 0) { + @header('HTTP/1.0 404 Not Found'); + } + } +} diff --git a/wcfsetup/install/files/lib/system/page/handler/TrophyListPageHandler.class.php b/wcfsetup/install/files/lib/system/page/handler/TrophyListPageHandler.class.php new file mode 100644 index 0000000000..7182263987 --- /dev/null +++ b/wcfsetup/install/files/lib/system/page/handler/TrophyListPageHandler.class.php @@ -0,0 +1,23 @@ + + * @package WoltLabSuite\Core\System\Page\Handler + * @since 3.1 + */ +class TrophyListPageHandler extends AbstractLookupPageHandler { + use TDecoratedCategoryOnlineLocationLookupPageHandler; + + /** + * @inheritDoc + */ + protected function getDecoratedCategoryClass() { + return TrophyCategory::class; + } +} diff --git a/wcfsetup/install/files/lib/system/page/handler/TrophyPageHandler.class.php b/wcfsetup/install/files/lib/system/page/handler/TrophyPageHandler.class.php new file mode 100644 index 0000000000..08b0c0f7be --- /dev/null +++ b/wcfsetup/install/files/lib/system/page/handler/TrophyPageHandler.class.php @@ -0,0 +1,64 @@ + + * @package WoltLabSuite\Core\System\Page\Handler + * @since 3.1 + */ +class TrophyPageHandler extends AbstractLookupPageHandler { + /** + * @inheritDoc + */ + public function getLink($objectID) { + return TrophyCache::getInstance()->getTrophyByID($objectID)->getLink(); + } + + /** + * @inheritDoc + */ + public function isValid($objectID) { + return TrophyCache::getInstance()->getTrophyByID($objectID) !== null; + } + + /** @noinspection PhpMissingParentCallCommonInspection */ + /** + * @inheritDoc + */ + public function isVisible($objectID = null) { + return WCF::getSession()->getPermission('user.profile.trophy.canSeeTrophies'); + } + + /** + * @inheritDoc + */ + public function lookup($searchString) { + $trophyList = new TrophyList(); + if (!empty($trophyList->sqlJoins)) $trophyList->sqlJoins .= ', '; + $trophyList->sqlJoins = "LEFT JOIN wcf".WCF_N."_language_item language_item ON (language_item.languageItem = trophy.title)"; + $trophyList->getConditionBuilder()->add('(trophy.title LIKE ? OR language_item.languageItemValue LIKE ?)', ['%' . $searchString . '%', '%' . $searchString . '%']); + $trophyList->sqlLimit = 10; + $trophyList->sqlOrderBy = 'title'; + $trophyList->readObjects(); + + $results = []; + foreach ($trophyList->getObjects() as $trophy) { + $results[] = [ + 'description' => $trophy->getDescription(), + 'image' => $trophy->renderTrophy(48), + 'link' => $trophy->getLink(), + 'objectID' => $trophy->trophyID, + 'title' => $trophy->getTitle() + ]; + } + + return $results; + } +} diff --git a/wcfsetup/install/files/style/ui/trophy.scss b/wcfsetup/install/files/style/ui/trophy.scss index 94c25b53f4..6458ff7045 100644 --- a/wcfsetup/install/files/style/ui/trophy.scss +++ b/wcfsetup/install/files/style/ui/trophy.scss @@ -29,6 +29,10 @@ font-size: 18px; } + &.icon48 { + font-size: 27px; + } + &.icon64 { font-size: 36px; }