84b5902419fc26f6a62cdd19bef954010ef6c8a0
[GitHub/WoltLab/WCF.git] /
1 <?php
2 namespace wcf\system\page\handler;
3 use wcf\data\category\AbstractDecoratedCategory;
4 use wcf\data\page\Page;
5 use wcf\data\user\online\UserOnline;
6 use wcf\data\IAccessibleObject;
7 use wcf\system\exception\ParentClassException;
8 use wcf\system\WCF;
9
10 /**
11 * Implementation of the `IOnlineLocationPageHandler` interface for decorated category-bound pages.
12 *
13 * @author Matthias Schmidt
14 * @copyright 2001-2018 WoltLab GmbH
15 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
16 * @package WoltLabSuite\Core\System\Page\Handler
17 * @since 3.0
18 */
19 trait TDecoratedCategoryOnlineLocationPageHandler {
20 use TOnlineLocationPageHandler;
21
22 /**
23 * Returns the name of the decorated class name.
24 *
25 * @return string
26 */
27 abstract protected function getDecoratedCategoryClass();
28
29 /**
30 * Returns the textual description if a user is currently online viewing this page.
31 *
32 * @param Page $page visited page
33 * @param UserOnline $user user online object with request data
34 * @return string
35 * @see IOnlineLocationPageHandler::getOnlineLocation()
36 */
37 public function getOnlineLocation(Page $page, UserOnline $user) {
38 if ($user->pageObjectID === null) {
39 return '';
40 }
41
42 $className = $this->getDecoratedCategoryClass();
43 if (!is_subclass_of($className, AbstractDecoratedCategory::class)) {
44 throw new ParentClassException($className, AbstractDecoratedCategory::class);
45 }
46
47 /** @var AbstractDecoratedCategory $category */
48 /** @noinspection PhpUndefinedMethodInspection */
49 $category = $className::getCategory($user->pageObjectID);
50 if ($category === null) {
51 return '';
52 }
53
54 if ($category instanceof IAccessibleObject && !$category->isAccessible()) {
55 return null;
56 }
57
58 return WCF::getLanguage()->getDynamicVariable('wcf.page.onlineLocation.'.$page->identifier, ['category' => $category]);
59 }
60 }