ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
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.

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 }
Class ilChatroom.
static byObjectId(int $object_id)
setXMLContent(string $a_xml_content)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References $room, ILIAS\GlobalScreen\Provider\__construct(), ilChatroom\byObjectId(), and ilSaxParser\setXMLContent().

+ Here is the call graph for this function:

Member Function Documentation

◆ getImportInstallId()

ilChatroomXMLParser::getImportInstallId ( )

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

53 : ?string
54 {
56 }

References $import_install_id.

Referenced by isSameInstallation().

+ 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 72 of file class.ilChatroomXMLParser.php.

72 : void
73 {
74 switch ($a_name) {
75 case 'Body':
76 $this->timestamp = null;
77 $this->message = null;
78 break;
79
80 case 'Messages':
81 $this->in_messages = true;
82 break;
83 }
84 }

Referenced by setHandlers().

+ Here is the caller graph for this function:

◆ handlerCharacterData()

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

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

164 : void
165 {
166 if ($a_data !== "\n") {
167 $this->cdata .= preg_replace("/\t+/", ' ', $a_data);
168 }
169 }

Referenced by setHandlers().

+ Here is the caller graph for this function:

◆ handlerEndTag()

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

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

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

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

Referenced by setHandlers().

+ 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.

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

References getImportInstallId(), and IL_INST_ID.

Referenced by handlerEndTag().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setHandlers()

ilChatroomXMLParser::setHandlers (   $a_xml_parser)
Parameters
XMLParser | resource$a_xml_parser
Returns
void

Reimplemented from ilSaxParser.

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

63 : void
64 {
65 xml_set_element_handler($a_xml_parser, $this->handlerBeginTag(...), $this->handlerEndTag(...));
66 xml_set_character_data_handler($a_xml_parser, $this->handlerCharacterData(...));
67 }
handlerEndTag(XMLParser $a_xml_parser, string $a_name)
handlerBeginTag(XMLParser $a_xml_parser, string $a_name, array $a_attribs)
handlerCharacterData(XMLParser $a_xml_parser, string $a_data)

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

+ Here is the call graph for this function:

◆ setImportInstallId()

ilChatroomXMLParser::setImportInstallId ( ?string  $id)

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

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

References $id.

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.

Referenced by handlerEndTag().

◆ $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: