ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilChatBlock.php
Go to the documentation of this file.
1 <?php
2 
3 include_once "Modules/Chat/classes/class.ilChatRoom.php";
4 include_once "Modules/Chat/classes/class.ilObjChat.php";
5 include_once "Modules/Chat/classes/class.ilChatBlockedUsers.php";
6 
7 class ilChatBlock {
8  private function getReadableAreas() {
9  global $ilUser, $rbacsystem;
10 
11  $rooms = ilChatRoom::getAllRooms();
12 
13  $titel = array();
14  foreach($rooms as $k => $v) {
15  $titel[$k] = strtolower($v['title']);
16  }
17  array_multisort($titel, SORT_STRING, $rooms);
18 
19  $readable_rooms = array();
20 
21  for ($i = 0; $i < count($rooms); $i++)
22  {
23  if (ilChatBlockedUsers::_isBlocked($rooms[$i]['obj_id'], $ilUser->getId()))
24  {
25  continue;
26  }
27  $room_obj = new ilChatRoom($rooms[$i]["obj_id"]);
28  $priv_rooms = $room_obj->getAllRoomsOfObject();
29  $rooms[$i]["sub"] = array();
30  foreach($priv_rooms as $room_id => $pr)
31  {
32  $room_obj->setRoomId($room_id);
33  if (
34  $room_obj->isInvited($ilUser->getId()) ||
35  $room_obj->isOwner($ilUser->getId()) ||
36  $rbacsystem->checkAccess('moderate', $room_obj->getRoomId())
37  )
38  {
39  $rooms[$i]["sub"][] = array(
40  'room_id' => $room_obj->getRoomId(),
41  'title' => $room_obj->getTitle()
42  );
43  }
44  }
45  $titel = array();
46 
47  foreach($rooms[$i]["sub"] as $k => $v) {
48  $titel[$k] = strtolower($v['title']);
49  }
50 
51  array_multisort($titel, SORT_STRING, $rooms[$i]["sub"]);
52  $readable_rooms[] = $rooms[$i];
53  }
54  return $readable_rooms;
55  }
56 
57  public function getRoomSelect()
58  {
59  global $lng, $ilUser;
60 
61  $sel_ref_id = false;
62  $sel_room_id = false;
63 
64  if ($ilUser->getPref('chatviewer_last_selected_room'))
65  {
66  $parts = split(",", $ilUser->getPref('chatviewer_last_selected_room'));
67  $sel_ref_id = $parts[0];
68  if ($parts[1])
69  $sel_room_id = $parts[1];
70  }
71 
72  $readable = $this->getReadableAreas();
73  $tpl = new ilTemplate("tpl.chat_block_room_select.html", true, true, "Modules/Chat");
74  $tpl->setVariable('TXT_SELECT_ROOM', $lng->txt('chat_select_room'));
75  foreach($readable as $room)
76  {
77  $tpl->setCurrentBlock("room_row");
78  $tpl->setVariable("ROW_VALUE", $room["ref_id"]);
79  $tpl->setVariable("ROW_CAPTION", $room["title"]);
80 
81  if ($sel_ref_id == $room["obj_id"] && !$sel_room_id)
82  $tpl->setVariable('ROW_SELECTED', 'selected="selected"');
83 
84  $tpl->parseCurrentBlock("select_room_row");
85  foreach($room["sub"] as $priv_room)
86  {
87  $tpl->setCurrentBlock("room_row");
88  $tpl->setVariable("ROW_VALUE_PRIV", $room["ref_id"].','.$priv_room['room_id']);
89  $tpl->setVariable("ROW_CAPTION_PRIV", $priv_room["title"]);
90  if ($sel_ref_id == $room["obj_id"] && $sel_room_id == $priv_room['room_id'])
91  $tpl->setVariable('ROW_SELECTED_PRIV', 'selected="selected"');
92  $tpl->parseCurrentBlock("select_privroom_row");
93  }
94 
95  }
96  return $tpl->get();
97  }
98 
99  public function getMessages($obj_id, $room_id, $last_known_id, &$new_last_known_id = -1)
100  {
101  $room = new ilChatRoom($obj_id);
102  $room->setRoomId($room_id);
103  $messages = $room->getNewMessages($last_known_id, $new_last_known_id, time() - 60*60*12);
104 
105  return $messages;
106  }
107 }