ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilChatroomXMLParser Class Reference
+ Inheritance diagram for ilChatroomXMLParser:
+ Collaboration diagram for ilChatroomXMLParser:

Public Member Functions

 __construct (protected ilObjChatroom $chat, string $a_xml_data)
 
 setImportInstallId (?string $id)
 
 getImportInstallId ()
 
 setHandlers ($a_xml_parser)
 
 handlerBeginTag (XMLParser $a_xml_parser, string $a_name, array $a_attribs)
 
 handlerEndTag (XMLParser $a_xml_parser, string $a_name)
 
 handlerCharacterData (XMLParser $a_xml_parser, string $a_data)
 
- Public Member Functions inherited from ilSaxParser
 __construct (?string $path_to_file='', ?bool $throw_exception=false)
 
 setXMLContent (string $a_xml_content)
 
 getXMLContent ()
 
 getInputType ()
 
 startParsing ()
 stores xml data in array More...
 
 createParser ()
 
 setHandlers ($a_xml_parser)
 
 parse ($a_xml_parser, $a_fp=null)
 

Protected Attributes

ilChatroom $room
 
string $cdata = ''
 
bool $in_messages = false
 
string $import_install_id = null
 
int $exportRoomId = 0
 
int $timestamp = 0
 
string $message = ''
 
string $title = ''
 
- Protected Attributes inherited from ilSaxParser
ilLanguage $lng = null
 

Private Member Functions

 isSameInstallation ()
 

Additional Inherited Members

- Data Fields inherited from ilSaxParser
string $xml_file
 
bool $throw_exception = false
 
- Protected Member Functions inherited from ilSaxParser
 openXMLFile ()
 
 handleError (string $message)
 
 setThrowException (bool $throw_exception)
 

Detailed Description

Definition at line 21 of file class.ilChatroomXMLParser.php.

Constructor & Destructor Documentation

◆ __construct()

ilChatroomXMLParser::__construct ( protected ilObjChatroom  $chat,
string  $a_xml_data 
)

Definition at line 32 of file class.ilChatroomXMLParser.php.

References $room, ILIAS\MetaData\Repository\Validation\Data\__construct(), ilChatroom\byObjectId(), and ilSaxParser\setXMLContent().

33  {
35 
36  $room = ilChatroom::byObjectId($this->chat->getId());
37  if ($room !== null) {
38  $this->room = $room;
39  } else {
40  $this->room = new ilChatroom();
41  $this->room->setSetting('object_id', $this->chat->getId());
42  $this->room->save();
43  }
44 
45  $this->setXMLContent('<?xml version="1.0" encoding="utf-8"?>' . $a_xml_data);
46  }
__construct(VocabulariesInterface $vocabularies)
Class ilChatroom.
static byObjectId(int $object_id)
setXMLContent(string $a_xml_content)
+ Here is the call graph for this function:

Member Function Documentation

◆ getImportInstallId()

ilChatroomXMLParser::getImportInstallId ( )

Definition at line 53 of file class.ilChatroomXMLParser.php.

References $import_install_id.

Referenced by isSameInstallation().

53  : ?string
54  {
56  }
+ Here is the caller graph for this function:

◆ handlerBeginTag()

ilChatroomXMLParser::handlerBeginTag ( XMLParser  $a_xml_parser,
string  $a_name,
array  $a_attribs 
)
Parameters
array<string,string>$a_attribs

Definition at line 73 of file class.ilChatroomXMLParser.php.

Referenced by setHandlers().

73  : void
74  {
75  switch ($a_name) {
76  case 'Messages':
77  $this->in_messages = true;
78  break;
79  }
80  }
+ Here is the caller graph for this function:

◆ handlerCharacterData()

ilChatroomXMLParser::handlerCharacterData ( XMLParser  $a_xml_parser,
string  $a_data 
)

Definition at line 162 of file class.ilChatroomXMLParser.php.

Referenced by setHandlers().

162  : void
163  {
164  if ($a_data !== "\n") {
165  $this->cdata .= preg_replace("/\t+/", ' ', $a_data);
166  }
167  }
+ Here is the caller graph for this function:

◆ handlerEndTag()

ilChatroomXMLParser::handlerEndTag ( XMLParser  $a_xml_parser,
string  $a_name 
)

Definition at line 82 of file class.ilChatroomXMLParser.php.

References $cdata, $timestamp, ILIAS\Repository\int(), isSameInstallation(), and ilUtil\stripSlashes().

Referenced by setHandlers().

82  : void
83  {
84  $this->cdata = trim($this->cdata);
85 
86  switch ($a_name) {
87  case 'Title':
88  $this->chat->setTitle(ilUtil::stripSlashes($this->cdata));
89  break;
90 
91  case 'Description':
92  $this->chat->setDescription(ilUtil::stripSlashes($this->cdata));
93  break;
94 
95  case 'OnlineStatus':
96  $this->chat->setOfflineStatus(
97  ((int) $this->cdata) === 0
98  );
99  break;
100 
101  case 'AllowAnonymousAccess':
102  $this->room->setSetting('allow_anonymous', (int) $this->cdata);
103  break;
104 
105  case 'AllowCustomUsernames':
106  $this->room->setSetting('allow_custom_usernames', (int) $this->cdata);
107  break;
108 
109  case 'EnableHistory':
110  $this->room->setSetting('enable_history', (int) $this->cdata);
111  break;
112 
113  case 'DisplayPastMessages':
114  $this->room->setSetting('display_past_msgs', (int) $this->cdata);
115  break;
116 
117  case 'AutoGeneratedUsernameSchema':
118  $this->room->setSetting('autogen_usernames', ilUtil::stripSlashes($this->cdata));
119  break;
120 
121  case 'RoomId':
122  $this->exportRoomId = (int) $this->cdata;
123  break;
124 
125  case 'CreatedTimestamp':
126  $this->timestamp = (int) $this->cdata;
127  break;
128 
129  case 'Body':
130  $this->message = $this->cdata;
131  break;
132 
133  case 'Message':
134  break;
135 
136  case 'Messages':
137  if ($this->isSameInstallation()) {
138  $message = json_decode($this->message, true, 512, JSON_THROW_ON_ERROR);
139  if (is_array($message)) {
140  $message['roomId'] = $this->room->getRoomId();
141  $message['timestamp'] = $this->timestamp;
142 
143  $this->room->addHistoryEntry($message);
144  }
145  }
146 
147  $this->timestamp = 0;
148  $this->in_messages = false;
149  break;
150 
151  case 'Chatroom':
152  // Set imported chats to offline
153  $this->chat->setOfflineStatus(true);
154  $this->chat->update();
155  $this->room->save();
156  break;
157  }
158 
159  $this->cdata = '';
160  }
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isSameInstallation()

ilChatroomXMLParser::isSameInstallation ( )
private

Definition at line 58 of file class.ilChatroomXMLParser.php.

References getImportInstallId(), and IL_INST_ID.

Referenced by handlerEndTag().

58  : bool
59  {
60  return defined('IL_INST_ID') && IL_INST_ID > 0 && $this->getImportInstallId() == IL_INST_ID;
61  }
const IL_INST_ID
Definition: constants.php:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setHandlers()

ilChatroomXMLParser::setHandlers (   $a_xml_parser)

Definition at line 63 of file class.ilChatroomXMLParser.php.

References handlerBeginTag(), handlerCharacterData(), and handlerEndTag().

63  : void
64  {
65  xml_set_object($a_xml_parser, $this);
66  xml_set_element_handler($a_xml_parser, $this->handlerBeginTag(...), $this->handlerEndTag(...));
67  xml_set_character_data_handler($a_xml_parser, $this->handlerCharacterData(...));
68  }
handlerCharacterData(XMLParser $a_xml_parser, string $a_data)
handlerEndTag(XMLParser $a_xml_parser, string $a_name)
handlerBeginTag(XMLParser $a_xml_parser, string $a_name, array $a_attribs)
+ Here is the call graph for this function:

◆ setImportInstallId()

ilChatroomXMLParser::setImportInstallId ( ?string  $id)

Definition at line 48 of file class.ilChatroomXMLParser.php.

References $id.

48  : void
49  {
50  $this->import_install_id = $id;
51  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

Field Documentation

◆ $cdata

string ilChatroomXMLParser::$cdata = ''
protected

Definition at line 24 of file class.ilChatroomXMLParser.php.

Referenced by handlerEndTag().

◆ $exportRoomId

int ilChatroomXMLParser::$exportRoomId = 0
protected

Definition at line 27 of file class.ilChatroomXMLParser.php.

◆ $import_install_id

string ilChatroomXMLParser::$import_install_id = null
protected

Definition at line 26 of file class.ilChatroomXMLParser.php.

Referenced by getImportInstallId().

◆ $in_messages

bool ilChatroomXMLParser::$in_messages = false
protected

Definition at line 25 of file class.ilChatroomXMLParser.php.

◆ $message

string ilChatroomXMLParser::$message = ''
protected

Definition at line 29 of file class.ilChatroomXMLParser.php.

◆ $room

ilChatroom ilChatroomXMLParser::$room
protected

Definition at line 23 of file class.ilChatroomXMLParser.php.

Referenced by __construct().

◆ $timestamp

int ilChatroomXMLParser::$timestamp = 0
protected

Definition at line 28 of file class.ilChatroomXMLParser.php.

Referenced by handlerEndTag().

◆ $title

string ilChatroomXMLParser::$title = ''
protected

Definition at line 30 of file class.ilChatroomXMLParser.php.


The documentation for this class was generated from the following file: