40 parent::__construct();
42 $this->
setXMLContent(
'<?xml version="1.0" encoding="utf-8"?>' . $a_xml_data);
43 $this->aobject =
new ilObjUser(ANONYMOUS_USER_ID);
44 $this->db = $DIC->database();
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');
107 $this->entity =
'forum';
108 $this->forumArray = array();
112 $this->entity =
'thread';
113 $this->threadArray = array();
117 $this->mediaObjects = array();
118 $this->entity =
'post';
119 $this->postArray = array();
123 $this->entity =
'content';
124 $this->contentArray = array();
128 $this->mediaObjects[] = $a_attribs;
141 $this->cdata = trim($this->cdata);
142 $arrayname = strtolower($this->entity) .
'Array';
143 $x = &$this->$arrayname;
147 $query_num_posts =
"SELECT COUNT(pos_pk) cnt 149 WHERE pos_top_fk = " . $this->db->quote(
150 $this->lastHandledForumId,
154 $res_pos = $this->db->query($query_num_posts);
155 $data_pos = $this->db->fetchAssoc($res_pos);
156 $num_posts = $data_pos[
'cnt'];
158 $query_num_threads =
"SELECT COUNT(thr_pk) cnt 160 WHERE thr_top_fk = " . $this->db->quote(
161 $this->lastHandledForumId,
165 $res_thr = $this->db->query($query_num_threads);
166 $data_thr = $this->db->fetchAssoc($res_thr);
167 $num_threads = $data_thr[
'cnt'];
169 $update_str =
"$this->lastHandledForumId#$this->lastHandledThreadId#$this->lastHandledPostId";
170 $this->db->manipulateF(
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) {
275 $this->forum->createSettings();
278 $this->forumArray[
'UserId'],
282 $this->frm_last_mapped_top_usr_id = $forum_array[
'usr_id'];
285 $this->forumArray[
'UpdateUserId'],
292 $this->forum->setTitle($this->forumArray[
"Title"]);
293 $this->forum->setDescription($this->forumArray[
"Description"]);
294 $this->forum->update($update_forum_array[
'usr_id']);
298 $newObjProp->setDefaultView((
int) $this->forumArray[
'DefaultView']);
299 $newObjProp->setAnonymisation((
int) $this->forumArray[
'Pseudonyms']);
300 $newObjProp->setStatisticsStatus((
int) $this->forumArray[
'Statistics']);
301 $newObjProp->setIsThreadRatingEnabled((
int) $this->forumArray[
'ThreadRatings']);
302 $newObjProp->setPostActivation((
int) $this->forumArray[
'PostingActivation']);
303 $newObjProp->setPresetSubject((
int) $this->forumArray[
'PresetSubject']);
304 $newObjProp->setAddReSubject((
int) $this->forumArray[
'PresetRe']);
305 $newObjProp->setNotificationType($this->forumArray[
'NotificationType'] ? $this->forumArray[
'NotificationType'] :
'all_users');
306 $newObjProp->setAdminForceNoti((
int) $this->forumArray[
'ForceNotification']);
307 $newObjProp->setUserToggleNoti((
int) $this->forumArray[
'ToggleNotification']);
308 $newObjProp->setFileUploadAllowed((
int) $this->forumArray[
'FileUpload']);
309 $newObjProp->setThreadSorting((
int)$this->forumArray[
'Sorting']);
310 $newObjProp->setMarkModeratorPosts((
int)$this->forumArray[
'MarkModeratorPosts']);
311 $newObjProp->update();
314 $this->forum_obj_id = $newObjProp->getObjId();
315 $this->mapping[
'frm'][$this->forumArray[
'Id']] =
$id;
316 $this->lastHandledForumId =
$id;
318 unset($this->forumArray);
324 $update_str =
"$this->lastHandledForumId#$this->lastHandledThreadId#$this->lastHandledPostId";
325 $this->db->manipulateF(
327 SET thr_last_post = %s 329 array(
'text',
'integer'),
330 array($update_str, $this->lastHandledThreadId)
335 $x[
'Subject'] = $this->cdata;
339 $x[
'Alias'] = $this->cdata;
343 $x[
'Sticky'] = $this->cdata;
347 $x[
'Sorting'] = $this->cdata;
350 case 'MarkModeratorPosts':
351 $x[
'MarkModeratorPosts'] = $this->cdata;
355 $x[
'Closed'] = $this->cdata;
357 if ($this->entity ==
'thread' && $this->threadArray) {
359 $this->forumThread->setId($this->threadArray[
'Id']);
360 $this->forumThread->setForumId($this->lastHandledForumId);
361 $this->forumThread->setSubject($this->threadArray[
'Subject']);
362 $this->forumThread->setSticky($this->threadArray[
'Sticky']);
363 $this->forumThread->setClosed($this->threadArray[
'Closed']);
364 $this->forumThread->setCreateDate($this->threadArray[
'CreateDate']);
365 $this->forumThread->setChangeDate($this->threadArray[
'UpdateDate']);
366 $this->forumThread->setImportName($this->threadArray[
'ImportName']);
369 $this->threadArray[
'UserId'],
370 $this->threadArray[
'Alias']
373 $this->forumThread->setDisplayUserId($usr_data[
'usr_id']);
374 $this->forumThread->setUserAlias($usr_data[
'usr_alias']);
377 $this->threadArray[
'AuthorId'] = $this->threadArray[
'UserId'];
381 $this->threadArray[
'AuthorId']
383 $this->forumThread->setThrAuthorId((
int) $author_id_data[
'usr_id']);
385 $this->forumThread->insert();
387 $this->mapping[
'thr'][$this->threadArray[
'Id']] = $this->forumThread->getId();
388 $this->lastHandledThreadId = $this->forumThread->getId();
390 unset($this->threadArray);
399 $x[
'Censorship'] = $this->cdata;
402 case 'CensorshipMessage':
403 $x[
'CensorshipMessage'] = $this->cdata;
407 $x[
'Notification'] = $this->cdata;
411 $x[
'ImportName'] = $this->cdata;
415 $x[
'Status'] = $this->cdata;
419 $x[
'Message'] = $this->cdata;
423 $x[
'Lft'] = $this->cdata;
427 $x[
'Rgt'] = $this->cdata;
431 $x[
'Depth'] = $this->cdata;
435 $x[
'ParentId'] = $this->cdata;
437 if ($this->entity ==
'post' && $this->postArray) {
439 $this->forumPost->setId($this->postArray[
'Id']);
440 $this->forumPost->setCensorship($this->postArray[
'Censorship']);
441 $this->forumPost->setCensorshipComment($this->postArray[
'CensorshipMessage']);
442 $this->forumPost->setNotification($this->postArray[
'Notification']);
443 $this->forumPost->setImportName($this->postArray[
'ImportName']);
444 $this->forumPost->setStatus($this->postArray[
'Status']);
445 $this->forumPost->setMessage($this->postArray[
'Message']);
446 $this->forumPost->setSubject($this->postArray[
'Subject']);
447 $this->forumPost->setLft($this->postArray[
'Lft']);
448 $this->forumPost->setRgt($this->postArray[
'Rgt']);
449 $this->forumPost->setDepth($this->postArray[
'Depth']);
450 $this->forumPost->setParentId($this->postArray[
'ParentId']);
451 $this->forumPost->setThread($this->forumThread);
452 $this->forumPost->setThreadId($this->lastHandledThreadId);
453 $this->forumPost->setForumId($this->lastHandledForumId);
454 $this->forumPost->setCreateDate($this->postArray[
'CreateDate']);
455 $this->forumPost->setChangeDate($this->postArray[
'UpdateDate']);
458 $this->postArray[
'UserId'],
459 $this->postArray[
'Alias']
462 $this->postArray[
'UpdateUserId']
464 $this->forumPost->setDisplayUserId($usr_data[
'usr_id']);
465 $this->forumPost->setUserAlias($usr_data[
'usr_alias']);
466 $this->forumPost->setUpdateUserId($update_usr_data[
'usr_id']);
469 $this->postArray[
'AuthorId'] = $this->postArray[
'UserId'];
472 $this->postArray[
'AuthorId']
474 $this->forumPost->setPosAuthorId((
int) $author_id_data[
'usr_id']);
476 if ($this->postArray[
'isAuthorModerator'] ===
'NULL') {
477 $this->forumPost->setIsAuthorModerator(null);
479 $this->forumPost->setIsAuthorModerator((
int) $this->postArray[
'isAuthorModerator']);
482 $this->forumPost->insert();
484 if ($this->mapping[
'pos'][$this->postArray[
'ParentId']]) {
485 $parentId = $this->mapping[
'pos'][$this->postArray[
'ParentId']];
490 $postTreeNodeId = $this->db->nextId(
'frm_posts_tree');
491 $this->db->insert(
'frm_posts_tree', array(
492 'fpt_pk' => array(
'integer', $postTreeNodeId),
493 'thr_fk' => array(
'integer', $this->lastHandledThreadId),
494 'pos_fk' => array(
'integer', $this->forumPost->getId()),
495 'parent_pos' => array(
'integer', $parentId),
496 'lft' => array(
'integer', $this->postArray[
'Lft']),
497 'rgt' => array(
'integer', $this->postArray[
'Rgt']),
498 'depth' => array(
'integer', $this->postArray[
'Depth']),
499 'fpt_date' => array(
'timestamp', date(
'Y-m-d H:i:s'))
502 $this->mapping[
'pos'][$this->postArray[
'Id']] = $this->forumPost->getId();
503 $this->lastHandledPostId = $this->forumPost->getId();
505 $media_objects_found =
false;
506 foreach ($this->mediaObjects as $mob_attr) {
508 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) {
527 $this->forumPost->update();
530 unset($this->postArray);
536 $x[
'content'] = $this->cdata;
540 $filedata =
new ilFileDataForum($this->forum->getId(), $this->lastHandledPostId);
542 $importPath = $this->contentArray[
'content'];
544 if (strlen($importPath)) {
547 $newFilename = preg_replace(
"/^\d+_\d+(_.*)/ims", $this->forum->getId() .
"_" . $this->lastHandledPostId .
"$1", basename($importPath));
548 $path = $filedata->getForumPath();
549 $newPath = $path .
'/' . $newFilename;
550 @copy($importPath, $newPath);
562 $select =
'SELECT od.obj_id, ud.login 564 INNER JOIN usr_data ud 565 ON od.obj_id = ud.usr_id';
567 if ($param ==
'import') {
568 $where =
' WHERE od.import_id = ' . $this->db->quote(
569 'il_' . $this->import_install_id .
'_usr_' . $imp_usr_id,
574 if ($param ==
'user') {
575 $where =
' WHERE ud.usr_id = ' . $this->db->quote(
581 $query = $this->db->query($select . $where);
583 while (
$res = $this->db->fetchAssoc(
$query)) {
589 'usr_id' =>
$res[
'obj_id'],
590 'usr_alias' =>
$res[
'login']
600 'usr_id' => $this->aobject->getId(),
601 'usr_alias' => $this->aobject->getLogin()
608 if ((
int) $imp_usr_id > 0) {
611 if ($this->import_install_id != IL_INST_ID && IL_INST_ID > 0) {
613 if ($this->user_id_mapping[$imp_usr_id]) {
614 return $this->user_id_mapping[$imp_usr_id];
619 $this->user_id_mapping[$imp_usr_id] =
$res;
624 $this->user_id_mapping[$imp_usr_id] = $return_value;
626 return $return_value;
629 } elseif ($this->import_install_id == IL_INST_ID && IL_INST_ID == 0) {
631 if ($this->user_id_mapping[$imp_usr_id]) {
632 return $this->user_id_mapping[$imp_usr_id];
637 $this->user_id_mapping[$imp_usr_id] =
$res;
642 if ($this->user_id_mapping[$imp_usr_id]) {
643 return $this->user_id_mapping[$imp_usr_id];
648 $this->user_id_mapping[$imp_usr_id] =
$res;
653 $this->user_id_mapping[$imp_usr_id] = $return_value;
655 return $return_value;
662 if ($this->user_id_mapping[$imp_usr_id]) {
663 return $this->user_id_mapping[$imp_usr_id];
668 $this->user_id_mapping[$imp_usr_id] =
$res;
673 $this->user_id_mapping[$imp_usr_id] = $return_value;
675 return $return_value;
681 'usr_id' => $imp_usr_id,
682 'usr_alias' => $imp_usr_alias
689 $this->import_install_id =
$id;
694 $query =
"SELECT top_pk FROM frm_data 695 WHERE top_frm_fk = " . $this->db->quote(
696 $this->forum->getId(),
702 return $data[
'top_pk'];
713 if ($a_data !=
"\n") {
715 $a_data = preg_replace(
"/\t+/",
" ", $a_data);
717 $this->cdata .= $a_data;
730 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
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)