ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilChatroomBlock.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
5 
12 {
16  private function getReadableAreas()
17  {
22  global $ilUser, $ilAccess;
23 
24  $readable_rooms = array();
25 
26  $chatroom_objects = ilChatroom::getUntrashedChatReferences();
27  foreach($chatroom_objects as $object)
28  {
29  if(isset($readable_rooms[$object['obj_id']]))
30  {
31  continue;
32  }
33 
34  if($ilAccess->checkAccess('read', '', $object['ref_id']))
35  {
36  $room = ilChatroom::byObjectId($object['obj_id']);
37  if($room && !$room->isUserBanned($ilUser->getId()))
38  {
39  $readable_rooms[$object['obj_id']] = array(
40  'ref_id' => $object['ref_id'],
41  'obj_id' => $object['obj_id'],
42  'room_id' => $room->getRoomId(),
43  'title' => $object['title']
44  );
45  }
46  }
47  }
48 
49  $title = array();
50  foreach($readable_rooms as $k => $v)
51  {
52  $title[$k] = strtolower($v['title']);
53  }
54  array_multisort($title, SORT_STRING, $readable_rooms);
55 
56  return $readable_rooms;
57  }
58 
62  public function getRoomSelect()
63  {
68  global $lng, $ilUser;
69 
70  $readable = $this->getReadableAreas();
71  $tpl = new ilTemplate('tpl.chatroom_block_room_select.html', true, true, 'Modules/Chatroom');
72  $tpl->setVariable('TXT_SELECT_ROOM', $lng->txt('chat_select_room'));
73  foreach($readable as $room)
74  {
75  $tpl->setCurrentBlock('select_room_row');
76  $tpl->setVariable('ROW_VALUE', $room['ref_id']);
77  $tpl->setVariable('ROW_CAPTION', $room['title']);
78 
79  if($ilUser->getPref('chatviewer_last_selected_room') == $room['ref_id'])
80  $tpl->setVariable('ROW_SELECTED', 'selected="selected"');
81 
82  $tpl->parseCurrentBlock();
83  }
84 
85  return $tpl->get();
86  }
87 
92  public function getMessages(ilChatroom $room)
93  {
97  global $ilUser;
98 
99  include 'Modules/Chatroom/classes/class.ilChatroomUser.php';
100  $messages = $room->getLastMessagesForChatViewer($room->getSetting('display_past_msgs'), new ilChatroomUser($ilUser, $room));
101 
102  $output_messages = array();
103 
104  foreach($messages as $msg)
105  {
106  $output_messages[] = $msg;
107  }
108 
109  return $output_messages;
110  }
111 }