2 declare(strict_types=1);
3 namespace wcf\system\page\handler;
4 use wcf\data\category\AbstractDecoratedCategory;
5 use wcf\data\page\Page;
6 use wcf\data\user\online\UserOnline;
7 use wcf\data\IAccessibleObject;
8 use wcf\system\exception\ParentClassException;
12 * Implementation of the `IOnlineLocationPageHandler` interface for decorated category-bound pages.
14 * @author Matthias Schmidt
15 * @copyright 2001-2018 WoltLab GmbH
16 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
17 * @package WoltLabSuite\Core\System\Page\Handler
20 trait TDecoratedCategoryOnlineLocationPageHandler {
21 use TOnlineLocationPageHandler;
24 * Returns the name of the decorated class name.
28 abstract protected function getDecoratedCategoryClass();
31 * Returns the textual description if a user is currently online viewing this page.
33 * @param Page $page visited page
34 * @param UserOnline $user user online object with request data
36 * @see IOnlineLocationPageHandler::getOnlineLocation()
38 public function getOnlineLocation(Page $page, UserOnline $user) {
39 if ($user->pageObjectID === null) {
43 $className = $this->getDecoratedCategoryClass();
44 if (!is_subclass_of($className, AbstractDecoratedCategory::class)) {
45 throw new ParentClassException($className, AbstractDecoratedCategory::class);
48 /** @var AbstractDecoratedCategory $category */
49 /** @noinspection PhpUndefinedMethodInspection */
50 $category = $className::getCategory($user->pageObjectID);
51 if ($category === null) {
55 if ($category instanceof IAccessibleObject && !$category->isAccessible()) {
59 return WCF::getLanguage()->getDynamicVariable('wcf.page.onlineLocation.'.$page->identifier, ['category' => $category]);