ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilChatUserActionProvider.php
Go to the documentation of this file.
1<?php
2
24{
26 protected static array $user_access = [];
28 protected static array $accepts_messages_cache = [];
29 protected int $pub_ref_id = 0;
30 protected bool $chat_enabled = false;
31 protected bool $osc_enabled = false;
33
34 public function __construct()
35 {
37
38 global $DIC;
39
40 $this->pub_ref_id = ilObjChatroom::_getPublicRefId();
41
42 $chatSettings = new ilSetting('chatroom');
43 $this->chat_enabled = (bool) $chatSettings->get('chat_enabled');
44 $this->osc_enabled = (bool) $chatSettings->get('enable_osc');
45
46 $this->lng->loadLanguageModule('chatroom');
47 $this->ctrl = $DIC->ctrl();
48 }
49
50 public function getComponentId(): string
51 {
52 return "chtr";
53 }
54
58 public function getActionTypes(): array
59 {
60 return [
61 "invite" => $this->lng->txt('chat_user_action_invite_public_room'),
62 "invite_osd" => $this->lng->txt('chat_user_action_invite_osd')
63 ];
64 }
65
66 protected function checkUserChatAccess(int $a_user_id): bool
67 {
68 if (!array_key_exists($a_user_id, self::$user_access)) {
69 self::$user_access[$a_user_id] = $GLOBALS['DIC']->rbac()->system()->checkAccessOfUser($a_user_id, 'read', $this->pub_ref_id);
70 }
71
72 return self::$user_access[$a_user_id];
73 }
74
75 protected function acceptsMessages(int $a_user_id): bool
76 {
77 if (!array_key_exists($a_user_id, self::$accepts_messages_cache)) {
78 self::$accepts_messages_cache[$a_user_id] = ilUtil::yn2tf(
79 ilObjUser::_lookupPref($a_user_id, 'chat_osc_accept_msg') ?? 'n'
80 );
81 }
82
83 return (bool) self::$accepts_messages_cache[$a_user_id];
84 }
85
89 public function collectActionsForTargetUser(int $a_target_user): ilUserActionCollection
90 {
91 $coll = new ilUserActionCollection();
92
93 if (!$this->chat_enabled) {
94 return $coll;
95 }
96
97 if ($this->checkUserChatAccess($this->getUserId()) && $a_target_user != $this->getUserId()) {
98 if ($this->checkUserChatAccess($a_target_user)) {
99 $f = new ilUserAction();
100 $f->setType("invite");
101 $f->setText($this->lng->txt('chat_user_action_invite_public_room'));
102 $this->ctrl->setParameterByClass(ilObjChatroomGUI::class, 'ref_id', $this->pub_ref_id);
103 $this->ctrl->setParameterByClass(ilObjChatroomGUI::class, 'user', $a_target_user);
104 $f->setHref($this->ctrl->getLinkTargetByClass([ilRepositoryGUI::class, ilObjChatroomGUI::class], 'inviteUsersToPrivateRoom-byId'));
105 $coll->addAction($f);
106 }
107 }
108
109 if ($this->osc_enabled && $a_target_user != $this->getUserId()) {
110 $f = new ilUserAction();
111 $f->setHref('#');
112 $f->setType("invite_osd");
113 if ($this->acceptsMessages($a_target_user)) {
114 $f->setText($this->lng->txt('chat_osc_start_conversation'));
115 $f->setData([
116 'onscreenchat-userid' => $a_target_user,
117 'onscreenchat-username' => ilObjUser::_lookupLogin($a_target_user)
118 ]);
119 } else {
120 $f->setText($this->lng->txt('chat_osc_doesnt_accept_msg'));
121 $f->setData([
122 'onscreenchat-inact-userid' => $a_target_user
123 ]);
124 }
125 $coll->addAction($f);
126 }
127
128 return $coll;
129 }
130}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
collectActionsForTargetUser(int $a_target_user)
Collect all actions.
static _lookupPref(int $a_usr_id, string $a_keyword)
static _lookupLogin(int $a_user_id)
ILIAS Setting Class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
A class that provides a collection of actions on users.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static yn2tf(string $a_yn)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26
$GLOBALS["DIC"]
Definition: wac.php:54