Add trophy list page
authorJoshua Rüsweg <josh@bastelstu.be>
Wed, 19 Jul 2017 20:34:53 +0000 (22:34 +0200)
committerJoshua Rüsweg <josh@bastelstu.be>
Wed, 19 Jul 2017 20:34:53 +0000 (22:34 +0200)
See #2315

com.woltlab.wcf/page.xml
com.woltlab.wcf/templates/trophyList.tpl [new file with mode: 0644]
wcfsetup/install/files/lib/page/TrophyListPage.class.php [new file with mode: 0644]

index a9c03d5d633fe375b4647ad49db3c0a46642fb8b..53629e03e2cbca1a6b90ca3b961cdab56ddb4d2a 100644 (file)
                                <title>Kontakt</title>
                        </content>
                </page>
+               <page identifier="com.woltlab.wcf.TrophyList">
+                       <pageType>system</pageType>
+                       <controller>wcf\page\TrophyListPage</controller>
+                       <name language="de">Trophäen</name>
+                       <name language="en">Trophies</name>
+                       <parent>com.woltlab.wcf.MembersList</parent>
+                       <permissions>user.profile.trophy.canSeeTrophies</permissions>
+                       <options>module_trophy</options>
+                       <allowSpidersToIndex>1</allowSpidersToIndex>
+               </page>
                
                <!-- static -->
                <page identifier="com.woltlab.wcf.Dashboard">
diff --git a/com.woltlab.wcf/templates/trophyList.tpl b/com.woltlab.wcf/templates/trophyList.tpl
new file mode 100644 (file)
index 0000000..7b50e06
--- /dev/null
@@ -0,0 +1,80 @@
+{capture assign='pageTitle'}{$category->getTitle()}{if $pageNo > 1} - {lang}wcf.page.pageNo{/lang}{/if}{/capture}
+
+{capture assign='contentHeader'}
+       <header class="contentHeader messageGroupContentHeader">
+               <div class="contentHeaderTitle">
+                       <h1 class="contentTitle">{$category->getTitle()}</h1>
+                       <ul class="inlineList contentHeaderMetaData">
+                               <li>
+                                       {$category->getDescription()}
+                               </li>
+                       </ul>
+               </div>
+       </header>
+{/capture}
+
+{capture assign='headContent'}
+       {if $pageNo < $pages}
+               <link rel="next" href="{link controller='TrophyList' object=$category}pageNo={@$pageNo+1}{/link}">
+       {/if}
+       {if $pageNo > 1}
+               <link rel="prev" href="{link controller='TrophyList' object=$category}{if $pageNo > 2}pageNo={@$pageNo-1}{/if}{/link}">
+       {/if}
+{/capture}
+
+{include file='header'}
+
+{hascontent}
+       <div class="paginationTop">
+               {content}
+                       {pages print=true assign='pagesLinks' controller='TrophyList' object=$category link="pageNo=%d"}
+               {/content}
+       </div>
+{/hascontent}
+
+<div class="section">
+       <nav class="tabMenu">
+               <ul>
+                       {foreach from=$categories item='menuCategory'}
+                               <li{if $menuCategory->categoryID == $category->categoryID} class="active"{/if}><a href="{$menuCategory->getLink()}">{$menuCategory->getTitle()}</a></li>
+                       {/foreach}
+               </ul>
+       </nav>
+
+       <div class="tabMenuContent">
+               {if $objects|count}
+                       <ol class="section containerBoxList trophyCategoryList tripleColumned">
+                               {foreach from=$objects item=trophy}
+                                       <li class="box64">
+                                               <div>{@$trophy->renderTrophy(64)}</div>
+
+                                               <div class="sidebarItemTitle">
+                                                       <h3><a href="{$trophy->getLink()}">{@$trophy->getTitle()}</a></h3>
+                                                       <small>{@$trophy->getDescription()}</small>
+                                               </div>
+                                       </li>
+                               {/foreach}
+                       </ol>
+               {else}
+                       <p class="info">{lang}wcf.global.noItems{/lang}</p>
+               {/if}
+       </div>
+</div>
+
+<footer class="contentFooter">
+       {hascontent}
+               <div class="paginationBottom">
+                       {content}{@$pagesLinks}{/content}
+               </div>
+       {/hascontent}
+
+       {hascontent}
+               <nav class="contentFooterNavigation">
+                       <ul>
+                               {content}{event name='contentFooterNavigation'}{/content}
+                       </ul>
+               </nav>
+       {/hascontent}
+</footer>
+
+{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
new file mode 100644 (file)
index 0000000..a60d379
--- /dev/null
@@ -0,0 +1,125 @@
+<?php
+namespace wcf\page;
+use wcf\data\trophy\category\TrophyCategory;
+use wcf\data\trophy\category\TrophyCategoryCache;
+use wcf\data\trophy\TrophyList;
+use wcf\system\exception\IllegalLinkException;
+use wcf\system\exception\PermissionDeniedException;
+use wcf\system\WCF;
+
+/**
+ * Represents a trophy page.
+ *
+ * @author     Joshua Ruesweg
+ * @copyright  2001-2017 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core\Page
+ *
+ * @property   TrophyList      $objectList
+ */
+class TrophyListPage extends MultipleLinkPage {
+       /**
+        * @inheritDoc
+        */
+       public $neededModules = ['MODULE_TROPHY'];
+       
+       /**
+        * @inheritDoc
+        */
+       public $neededPermissions = ['user.profile.trophy.canSeeTrophies'];
+       
+       /**
+        * @inheritDoc
+        */
+       public $itemsPerPage = 30;
+       
+       /**
+        * @inheritDoc
+        */
+       public $objectListClassName = TrophyList::class;
+       
+       /**
+        * selected sort field
+        * @var string
+        */
+       public $sortField = 'trophyID';
+       
+       /**
+        * selected sort order
+        * @var string
+        */
+       public $sortOrder = 'ASC';
+       
+       /**
+        * the category id filter
+        * @var int
+        */
+       public $categoryID = 0;
+       
+       /**
+        * The category object filter 
+        * @var TrophyCategory
+        */
+       public $category;
+       
+       /**
+        * @inheritDoc
+        */
+       public function readParameters() {
+               parent::readParameters();
+               
+               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) {
+                       throw new IllegalLinkException();
+               }
+               
+               if (!$this->category->isAccessible()) {
+                       throw new PermissionDeniedException();
+               }
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       protected function initObjectList() {
+               parent::initObjectList();
+               
+               $this->objectList->getConditionBuilder()->add('isDisabled = ?', [0]);
+               $this->objectList->getConditionBuilder()->add('categoryID = ?', [$this->categoryID]);
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       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()
+               ]);
+       }
+}