b9a475e0a8ba0cb7e010bce4824c4645d09c161a
[GitHub/WoltLab/WCF.git] /
1 <?php
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;
9 use wcf\system\WCF;
10
11 /**
12 * Implementation of the `IOnlineLocationPageHandler` interface for decorated category-bound pages.
13 *
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
18 * @since 3.0
19 */
20 trait TDecoratedCategoryOnlineLocationPageHandler {
21 use TOnlineLocationPageHandler;
22
23 /**
24 * Returns the name of the decorated class name.
25 *
26 * @return string
27 */
28 abstract protected function getDecoratedCategoryClass();
29
30 /**
31 * Returns the textual description if a user is currently online viewing this page.
32 *
33 * @param Page $page visited page
34 * @param UserOnline $user user online object with request data
35 * @return string
36 * @see IOnlineLocationPageHandler::getOnlineLocation()
37 */
38 public function getOnlineLocation(Page $page, UserOnline $user) {
39 if ($user->pageObjectID === null) {
40 return '';
41 }
42
43 $className = $this->getDecoratedCategoryClass();
44 if (!is_subclass_of($className, AbstractDecoratedCategory::class)) {
45 throw new ParentClassException($className, AbstractDecoratedCategory::class);
46 }
47
48 /** @var AbstractDecoratedCategory $category */
49 /** @noinspection PhpUndefinedMethodInspection */
50 $category = $className::getCategory($user->pageObjectID);
51 if ($category === null) {
52 return '';
53 }
54
55 if ($category instanceof IAccessibleObject && !$category->isAccessible()) {
56 return null;
57 }
58
59 return WCF::getLanguage()->getDynamicVariable('wcf.page.onlineLocation.'.$page->identifier, ['category' => $category]);
60 }
61 }