Remove `@noinspection PhpUnusedParameterInspection` comments
[GitHub/WoltLab/com.woltlab.wcf.conversation.git] / files / lib / system / page / handler / TConversationOnlineLocationPageHandler.class.php
1 <?php
2
3 namespace wcf\system\page\handler;
4
5 use wcf\data\conversation\Conversation;
6 use wcf\data\page\Page;
7 use wcf\data\user\online\UserOnline;
8 use wcf\system\cache\runtime\UserConversationRuntimeCache;
9 use wcf\system\WCF;
10
11 /**
12 * Implementation of the online location-related page handler methods for conversations.
13 *
14 * @author Matthias Schmidt
15 * @copyright 2001-2019 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 TConversationOnlineLocationPageHandler
21 {
22 use TOnlineLocationPageHandler;
23
24 /**
25 * Returns the textual description if a user is currently online viewing this page.
26 *
27 * @param Page $page visited page
28 * @param UserOnline $user user online object with request data
29 * @return string
30 * @see IOnlineLocationPageHandler::getOnlineLocation()
31 *
32 */
33 public function getOnlineLocation(Page $page, UserOnline $user)
34 {
35 if ($user->pageObjectID === null) {
36 return '';
37 }
38
39 $conversation = UserConversationRuntimeCache::getInstance()->getObject($user->pageObjectID);
40 if ($conversation === null || !$conversation->canRead()) {
41 return '';
42 }
43
44 if ($conversation->userID != WCF::getUser()->userID && $user->userID != WCF::getUser()->userID) {
45 // Make sure that requests from invisible participants are not listed
46 // if the active user is not the author of the conversation.
47 $userConversation = Conversation::getUserConversation($conversation->conversationID, $user->userID);
48 if ($userConversation !== null && $userConversation->isInvisible) {
49 return '';
50 }
51 }
52
53 return WCF::getLanguage()->getDynamicVariable(
54 'wcf.page.onlineLocation.' . $page->identifier,
55 ['conversation' => $conversation]
56 );
57 }
58
59 /**
60 * Prepares fetching all necessary data for the textual description if a user is currently online
61 * viewing this page.
62 *
63 * @param Page $page visited page
64 * @param UserOnline $user user online object with request data
65 * @see IOnlineLocationPageHandler::prepareOnlineLocation()
66 */
67 public function prepareOnlineLocation(
68 Page $page,
69 UserOnline $user
70 ) {
71 if ($user->pageObjectID !== null) {
72 UserConversationRuntimeCache::getInstance()->cacheObjectID($user->pageObjectID);
73 }
74 }
75 }