ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilChatUserActionProvider.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
3
12{
16 protected static $user_access = array();
17
21 protected static $accepts_messages_cache = array();
22
26 protected $pub_ref_id = 0;
27
32 protected $chat_enabled = false;
33
37 protected $osc_enabled = false;
38
42 public function __construct()
43 {
45
46 include_once 'Modules/Chatroom/classes/class.ilObjChatroom.php';
47 $this->pub_ref_id = ilObjChatroom::_getPublicRefId();
48
49 $chatSettings = new ilSetting('chatroom');
50 $this->chat_enabled = $chatSettings->get('chat_enabled');
51 $this->osc_enabled = $chatSettings->get('enable_osc');
52
53 $this->lng->loadLanguageModule('chatroom');
54 }
55
59 public function getComponentId()
60 {
61 return "chtr";
62 }
63
67 public function getActionTypes()
68 {
69 return array(
70 "invite" => $this->lng->txt('chat_user_action_invite_public_room'),
71 "invite_osd" => $this->lng->txt('chat_user_action_invite_osd')
72 );
73 }
74
75
82 protected function checkUserChatAccess($a_user_id)
83 {
84 if (!array_key_exists($a_user_id, self::$user_access)) {
85 self::$user_access[$a_user_id] = $GLOBALS['DIC']->rbac()->system()->checkAccessOfUser($a_user_id, 'read', $this->pub_ref_id);
86 }
87
88 return self::$user_access[$a_user_id];
89 }
90
95 protected function acceptsMessages($a_user_id)
96 {
97 if (!array_key_exists($a_user_id, self::$accepts_messages_cache)) {
98 self::$accepts_messages_cache[$a_user_id] = ilUtil::yn2tf(ilObjUser::_lookupPref($a_user_id, 'chat_osc_accept_msg'));
99 }
100
101 return self::$accepts_messages_cache[$a_user_id];
102 }
103
110 public function collectActionsForTargetUser($a_target_user)
111 {
113
114 if (!$this->chat_enabled) {
115 return $coll;
116 }
117
118 if ($this->checkUserChatAccess($this->getUserId()) && $a_target_user != $this->getUserId()) {
119 if ($this->checkUserChatAccess($a_target_user)) {
120 $f = new ilUserAction();
121 $f->setType("invite");
122 $f->setText($this->lng->txt('chat_invite_public_room'));
123 $f->setHref('./ilias.php?baseClass=ilRepositoryGUI&amp;ref_id=' . $this->pub_ref_id . '&amp;usr_id=' . $a_target_user . '&amp;cmd=view-invitePD');
124 $coll->addAction($f);
125 }
126 }
127
128 if ($this->osc_enabled && $a_target_user != $this->getUserId()) {
129 $f = new ilUserAction();
130 $f->setHref('#');
131 $f->setType("invite_osd");
132 if ($this->acceptsMessages($a_target_user)) {
133 $f->setText($this->lng->txt('chat_osc_start_conversation'));
134 $f->setData(array(
135 'onscreenchat-userid' => $a_target_user,
136 'onscreenchat-username' => ilObjUser::_lookupLogin($a_target_user)
137 ));
138 } else {
139 $f->setText($this->lng->txt('chat_osc_doesnt_accept_msg'));
140 $f->setData(array(
141 'onscreenchat-inact-userid' => $a_target_user
142 ));
143 }
144 $coll->addAction($f);
145 }
146
147 return $coll;
148 }
149}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
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
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc