ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilChatroomXMLWriter.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 {
26  protected ilObjChatroom $chat;
27  protected ilChatroom $room;
28 
29  public function __construct(ilObjChatroom $chat)
30  {
31  $this->chat = $chat;
32 
33  $this->room = ilChatroom::byObjectId($this->chat->getId());
34  if (!$this->room) {
35  $this->room = new ilChatroom();
36  $this->room->setSetting('object_id', $this->chat->getId());
37  }
38 
40  }
41 
42  public function start(): void
43  {
44  $this->xmlStartTag('Chatroom');
45 
46  $this->xmlElement('ObjId', null, (string) $this->chat->getId());
47  $this->xmlElement('RoomId', null, (string) $this->room->getRoomId());
48  $this->xmlElement('Title', null, $this->chat->getTitle());
49  $this->xmlElement('Description', null, $this->chat->getDescription());
50  $this->xmlElement('OnlineStatus', null, (string) ((int) $this->room->getSetting('online_status')));
51  $this->xmlElement('AllowAnonymousAccess', null, (string) ((int) $this->room->getSetting('allow_anonymous')));
52  $this->xmlElement('AllowCustomUsernames', null, (string) ((int) $this->room->getSetting('allow_custom_usernames')));
53  $this->xmlElement('EnableHistory', null, (string) ((int) $this->room->getSetting('enable_history')));
54  $this->xmlElement('RestrictHistory', null, (string) ((int) $this->room->getSetting('restrict_history')));
55  $this->xmlElement('PrivateRoomsEnabled', null, (string) ((int) $this->room->getSetting('private_rooms_enabled')));
56  $this->xmlElement('DisplayPastMessages', null, (string) ((int) $this->room->getSetting('display_past_msgs')));
57  $this->xmlElement('AutoGeneratedUsernameSchema', null, (string) $this->room->getSetting('autogen_usernames'));
58 
59  if ($this->room->getRoomId() > 0) {
60  $this->exportData();
61  }
62 
63  $this->xmlEndTag('Chatroom');
64  }
65 
66  private function exportData(): void
67  {
68  $privateRooms = $this->room->getPrivateRooms();
69  if (count($privateRooms) > 0) {
70  $this->xmlStartTag('SubRooms');
71  foreach ($privateRooms as $privateRoom) {
72  $this->xmlStartTag('SubRoom');
73  $this->xmlElement('SubRoomId', null, (string) ((int) $privateRoom['proom_id']));
74  $this->xmlElement('Title', null, (string) $privateRoom['title']);
75  $this->xmlElement('Owner', null, (string) ((int) $privateRoom['owner']));
76  $this->xmlElement('Closed', null, (string) ((int) $privateRoom['closed']));
77  $this->xmlElement('Public', null, (string) ((int) $privateRoom['is_public']));
78  $this->xmlElement('CreatedTimestamp', null, (string) ((int) $privateRoom['created']));
79 
80  foreach ($this->room->getPrivilegedUsersForPrivateRoom((int) $privateRoom['proom_id']) as $usrId) {
81  $this->xmlElement('PrivilegedUserId', null, (string) $usrId);
82  }
83 
84  $this->xmlEndTag('SubRoom');
85  }
86  $this->xmlEndTag('SubRooms');
87  }
88 
89  $history = $this->room->getHistory(null, null, null, null, false);
90  if (count($history) > 0) {
91  $this->xmlStartTag('Messages');
92  foreach ($history as $entry) {
93  $this->xmlStartTag('Message');
94  $this->xmlElement('SubRoomId', null, (string) ((int) $entry['sub_room']));
95  $this->xmlElement('Body', null, json_encode($entry['message'], JSON_THROW_ON_ERROR));
96  $this->xmlElement('CreatedTimestamp', null, (string) ((int) $entry['timestamp']));
97  $this->xmlEndTag('Message');
98  }
99  $this->xmlEndTag('Messages');
100  }
101  }
102 
103  public function getXML(): string
104  {
105  // Replace ascii code 11 characters because of problems with xml sax parser
106  return str_replace('&#11;', '', $this->xmlDumpMem(false));
107  }
108 }
Class ilChatroomXMLWriter.
__construct(ilObjChatroom $chat)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlEndTag(string $tag)
Writes an endtag.
Class ilChatroom.
__construct(Container $dic, ilPlugin $plugin)
static byObjectId(int $object_id)
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
xmlDumpMem(bool $format=true)
Returns xml document from memory.