ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilForumXMLParser Class Reference
+ Inheritance diagram for ilForumXMLParser:
+ Collaboration diagram for ilForumXMLParser:

Public Member Functions

 __construct ($forum, $a_xml_data)
 Constructor.
 setImportDirectory ($a_val)
 Set import directory.
 getImportDirectory ()
 Get import directory.
 setHandlers ($a_xml_parser)
 set event handlers
 handlerBeginTag ($a_xml_parser, $a_name, $a_attribs)
 handler for begin of element
 handlerEndTag ($a_xml_parser, $a_name)
 handler for end of element
 setImportInstallId ($id)
 handlerCharacterData ($a_xml_parser, $a_data)
 handler for character data
 start ()
 starts parsing an changes object by side effect.
- Public Member Functions inherited from ilSaxParser
 ilSaxParser ($a_xml_file= '', $throwException=false)
 Constructor setup ILIAS global object public.
 setXMLContent ($a_xml_content)
 getXMLContent ()
 getInputType ()
 startParsing ()
 stores xml data in array
 createParser ()
 create parser
 setOptions ($a_xml_parser)
 set parser options
 openXMLFile ()
 open xml file
 parse ($a_xml_parser, $a_fp=null)
 parse xml file
 freeParser ($a_xml_parser)
 free xml parser handle
 setThrowException ($throwException)
 set error handling
- Public Member Functions inherited from PEAR
 PEAR ($error_class=null)
 Constructor.
 _PEAR ()
 Destructor (the emulated type of...).
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.
 registerShutdownFunc ($func, $args=array())
 Use this function to register a shutdown method for static classes.
 isError ($data, $code=null)
 Tell whether a value is a PEAR error.
 setErrorHandling ($mode=null, $options=null)
 Sets how errors generated by this object should be handled.
 expectError ($code= '*')
 This method is used to tell which errors you expect to get.
 popExpect ()
 This method pops one element off the expected error codes stack.
 _checkDelExpect ($error_code)
 This method checks unsets an error code if available.
 delExpect ($error_code)
 This method deletes all occurences of the specified element from the expected error codes stack.
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.
throwError ($message=null, $code=null, $userinfo=null)
 Simpler form of raiseError with fewer options.
 staticPushErrorHandling ($mode, $options=null)
 staticPopErrorHandling ()
 pushErrorHandling ($mode, $options=null)
 Push a new error handler on top of the error handler options stack.
 popErrorHandling ()
 Pop the last error handler used.
 loadExtension ($ext)
 OS independant PHP extension load.

Private Member Functions

 getIdAndAliasArray ($imp_usr_id, $param= 'import')
 getAnonymousArray ()
 getUserIdAndAlias ($imp_usr_id, $imp_usr_alias= '')
 getNewForumPk ()

Private Attributes

 $forum
 $entity
 $mapping
 $import_install_id = null
 $user_id_mapping = array()

Additional Inherited Members

- Data Fields inherited from ilSaxParser
 $input_type = null
 $xml_content = ''
 $ilias
 $lng
 $xml_file
 $throwException = false
- Protected Member Functions inherited from ilSaxParser
 handleError ($message, $code)
 use given error handler to handle error message or internal ilias error message handle

Detailed Description

Definition at line 7 of file class.ilForumXMLParser.php.

Constructor & Destructor Documentation

ilForumXMLParser::__construct (   $forum,
  $a_xml_data 
)

Constructor.

Parameters
ilObjForum$forumexisting forum object
string$a_xml_filexml data public

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

References $forum, and ilSaxParser\setXMLContent().

{
$this->forum = $forum;
$this->setXMLContent('<?xml version="1.0" encoding="utf-8"?>'.$a_xml_data);
$this->aobject = new ilObjUser(ANONYMOUS_USER_ID);
}

+ Here is the call graph for this function:

Member Function Documentation

ilForumXMLParser::getAnonymousArray ( )
private

Definition at line 547 of file class.ilForumXMLParser.php.

Referenced by getUserIdAndAlias().

{
return array(
'usr_id' => $this->aobject->getId(),
'usr_alias' => $this->aobject->getLogin()
);
}

+ Here is the caller graph for this function:

ilForumXMLParser::getIdAndAliasArray (   $imp_usr_id,
  $param = 'import' 
)
private

Definition at line 504 of file class.ilForumXMLParser.php.

References $query, and $res.

Referenced by getUserIdAndAlias().

{
global $ilDB;
$select = 'SELECT od.obj_id, ud.login
FROM object_data od
INNER JOIN usr_data ud
ON od.obj_id = ud.usr_id';
if($param == 'import')
{
$where = ' WHERE od.import_id = '.$ilDB->quote(
'il_'.$this->import_install_id.'_usr_'.$imp_usr_id, 'text'
);
}
if($param == 'user')
{
$where = ' WHERE ud.usr_id = '.$ilDB->quote(
$imp_usr_id, 'integer'
);
}
$query = $ilDB->query($select.$where);
while( $res = $ilDB->fetchAssoc($query) )
{
break;
}
if($res)
{
return array(
'usr_id' => $res['obj_id'],
'usr_alias' => $res['login']
);
}
else
{
return false;
}
}

+ Here is the caller graph for this function:

ilForumXMLParser::getImportDirectory ( )

Get import directory.

Returns
string import directory

Definition at line 55 of file class.ilForumXMLParser.php.

Referenced by handlerEndTag().

{
return $this->importDirectory;
}

+ Here is the caller graph for this function:

ilForumXMLParser::getNewForumPk ( )
private

Definition at line 676 of file class.ilForumXMLParser.php.

References $data, $query, and $res.

Referenced by handlerEndTag().

{
global $ilDB;
$query = "SELECT top_pk FROM frm_data
WHERE top_frm_fk = ".$ilDB->quote(
$this->forum->getId(), 'integer');
$res = $ilDB->query($query);
$data = $ilDB->fetchAssoc($res);
return $data['top_pk'];
}

+ Here is the caller graph for this function:

ilForumXMLParser::getUserIdAndAlias (   $imp_usr_id,
  $imp_usr_alias = '' 
)
private

Definition at line 556 of file class.ilForumXMLParser.php.

References $res, getAnonymousArray(), and getIdAndAliasArray().

Referenced by handlerEndTag().

{
global $ilDB;
if( (int)$imp_usr_id > 0 )
{
$newUsrId = -1;
if( $this->import_install_id != IL_INST_ID && IL_INST_ID > 0 )
{
// Different installations
if( $this->user_id_mapping[$imp_usr_id] )
{
return $this->user_id_mapping[$imp_usr_id];
}
else
{
$res = $this->getIdAndAliasArray($imp_usr_id, 'import');
if($res)
{
$this->user_id_mapping[$imp_usr_id] = $res;
return $res;
}
else
{
$return_value = $this->getAnonymousArray();
$this->user_id_mapping[$imp_usr_id] = $return_value;
return $return_value;
}
}
}
else if( $this->import_install_id == IL_INST_ID && IL_INST_ID == 0 )
{
// Eventually different installations. We cannot determine it.
if( $this->user_id_mapping[$imp_usr_id] )
{
return $this->user_id_mapping[$imp_usr_id];
}
else
{
$res = $this->getIdAndAliasArray($imp_usr_id, 'import');
if($res)
{
$this->user_id_mapping[$imp_usr_id] = $res;
return $res;
}
else
{
// Same installation
if( $this->user_id_mapping[$imp_usr_id] )
{
return $this->user_id_mapping[$imp_usr_id];
}
else
{
$res = $this->getIdAndAliasArray($imp_usr_id, 'user');
if($res)
{
$this->user_id_mapping[$imp_usr_id] = $res;
return $res;
}
else
{
$return_value = $this->getAnonymousArray();
$this->user_id_mapping[$imp_usr_id] = $return_value;
return $return_value;
}
}
}
}
}
else
{
// Same installation
if( $this->user_id_mapping[$imp_usr_id] )
{
return $this->user_id_mapping[$imp_usr_id];
}
else
{
$res = $this->getIdAndAliasArray($imp_usr_id, 'user');
if($res)
{
$this->user_id_mapping[$imp_usr_id] = $res;
return $res;
}
else
{
$return_value = $this->getAnonymousArray();
$this->user_id_mapping[$imp_usr_id] = $return_value;
return $return_value;
}
}
}
}
else
{
return array(
'usr_id' => $imp_usr_id,
'usr_alias' => $imp_usr_alias
);
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilForumXMLParser::handlerBeginTag (   $a_xml_parser,
  $a_name,
  $a_attribs 
)

handler for begin of element

Parameters
resource$a_xml_parserxml parser
string$a_nameelement name
array$a_attribselement attributes array

Definition at line 79 of file class.ilForumXMLParser.php.

{
switch($a_name)
{
case 'Forum':
$this->entity = 'forum';
$this->forumArray = array();
break;
case 'Thread':
$this->entity = 'thread';
$this->threadArray = array();
break;
case 'Post':
$this->entity = 'post';
$this->postArray = array();
break;
case 'Content':
$this->entity = 'content';
$this->contentArray = array();
break;
/* case 'ContentThumbnail':
$this->entity = 'content_thumb';
$this->content_thumbArray = array();
break;*/
}
}
ilForumXMLParser::handlerCharacterData (   $a_xml_parser,
  $a_data 
)

handler for character data

Parameters
resource$a_xml_parserxml parser
string$a_datacharacter data

Definition at line 695 of file class.ilForumXMLParser.php.

{
if($a_data != "\n")
{
// Replace multiple tabs with one space
$a_data = preg_replace("/\t+/"," ",$a_data);
$this->cdata .= $a_data;
}
}
ilForumXMLParser::handlerEndTag (   $a_xml_parser,
  $a_name 
)

handler for end of element

Parameters
resource$a_xml_parserxml parser
string$a_nameelement name

Definition at line 116 of file class.ilForumXMLParser.php.

References $_SESSION, $ilUser, $path, getImportDirectory(), ilForumProperties\getInstance(), getNewForumPk(), and getUserIdAndAlias().

{
global $ilDB, $ilUser;
$this->cdata = trim($this->cdata);
$arrayname = strtolower($this->entity).'Array';
$x = &$this->$arrayname;
switch($a_name)
{
case 'Forum':
$query_num_posts = "SELECT COUNT(pos_pk) cnt
FROM frm_posts
WHERE pos_top_fk = ".$ilDB->quote(
$this->lastHandledForumId, 'integer');
$res_pos = $ilDB->query($query_num_posts);
$data_pos = $ilDB->fetchAssoc($res_pos);
$num_posts = $data_pos['cnt'];
$query_num_threads = "SELECT COUNT(thr_pk) cnt
FROM frm_threads
WHERE thr_top_fk = ".$ilDB->quote(
$this->lastHandledForumId, 'integer');
$res_thr = $ilDB->query($query_num_threads);
$data_thr = $ilDB->fetchAssoc($res_thr);
$num_threads = $data_thr['cnt'];
$update_str = "$this->lastHandledForumId#$this->lastHandledThreadId#$this->lastHandledPostId";
$ilDB->manipulateF(
"UPDATE frm_data
SET top_last_post = %s,
top_num_posts = %s,
top_num_threads = %s
WHERE top_frm_fk = %s",
array('text', 'integer', 'integer', 'integer'),
array($update_str, $num_posts, $num_threads, $this->forum_obj_id)
);
break;
case 'Id':
$x['Id'] = $this->cdata;
break;
case 'ObjId':
$x['ObjId'] = $this->cdata;
break;
case 'Title':
$x['Title'] = $this->cdata;
break;
case 'Description':
$x['Description'] = $this->cdata;
break;
case 'DefaultView':
$x['DefaultView'] = $this->cdata;
break;
case 'Pseudonyms':
$x['Pseudonyms'] = $this->cdata;
break;
case 'Statistics':
$x['Statistics'] = $this->cdata;
break;
case 'PostingActivation':
$x['PostingActivation'] = $this->cdata;
break;
case 'PresetSubject':
$x['PresetSubject'] = $this->cdata;
break;
case 'PresetRe':
$x['PresetRe'] = $this->cdata;
break;
case 'NotificationType':
$x['NotificationType'] = $this->cdata;
break;
case 'ForceNotification':
$x['ForceNotification'] = $this->cdata;
break;
case 'ToggleNotification':
$x['ToggleNotification'] = $this->cdata;
break;
case 'LastPost':
$x['LastPost'] = $this->cdata;
break;
case 'Moderator':
$x['Moderator'] = $this->cdata;
break;
case 'CreateDate':
$x['CreateDate'] = $this->cdata;
break;
case 'UpdateDate':
$x['UpdateDate'] = $this->cdata;
break;
case 'UpdateUserId':
$x['UpdateUserId'] = $this->cdata;
break;
case 'UserId':
$x['UserId'] = $this->cdata;
if( $this->entity == 'forum' && $this->forumArray )
{
// createSettings accesses superglobal $_GET array, which can cause problems
// with public_notifications of block settings
$this->forum->createSettings();
$forum_array = $this->getUserIdAndAlias(
$this->forumArray['UserId'], ''
);
// Store old user id
$oldUsrId = $ilUser->getId();
// Manipulate user object
$ilUser->setId($forum_array['usr_id']);
// create frm_data
$this->forum->saveData( array() );
// Restore old user id
$ilUser->setId($oldUsrId);
$update_forum_array = $this->getUserIdAndAlias(
$this->forumArray['UpdateUserId'], ''
);
// Store old user id
$oldUsrId = $_SESSION["AccountId"];
// Manipulate user object
$_SESSION["AccountId"] = $update_forum_array['usr_id'];
$this->forum->setTitle($this->forumArray["Title"]);
$this->forum->setDescription($this->forumArray["Description"]);
$this->forum->update();
// Restore old user id
$_SESSION["AccountId"] = $oldUsrId;
// create frm_settings
$this->forum->getId() );
$newObjProp->setDefaultView(
(int) $this->forumArray['DefaultView'] );
$newObjProp->setAnonymisation(
(int) $this->forumArray['Pseudonyms'] );
$newObjProp->setStatisticsStatus(
(int) $this->forumArray['Statistics'] );
$newObjProp->setPostActivation(
(int) $this->forumArray['PostingActivation'] );
$newObjProp->setPresetSubject(
(int) $this->forumArray['PresetSubject'] );
$newObjProp->setAddReSubject(
(int) $this->forumArray['PresetRe'] );
$newObjProp->setNotificationType(
$this->forumArray['NotificationType'] ?
$this->forumArray['NotificationType'] : 'all_users');
$newObjProp->setAdminForceNoti(
(int) $this->forumArray['ForceNotification'] );
$newObjProp->setUserToggleNoti(
(int) $this->forumArray['ToggleNotification'] );
$newObjProp->insert();
$id = $this->getNewForumPk();
$this->forum_obj_id = $newObjProp->getObjId();
$this->mapping['frm'][$this->forumArray['Id']] = $id;
$this->lastHandledForumId = $id;
unset($this->forumArray);
}
break;
case 'Thread':
$update_str = "$this->lastHandledForumId#$this->lastHandledThreadId#$this->lastHandledPostId";
$ilDB->manipulateF(
"UPDATE frm_threads
SET thr_last_post = %s
WHERE thr_pk = %s",
array('text', 'integer'),
array($update_str, $this->lastHandledThreadId)
);
break;
case 'Subject':
$x['Subject'] = $this->cdata;
break;
case 'Alias':
$x['Alias'] = $this->cdata;
break;
case 'Sticky':
$x['Sticky'] = $this->cdata;
break;
case 'Closed':
$x['Closed'] = $this->cdata;
if($this->entity == 'thread' && $this->threadArray)
{
require_once 'Modules/Forum/classes/class.ilForumTopic.php';
$this->forumThread = new ilForumTopic();
$this->forumThread->setId($this->threadArray['Id']);
$this->forumThread->setForumId( $this->lastHandledForumId );
$this->forumThread->setSubject($this->threadArray['Subject']);
$this->forumThread->setSticky($this->threadArray['Sticky']);
$this->forumThread->setClosed($this->threadArray['Closed']);
$this->forumThread->setCreateDate($this->threadArray['CreateDate']);
$this->forumThread->setChangeDate($this->threadArray['UpdateDate']);
$this->forumThread->setImportName($this->threadArray['ImportName']);
$usr_data = $this->getUserIdAndAlias(
$this->threadArray['UserId'], $this->threadArray['Alias']
);
$this->forumThread->setUserId($usr_data['usr_id']);
$this->forumThread->setUserAlias($usr_data['usr_alias']);
$this->forumThread->insert();
$this->mapping['thr'][$this->threadArray['Id']] = $this->forumThread->getId();
$this->lastHandledThreadId = $this->forumThread->getId();
unset($this->threadArray);
}
break;
case 'Post':
break;
case 'Censorship':
$x['Censorship'] = $this->cdata;
break;
case 'CensorshipMessage':
$x['CensorshipMessage'] = $this->cdata;
break;
case 'Notification':
$x['Notification'] = $this->cdata;
break;
case 'ImportName':
$x['ImportName'] = $this->cdata;
break;
case 'Status':
$x['Status'] = $this->cdata;
break;
case 'Message':
$x['Message'] = $this->cdata;
break;
case 'Lft':
$x['Lft'] = $this->cdata;
break;
case 'Rgt':
$x['Rgt'] = $this->cdata;
break;
case 'Depth':
$x['Depth'] = $this->cdata;
break;
case 'ParentId':
$x['ParentId'] = $this->cdata;
if($this->entity == 'post' && $this->postArray)
{
require_once 'Modules/Forum/classes/class.ilForumPost.php';
$this->forumPost = new ilForumPost();
$this->forumPost->setId($this->postArray['Id']);
$this->forumPost->setCensorship($this->postArray['Censorship']);
$this->forumPost->setCensorshipComment($this->postArray['CensorshipMessage']);
$this->forumPost->setNotification($this->postArray['Notification']);
$this->forumPost->setImportName($this->postArray['ImportName']);
$this->forumPost->setStatus($this->postArray['Status']);
$this->forumPost->setMessage($this->postArray['Message']);
$this->forumPost->setSubject($this->postArray['Subject']);
$this->forumPost->setLft($this->postArray['Lft']);
$this->forumPost->setRgt($this->postArray['Rgt']);
$this->forumPost->setDepth($this->postArray['Depth']);
$this->forumPost->setParentId($this->postArray['ParentId']);
$this->forumPost->setThread($this->forumThread);
$this->forumPost->setThreadId($this->lastHandledThreadId);
$this->forumPost->setForumId($this->lastHandledForumId);
$this->forumPost->setCreateDate($this->postArray['CreateDate']);
$this->forumPost->setChangeDate($this->postArray['UpdateDate']);
$usr_data = $this->getUserIdAndAlias(
$this->postArray['UserId'], $this->postArray['Alias']
);
$update_usr_data = $this->getUserIdAndAlias(
$this->postArray['UpdateUserId']
);
$this->forumPost->setUserId($usr_data['usr_id']);
$this->forumPost->setUserAlias($usr_data['usr_alias']);
$this->forumPost->setUpdateUserId($update_usr_data['usr_id']);
$this->forumPost->insert();
if($this->mapping['pos'][$this->postArray['ParentId']])
{
$parentId = $this->mapping['pos'][$this->postArray['ParentId']];
}
else
{
$parentId = 0;
}
$postTreeNodeId = $ilDB->nextId('frm_posts_tree');
$ilDB->insert('frm_posts_tree', array(
'fpt_pk' => array('integer', $postTreeNodeId),
'thr_fk' => array('integer', $this->lastHandledThreadId),
'pos_fk' => array('integer', $this->forumPost->getId()),
'parent_pos' => array('integer', $parentId),
'lft' => array('integer', $this->postArray['Lft']),
'rgt' => array('integer', $this->postArray['Rgt']),
'depth' => array('integer', $this->postArray['Depth']),
'fpt_date' => array('timestamp', date('Y-m-d H:i:s'))
));
$this->mapping['pos'][$this->postArray['Id']] = $this->forumPost->getId();
$this->lastHandledPostId = $this->forumPost->getId();
unset($this->postArray);
}
break;
case 'Content':
$x['content'] = $this->cdata;
break;
/* case 'ContentThumbnail':
$x['content_thumb'] = $this->cdata;
break;*/
case 'Attachment':
$filedata = new ilFileDataForum($this->forum->getId(), $this->lastHandledPostId);
$importPath = $this->contentArray['content'];
if( strlen($importPath) )
{
$importPath = $this->getImportDirectory().'/'.$importPath;
$newFilename = preg_replace("/^\d+_\d+(_.*)/ims", $this->forum->getId()."_".$this->lastHandledPostId."$1", basename($importPath));
$path = $filedata->getForumPath();
$newPath = $path.'/'.$newFilename;
@copy($importPath, $newPath);
}
/* $importPathThumbnail = $this->content_thumbArray['content_thumb'];
if( strlen($importPathThumbnail) )
{
$importPathThumbnail = $this->getImportDirectory().'/'.$importPathThumbnail;
$newThumbFilename = preg_replace("/^\d+_\d+(_.*)/ims", $this->forum->getId()."_".$this->lastHandledPostId."$1", basename($importPathThumbnail));
$thumbPath = $filedata->getThumbPath();
$newThumbnailPath = $thumbPath.'/'.$newThumbFilename;
@copy($importPathThumbnail, $newThumbnailPath);
}*/
break;
}
$this->cdata = '';
return;
}

+ Here is the call graph for this function:

ilForumXMLParser::setHandlers (   $a_xml_parser)

set event handlers

Parameters
resourcereference to the xml parser private

Reimplemented from ilSaxParser.

Definition at line 65 of file class.ilForumXMLParser.php.

{
xml_set_object($a_xml_parser, $this);
xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
}
ilForumXMLParser::setImportDirectory (   $a_val)

Set import directory.

Parameters
stringimport directory

Definition at line 45 of file class.ilForumXMLParser.php.

{
$this->importDirectory = $a_val;
}
ilForumXMLParser::setImportInstallId (   $id)

Definition at line 671 of file class.ilForumXMLParser.php.

{
$this->import_install_id = $id;
}
ilForumXMLParser::start ( )

starts parsing an changes object by side effect.

Returns
boolean true, if no errors happend.

Definition at line 712 of file class.ilForumXMLParser.php.

References ilSaxParser\startParsing().

{
$this->startParsing();
return $this->result > 0;
}

+ Here is the call graph for this function:

Field Documentation

ilForumXMLParser::$entity
private

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

ilForumXMLParser::$forum
private

Definition at line 15 of file class.ilForumXMLParser.php.

Referenced by __construct().

ilForumXMLParser::$import_install_id = null
private

Definition at line 22 of file class.ilForumXMLParser.php.

ilForumXMLParser::$mapping
private
Initial value:
array(
'frm' => array(),
'thr' => array(),
'pos' => array()
)

Definition at line 17 of file class.ilForumXMLParser.php.

ilForumXMLParser::$user_id_mapping = array()
private

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


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