ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilChatroomXMLWriter.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2017 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Services/Xml/classes/class.ilXmlWriter.php';
5require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
6
11{
15 protected $chat;
16
20 protected $room;
21
27 {
28 $this->chat = $chat;
29
30 $this->room = ilChatroom::byObjectId($this->chat->getId());
31 if (!$this->room) {
32 $this->room = new ilChatroom();
33 $this->room->setSetting('object_id', $this->chat->getId());
34 }
35
36 parent::__construct();
37 }
38
42 public function start()
43 {
44 $this->xmlStartTag('Chatroom', null);
45
46 $this->xmlElement('ObjId', null, (int) $this->chat->getId());
47 $this->xmlElement('RoomId', null, (int) $this->room->getRoomId());
48 $this->xmlElement('Title', null, $this->chat->getTitle());
49 $this->xmlElement('Description', null, $this->chat->getDescription());
50 $this->xmlElement('OnlineStatus', null, (int) $this->room->getSetting('online_status'));
51 $this->xmlElement('AllowAnonymousAccess', null, (int) $this->room->getSetting('allow_anonymous'));
52 $this->xmlElement('AllowCustomUsernames', null, (int) $this->room->getSetting('allow_custom_usernames'));
53 $this->xmlElement('EnableHistory', null, (int) $this->room->getSetting('enable_history'));
54 $this->xmlElement('RestrictHistory', null, (int) $this->room->getSetting('restrict_history'));
55 $this->xmlElement('PrivateRoomsEnabled', null, (int) $this->room->getSetting('private_rooms_enabled'));
56 $this->xmlElement('DisplayPastMessages', null, (int) $this->room->getSetting('display_past_msgs'));
57 $this->xmlElement('AutoGeneratedUsernameSchema', null, $this->room->getSetting('autogen_usernames'));
58
59 if ((int) $this->room->getRoomId() > 0) {
60 $this->exportData();
61 }
62
63 $this->xmlEndTag('Chatroom');
64 }
65
69 private function exportData()
70 {
71 $privateRooms = $this->room->getPrivateRooms();
72 if (count($privateRooms) > 0) {
73 $this->xmlStartTag('SubRooms', null);
74 foreach ($privateRooms as $privateRoom) {
75 $this->xmlStartTag('SubRoom', null);
76 $this->xmlElement('SubRoomId', null, (int) $privateRoom['proom_id']);
77 $this->xmlElement('Title', null, $privateRoom['title']);
78 $this->xmlElement('Owner', null, (int) $privateRoom['owner']);
79 $this->xmlElement('Closed', null, (int) $privateRoom['closed']);
80 $this->xmlElement('Public', null, (int) $privateRoom['is_public']);
81 $this->xmlElement('CreatedTimestamp', null, (int) $privateRoom['created']);
82
83 foreach ($this->room->getPrivilegedUsersForPrivateRoom((int) $privateRoom['proom_id']) as $usrId) {
84 $this->xmlElement('PrivilegedUserId', null, $usrId);
85 }
86
87 $this->xmlEndTag('SubRoom');
88 }
89 $this->xmlEndTag('SubRooms');
90 }
91
92 $history = $this->room->getHistory(null, null, null, null, false);
93 if (count($history) > 0) {
94 $this->xmlStartTag('Messages', null);
95 foreach ($history as $entry) {
96 $this->xmlStartTag('Message', null);
97 $this->xmlElement('SubRoomId', null, (int) $entry['sub_room']);
98 $this->xmlElement('Body', null, json_encode($entry['message']));
99 $this->xmlElement('CreatedTimestamp', null, (int) $entry['timestamp']);
100 $this->xmlEndTag('Message');
101 }
102 $this->xmlEndTag('Messages');
103 }
104 }
105
109 public function getXML()
110 {
111 // Replace ascii code 11 characters because of problems with xml sax parser
112 return str_replace('&#11;', '', $this->xmlDumpMem(false));
113 }
114}
An exception for terminatinating execution or to throw for unit testing.
Class ilChatroomXMLWriter.
__construct(ilObjChatroom $chat)
ilChatroomXMLWriter constructor.
Class ilChatroom.
static byObjectId($object_id)
Returns ilChatroom object by given $object_id.
Class ilObjChatroom.
XML writer class.
xmlEndTag($tag)
Writes an endtag.
xmlDumpMem($format=true)
Returns xml document from memory.
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
xmlStartTag($tag, $attrs=null, $empty=false, $encode=true, $escape=true)
Writes a starttag.