Add missing `license` element in `package.xsd`
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / page / handler / TUserOnlineLocationPageHandler.class.php
1 <?php
2 namespace wcf\system\page\handler;
3 use wcf\data\page\Page;
4 use wcf\data\user\online\UserOnline;
5 use wcf\system\cache\runtime\UserRuntimeCache;
6 use wcf\system\WCF;
7
8 /**
9 * Implementation of the `IOnlineLocationPageHandler` interface for user-bound pages.
10 *
11 * @author Matthias Schmidt
12 * @copyright 2001-2019 WoltLab GmbH
13 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14 * @package WoltLabSuite\Core\System\Page\Handler
15 * @since 3.0
16 */
17 trait TUserOnlineLocationPageHandler {
18 use TOnlineLocationPageHandler;
19
20 /**
21 * Returns the textual description if a user is currently online viewing this page.
22 *
23 * @param Page $page visited page
24 * @param UserOnline $user user online object with request data
25 * @return string
26 * @see IOnlineLocationPageHandler::getOnlineLocation()
27 */
28 public function getOnlineLocation(Page $page, UserOnline $user) {
29 if ($user->pageObjectID === null) {
30 return '';
31 }
32
33 $userObject = UserRuntimeCache::getInstance()->getObject($user->pageObjectID);
34 if ($userObject === null) {
35 return '';
36 }
37
38 return WCF::getLanguage()->getDynamicVariable('wcf.page.onlineLocation.'.$page->identifier, ['user' => $userObject]);
39 }
40
41 /**
42 * Prepares fetching all necessary data for the textual description if a user is currently online
43 * viewing this page.
44 *
45 * @param Page $page visited page
46 * @param UserOnline $user user online object with request data
47 * @see IOnlineLocationPageHandler::prepareOnlineLocation()
48 */
49 public function prepareOnlineLocation(/** @noinspection PhpUnusedParameterInspection */Page $page, UserOnline $user) {
50 if ($user->pageObjectID !== null) {
51 UserRuntimeCache::getInstance()->cacheObjectID($user->pageObjectID);
52 }
53 }
54 }