ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilUsersOnlineBlockGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once("Services/Block/classes/class.ilBlockGUI.php");
5require_once 'Services/Mail/classes/class.ilMailFormCall.php';
6include_once 'Services/Mail/classes/class.ilMailGlobalServices.php';
7
18{
22 protected $settings;
23
27 protected $db;
28
32 protected $rbacsystem;
33
34 public static $block_type = "pdusers";
35
39 public function __construct()
40 {
41 global $DIC;
42
43 $this->ctrl = $DIC->ctrl();
44 $this->lng = $DIC->language();
45 $this->user = $DIC->user();
46 $this->settings = $DIC->settings();
47 $this->db = $DIC->database();
48 $this->rbacsystem = $DIC->rbac()->system();
49 $lng = $DIC->language();
50
51 parent::__construct();
52
53 $this->setLimit(10);
54 $this->setTitle($lng->txt("users_online"));
56
57 // mjansen: Used for mail referer link (@see fillRow). I don't want to create a new instance in each fillRow call.
58 $this->topGuiObj = new ilPersonalDesktopGUI();
59 }
60
66 public static function getBlockType()
67 {
68 return self::$block_type;
69 }
70
76 public static function isRepositoryObject()
77 {
78 return false;
79 }
80
84 public static function getScreenMode()
85 {
86 global $DIC;
87
88 $ilCtrl = $DIC->ctrl();
89
90 if ($ilCtrl->getCmdClass() == "ilpublicuserprofilegui") {
91 return IL_SCREEN_FULL;
92 }
93
94 switch ($ilCtrl->getCmd()) {
95 case "showUserProfile":
96 return IL_SCREEN_FULL;
97 break;
98
99 default:
100 return IL_SCREEN_SIDE;
101 break;
102 }
103 }
104
108 public function executeCommand()
109 {
111
112 $next_class = $ilCtrl->getNextClass();
113 $cmd = $ilCtrl->getCmd("getHTML");
114
115 switch ($next_class) {
116 // profile
117 case "ilpublicuserprofilegui":
118 include_once('./Services/User/classes/class.ilPublicUserProfileGUI.php');
119 $profile_gui = new ilPublicUserProfileGUI($_GET["user"]);
120 $profile_gui->setBackUrl($ilCtrl->getParentReturn($this));
121 return $ilCtrl->forwardCommand($profile_gui);
122 break;
123
124 default:
125 return $this->$cmd();
126 }
127 }
128
129 public function getHTML()
130 {
132
133 $this->users_online_pref = $ilUser->getPref("show_users_online");
134
135 if ($this->users_online_pref != "y" && $this->users_online_pref != "associated") {
136 return "";
137 }
138
139 $this->getUsers();
140
141 if ($this->getCurrentDetailLevel() == 0) {
142 return "";
143 } else {
144 return parent::getHTML();
145 }
146 }
147
151 public function getUsers()
152 {
154
155 if ($this->users_online_pref == "associated") {
156 $this->users = ilUtil::getAssociatedUsersOnline($ilUser->getId(), true);
157 } else {
158 $this->users = ilObjUser::_getUsersOnline(0, true);
159 }
160
161 $this->num_users = 0;
162
163 // add current user always to list
164 if ($ilUser->getId() != ANONYMOUS_USER_ID &&
165 ilObjUser::_lookupPref($ilUser->getId(), "hide_own_online_status") != "y") {
166 $this->users[$ilUser->getId()] =
167 array("user_id" => $ilUser->getId(),
168 "firstname" => $ilUser->getFirstname(),
169 "lastname" => $ilUser->getLastname(),
170 "title" => $ilUser->getUTitle(),
171 "login" => $ilUser->getLogin());
172 }
173
174 foreach ($this->users as $user_id => $user) {
175 if ($user_id != ANONYMOUS_USER_ID) {
176 $this->num_users++;
177 } else {
178 $this->visitors = $user["num"];
179 }
180 }
181 }
182
186 public function fillDataSection()
187 {
188 include_once("Services/Notes/classes/class.ilNote.php");
189
190 if ($this->getCurrentDetailLevel() > 1 && $this->num_users > 0) {
191 $this->setRowTemplate("tpl.users_online_row.html", "Services/PersonalDesktop");
192 $this->getListRowData();
193 if ($this->getCurrentDetailLevel() > 2) {
194 $this->setColSpan(2);
195 }
196 parent::fillDataSection();
197 } else {
198 $this->setEnableNumInfo(false);
199 $this->setDataSection($this->getOverview());
200 }
201 }
202
203
207 public function getListRowData()
208 {
211
212 $data = array();
213
214 $this->mail_allowed = ($ilUser->getId() != ANONYMOUS_USER_ID &&
215 $rbacsystem->checkAccess('internal_mail', ilMailGlobalServices::getMailObjectRefId()));
216
217 foreach ($this->users as $user_id => $user) {
218 $data[] = array(
219 "id" => $user_id,
220 "login" => $user["login"]
221 );
222 }
223 $this->setData($data);
224
225 // we do not have at least one (non hidden) active user
226 if (count($data) == 0) {
227 $this->setEnableNumInfo(false);
228 $this->setCurrentDetailLevel(1);
229 $this->enabledetailrow = false;
230 $this->setDataSection($this->getOverview());
231 }
232 }
233
237 public function fillRow($a_set)
238 {
244
245 // mail link
246 $a_set["mail_to"] = "";
247 if ($this->mail_allowed &&
248 $rbacsystem->checkAccessOfUser($a_set['id'], 'internal_mail', ilMailGlobalServices::getMailObjectRefId())) {
249 $a_set['mail_url'] = ilMailFormCall::getLinkTarget($this->topGuiObj, '', array(), array('type' => 'new', 'rcp_to' => urlencode($a_set['login'])));
250 }
251
252 // check for profile
253 $a_set["profile"] = in_array(
254 ilObjUser::_lookupPref($a_set["id"], "public_profile"),
255 array("y", "g")
256 );
257
258 // user image
259 if ($this->getCurrentDetailLevel() > 2) {
260 if ($a_set["mail_url"] != "") {
261 $this->tpl->setCurrentBlock("mailto_link");
262 $this->tpl->setVariable("TXT_MAIL", $lng->txt("mail"));
263 $this->tpl->setVariable("MAIL_URL", $a_set["mail_url"]);
264 $this->tpl->parseCurrentBlock();
265 }
266
267 $chatSettings = new ilSetting('chatroom');
268 if (/*ilChatServerConfig::_isActive() && */$chatSettings->get('chat_enabled')) {
269 if (!$this->__showActiveChatsOfUser($a_set["id"])) {
270 // Show invite to chat
271 $this->__showChatInvitation($a_set["id"]);
272 }
273
274 include_once './Modules/Chatroom/classes/class.ilObjChatroom.php';
275 if ($a_set["id"] == $ilUser->getId() &&
276 $rbacsystem->checkAccess('read', ilObjChatroom::_getPublicRefId())) {
277 $this->tpl->setCurrentBlock('chat_link');
278 $this->tpl->setVariable('TXT_CHAT_INVITE', $lng->txt('chat_enter_public_room'));
279 $this->tpl->setVariable('TXT_CHAT_INVITE_TOOLTIP', $lng->txt('chat_enter_public_room_tooltip'));
280 $this->tpl->setVariable('CHAT_LINK', './ilias.php?baseClass=ilRepositoryGUI&cmd=view&ref_id=' . ilObjChatroom::_getPublicRefId());
281 $this->tpl->parseCurrentBlock();
282 }
283 }
284
285 // user image
286 $this->tpl->setCurrentBlock("usr_image");
287 $this->tpl->setVariable(
288 "USR_IMAGE",
289 ilObjUser::_getPersonalPicturePath($a_set["id"], "xxsmall")
290 );
291 $this->tpl->setVariable("USR_ALT", $lng->txt("personal_picture"));
292 $this->tpl->parseCurrentBlock();
293 $this->tpl->touchBlock("usr_image_space");
294 }
295
296 // username
297 if (!$a_set["profile"]) {
298 $this->tpl->setVariable("USR_LOGIN", $a_set["login"]);
299 } elseif ($this->getCurrentDetailLevel() > 2) {
300 $this->tpl->setVariable("USR_LOGIN", "<br />" . $a_set["login"]);
301 } else {
302 $this->tpl->setVariable("USR_LOGIN", " [" . $a_set["login"] . "]");
303 }
304
305 // profile link
306 if ($a_set["profile"]) {
307 include_once "Services/User/classes/class.ilUserUtil.php";
308 $user_name = ilUserUtil::getNamePresentation($a_set["id"], false, false, "", false, true, false);
309
310 $this->tpl->setCurrentBlock("profile_link");
311 $this->tpl->setVariable("TXT_VIEW", $lng->txt("profile"));
312
313 // see ilPersonalProfileGUI::getProfilePortfolio()
314 $has_prtf = false;
315 if ($ilSetting->get('user_portfolios')) {
316 include_once "Modules/Portfolio/classes/class.ilObjPortfolio.php";
317 $has_prtf = ilObjPortfolio::getDefaultPortfolio($a_set["id"]);
318 }
319 if (!$has_prtf) {
320 // (simple) profile: center column
321 $ilCtrl->setParameter($this, "user", $a_set["id"]);
322 $this->tpl->setVariable(
323 "LINK_PROFILE",
324 $ilCtrl->getLinkTargetByClass("ilpublicuserprofilegui", "getHTML")
325 );
326 } else {
327 // portfolio: fullscreen
328 include_once "Services/Link/classes/class.ilLink.php";
329 $this->tpl->setVariable("LINK_PROFILE", ilLink::_getLink($a_set["id"], "usr"));
330 $this->tpl->setVariable("LINK_TARGET", "_blank");
331 }
332
333 $this->tpl->setVariable("USR_ID", $a_set["id"]);
334 $this->tpl->setVariable("LINK_FULLNAME", $user_name);
335 $this->tpl->parseCurrentBlock();
336 } else {
337 $this->tpl->setVariable("USR_FULLNAME", "");
338 }
339 }
340
344 public function getOverview()
345 {
347
348 // parse visitors text
349 if (empty($this->visitors) || $this->users_online_pref == "associated") {
350 $visitor_text = "";
351 } elseif ($this->visitors == "1") {
352 $visitor_text = "1 " . $lng->txt("visitor");
353 } else {
354 $visitor_text = $visitors . " " . $lng->txt("visitors");
355 }
356
357 // parse registered users text
358 if ($this->num_users > 0) {
359 $user_kind = ($this->users_online_pref == "associated") ? "associated_user" : "registered_user";
360 if ($this->num_users == 1) {
361 $user_list = $this->num_users . " " . $lng->txt($user_kind);
362 } else {
363 $user_list = $this->num_users . " " . $lng->txt($user_kind . "s");
364 }
365
366 if (!empty($visitor_text)) {
367 $user_list .= " " . $lng->txt("and") . " " . $visitor_text;
368 }
369 } else {
370 $user_list = $visitor_text;
371 }
372
373 return '<div class="small">' . $user_list . "</div>";
374 }
375
376 public function __showActiveChatsOfUser($a_usr_id)
377 {
378 return false;
379 }
380
381 public function __showChatInvitation($a_usr_id)
382 {
386
387 include_once './Modules/Chatroom/classes/class.ilObjChatroom.php';
388
389 if ($a_usr_id == $ilUser->getId()) {
390 return false;
391 }
392
393 if ($rbacsystem->checkAccess('read', ilObjChatroom::_getPublicRefId())
394 and $rbacsystem->checkAccessOfUser($a_usr_id, 'read', ilObjChatroom::_getPublicRefId())) {
395 $this->tpl->setCurrentBlock("chat_link");
396 $this->tpl->setVariable("TXT_CHAT_INVITE", $lng->txt('chat_invite_public_room'));
397 $this->tpl->setVariable("CHAT_LINK", './ilias.php?baseClass=ilRepositoryGUI&ref_id=' . ilObjChatroom::_getPublicRefId() . '&usr_id=' . $a_usr_id . '&cmd=view-invitePD');
398 $this->tpl->setVariable('TXT_CHAT_INVITE_TOOLTIP', $lng->txt('chat_invite_public_room_tooltip'));
399 $this->tpl->parseCurrentBlock();
400
401 return true;
402 }
403 return false;
404 }
405}
user()
Definition: user.php:4
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
const IL_SCREEN_SIDE
const IL_SCREEN_FULL
This class represents a block method of a block.
setRowTemplate($a_rowtemplatename, $a_rowtemplatedir="")
Set Row Template Name.
setLimit($a_limit)
Set Limit.
getCurrentDetailLevel()
Get Current Detail Level.
setAvailableDetailLevels($a_max, $a_min=0)
Set Available Detail Levels.
setData($a_data)
Set Data.
setDataSection($a_content)
Call this from overwritten fillDataSection(), if standard row based data is not used.
setColSpan($a_colspan)
Set Columns Span.
setTitle($a_title)
Set Title.
setEnableNumInfo($a_enablenuminfo)
Set Enable Item Number Info.
setCurrentDetailLevel($a_currentdetaillevel)
Set Current Detail Level.
static getLinkTarget($gui, $cmd, array $gui_params=array(), array $mail_params=array(), $context_params=array())
static getMailObjectRefId()
Determines the reference id of the mail object and stores this information in a local cache variable.
static getDefaultPortfolio($a_user_id)
Get default portfolio of user.
static _lookupPref($a_usr_id, $a_keyword)
GUI class for personal desktop.
GUI class for public user profile presentation.
ILIAS Setting Class.
static getNamePresentation( $a_user_id, $a_user_image=false, $a_profile_link=false, $a_profile_back_link="", $a_force_first_lastname=false, $a_omit_login=false, $a_sortable=true, $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
BlockGUI class for Personal Desktop Users Online block.
static isRepositoryObject()
Is block used in repository object?
static getBlockType()
Get block type.
fillRow($a_set)
get flat bookmark list for personal desktop
static getScreenMode()
Get Screen Mode for current command.
static getAssociatedUsersOnline($a_user_id)
reads all active sessions from db and returns users that are online and who have a local role in a gr...
global $ilCtrl
Definition: ilias.php:18
global $ilSetting
Definition: privfeed.php:17
global $DIC
Definition: saml.php:7
settings()
Definition: settings.php:2
$ilUser
Definition: imgupload.php:18