ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilChatUserActionProvider.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once("./Services/User/Actions/classes/class.ilUserActionProvider.php");
6
15{
19 protected static $user_access = array();
20
24 protected static $accepts_messages_cache = array();
25
29 protected $pub_ref_id = 0;
30
35 protected $chat_enabled = false;
36
40 protected $osc_enabled = false;
41
45 public function __construct()
46 {
47 parent::__construct();
48
49 include_once 'Modules/Chatroom/classes/class.ilObjChatroom.php';
50 $this->pub_ref_id = ilObjChatroom::_getPublicRefId();
51
52 $chatSettings = new ilSetting('chatroom');
53 $this->chat_enabled = $chatSettings->get('chat_enabled');
54 $this->osc_enabled = $chatSettings->get('enable_osc');
55
56 $this->lng->loadLanguageModule('chatroom');
57 }
58
62 function getComponentId()
63 {
64 return "chtr";
65 }
66
70 function getActionTypes()
71 {
72 return array(
73 "invite" => $this->lng->txt('chat_user_action_invite_public_room'),
74 "invite_osd" => $this->lng->txt('chat_user_action_invite_osd')
75 );
76 }
77
78
85 protected function checkUserChatAccess($a_user_id)
86 {
87 if(!array_key_exists($a_user_id, self::$user_access))
88 {
89 self::$user_access[$a_user_id] = $GLOBALS['DIC']->rbac()->system()->checkAccessOfUser($a_user_id, 'read', $this->pub_ref_id);
90 }
91
92 return self::$user_access[$a_user_id];
93 }
94
99 protected function acceptsMessages($a_user_id)
100 {
101 if(!array_key_exists($a_user_id, self::$accepts_messages_cache))
102 {
103 self::$accepts_messages_cache[$a_user_id] = ilUtil::yn2tf(ilObjUser::_lookupPref($a_user_id, 'chat_osc_accept_msg'));
104 }
105
106 return self::$accepts_messages_cache[$a_user_id];
107 }
108
115 function collectActionsForTargetUser($a_target_user)
116 {
118 include_once("./Services/User/Actions/classes/class.ilUserAction.php");
119
120 require_once 'Services/User/classes/class.ilObjUser.php';
121
122 if(!$this->chat_enabled)
123 {
124 return $coll;
125 }
126
127 if($this->checkUserChatAccess($this->getUserId()))
128 {
129 // no chat with user him/herself
130 if ($a_target_user != $this->getUserId())
131 {
132 if($this->checkUserChatAccess($a_target_user))
133 {
134 $f = new ilUserAction();
135 $f->setType("invite");
136 $f->setText($this->lng->txt('chat_invite_public_room'));
137 $f->setHref('./ilias.php?baseClass=ilRepositoryGUI&amp;ref_id=' . $this->pub_ref_id . '&amp;usr_id=' . $a_target_user . '&amp;cmd=view-invitePD');
138 $coll->addAction($f);
139 }
140 }
141 }
142
143 if($this->osc_enabled)
144 {
145 $f = new ilUserAction();
146 $f->setHref('#');
147 $f->setType("invite_osd");
148 if($this->acceptsMessages($a_target_user))
149 {
150 $f->setText($this->lng->txt('chat_osc_start_conversation'));
151 $f->setData(array(
152 'onscreenchat-userid' => $a_target_user,
153 'onscreenchat-username' => ilObjUser::_lookupLogin($a_target_user)
154 ));
155 }
156 else
157 {
158 $f->setText($this->lng->txt('chat_osc_doesnt_accept_msg'));
159 $f->setData(array(
160 'onscreenchat-inact-userid' => $a_target_user
161 ));
162 }
163 $coll->addAction($f);
164 }
165
166 return $coll;
167 }
168}
169?>
An exception for terminatinating execution or to throw for unit testing.
$osc_enabled
Boolean to indicate if on screen chat is enabled.
getComponentId()
string component id as defined in services.xml/module.xml
getActionTypes()
array[string] keys must be unique action ids (strings), values should be the names of the actions (fr...
collectActionsForTargetUser($a_target_user)
Collect all actions.
$chat_enabled
Boolean to indicate if the chat is enabled.
checkUserChatAccess($a_user_id)
Check user chat access.
static _lookupPref($a_usr_id, $a_keyword)
static _lookupLogin($a_user_id)
lookup login
ILIAS Setting Class.
A class that provides a collection of actions on users.
Action that can be performed on a user.
static yn2tf($a_yn)
convert "y"/"n" to true/false
$GLOBALS['loaded']
Global hash that tracks already loaded includes.