ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilChatroomXMLWriter.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
26 protected ilChatroom $room;
27
28 public function __construct(protected ilObjChatroom $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
37 }
38
39 public function start(): void
40 {
41 $this->xmlStartTag('Chatroom');
42
43 $this->xmlElement('ObjId', null, (string) $this->chat->getId());
44 $this->xmlElement('RoomId', null, (string) $this->room->getRoomId());
45 $this->xmlElement('Title', null, $this->chat->getTitle());
46 $this->xmlElement('Description', null, $this->chat->getDescription());
47 $this->xmlElement('OnlineStatus', null, (string) ((int) (!$this->chat->getOfflineStatus())));
48 $this->xmlElement('AllowAnonymousAccess', null, (string) ((int) $this->room->getSetting('allow_anonymous')));
49 $this->xmlElement('AllowCustomUsernames', null, (string) ((int) $this->room->getSetting('allow_custom_usernames')));
50 $this->xmlElement('EnableHistory', null, (string) ((int) $this->room->getSetting('enable_history')));
51 $this->xmlElement('DisplayPastMessages', null, (string) ((int) $this->room->getSetting('display_past_msgs')));
52 $this->xmlElement('AutoGeneratedUsernameSchema', null, (string) $this->room->getSetting('autogen_usernames'));
53
54 if ($this->room->getRoomId() > 0) {
55 $this->exportData();
56 }
57
58 $this->xmlEndTag('Chatroom');
59 }
60
61 private function exportData(): void
62 {
63 $history = $this->room->getHistory(null, null, null, false);
64 if (count($history) > 0) {
65 $this->xmlStartTag('Messages');
66 foreach ($history as $entry) {
67 $this->xmlStartTag('Message');
68 $this->xmlElement('Body', null, json_encode($entry['message'], JSON_THROW_ON_ERROR));
69 $this->xmlElement('CreatedTimestamp', null, (string) ((int) $entry['timestamp']));
70 $this->xmlEndTag('Message');
71 }
72 $this->xmlEndTag('Messages');
73 }
74 }
75
76 public function getXML(): string
77 {
78 // Replace ascii code 11 characters because of problems with xml sax parser
79 return str_replace('&#11;', '', $this->xmlDumpMem(false));
80 }
81}
Class ilChatroomXMLWriter.
__construct(protected ilObjChatroom $chat)
Class ilChatroom.
static byObjectId(int $object_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
xmlEndTag(string $tag)
Writes an endtag.
xmlDumpMem(bool $format=true)
Returns xml document from memory.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc