4 include_once
'./Services/Xml/classes/class.ilSaxParser.php';
5 require_once
'Modules/Forum/classes/class.ilForumProperties.php';
6 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
41 parent::__construct();
43 $this->
setXMLContent(
'<?xml version="1.0" encoding="utf-8"?>'.$a_xml_data);
44 $this->aobject =
new ilObjUser(ANONYMOUS_USER_ID);
54 $this->importDirectory = $a_val;
64 return $this->importDirectory;
91 xml_set_object($a_xml_parser, $this);
92 xml_set_element_handler($a_xml_parser,
'handlerBeginTag',
'handlerEndTag');
93 xml_set_character_data_handler($a_xml_parser,
'handlerCharacterData');
108 $this->entity =
'forum';
109 $this->forumArray = array();
113 $this->entity =
'thread';
114 $this->threadArray = array();
118 $this->mediaObjects = array();
119 $this->entity =
'post';
120 $this->postArray = array();
124 $this->entity =
'content';
125 $this->contentArray = array();
129 $this->mediaObjects[] = $a_attribs;
144 $this->cdata = trim($this->cdata);
145 $arrayname = strtolower($this->entity).
'Array';
146 $x = &$this->$arrayname;
151 $query_num_posts =
"SELECT COUNT(pos_pk) cnt 153 WHERE pos_top_fk = ".$ilDB->quote(
154 $this->lastHandledForumId,
'integer');
156 $res_pos = $ilDB->query($query_num_posts);
157 $data_pos = $ilDB->fetchAssoc($res_pos);
158 $num_posts = $data_pos[
'cnt'];
160 $query_num_threads =
"SELECT COUNT(thr_pk) cnt 162 WHERE thr_top_fk = ".$ilDB->quote(
163 $this->lastHandledForumId,
'integer');
165 $res_thr = $ilDB->query($query_num_threads);
166 $data_thr = $ilDB->fetchAssoc($res_thr);
167 $num_threads = $data_thr[
'cnt'];
169 $update_str =
"$this->lastHandledForumId#$this->lastHandledThreadId#$this->lastHandledPostId";
172 SET top_last_post = %s, 174 top_num_threads = %s, 176 WHERE top_frm_fk = %s",
177 array(
'text',
'integer',
'integer',
'integer',
'integer'),
178 array($update_str, $num_posts, $num_threads, $this->frm_last_mapped_top_usr_id, $this->forum_obj_id)
183 $x[
'Id'] = $this->cdata;
187 $x[
'ObjId'] = $this->cdata;
191 $x[
'Title'] = $this->cdata;
195 $x[
'Description'] = $this->cdata;
199 $x[
'DefaultView'] = $this->cdata;
203 $x[
'Pseudonyms'] = $this->cdata;
207 $x[
'Statistics'] = $this->cdata;
210 case 'ThreadRatings':
211 $x[
'ThreadRatings'] = $this->cdata;
214 case 'PostingActivation':
215 $x[
'PostingActivation'] = $this->cdata;
218 case 'PresetSubject':
219 $x[
'PresetSubject'] = $this->cdata;
223 $x[
'PresetRe'] = $this->cdata;
226 case 'NotificationType':
227 $x[
'NotificationType'] = $this->cdata;
230 case 'ForceNotification':
231 $x[
'ForceNotification'] = $this->cdata;
234 case 'ToggleNotification':
235 $x[
'ToggleNotification'] = $this->cdata;
239 $x[
'LastPost'] = $this->cdata;
243 $x[
'Moderator'] = $this->cdata;
247 $x[
'CreateDate'] = $this->cdata;
251 $x[
'UpdateDate'] = $this->cdata;
255 $x[
'UpdateUserId'] = $this->cdata;
259 $x[
'AuthorId'] = $this->cdata;
261 case 'isAuthorModerator':
262 $x[
'isAuthorModerator'] = $this->cdata;
266 $x[
'UserId'] = $this->cdata;
267 if( $this->entity ==
'forum' && $this->forumArray )
272 $this->forum->createSettings();
275 $this->forumArray[
'UserId'],
'' 278 $this->frm_last_mapped_top_usr_id = $forum_array[
'usr_id'];
281 $this->forumArray[
'UpdateUserId'],
'' 286 $_SESSION[
"AccountId"] = $update_forum_array[
'usr_id'];
287 $this->forum->setTitle($this->forumArray[
"Title"]);
288 $this->forum->setDescription($this->forumArray[
"Description"]);
289 $this->forum->update();
295 $newObjProp->setDefaultView((
int)$this->forumArray[
'DefaultView']);
296 $newObjProp->setAnonymisation((
int)$this->forumArray[
'Pseudonyms']);
297 $newObjProp->setStatisticsStatus((
int)$this->forumArray[
'Statistics']);
298 $newObjProp->setIsThreadRatingEnabled((
int)$this->forumArray[
'ThreadRatings']);
299 $newObjProp->setPostActivation((
int)$this->forumArray[
'PostingActivation']);
300 $newObjProp->setPresetSubject((
int)$this->forumArray[
'PresetSubject']);
301 $newObjProp->setAddReSubject((
int)$this->forumArray[
'PresetRe']);
302 $newObjProp->setNotificationType($this->forumArray[
'NotificationType'] ? $this->forumArray[
'NotificationType'] :
'all_users');
303 $newObjProp->setAdminForceNoti((
int)$this->forumArray[
'ForceNotification']);
304 $newObjProp->setUserToggleNoti((
int)$this->forumArray[
'ToggleNotification']);
305 $newObjProp->update();
308 $this->forum_obj_id = $newObjProp->getObjId();
309 $this->mapping[
'frm'][$this->forumArray[
'Id']] = $id;
310 $this->lastHandledForumId = $id;
312 unset($this->forumArray);
318 $update_str =
"$this->lastHandledForumId#$this->lastHandledThreadId#$this->lastHandledPostId";
321 SET thr_last_post = %s 323 array(
'text',
'integer'),
324 array($update_str, $this->lastHandledThreadId)
329 $x[
'Subject'] = $this->cdata;
333 $x[
'Alias'] = $this->cdata;
337 $x[
'Sticky'] = $this->cdata;
341 $x[
'Closed'] = $this->cdata;
343 if($this->entity ==
'thread' && $this->threadArray)
345 require_once
'Modules/Forum/classes/class.ilForumTopic.php';
348 $this->forumThread->setId($this->threadArray[
'Id']);
349 $this->forumThread->setForumId( $this->lastHandledForumId );
350 $this->forumThread->setSubject($this->threadArray[
'Subject']);
351 $this->forumThread->setSticky($this->threadArray[
'Sticky']);
352 $this->forumThread->setClosed($this->threadArray[
'Closed']);
353 $this->forumThread->setCreateDate($this->threadArray[
'CreateDate']);
354 $this->forumThread->setChangeDate($this->threadArray[
'UpdateDate']);
355 $this->forumThread->setImportName($this->threadArray[
'ImportName']);
358 $this->threadArray[
'UserId'], $this->threadArray[
'Alias']
361 $this->forumThread->setDisplayUserId($usr_data[
'usr_id']);
362 $this->forumThread->setUserAlias($usr_data[
'usr_alias']);
366 $this->threadArray[
'AuthorId'] = $this->threadArray[
'UserId'];
370 $this->threadArray[
'AuthorId']
372 $this->forumThread->setThrAuthorId((
int)$author_id_data[
'usr_id']);
374 $this->forumThread->insert();
376 $this->mapping[
'thr'][$this->threadArray[
'Id']] = $this->forumThread->getId();
377 $this->lastHandledThreadId = $this->forumThread->getId();
379 unset($this->threadArray);
388 $x[
'Censorship'] = $this->cdata;
391 case 'CensorshipMessage':
392 $x[
'CensorshipMessage'] = $this->cdata;
396 $x[
'Notification'] = $this->cdata;
400 $x[
'ImportName'] = $this->cdata;
404 $x[
'Status'] = $this->cdata;
408 $x[
'Message'] = $this->cdata;
412 $x[
'Lft'] = $this->cdata;
416 $x[
'Rgt'] = $this->cdata;
420 $x[
'Depth'] = $this->cdata;
424 $x[
'ParentId'] = $this->cdata;
426 if($this->entity ==
'post' && $this->postArray)
428 require_once
'Modules/Forum/classes/class.ilForumPost.php';
431 $this->forumPost->setId($this->postArray[
'Id']);
432 $this->forumPost->setCensorship($this->postArray[
'Censorship']);
433 $this->forumPost->setCensorshipComment($this->postArray[
'CensorshipMessage']);
434 $this->forumPost->setNotification($this->postArray[
'Notification']);
435 $this->forumPost->setImportName($this->postArray[
'ImportName']);
436 $this->forumPost->setStatus($this->postArray[
'Status']);
437 $this->forumPost->setMessage($this->postArray[
'Message']);
438 $this->forumPost->setSubject($this->postArray[
'Subject']);
439 $this->forumPost->setLft($this->postArray[
'Lft']);
440 $this->forumPost->setRgt($this->postArray[
'Rgt']);
441 $this->forumPost->setDepth($this->postArray[
'Depth']);
442 $this->forumPost->setParentId($this->postArray[
'ParentId']);
443 $this->forumPost->setThread($this->forumThread);
444 $this->forumPost->setThreadId($this->lastHandledThreadId);
445 $this->forumPost->setForumId($this->lastHandledForumId);
446 $this->forumPost->setCreateDate($this->postArray[
'CreateDate']);
447 $this->forumPost->setChangeDate($this->postArray[
'UpdateDate']);
450 $this->postArray[
'UserId'], $this->postArray[
'Alias']
453 $this->postArray[
'UpdateUserId']
455 $this->forumPost->setDisplayUserId($usr_data[
'usr_id']);
456 $this->forumPost->setUserAlias($usr_data[
'usr_alias']);
457 $this->forumPost->setUpdateUserId($update_usr_data[
'usr_id']);
461 $this->postArray[
'AuthorId'] = $this->postArray[
'UserId'];
464 $this->postArray[
'AuthorId']
466 $this->forumPost->setPosAuthorId((
int)$author_id_data[
'usr_id']);
468 if($this->postArray[
'isAuthorModerator'] ===
'NULL')
470 $this->forumPost->setIsAuthorModerator(NULL);
474 $this->forumPost->setIsAuthorModerator((
int)$this->postArray[
'isAuthorModerator']);
477 $this->forumPost->insert();
479 if($this->mapping[
'pos'][$this->postArray[
'ParentId']])
481 $parentId = $this->mapping[
'pos'][$this->postArray[
'ParentId']];
488 $postTreeNodeId = $ilDB->nextId(
'frm_posts_tree');
489 $ilDB->insert(
'frm_posts_tree', array(
490 'fpt_pk' => array(
'integer', $postTreeNodeId),
491 'thr_fk' => array(
'integer', $this->lastHandledThreadId),
492 'pos_fk' => array(
'integer', $this->forumPost->getId()),
493 'parent_pos' => array(
'integer', $parentId),
494 'lft' => array(
'integer', $this->postArray[
'Lft']),
495 'rgt' => array(
'integer', $this->postArray[
'Rgt']),
496 'depth' => array(
'integer', $this->postArray[
'Depth']),
497 'fpt_date' => array(
'timestamp', date(
'Y-m-d H:i:s'))
500 $this->mapping[
'pos'][$this->postArray[
'Id']] = $this->forumPost->getId();
501 $this->lastHandledPostId = $this->forumPost->getId();
503 $media_objects_found =
false;
504 foreach($this->mediaObjects as $mob_attr)
507 if(file_exists($importfile))
512 $this->forumPost->setMessage(
515 "src=\"" . $mob_attr[
"label"] .
"\"",
516 "src=\"" . preg_replace(
"/(il)_[\d]+_(mob)_([\d]+)/",
"$1_0_$2_$3", $mob_attr[
"label"]) .
"\"" 518 "src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $mob->getId() .
"\"",
519 $this->forumPost->getMessage()
522 $media_objects_found =
true;
526 if($media_objects_found)
528 $this->forumPost->update();
531 unset($this->postArray);
537 $x[
'content'] = $this->cdata;
541 $filedata =
new ilFileDataForum($this->forum->getId(), $this->lastHandledPostId);
543 $importPath = $this->contentArray[
'content'];
545 if( strlen($importPath) )
549 $newFilename = preg_replace(
"/^\d+_\d+(_.*)/ims", $this->forum->getId().
"_".$this->lastHandledPostId.
"$1", basename($importPath));
550 $path = $filedata->getForumPath();
551 $newPath = $path.
'/'.$newFilename;
552 @copy($importPath, $newPath);
566 $select =
'SELECT od.obj_id, ud.login 568 INNER JOIN usr_data ud 569 ON od.obj_id = ud.usr_id';
571 if($param ==
'import')
573 $where =
' WHERE od.import_id = '.$ilDB->quote(
574 'il_'.$this->import_install_id.
'_usr_'.$imp_usr_id,
'text' 580 $where =
' WHERE ud.usr_id = '.$ilDB->quote(
581 $imp_usr_id,
'integer' 585 $query = $ilDB->query($select.$where);
595 'usr_id' =>
$res[
'obj_id'],
596 'usr_alias' =>
$res[
'login']
608 'usr_id' => $this->aobject->getId(),
609 'usr_alias' => $this->aobject->getLogin()
618 if( (
int)$imp_usr_id > 0 )
622 if( $this->import_install_id != IL_INST_ID && IL_INST_ID > 0 )
625 if( $this->user_id_mapping[$imp_usr_id] )
627 return $this->user_id_mapping[$imp_usr_id];
635 $this->user_id_mapping[$imp_usr_id] =
$res;
642 $this->user_id_mapping[$imp_usr_id] = $return_value;
644 return $return_value;
648 else if( $this->import_install_id == IL_INST_ID && IL_INST_ID == 0 )
651 if( $this->user_id_mapping[$imp_usr_id] )
653 return $this->user_id_mapping[$imp_usr_id];
661 $this->user_id_mapping[$imp_usr_id] =
$res;
668 if( $this->user_id_mapping[$imp_usr_id] )
670 return $this->user_id_mapping[$imp_usr_id];
678 $this->user_id_mapping[$imp_usr_id] =
$res;
685 $this->user_id_mapping[$imp_usr_id] = $return_value;
687 return $return_value;
696 if( $this->user_id_mapping[$imp_usr_id] )
698 return $this->user_id_mapping[$imp_usr_id];
706 $this->user_id_mapping[$imp_usr_id] =
$res;
713 $this->user_id_mapping[$imp_usr_id] = $return_value;
715 return $return_value;
723 'usr_id' => $imp_usr_id,
724 'usr_alias' => $imp_usr_alias
731 $this->import_install_id = $id;
738 $query =
"SELECT top_pk FROM frm_data 739 WHERE top_frm_fk = ".$ilDB->quote(
740 $this->forum->getId(),
'integer');
744 return $data[
'top_pk'];
758 $a_data = preg_replace(
"/\t+/",
" ",$a_data);
760 $this->cdata .= $a_data;
773 return $this->result > 0;
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
handler for begin of element
getImportDirectory()
Get import directory.
startParsing()
stores xml data in array
getUserIdAndAlias($imp_usr_id, $imp_usr_alias='')
handlerEndTag($a_xml_parser, $a_name)
handler for end of element
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
getIdAndAliasArray($imp_usr_id, $param='import')
__construct($forum, $a_xml_data)
Constructor.
static getInstance($a_obj_id=0)
handlerCharacterData($a_xml_parser, $a_data)
handler for character data
setHandlers($a_xml_parser)
set event handlers
start()
starts parsing an changes object by side effect.
This class handles all operations on files for the forum object.
setSchemaVersion($schema_version)
setImportDirectory($a_val)
Set import directory.
setXMLContent($a_xml_content)