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[
'FileUpload'] = $this->cdata;
259 $x[
'UpdateUserId'] = $this->cdata;
263 $x[
'AuthorId'] = $this->cdata;
265 case 'isAuthorModerator':
266 $x[
'isAuthorModerator'] = $this->cdata;
270 $x[
'UserId'] = $this->cdata;
271 if( $this->entity ==
'forum' && $this->forumArray )
276 $this->forum->createSettings();
279 $this->forumArray[
'UserId'],
'' 282 $this->frm_last_mapped_top_usr_id = $forum_array[
'usr_id'];
285 $this->forumArray[
'UpdateUserId'],
'' 291 $this->forum->setTitle($this->forumArray[
"Title"]);
292 $this->forum->setDescription($this->forumArray[
"Description"]);
293 $this->forum->update($update_forum_array[
'usr_id']);
297 $newObjProp->setDefaultView((
int)$this->forumArray[
'DefaultView']);
298 $newObjProp->setAnonymisation((
int)$this->forumArray[
'Pseudonyms']);
299 $newObjProp->setStatisticsStatus((
int)$this->forumArray[
'Statistics']);
300 $newObjProp->setIsThreadRatingEnabled((
int)$this->forumArray[
'ThreadRatings']);
301 $newObjProp->setPostActivation((
int)$this->forumArray[
'PostingActivation']);
302 $newObjProp->setPresetSubject((
int)$this->forumArray[
'PresetSubject']);
303 $newObjProp->setAddReSubject((
int)$this->forumArray[
'PresetRe']);
304 $newObjProp->setNotificationType($this->forumArray[
'NotificationType'] ? $this->forumArray[
'NotificationType'] :
'all_users');
305 $newObjProp->setAdminForceNoti((
int)$this->forumArray[
'ForceNotification']);
306 $newObjProp->setUserToggleNoti((
int)$this->forumArray[
'ToggleNotification']);
307 $newObjProp->setFileUploadAllowed((
int)$this->forumArray[
'FileUpload']);
308 $newObjProp->setThreadSorting($this->forumArray[
'Sorting']);
309 $newObjProp->setMarkModeratorPosts($this->forumArray[
'MarkModeratorPosts']);
310 $newObjProp->update();
313 $this->forum_obj_id = $newObjProp->getObjId();
314 $this->mapping[
'frm'][$this->forumArray[
'Id']] = $id;
315 $this->lastHandledForumId = $id;
317 unset($this->forumArray);
323 $update_str =
"$this->lastHandledForumId#$this->lastHandledThreadId#$this->lastHandledPostId";
326 SET thr_last_post = %s 328 array(
'text',
'integer'),
329 array($update_str, $this->lastHandledThreadId)
334 $x[
'Subject'] = $this->cdata;
338 $x[
'Alias'] = $this->cdata;
342 $x[
'Sticky'] = $this->cdata;
346 $x[
'Sorting'] = $this->cdata;
349 case 'MarkModeratorPosts':
350 $x[
'MarkModeratorPosts'] = $this->cdata;
354 $x[
'Closed'] = $this->cdata;
356 if($this->entity ==
'thread' && $this->threadArray)
358 require_once
'Modules/Forum/classes/class.ilForumTopic.php';
361 $this->forumThread->setId($this->threadArray[
'Id']);
362 $this->forumThread->setForumId( $this->lastHandledForumId );
363 $this->forumThread->setSubject($this->threadArray[
'Subject']);
364 $this->forumThread->setSticky($this->threadArray[
'Sticky']);
365 $this->forumThread->setClosed($this->threadArray[
'Closed']);
366 $this->forumThread->setCreateDate($this->threadArray[
'CreateDate']);
367 $this->forumThread->setChangeDate($this->threadArray[
'UpdateDate']);
368 $this->forumThread->setImportName($this->threadArray[
'ImportName']);
371 $this->threadArray[
'UserId'], $this->threadArray[
'Alias']
374 $this->forumThread->setDisplayUserId($usr_data[
'usr_id']);
375 $this->forumThread->setUserAlias($usr_data[
'usr_alias']);
379 $this->threadArray[
'AuthorId'] = $this->threadArray[
'UserId'];
383 $this->threadArray[
'AuthorId']
385 $this->forumThread->setThrAuthorId((
int)$author_id_data[
'usr_id']);
387 $this->forumThread->insert();
389 $this->mapping[
'thr'][$this->threadArray[
'Id']] = $this->forumThread->getId();
390 $this->lastHandledThreadId = $this->forumThread->getId();
392 unset($this->threadArray);
401 $x[
'Censorship'] = $this->cdata;
404 case 'CensorshipMessage':
405 $x[
'CensorshipMessage'] = $this->cdata;
409 $x[
'Notification'] = $this->cdata;
413 $x[
'ImportName'] = $this->cdata;
417 $x[
'Status'] = $this->cdata;
421 $x[
'Message'] = $this->cdata;
425 $x[
'Lft'] = $this->cdata;
429 $x[
'Rgt'] = $this->cdata;
433 $x[
'Depth'] = $this->cdata;
437 $x[
'ParentId'] = $this->cdata;
439 if($this->entity ==
'post' && $this->postArray)
441 require_once
'Modules/Forum/classes/class.ilForumPost.php';
444 $this->forumPost->setId($this->postArray[
'Id']);
445 $this->forumPost->setCensorship($this->postArray[
'Censorship']);
446 $this->forumPost->setCensorshipComment($this->postArray[
'CensorshipMessage']);
447 $this->forumPost->setNotification($this->postArray[
'Notification']);
448 $this->forumPost->setImportName($this->postArray[
'ImportName']);
449 $this->forumPost->setStatus($this->postArray[
'Status']);
450 $this->forumPost->setMessage($this->postArray[
'Message']);
451 $this->forumPost->setSubject($this->postArray[
'Subject']);
452 $this->forumPost->setLft($this->postArray[
'Lft']);
453 $this->forumPost->setRgt($this->postArray[
'Rgt']);
454 $this->forumPost->setDepth($this->postArray[
'Depth']);
455 $this->forumPost->setParentId($this->postArray[
'ParentId']);
456 $this->forumPost->setThread($this->forumThread);
457 $this->forumPost->setThreadId($this->lastHandledThreadId);
458 $this->forumPost->setForumId($this->lastHandledForumId);
459 $this->forumPost->setCreateDate($this->postArray[
'CreateDate']);
460 $this->forumPost->setChangeDate($this->postArray[
'UpdateDate']);
463 $this->postArray[
'UserId'], $this->postArray[
'Alias']
466 $this->postArray[
'UpdateUserId']
468 $this->forumPost->setDisplayUserId($usr_data[
'usr_id']);
469 $this->forumPost->setUserAlias($usr_data[
'usr_alias']);
470 $this->forumPost->setUpdateUserId($update_usr_data[
'usr_id']);
474 $this->postArray[
'AuthorId'] = $this->postArray[
'UserId'];
477 $this->postArray[
'AuthorId']
479 $this->forumPost->setPosAuthorId((
int)$author_id_data[
'usr_id']);
481 if($this->postArray[
'isAuthorModerator'] ===
'NULL')
483 $this->forumPost->setIsAuthorModerator(NULL);
487 $this->forumPost->setIsAuthorModerator((
int)$this->postArray[
'isAuthorModerator']);
490 $this->forumPost->insert();
492 if($this->mapping[
'pos'][$this->postArray[
'ParentId']])
494 $parentId = $this->mapping[
'pos'][$this->postArray[
'ParentId']];
501 $postTreeNodeId = $ilDB->nextId(
'frm_posts_tree');
502 $ilDB->insert(
'frm_posts_tree',
array(
503 'fpt_pk' =>
array(
'integer', $postTreeNodeId),
504 'thr_fk' =>
array(
'integer', $this->lastHandledThreadId),
505 'pos_fk' =>
array(
'integer', $this->forumPost->getId()),
506 'parent_pos' =>
array(
'integer', $parentId),
507 'lft' =>
array(
'integer', $this->postArray[
'Lft']),
508 'rgt' =>
array(
'integer', $this->postArray[
'Rgt']),
509 'depth' =>
array(
'integer', $this->postArray[
'Depth']),
510 'fpt_date' =>
array(
'timestamp',
date(
'Y-m-d H:i:s'))
513 $this->mapping[
'pos'][$this->postArray[
'Id']] = $this->forumPost->getId();
514 $this->lastHandledPostId = $this->forumPost->getId();
516 $media_objects_found =
false;
517 foreach($this->mediaObjects as $mob_attr)
520 if(file_exists($importfile))
525 $this->forumPost->setMessage(
528 "src=\"" . $mob_attr[
"label"] .
"\"",
529 "src=\"" . preg_replace(
"/(il)_[\d]+_(mob)_([\d]+)/",
"$1_0_$2_$3", $mob_attr[
"label"]) .
"\"" 531 "src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $mob->getId() .
"\"",
532 $this->forumPost->getMessage()
535 $media_objects_found =
true;
539 if($media_objects_found)
541 $this->forumPost->update();
544 unset($this->postArray);
550 $x[
'content'] = $this->cdata;
554 $filedata =
new ilFileDataForum($this->forum->getId(), $this->lastHandledPostId);
556 $importPath = $this->contentArray[
'content'];
558 if( strlen($importPath) )
562 $newFilename = preg_replace(
"/^\d+_\d+(_.*)/ims", $this->forum->getId().
"_".$this->lastHandledPostId.
"$1", basename($importPath));
563 $path = $filedata->getForumPath();
564 $newPath = $path.
'/'.$newFilename;
565 @copy($importPath, $newPath);
579 $select =
'SELECT od.obj_id, ud.login 581 INNER JOIN usr_data ud 582 ON od.obj_id = ud.usr_id';
584 if($param ==
'import')
586 $where =
' WHERE od.import_id = '.$ilDB->quote(
587 'il_'.$this->import_install_id.
'_usr_'.$imp_usr_id,
'text' 593 $where =
' WHERE ud.usr_id = '.$ilDB->quote(
594 $imp_usr_id,
'integer' 598 $query = $ilDB->query($select.$where);
608 'usr_id' =>
$res[
'obj_id'],
609 'usr_alias' =>
$res[
'login']
621 'usr_id' => $this->aobject->getId(),
622 'usr_alias' => $this->aobject->getLogin()
631 if( (
int)$imp_usr_id > 0 )
635 if( $this->import_install_id != IL_INST_ID && IL_INST_ID > 0 )
638 if( $this->user_id_mapping[$imp_usr_id] )
640 return $this->user_id_mapping[$imp_usr_id];
648 $this->user_id_mapping[$imp_usr_id] =
$res;
655 $this->user_id_mapping[$imp_usr_id] = $return_value;
657 return $return_value;
661 else if( $this->import_install_id == IL_INST_ID && IL_INST_ID == 0 )
664 if( $this->user_id_mapping[$imp_usr_id] )
666 return $this->user_id_mapping[$imp_usr_id];
674 $this->user_id_mapping[$imp_usr_id] =
$res;
681 if( $this->user_id_mapping[$imp_usr_id] )
683 return $this->user_id_mapping[$imp_usr_id];
691 $this->user_id_mapping[$imp_usr_id] =
$res;
698 $this->user_id_mapping[$imp_usr_id] = $return_value;
700 return $return_value;
709 if( $this->user_id_mapping[$imp_usr_id] )
711 return $this->user_id_mapping[$imp_usr_id];
719 $this->user_id_mapping[$imp_usr_id] =
$res;
726 $this->user_id_mapping[$imp_usr_id] = $return_value;
728 return $return_value;
736 'usr_id' => $imp_usr_id,
737 'usr_alias' => $imp_usr_alias
744 $this->import_install_id = $id;
751 $query =
"SELECT top_pk FROM frm_data 752 WHERE top_frm_fk = ".$ilDB->quote(
753 $this->forum->getId(),
'integer');
757 return $data[
'top_pk'];
771 $a_data = preg_replace(
"/\t+/",
" ",$a_data);
773 $this->cdata .= $a_data;
786 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
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
setHandlers($a_xml_parser)
set event handlers
start()
starts parsing an changes object by side effect.
Create styles array
The data for the language used.
This class handles all operations on files for the forum object.
setSchemaVersion($schema_version)
setImportDirectory($a_val)
Set import directory.
setXMLContent($a_xml_content)