ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilChatroomXMLParser Class Reference

Class ilChatroomXMLParser. More...

+ Inheritance diagram for ilChatroomXMLParser:
+ Collaboration diagram for ilChatroomXMLParser:

Public Member Functions

 __construct ($chat, $a_xml_data)
 Constructor. More...
 
 setImportInstallId ($id)
 
 getImportInstallId ()
 
 setHandlers ($a_xml_parser)
 
 handlerBeginTag ($a_xml_parser, $a_name, $a_attribs)
 
 handlerEndTag ($a_xml_parser, $a_name)
 
 handlerCharacterData ($a_xml_parser, $a_data)
 
- Public Member Functions inherited from ilSaxParser
 __construct ($a_xml_file='', $throwException=false)
 Constructor setup ILIAS global object public. More...
 
 setXMLContent ($a_xml_content)
 
 getXMLContent ()
 
 getInputType ()
 
 startParsing ()
 stores xml data in array More...
 
 createParser ()
 create parser More...
 
 setOptions ($a_xml_parser)
 set parser options More...
 
 setHandlers ($a_xml_parser)
 set event handler should be overwritten by inherited class private More...
 
 openXMLFile ()
 open xml file More...
 
 parse ($a_xml_parser, $a_fp=null)
 parse xml file More...
 
 freeParser ($a_xml_parser)
 free xml parser handle More...
 
 setThrowException ($throwException)
 set error handling More...
 
- Public Member Functions inherited from PEAR
 __construct ($error_class=null)
 Constructor. More...
 
 _PEAR ()
 Destructor (the emulated type of...). More...
 
 registerShutdownFunc ($func, $args=array())
 Use this function to register a shutdown method for static classes. More...
 
 isError ($data, $code=null)
 Tell whether a value is a PEAR error. More...
 
 expectError ($code=' *')
 This method is used to tell which errors you expect to get. More...
 
 popExpect ()
 This method pops one element off the expected error codes stack. More...
 
 _checkDelExpect ($error_code)
 This method checks unsets an error code if available. More...
 
 delExpect ($error_code)
 This method deletes all occurences of the specified element from the expected error codes stack. More...
 
