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";
44 parent::__construct();
46 $this->
setXMLContent(
'<?xml version="1.0" encoding="utf-8"?>' . $a_xml_data);
47 $this->aobject =
new ilObjUser(ANONYMOUS_USER_ID);
48 $this->db = $DIC->database();
58 $this->importDirectory = $a_val;
68 return $this->importDirectory;
95 xml_set_object($a_xml_parser, $this);
96 xml_set_element_handler($a_xml_parser,
'handlerBeginTag',
'handlerEndTag');
97 xml_set_character_data_handler($a_xml_parser,
'handlerCharacterData');
111 $this->entity =
'forum';
112 $this->forumArray =
array();
116 $this->entity =
'thread';
117 $this->threadArray =
array();
121 $this->mediaObjects =
array();
122 $this->entity =
'post';
123 $this->postArray =
array();
127 $this->entity =
'content';
128 $this->contentArray =
array();
132 $this->mediaObjects[] = $a_attribs;
145 $this->cdata = trim($this->cdata);
146 $arrayname = strtolower($this->entity) .
'Array';
147 $x = &$this->$arrayname;
151 $query_num_posts =
"SELECT COUNT(pos_pk) cnt 153 WHERE pos_top_fk = " . $this->db->quote(
154 $this->lastHandledForumId,
158 $res_pos = $this->db->query($query_num_posts);
159 $data_pos = $this->db->fetchAssoc($res_pos);
160 $num_posts = $data_pos[
'cnt'];
162 $query_num_threads =
"SELECT COUNT(thr_pk) cnt 164 WHERE thr_top_fk = " . $this->db->quote(
165 $this->lastHandledForumId,
169 $res_thr = $this->db->query($query_num_threads);
170 $data_thr = $this->db->fetchAssoc($res_thr);
171 $num_threads = $data_thr[
'cnt'];
173 $update_str =
"$this->lastHandledForumId#$this->lastHandledThreadId#$this->lastHandledPostId";
174 $this->db->manipulateF(
176 SET top_last_post = %s, 178 top_num_threads = %s, 180 WHERE top_frm_fk = %s",
181 array(
'text',
'integer',
'integer',
'integer',
'integer'),
182 array($update_str, $num_posts, $num_threads, $this->frm_last_mapped_top_usr_id, $this->forum_obj_id)
187 $x[
'Id'] = $this->cdata;
191 $x[
'ObjId'] = $this->cdata;
195 $x[
'Title'] = $this->cdata;
199 $x[
'Description'] = $this->cdata;
203 $x[
'DefaultView'] = $this->cdata;
207 $x[
'Pseudonyms'] = $this->cdata;
211 $x[
'Statistics'] = $this->cdata;
214 case 'ThreadRatings':
215 $x[
'ThreadRatings'] = $this->cdata;
218 case 'PostingActivation':
219 $x[
'PostingActivation'] = $this->cdata;
222 case 'PresetSubject':
223 $x[
'PresetSubject'] = $this->cdata;
227 $x[
'PresetRe'] = $this->cdata;
230 case 'NotificationType':
231 $x[
'NotificationType'] = $this->cdata;
234 case 'ForceNotification':
235 $x[
'ForceNotification'] = $this->cdata;
238 case 'ToggleNotification':
239 $x[
'ToggleNotification'] = $this->cdata;
243 $x[
'LastPost'] = $this->cdata;
247 $x[
'Moderator'] = $this->cdata;
251 $x[
'CreateDate'] = $this->cdata;
255 $x[
'UpdateDate'] = $this->cdata;
259 $x[
'FileUpload'] = $this->cdata;
263 $x[
'UpdateUserId'] = $this->cdata;
267 $x[
'AuthorId'] = $this->cdata;
269 case 'isAuthorModerator':
270 $x[
'isAuthorModerator'] = $this->cdata;
274 $x[
'UserId'] = $this->cdata;
275 if ($this->entity ==
'forum' && $this->forumArray) {
279 $this->forum->createSettings();
282 $this->forumArray[
'UserId'],
286 $this->frm_last_mapped_top_usr_id = $forum_array[
'usr_id'];
289 $this->forumArray[
'UpdateUserId'],
296 $this->forum->setTitle($this->forumArray[
"Title"]);
297 $this->forum->setDescription($this->forumArray[
"Description"]);
298 $this->forum->update($update_forum_array[
'usr_id']);
302 $newObjProp->setDefaultView((
int) $this->forumArray[
'DefaultView']);
303 $newObjProp->setAnonymisation((
int) $this->forumArray[
'Pseudonyms']);
304 $newObjProp->setStatisticsStatus((
int) $this->forumArray[
'Statistics']);
305 $newObjProp->setIsThreadRatingEnabled((
int) $this->forumArray[
'ThreadRatings']);
306 $newObjProp->setPostActivation((
int) $this->forumArray[
'PostingActivation']);
307 $newObjProp->setPresetSubject((
int) $this->forumArray[
'PresetSubject']);
308 $newObjProp->setAddReSubject((
int) $this->forumArray[
'PresetRe']);
309 $newObjProp->setNotificationType($this->forumArray[
'NotificationType'] ? $this->forumArray[
'NotificationType'] :
'all_users');
310 $newObjProp->setAdminForceNoti((
int) $this->forumArray[
'ForceNotification']);
311 $newObjProp->setUserToggleNoti((
int) $this->forumArray[
'ToggleNotification']);
312 $newObjProp->setFileUploadAllowed((
int) $this->forumArray[
'FileUpload']);
313 $newObjProp->setThreadSorting($this->forumArray[
'Sorting']);
314 $newObjProp->setMarkModeratorPosts($this->forumArray[
'MarkModeratorPosts']);
315 $newObjProp->update();
318 $this->forum_obj_id = $newObjProp->getObjId();
319 $this->mapping[
'frm'][$this->forumArray[
'Id']] =
$id;
320 $this->lastHandledForumId =
$id;
322 unset($this->forumArray);
328 $update_str =
"$this->lastHandledForumId#$this->lastHandledThreadId#$this->lastHandledPostId";
329 $this->db->manipulateF(
331 SET thr_last_post = %s 333 array(
'text',
'integer'),
334 array($update_str, $this->lastHandledThreadId)
339 $x[
'Subject'] = $this->cdata;
343 $x[
'Alias'] = $this->cdata;
347 $x[
'Sticky'] = $this->cdata;
351 $x[
'Sorting'] = $this->cdata;
354 case 'MarkModeratorPosts':
355 $x[
'MarkModeratorPosts'] = $this->cdata;
359 $x[
'Closed'] = $this->cdata;
361 if ($this->entity ==
'thread' && $this->threadArray) {
362 require_once
'Modules/Forum/classes/class.ilForumTopic.php';
365 $this->forumThread->setId($this->threadArray[
'Id']);
366 $this->forumThread->setForumId($this->lastHandledForumId);
367 $this->forumThread->setSubject($this->threadArray[
'Subject']);
368 $this->forumThread->setSticky($this->threadArray[
'Sticky']);
369 $this->forumThread->setClosed($this->threadArray[
'Closed']);
370 $this->forumThread->setCreateDate($this->threadArray[
'CreateDate']);
371 $this->forumThread->setChangeDate($this->threadArray[
'UpdateDate']);
372 $this->forumThread->setImportName($this->threadArray[
'ImportName']);
375 $this->threadArray[
'UserId'],
376 $this->threadArray[
'Alias']
379 $this->forumThread->setDisplayUserId($usr_data[
'usr_id']);
380 $this->forumThread->setUserAlias($usr_data[
'usr_alias']);
383 $this->threadArray[
'AuthorId'] = $this->threadArray[
'UserId'];
387 $this->threadArray[
'AuthorId']
389 $this->forumThread->setThrAuthorId((
int) $author_id_data[
'usr_id']);
391 $this->forumThread->insert();
393 $this->mapping[
'thr'][$this->threadArray[
'Id']] = $this->forumThread->getId();
394 $this->lastHandledThreadId = $this->forumThread->getId();
396 unset($this->threadArray);
405 $x[
'Censorship'] = $this->cdata;
408 case 'CensorshipMessage':
409 $x[
'CensorshipMessage'] = $this->cdata;
413 $x[
'Notification'] = $this->cdata;
417 $x[
'ImportName'] = $this->cdata;
421 $x[
'Status'] = $this->cdata;
425 $x[
'Message'] = $this->cdata;
429 $x[
'Lft'] = $this->cdata;
433 $x[
'Rgt'] = $this->cdata;
437 $x[
'Depth'] = $this->cdata;
441 $x[
'ParentId'] = $this->cdata;
443 if ($this->entity ==
'post' && $this->postArray) {
444 require_once
'Modules/Forum/classes/class.ilForumPost.php';
447 $this->forumPost->setId($this->postArray[
'Id']);
448 $this->forumPost->setCensorship($this->postArray[
'Censorship']);
449 $this->forumPost->setCensorshipComment($this->postArray[
'CensorshipMessage']);
450 $this->forumPost->setNotification($this->postArray[
'Notification']);
451 $this->forumPost->setImportName($this->postArray[
'ImportName']);
452 $this->forumPost->setStatus($this->postArray[
'Status']);
453 $this->forumPost->setMessage($this->postArray[
'Message']);
454 $this->forumPost->setSubject($this->postArray[
'Subject']);
455 $this->forumPost->setLft($this->postArray[
'Lft']);
456 $this->forumPost->setRgt($this->postArray[
'Rgt']);
457 $this->forumPost->setDepth($this->postArray[
'Depth']);
458 $this->forumPost->setParentId($this->postArray[
'ParentId']);
459 $this->forumPost->setThread($this->forumThread);
460 $this->forumPost->setThreadId($this->lastHandledThreadId);
461 $this->forumPost->setForumId($this->lastHandledForumId);
462 $this->forumPost->setCreateDate($this->postArray[
'CreateDate']);
463 $this->forumPost->setChangeDate($this->postArray[
'UpdateDate']);
466 $this->postArray[
'UserId'],
467 $this->postArray[
'Alias']
470 $this->postArray[
'UpdateUserId']
472 $this->forumPost->setDisplayUserId($usr_data[
'usr_id']);
473 $this->forumPost->setUserAlias($usr_data[
'usr_alias']);
474 $this->forumPost->setUpdateUserId($update_usr_data[
'usr_id']);
477 $this->postArray[
'AuthorId'] = $this->postArray[
'UserId'];
480 $this->postArray[
'AuthorId']
482 $this->forumPost->setPosAuthorId((
int) $author_id_data[
'usr_id']);
484 if ($this->postArray[
'isAuthorModerator'] ===
'NULL') {
485 $this->forumPost->setIsAuthorModerator(null);
487 $this->forumPost->setIsAuthorModerator((
int) $this->postArray[
'isAuthorModerator']);
490 $this->forumPost->insert();
492 if ($this->mapping[
'pos'][$this->postArray[
'ParentId']]) {
493 $parentId = $this->mapping[
'pos'][$this->postArray[
'ParentId']];
498 $postTreeNodeId = $this->db->nextId(
'frm_posts_tree');
499 $this->db->insert(
'frm_posts_tree',
array(
500 'fpt_pk' =>
array(
'integer', $postTreeNodeId),
501 'thr_fk' =>
array(
'integer', $this->lastHandledThreadId),
502 'pos_fk' =>
array(
'integer', $this->forumPost->getId()),
503 'parent_pos' =>
array(
'integer', $parentId),
504 'lft' =>
array(
'integer', $this->postArray[
'Lft']),
505 'rgt' =>
array(
'integer', $this->postArray[
'Rgt']),
506 'depth' =>
array(
'integer', $this->postArray[
'Depth']),
507 'fpt_date' =>
array(
'timestamp',
date(
'Y-m-d H:i:s'))
510 $this->mapping[
'pos'][$this->postArray[
'Id']] = $this->forumPost->getId();
511 $this->lastHandledPostId = $this->forumPost->getId();
513 $media_objects_found =
false;
514 foreach ($this->mediaObjects as $mob_attr) {
516 if (file_exists($importfile)) {
520 $this->forumPost->setMessage(
523 "src=\"" . $mob_attr[
"label"] .
"\"",
524 "src=\"" . preg_replace(
"/(il)_[\d]+_(mob)_([\d]+)/",
"$1_0_$2_$3", $mob_attr[
"label"]) .
"\"" 526 "src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $mob->getId() .
"\"",
527 $this->forumPost->getMessage()
530 $media_objects_found =
true;
534 if ($media_objects_found) {
535 $this->forumPost->update();
538 unset($this->postArray);
544 $x[
'content'] = $this->cdata;
548 $filedata =
new ilFileDataForum($this->forum->getId(), $this->lastHandledPostId);
550 $importPath = $this->contentArray[
'content'];
552 if (strlen($importPath)) {
555 $newFilename = preg_replace(
"/^\d+_\d+(_.*)/ims", $this->forum->getId() .
"_" . $this->lastHandledPostId .
"$1", basename($importPath));
556 $path = $filedata->getForumPath();
557 $newPath = $path .
'/' . $newFilename;
558 @copy($importPath, $newPath);
570 $select =
'SELECT od.obj_id, ud.login 572 INNER JOIN usr_data ud 573 ON od.obj_id = ud.usr_id';
575 if ($param ==
'import') {
576 $where =
' WHERE od.import_id = ' . $this->db->quote(
577 'il_' . $this->import_install_id .
'_usr_' . $imp_usr_id,
582 if ($param ==
'user') {
583 $where =
' WHERE ud.usr_id = ' . $this->db->quote(
589 $query = $this->db->query($select . $where);
591 while (
$res = $this->db->fetchAssoc(
$query)) {
597 'usr_id' =>
$res[
'obj_id'],
598 'usr_alias' =>
$res[
'login']
608 'usr_id' => $this->aobject->getId(),
609 'usr_alias' => $this->aobject->getLogin()
616 if ((
int) $imp_usr_id > 0) {
619 if ($this->import_install_id != IL_INST_ID && IL_INST_ID > 0) {
621 if ($this->user_id_mapping[$imp_usr_id]) {
622 return $this->user_id_mapping[$imp_usr_id];
627 $this->user_id_mapping[$imp_usr_id] =
$res;
632 $this->user_id_mapping[$imp_usr_id] = $return_value;
634 return $return_value;
637 } elseif ($this->import_install_id == IL_INST_ID && IL_INST_ID == 0) {
639 if ($this->user_id_mapping[$imp_usr_id]) {
640 return $this->user_id_mapping[$imp_usr_id];
645 $this->user_id_mapping[$imp_usr_id] =
$res;
650 if ($this->user_id_mapping[$imp_usr_id]) {
651 return $this->user_id_mapping[$imp_usr_id];
656 $this->user_id_mapping[$imp_usr_id] =
$res;
661 $this->user_id_mapping[$imp_usr_id] = $return_value;
663 return $return_value;
670 if ($this->user_id_mapping[$imp_usr_id]) {
671 return $this->user_id_mapping[$imp_usr_id];
676 $this->user_id_mapping[$imp_usr_id] =
$res;
681 $this->user_id_mapping[$imp_usr_id] = $return_value;
683 return $return_value;
689 'usr_id' => $imp_usr_id,
690 'usr_alias' => $imp_usr_alias
697 $this->import_install_id =
$id;
702 $query =
"SELECT top_pk FROM frm_data 703 WHERE top_frm_fk = " . $this->db->quote(
704 $this->forum->getId(),
710 return $data[
'top_pk'];
721 if ($a_data !=
"\n") {
723 $a_data = preg_replace(
"/\t+/",
" ", $a_data);
725 $this->cdata .= $a_data;
738 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
if(!array_key_exists('StateId', $_REQUEST)) $id
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
foreach($_POST as $key=> $value) $res
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)