Merge branch '5.2' into 5.3
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / page / CategoryTrophyListPage.class.php
1 <?php
2 namespace wcf\page;
3 use wcf\data\trophy\category\TrophyCategory;
4 use wcf\data\trophy\category\TrophyCategoryCache;
5 use wcf\data\trophy\TrophyList;
6 use wcf\system\exception\IllegalLinkException;
7 use wcf\system\exception\PermissionDeniedException;
8 use wcf\system\request\LinkHandler;
9 use wcf\system\WCF;
10
11 /**
12 * Represents a trophy page.
13 *
14 * @author Joshua Ruesweg
15 * @copyright 2001-2019 WoltLab GmbH
16 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
17 * @package WoltLabSuite\Core\Page
18 * @since 5.2
19 *
20 * @property TrophyList $objectList
21 */
22 class CategoryTrophyListPage extends TrophyListPage {
23 /**
24 * the category id filter
25 * @var int
26 */
27 public $categoryID = 0;
28
29 /**
30 * The category object filter
31 * @var TrophyCategory
32 */
33 public $category;
34
35 /**
36 * @inheritDoc
37 */
38 public function readParameters() {
39 parent::readParameters();
40
41 if (isset($_REQUEST['id'])) $this->categoryID = intval($_REQUEST['id']);
42
43 $this->category = TrophyCategoryCache::getInstance()->getCategoryByID($this->categoryID);
44
45 if (!$this->category) {
46 throw new IllegalLinkException();
47 }
48
49 if (!$this->category->isAccessible()) {
50 throw new PermissionDeniedException();
51 }
52
53 $this->canonicalURL = LinkHandler::getInstance()->getLink('CategoryTrophyList', [
54 'object' => $this->category
55 ], ($this->pageNo > 1 ? 'pageNo=' . $this->pageNo : ''));
56 }
57
58 /**
59 * @inheritDoc
60 */
61 protected function initObjectList() {
62 MultipleLinkPage::initObjectList();
63
64 $this->objectList->sqlSelects = '(SELECT COUNT(*) FROM wcf'.WCF_N.'_user_trophy WHERE trophyID = trophy.trophyID) AS awarded';
65 $this->objectList->getConditionBuilder()->add('isDisabled = ?', [0]);
66 $this->objectList->getConditionBuilder()->add('categoryID = ?', [$this->categoryID]);
67 }
68
69 /**
70 * @inheritDoc
71 */
72 public function assignVariables() {
73 parent::assignVariables();
74
75 WCF::getTPL()->assign([
76 'category' => $this->category,
77 'categoryID' => $this->categoryID
78 ]);
79 }
80 }