<commit_before><?php

namespace wcf\page;

use wcf\data\trophy\category\TrophyCategory;
use wcf\data\trophy\Trophy;
use wcf\data\trophy\TrophyCache;
use wcf\data\user\trophy\UserTrophy;
use wcf\data\user\trophy\UserTrophyList;
use wcf\data\user\User;
use wcf\system\cache\builder\UserOptionCacheBuilder;
use wcf\system\cache\runtime\UserProfileRuntimeCache;
use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\exception\IllegalLinkException;
use wcf\system\exception\PermissionDeniedException;
use wcf\system\page\PageLocationManager;
use wcf\system\request\LinkHandler;
use wcf\system\WCF;

/**
 * Represents a trophy page.
 *
 * @author  <NAME>
 * @copyright   2001-2019 WoltLab GmbH
 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @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;

    /**
     * category object
     * @var TrophyCategory
     */
    public $category;

    /**
     * @inheritDoc
     */
    public function readData()
    {
        parent::readData();

        PageLocationManager::getInstance()->addParentLocation(
            'com.woltlab.wcf.TrophyCategoryList',
            $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();
        }

        $this->category = $this->trophy->getCategory();

        $this->canonicalURL = LinkHandler::getInstance()->getLink('Trophy', [
            'object' => $this->trophy,
        ], ($this->pageNo > 1 ? 'pageNo=' . $this->pageNo : ''));
    }

    /**
     * @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()]);
        $canViewTrophyDefaultValue = UserOptionCacheBuilder::getInstance()->getData()['options']['canViewTrophies']->defaultValue;
	    $canViewTrophiesOptionID = User::getUserOptionID('canViewTrophies');

        if (!WCF::getUser()->userID) {
            $this->objectList->getConditionBuilder()->add('user_trophy.userID IN (
                SELECT  userID<commit_msg>Fix codestyle<commit_after><?php

namespace wcf\page;

use wcf\data\trophy\category\TrophyCategory;
use wcf\data\trophy\Trophy;
use wcf\data\trophy\TrophyCache;
use wcf\data\user\trophy\UserTrophy;
use wcf\data\user\trophy\UserTrophyList;
use wcf\data\user\User;
use wcf\system\cache\builder\UserOptionCacheBuilder;
use wcf\system\cache\runtime\UserProfileRuntimeCache;
use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\exception\IllegalLinkException;
use wcf\system\exception\PermissionDeniedException;
use wcf\system\page\PageLocationManager;
use wcf\system\request\LinkHandler;
use wcf\system\WCF;

/**
 * Represents a trophy page.
 *
 * @author  <NAME>
 * @copyright   2001-2019 WoltLab GmbH
 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @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;

    /**
     * category object
     * @var TrophyCategory
     */
    public $category;

    /**
     * @inheritDoc
     */
    public function readData()
    {
        parent::readData();

        PageLocationManager::getInstance()->addParentLocation(
            'com.woltlab.wcf.TrophyCategoryList',
            $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();
        }

        $this->category = $this->trophy->getCategory();

        $this->canonicalURL = LinkHandler::getInstance()->getLink('Trophy', [
            'object' => $this->trophy,
        ], ($this->pageNo > 1 ? 'pageNo=' . $this->pageNo : ''));
    }

    /**
     * @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()]);
        $canViewTrophyDefaultValue = UserOptionCacheBuilder::getInstance()->getData()['options']['canViewTrophies']->defaultValue;
        $canViewTrophiesOptionID = User::getUserOptionID('canViewTrophies');

        if (!WCF::getUser()->userID) {
            $this->objectList->getConditionBuilder()->add('user_trophy.userID IN (
                SELECT  userID
{'fraction_non_alphanumeric': 0.14911463187325255, 'fraction_numerical': 0.003727865796831314, 'mean_word_length': 2.5450684285040115, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3103255', 'n_tokens_mistral': 2428, 'n_tokens_neox': 2252, 'n_words': 356}