Merge branch '3.0' into 3.1
[GitHub/WoltLab/com.woltlab.wcf.conversation.git] / files / lib / system / page / handler / TConversationOnlineLocationPageHandler.class.php
CommitLineData
95dea717
MS
1<?php
2namespace wcf\system\page\handler;
3use wcf\data\page\Page;
4use wcf\data\user\online\UserOnline;
5use wcf\system\cache\runtime\UserConversationRuntimeCache;
6use wcf\system\WCF;
7
8/**
9 * Implementation of the online location-related page handler methods for conversations.
10 *
11 * @author Matthias Schmidt
ca7ac0d3 12 * @copyright 2001-2018 WoltLab GmbH
95dea717 13 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
c032049e
MW
14 * @package WoltLabSuite\Core\System\Page\Handler
15 * @since 3.0
95dea717
MS
16 */
17trait TConversationOnlineLocationPageHandler {
18 use TOnlineLocationPageHandler;
19
20 /**
169f6617
MS
21 * Returns the textual description if a user is currently online viewing this page.
22 *
23 * @see IOnlineLocationPageHandler::getOnlineLocation()
24 *
25 * @param Page $page visited page
26 * @param UserOnline $user user online object with request data
27 * @return string
95dea717
MS
28 */
29 public function getOnlineLocation(Page $page, UserOnline $user) {
bf644591 30 if ($user->pageObjectID === null) {
95dea717
MS
31 return '';
32 }
33
bf644591 34 $conversation = UserConversationRuntimeCache::getInstance()->getObject($user->pageObjectID);
95dea717
MS
35 if ($conversation === null || !$conversation->canRead()) {
36 return '';
37 }
38
39 return WCF::getLanguage()->getDynamicVariable('wcf.page.onlineLocation.'.$page->identifier, ['conversation' => $conversation]);
40 }
41
42 /**
169f6617
MS
43 * Prepares fetching all necessary data for the textual description if a user is currently online
44 * viewing this page.
45 *
95dea717 46 * @see IOnlineLocationPageHandler::prepareOnlineLocation()
169f6617
MS
47 *
48 * @param Page $page visited page
49 * @param UserOnline $user user online object with request data
95dea717 50 */
467284a5 51 public function prepareOnlineLocation(/** @noinspection PhpUnusedParameterInspection */Page $page, UserOnline $user) {
bf644591
MW
52 if ($user->pageObjectID !== null) {
53 UserConversationRuntimeCache::getInstance()->cacheObjectID($user->pageObjectID);
95dea717
MS
54 }
55 }
56}