raiseError ($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
 This method is a wrapper that returns an instance of the configured error class with this object's default error handling applied. More...
 
throwError ($message=null, $code=null, $userinfo=null)
 Simpler form of raiseError with fewer options. More...
 
 staticPushErrorHandling ($mode, $options=null)
 
 staticPopErrorHandling ()
 
 pushErrorHandling ($mode, $options=null)
 Push a new error handler on top of the error handler options stack. More...
 
 popErrorHandling ()
 Pop the last error handler used. More...
 
 loadExtension ($ext)
 OS independant PHP extension load. More...
 

Protected Attributes

 $chat
 
 $room
 
 $import_install_id = null
 
 $cdata = ''
 
 $in_sub_rooms = false
 
 $in_messages = false
 
 $exportRoomId = 0
 
 $userIds = array()
 
 $exportSubRoomId = 0
 
 $owner = 0
 
 $closed = 0
 
 $public = 0
 
 $timestamp = 0
 
 $message = ''
 
 $title = ''
 
 $subRoomIdMapping = array()
 

Private Member Functions

 isSameInstallation ()
 

Additional Inherited Members

- Static Public Member Functions inherited from PEAR
static & getStaticProperty ($class, $var)
 If you have a class that's mostly/entirely static, and you need static properties, you can use this method to simulate them. More...
 
static setErrorHandling ($mode=null, $options=null)
 Sets how errors generated by this object should be handled. More...
 
- Data Fields inherited from ilSaxParser
 $input_type = null
 
 $xml_content = ''
 
 $ilias
 
 $lng
 
 $xml_file
 
 $throwException = false
 
- Data Fields inherited from PEAR
 $_debug = false
 
 $_default_error_mode = null
 
 $_default_error_options = null
 
 $_default_error_handler = ''
 
 $_error_class = 'PEAR_Error'
 
 $_expected_errors = array()
 
- Protected Member Functions inherited from ilSaxParser
 handleError ($message, $code)
 use given error handler to handle error message or internal ilias error message handle More...
 

Detailed Description

Class ilChatroomXMLParser.

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

Constructor & Destructor Documentation

◆ __construct()

ilChatroomXMLParser::__construct (   $chat,
  $a_xml_data 
)

Constructor.

Parameters
ilObjChatroom$chat
string$a_xml_data

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

References $chat, ilChatroom\byObjectId(), and ilSaxParser\setXMLContent().

100  {
101  parent::__construct();
102 
103  $this->chat = $chat;
104 
105  $this->room = ilChatroom::byObjectId($this->chat->getId());
106  if (!$this->room) {
107  $this->room = new ilChatroom();
108  $this->room->setSetting('object_id', $this->chat->getId());
109  $this->room->save();
110  }
111 
112  $this->setXMLContent('<?xml version="1.0" encoding="utf-8"?>' . $a_xml_data);
113  }
Class ilChatroom.
static byObjectId($object_id)
Returns ilChatroom object by given $object_id.
setXMLContent($a_xml_content)
+ Here is the call graph for this function:

Member Function Documentation

◆ getImportInstallId()

ilChatroomXMLParser::getImportInstallId ( )
Returns
int|null

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

References $import_install_id.

Referenced by isSameInstallation().

+ Here is the caller graph for this function:

◆ handlerBeginTag()

ilChatroomXMLParser::handlerBeginTag (   $a_xml_parser,
  $a_name,
  $a_attribs 
)
Parameters
$a_xml_parser
$a_name
$a_attribs

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

155  {
156  switch ($a_name) {
157  case 'SubRooms':
158  $this->in_sub_rooms = true;
159  break;
160 
161  case 'Messages':
162  $this->in_messages = true;
163  break;
164  }
165  }

◆ handlerCharacterData()

ilChatroomXMLParser::handlerCharacterData (   $a_xml_parser,
  $a_data 
)
Parameters
$a_xml_parser
$a_data

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

327  {
328  if ($a_data != "\n") {
329  $this->cdata .= preg_replace("/\t+/", " ", $a_data);
330  }
331  }

◆ handlerEndTag()

ilChatroomXMLParser::handlerEndTag (   $a_xml_parser,
  $a_name 
)
Parameters
$a_xml_parser
$a_name

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

References $cdata, $exportRoomId, $exportSubRoomId, $message, $timestamp, $user, and isSameInstallation().

172  {
173  $this->cdata = trim($this->cdata);
174 
175  switch ($a_name) {
176  case 'Title':
177  if ($this->in_sub_rooms) {
178  $this->title = $this->cdata;
179  } else {
180  $this->chat->setTitle($this->cdata);
181  }
182  break;
183 
184  case 'Description':
185  $this->chat->setDescription($this->cdata);
186  break;
187 
188  case 'OnlineStatus':
189  $this->room->setSetting('online_status', (int) $this->cdata);
190  break;
191 
192  case 'AllowAnonymousAccess':
193  $this->room->setSetting('allow_anonymous', (int) $this->cdata);
194  break;
195 
196  case 'AllowCustomUsernames':
197  $this->room->setSetting('allow_custom_usernames', (int) $this->cdata);
198  break;
199 
200  case 'EnableHistory':
201  $this->room->setSetting('enable_history', (int) $this->cdata);
202  break;
203 
204  case 'RestrictHistory':
205  $this->room->setSetting('restrict_history', (int) $this->cdata);
206  break;
207 
208  case 'PrivateRoomsEnabled':
209  $this->room->setSetting('private_rooms_enabled', (int) $this->cdata);
210  break;
211 
212  case 'DisplayPastMessages':
213  $this->room->setSetting('display_past_msgs', (int) $this->cdata);
214  break;
215 
216  case 'AutoGeneratedUsernameSchema':
217  $this->room->setSetting('autogen_usernames', $this->cdata);
218  break;
219 
220  case 'RoomId':
221  $this->exportRoomId = (int) $this->cdata;
222  break;
223 
224  case 'SubRoomId':
225  $this->exportSubRoomId = (int) $this->cdata;
226  break;
227 
228  case 'Owner':
229  $this->owner = (int) $this->cdata;
230  break;
231 
232  case 'Closed':
233  $this->closed = (int) $this->cdata;
234  break;
235 
236  case 'Public':
237  $this->public = (int) $this->cdata;
238  break;
239 
240  case 'CreatedTimestamp':
241  $this->timestamp = (int) $this->cdata;
242  break;
243 
244  case 'PrivilegedUserId':
245  $this->userIds[] = (int) $this->cdata;
246  break;
247 
248  case 'SubRoom':
249  if ($this->isSameInstallation() && $this->exportRoomId > 0) {
250  $user = new ilObjUser();
251  $user->setId($this->owner);
252 
253  $chat_user = new ilChatroomUser($user, $this->room);
254  $subRoomId = $this->room->addPrivateRoom(
255  $this->title,
256  $chat_user,
257  array(
258  'public' => (bool) $this->public,
259  'created' => (int) $this->timestamp,
260  'closed' => (bool) $this->closed
261  )
262  );
263 
264  foreach ($this->userIds as $userId) {
265  $this->room->inviteUserToPrivateRoom($userId, $subRoomId);
266  }
267 
268  $this->subRoomIdMapping[$this->exportRoomId] = $subRoomId;
269  }
270 
271  $this->exportSubRoomId = 0;
272  $this->title = '';
273  $this->owner = 0;
274  $this->closed = 0;
275  $this->public = 0;
276  $this->timestamp = 0;
277  $this->userIds = array();
278  break;
279 
280  case 'SubRooms':
281  $this->in_sub_rooms = false;
282  break;
283 
284  case 'Body':
285  $this->message = $this->cdata;
286  break;
287 
288  case 'Message':
289  if ($this->isSameInstallation()) {
290  $message = json_decode($this->message, true);
291  if (
292  is_array($message) &&
293  (!$this->exportSubRoomId || array_key_exists($this->exportSubRoomId, $this->subRoomIdMapping))
294  ) {
295  $message['roomId'] = $this->room->getRoomId();
296  $message['subRoomId'] = $this->exportSubRoomId ? $this->subRoomIdMapping[$this->exportSubRoomId] : 0;
297  $message['timestamp'] = $this->timestamp;
298 
299  $this->room->addHistoryEntry($message);
300  }
301  }
302 
303  $this->timestamp = 0;
304  $this->exportSubRoomId = 0;
305  break;
306 
307  case 'Messages':
308  $this->in_messages = false;
309  break;
310 
311  case 'Chatroom':
312  $this->chat->update();
313  // Set imported chats to offline
314  $this->room->setSetting('online_status', 0);
315  $this->room->save();
316  break;
317  }
318 
319  $this->cdata = '';
320  }
$user
Definition: migrateto20.php:57
Class ilChatroomUser.
+ Here is the call graph for this function:

◆ isSameInstallation()

ilChatroomXMLParser::isSameInstallation ( )
private
Returns
bool

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

References getImportInstallId().

Referenced by handlerEndTag().

135  {
136  return defined('IL_INST_ID') && IL_INST_ID > 0 && $this->getImportInstallId() == IL_INST_ID;
137  }
+ 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 142 of file class.ilChatroomXMLParser.php.

143  {
144  xml_set_object($a_xml_parser, $this);
145  xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
146  xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
147  }

◆ setImportInstallId()

ilChatroomXMLParser::setImportInstallId (   $id)
Parameters
int | null$id

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

References $id.

119  {
120  $this->import_install_id = $id;
121  }
if(!array_key_exists('StateId', $_REQUEST)) $id

Field Documentation

◆ $cdata

ilChatroomXMLParser::$cdata = ''
protected

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

Referenced by handlerEndTag().

◆ $chat

ilChatroomXMLParser::$chat
protected

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

Referenced by __construct().

◆ $closed

ilChatroomXMLParser::$closed = 0
protected

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

◆ $exportRoomId

ilChatroomXMLParser::$exportRoomId = 0
protected

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

Referenced by handlerEndTag().

◆ $exportSubRoomId

ilChatroomXMLParser::$exportSubRoomId = 0
protected

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

Referenced by handlerEndTag().

◆ $import_install_id

ilChatroomXMLParser::$import_install_id = null
protected

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

Referenced by getImportInstallId().

◆ $in_messages

ilChatroomXMLParser::$in_messages = false
protected

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

◆ $in_sub_rooms

ilChatroomXMLParser::$in_sub_rooms = false
protected

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

◆ $message

ilChatroomXMLParser::$message = ''
protected

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

Referenced by handlerEndTag().

◆ $owner

ilChatroomXMLParser::$owner = 0
protected

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

◆ $public

ilChatroomXMLParser::$public = 0
protected

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

◆ $room

ilChatroomXMLParser::$room
protected

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

◆ $subRoomIdMapping

ilChatroomXMLParser::$subRoomIdMapping = array()
protected

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

◆ $timestamp

ilChatroomXMLParser::$timestamp = 0
protected

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

Referenced by handlerEndTag().

◆ $title

ilChatroomXMLParser::$title = ''
protected

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

◆ $userIds

ilChatroomXMLParser::$userIds = array()
protected

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


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