ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilForumXMLParser.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24{
28 public static array $style_map = [];
29
30 private string $entity = '';
31 private array $mapping = [
32 'frm' => [],
33 'thr' => [],
34 'pos' => []
35 ];
36 private readonly ilDBInterface $db;
37 private readonly ilObjUser $aobject;
40 private ?string $importDirectory = null;
41 private ?string $schema_version = null;
42 private string $cdata = '';
43
44 private ?ilForumTopic $forumThread = null;
45 private ?ilForumPost $forumPost = null;
46 private ?int $forum_obj_id = null;
47 private ?int $frm_last_mapped_top_usr_id = null;
48 private ?int $lastHandledForumId = null;
49 private ?int $lastHandledThreadId = null;
50 private ?int $lastHandledPostId = null;
51 private ?int $last_handled_style_id = null;
52 private array $forumArray = [];
53 private array $postArray = [];
54 private array $threadArray = [];
55 private array $contentArray = [
56 'content' => ''
57 ];
58 private array $user_id_mapping = [];
59 private array $mediaObjects = [];
60 protected \ILIAS\Style\Content\DomainService $content_style_domain;
65 private array $post_tree_structure = [];
66
67
68 public function __construct(
69 private readonly ilObjForum $forum,
70 string $a_xml_data,
71 private readonly ilImportMapping $importMapping
72 ) {
73 global $DIC;
74
75 $this->db = $DIC->database();
76 $this->aobject = new ilObjUser(ANONYMOUS_USER_ID);
77
79
80 $this->content_style_domain = $DIC
81 ->contentStyle()
82 ->domain();
83
84 $this->setXMLContent('<?xml version="1.0" encoding="utf-8"?>' . $a_xml_data);
85 }
86
87 public function setImportDirectory(?string $a_val): void
88 {
89 $this->importDirectory = $a_val;
90 }
91
92 public function getImportDirectory(): ?string
93 {
95 }
96
97 public function getSchemaVersion(): ?string
98 {
100 }
101
102 public function setSchemaVersion(?string $schema_version): void
103 {
104 $this->schema_version = $schema_version;
105 }
106
107 public function setHandlers($a_xml_parser): void
108 {
109 xml_set_element_handler(
110 $a_xml_parser,
111 function (XMLParser $a_xml_parser, string $a_name, array $a_attribs): void {
112 $this->handlerBeginTag($a_xml_parser, $a_name, $a_attribs);
113 },
114 function (XMLParser $a_xml_parser, string $a_name): void {
115 $this->handlerEndTag($a_xml_parser, $a_name);
116 }
117 );
118 xml_set_character_data_handler($a_xml_parser, function (XMLParser $a_xml_parser, string $a_data): void {
119 $this->handlerCharacterData($a_xml_parser, $a_data);
120 });
121 }
122
123 public function handlerBeginTag(XMLParser $a_xml_parser, string $a_name, array $a_attribs): void
124 {
125 switch ($a_name) {
126 case 'Forum':
127 $this->entity = 'forum';
128 $this->forumArray = [];
129 break;
130
131 case 'Thread':
132 $this->entity = 'thread';
133 $this->post_tree_structure = [];
134 $this->threadArray = [];
135 break;
136
137 case 'Post':
138 $this->entity = 'post';
139 $this->postArray = [];
140 $this->mediaObjects = [];
141 break;
142
143 case 'Content':
144 $this->entity = 'content';
145 $this->contentArray = [
146 'content' => ''
147 ];
148 break;
149
150 case 'MediaObject':
151 $this->mediaObjects[] = $a_attribs;
152 break;
153 }
154
155 if (isset($a_attribs['Style'])) {
156 $this->last_handled_style_id = (int) $a_attribs['Style'];
157 }
158 }
159
160 public function handlerEndTag(XMLParser $a_xml_parser, string $a_name): void
161 {
162 $this->cdata = trim($this->cdata);
163 $property = strtolower($this->entity) . 'Array';
164
165 if (!property_exists($this, $property)) {
166 return;
167 }
168
169 $propertyValue = &$this->{$property};
170
171 switch ($a_name) {
172 case 'Forum':
173 $query_num_posts = 'SELECT COUNT(pos_pk) cnt FROM frm_posts WHERE pos_top_fk = ' . $this->db->quote(
174 $this->lastHandledForumId,
175 'integer'
176 );
177 $res_pos = $this->db->query($query_num_posts);
178 $data_pos = $this->db->fetchAssoc($res_pos);
179 $num_posts = (int) $data_pos['cnt'];
180
181 $query_num_threads = 'SELECT COUNT(thr_pk) cnt FROM frm_threads WHERE thr_top_fk = ' . $this->db->quote(
182 $this->lastHandledForumId,
183 'integer'
184 );
185 $res_thr = $this->db->query($query_num_threads);
186 $data_thr = $this->db->fetchAssoc($res_thr);
187 $num_threads = (int) $data_thr['cnt'];
188
189 $update_str = null;
190 if ($this->lastHandledPostId !== 0) {
191 $update_str = implode('#', [
192 (string) $this->lastHandledForumId,
193 (string) $this->lastHandledThreadId,
194 (string) $this->lastHandledPostId
195 ]);
196 }
197
198 $this->db->manipulateF(
199 'UPDATE frm_data
200 SET top_last_post = %s,
201 top_num_posts = %s,
202 top_num_threads = %s,
203 top_usr_id = %s
204 WHERE top_frm_fk = %s',
205 ['text', 'integer', 'integer', 'integer', 'integer'],
206 [$update_str, $num_posts, $num_threads, $this->frm_last_mapped_top_usr_id, $this->forum_obj_id]
207 );
208
209 ilLPStatusWrapper::_refreshStatus($this->forum->getId());
210 break;
211
212 case 'Id':
213 $propertyValue['Id'] = $this->cdata;
214 break;
215
216 case 'ObjId':
217 $propertyValue['ObjId'] = $this->cdata;
218 break;
219
220 case 'Title':
221 $propertyValue['Title'] = $this->cdata;
222 break;
223
224 case 'Description':
225 $propertyValue['Description'] = $this->cdata;
226 break;
227
228 case 'DefaultView':
229 $propertyValue['DefaultView'] = $this->cdata;
230 break;
231
232 case 'Pseudonyms':
233 $propertyValue['Pseudonyms'] = $this->cdata;
234 break;
235
236 case 'Statistics':
237 $propertyValue['Statistics'] = $this->cdata;
238 break;
239
240 case 'ThreadRatings':
241 $propertyValue['ThreadRatings'] = $this->cdata;
242 break;
243
244 case 'PostingActivation':
245 $propertyValue['PostingActivation'] = $this->cdata;
246 break;
247
248 case 'PresetSubject':
249 $propertyValue['PresetSubject'] = $this->cdata;
250 break;
251
252 case 'PresetRe':
253 $propertyValue['PresetRe'] = $this->cdata;
254 break;
255
256 case 'NotificationType':
257 $propertyValue['NotificationType'] = $this->cdata;
258 break;
259
260 case 'NotificationEvents':
261 $propertyValue['NotificationEvents'] = $this->cdata;
262 break;
263
264 case 'ForceNotification':
265 $propertyValue['ForceNotification'] = $this->cdata;
266 break;
267
268 case 'ToggleNotification':
269 $propertyValue['ToggleNotification'] = $this->cdata;
270 break;
271
272 case 'LastPost':
273 $propertyValue['LastPost'] = $this->cdata;
274 break;
275
276 case 'Moderator':
277 $propertyValue['Moderator'] = $this->cdata;
278 break;
279
280 case 'CreateDate':
281 $propertyValue['CreateDate'] = $this->cdata;
282 break;
283
284 case 'UpdateDate':
285 $propertyValue['UpdateDate'] = $this->cdata;
286 break;
287
288 case 'FileUpload':
289 $propertyValue['FileUpload'] = $this->cdata;
290 break;
291
292 case 'UpdateUserId':
293 $propertyValue['UpdateUserId'] = $this->cdata;
294 break;
295
296 case 'AuthorId':
297 $propertyValue['AuthorId'] = $this->cdata;
298 break;
299 case 'isAuthorModerator':
300 $propertyValue['isAuthorModerator'] = $this->cdata;
301 break;
302
303 case 'UserId':
304 $propertyValue['UserId'] = $this->cdata;
305 if ($this->entity === 'forum' && $this->forumArray !== []) {
307 // createSettings accesses superglobal $_GET array, which can cause problems
308 // with public_notifications of block settings
309 $this->forum->createSettings();
310
311 $forum_array = $this->getUserIdAndAlias(
312 (int) ($this->forumArray['UserId'] ?? 0),
313 ''
314 );
315 $this->frm_last_mapped_top_usr_id = $forum_array['usr_id'];
316
317 $update_forum_array = $this->getUserIdAndAlias(
318 (int) ($this->forumArray['UpdateUserId'] ?? 0),
319 ''
320 );
321 // Store old user id
322 // Manipulate user object
323 // changed smeyer 28.7.16: the session id is not manipulated
324 // anymore. Instead the user is passwd ilObjForum::update()
325 $this->forum->setTitle(ilUtil::stripSlashes((string) ($this->forumArray['Title'] ?? '')));
326 $this->forum->setDescription(
327 ilUtil::stripSlashes((string) ($this->forumArray['Description'] ?? ''))
328 );
329 $this->forum->update();
330 $this->forum->updateModificationUserId($update_forum_array['usr_id']);
331
332 $newObjProp = ilForumProperties::getInstance($this->forum->getId());
333 $newObjProp->setDefaultView(
334 (int) ($this->forumArray['DefaultView'] ?? ilForumProperties::VIEW_TREE)
335 );
336 $newObjProp->setAnonymisation((bool) ($this->forumArray['Pseudonyms'] ?? false));
337 $newObjProp->setStatisticsStatus((bool) ($this->forumArray['Statistics'] ?? false));
338 $newObjProp->setIsThreadRatingEnabled((bool) ($this->forumArray['ThreadRatings'] ?? false));
339 $newObjProp->setPostActivation((bool) ($this->forumArray['PostingActivation'] ?? false));
340 $newObjProp->setPresetSubject((bool) ($this->forumArray['PresetSubject'] ?? false));
341 $newObjProp->setAddReSubject((bool) ($this->forumArray['PresetRe'] ?? false));
342 $newObjProp->setNotificationType(
343 NotificationType::tryFrom(
344 $this->forumArray['NotificationType'] ?? NotificationType::ALL_USERS->value
345 ) ?? NotificationType::ALL_USERS
346 );
347 $newObjProp->setInterestedEvents((int) ($this->forumArray['NotificationEvents'] ?? 0));
348 $newObjProp->setAdminForceNoti((bool) ($this->forumArray['ForceNotification'] ?? false));
349 $newObjProp->setUserToggleNoti((bool) ($this->forumArray['ToggleNotification'] ?? false));
350 $newObjProp->setFileUploadAllowed((bool) ($this->forumArray['FileUpload'] ?? false));
351 $newObjProp->setMarkModeratorPosts((bool) ($this->forumArray['MarkModeratorPosts'] ?? false));
352 $newObjProp->update();
353
354 $id = $this->getNewForumPk();
355 $this->forum_obj_id = $newObjProp->getObjId();
356 $this->mapping['frm'][$this->forumArray['Id']] = $id;
357 $this->lastHandledForumId = $id;
358
359 $this->importMapping->addMapping(
360 'components/ILIAS/COPage',
361 'pg',
362 'frm:' . $this->forumArray['ObjId'],
363 'frm:' . $this->forum->getId()
364 );
365
366 $this->importMapping->addMapping(
367 'components/ILIAS/ILIASObject',
368 'obj',
369 $this->forumArray['ObjId'],
370 (string) $newObjProp->getObjId()
371 );
372
373 if ($this->last_handled_style_id) {
374 self::$style_map[$this->last_handled_style_id][] = $newObjProp->getObjId();
375 $this->last_handled_style_id = null;
376 }
377
378 $this->forumArray = [];
379 }
380 break;
381
382 case 'Thread':
383 $update_str = null;
384 if ($this->lastHandledPostId !== 0) {
385 $update_str = implode('#', [
386 (string) $this->lastHandledForumId,
387 (string) $this->lastHandledThreadId,
388 (string) $this->lastHandledPostId
389 ]);
390 }
391
392 $this->db->manipulateF(
393 'UPDATE frm_threads SET thr_last_post = %s WHERE thr_pk = %s',
394 ['text', 'integer'],
395 [$update_str, $this->lastHandledThreadId]
396 );
397 break;
398
399 case 'Subject':
400 $propertyValue['Subject'] = $this->cdata;
401 break;
402
403 case 'Alias':
404 $propertyValue['Alias'] = $this->cdata;
405 break;
406
407 case 'Sticky':
408 $propertyValue['Sticky'] = $this->cdata;
409 break;
410
411 case 'MarkModeratorPosts':
412 $propertyValue['MarkModeratorPosts'] = $this->cdata;
413 break;
414
415 case 'Closed':
416 $propertyValue['Closed'] = $this->cdata;
417
418 if ($this->entity === 'thread' && $this->lastHandledForumId && $this->threadArray !== []) {
419 $this->forumThread = new ilForumTopic();
420 $this->forumThread->setId((int) $this->threadArray['Id']);
421 $this->forumThread->setForumId($this->lastHandledForumId);
422 $this->forumThread->setSubject(
423 ilUtil::stripSlashes((string) ($this->threadArray['Subject'] ?? ''))
424 );
425 $this->forumThread->setSticky((bool) ($this->threadArray['Sticky'] ?? false));
426 $this->forumThread->setClosed((bool) ($this->threadArray['Closed'] ?? false));
427
428 $this->forumThread->setImportName(
429 isset($this->threadArray['ImportName']) ?
430 ilUtil::stripSlashes($this->threadArray['ImportName']) :
431 null
432 );
433 $this->forumThread->setCreateDate($this->threadArray['CreateDate']);
434 $this->forumThread->setChangeDate($this->threadArray['UpdateDate']);
435
436 $usr_data = $this->getUserIdAndAlias(
437 (int) ($this->threadArray['UserId'] ?? 0),
438 ilUtil::stripSlashes((string) ($this->threadArray['Alias'] ?? ''))
439 );
440
441 $this->forumThread->setDisplayUserId($usr_data['usr_id']);
442 $this->forumThread->setUserAlias($usr_data['usr_alias']);
443
444 if (version_compare($this->getSchemaVersion(), '4.5.0', '<=')) {
445 $this->threadArray['AuthorId'] = $this->threadArray['UserId'];
446 }
447
448 $author_id_data = $this->getUserIdAndAlias(
449 (int) ($this->threadArray['AuthorId'] ?? 0)
450 );
451 $this->forumThread->setThrAuthorId($author_id_data['usr_id']);
452
453 $this->forumThread->insert();
454
455 $this->mapping['thr'][$this->threadArray['Id']] = $this->forumThread->getId();
456 $this->lastHandledThreadId = $this->forumThread->getId();
457 $this->threadArray = [];
458 }
459 break;
460
461 case 'Post':
462 break;
463
464 case 'Censorship':
465 $propertyValue['Censorship'] = $this->cdata;
466 break;
467
468 case 'CensorshipMessage':
469 $propertyValue['CensorshipMessage'] = $this->cdata;
470 break;
471
472 case 'Notification':
473 $propertyValue['Notification'] = $this->cdata;
474 break;
475
476 case 'ImportName':
477 $propertyValue['ImportName'] = $this->cdata;
478 break;
479
480 case 'Status':
481 $propertyValue['Status'] = $this->cdata;
482 break;
483
484 case 'Message':
485 $propertyValue['Message'] = $this->cdata;
486 break;
487
488 case 'Lft':
489 $propertyValue['Lft'] = $this->cdata;
490 break;
491
492 case 'Rgt':
493 $propertyValue['Rgt'] = $this->cdata;
494 break;
495
496 case 'Depth':
497 $propertyValue['Depth'] = $this->cdata;
498 break;
499
500 case 'ParentId':
501 $propertyValue['ParentId'] = $this->cdata;
502
503 if (
504 $this->entity === 'post' &&
505 $this->lastHandledForumId &&
506 $this->postArray !== [] &&
507 $this->forumThread &&
508 $this->lastHandledThreadId
509 ) {
510 $this->forumPost = new ilForumPost();
511 $this->forumPost->setThread($this->forumThread);
512
513 $this->forumPost->setId((int) $this->postArray['Id']);
514 $this->forumPost->setCensorship((bool) ($this->postArray['Censorship'] ?? false));
515 $this->forumPost->setCensorshipComment(
516 ilUtil::stripSlashes((string) ($this->postArray['CensorshipMessage'] ?? ''))
517 );
518 $this->forumPost->setNotification((bool) ($this->postArray['Notification'] ?? false));
519 $this->forumPost->setStatus((bool) ($this->postArray['Status'] ?? false));
520 $purifier = ilHtmlPurifierFactory::getInstanceByType('frm_post');
521 $this->forumPost->setMessage($purifier->purify((string) ($this->postArray['Message'] ?? '')));
522 $this->forumPost->setSubject(ilUtil::stripSlashes((string) ($this->postArray['Subject'] ?? '')));
523 $this->forumPost->setLft((int) $this->postArray['Lft']);
524 $this->forumPost->setRgt((int) $this->postArray['Rgt']);
525 $this->forumPost->setDepth((int) $this->postArray['Depth']);
526 $this->forumPost->setParentId((int) $this->postArray['ParentId']);
527 $this->forumPost->setThreadId($this->lastHandledThreadId);
528 $this->forumPost->setForumId($this->lastHandledForumId);
529
530 $this->forumPost->setImportName(
531 isset($this->postArray['ImportName']) ?
532 ilUtil::stripSlashes($this->postArray['ImportName']) :
533 null
534 );
535 $this->forumPost->setCreateDate($this->postArray['CreateDate']);
536 $this->forumPost->setChangeDate($this->postArray['UpdateDate']);
537
538 $usr_data = $this->getUserIdAndAlias(
539 (int) ($this->postArray['UserId'] ?? 0),
540 ilUtil::stripSlashes((string) ($this->postArray['Alias'] ?? ''))
541 );
542 $update_usr_data = $this->getUserIdAndAlias(
543 (int) ($this->postArray['UpdateUserId'] ?? 0)
544 );
545 $this->forumPost->setDisplayUserId($usr_data['usr_id']);
546 $this->forumPost->setUserAlias($usr_data['usr_alias']);
547 $this->forumPost->setUpdateUserId($update_usr_data['usr_id']);
548
549 if (version_compare($this->getSchemaVersion(), '4.5.0', '<=')) {
550 $this->postArray['AuthorId'] = $this->postArray['UserId'];
551 }
552 $author_id_data = $this->getUserIdAndAlias(
553 (int) ($this->postArray['AuthorId'] ?? 0)
554 );
555 $this->forumPost->setPosAuthorId((int) $author_id_data['usr_id']);
556
557 if (isset($this->postArray['isAuthorModerator']) && strtoupper($this->postArray['isAuthorModerator']) === 'NULL') {
558 $this->forumPost->setIsAuthorModerator(false);
559 } else {
560 $this->forumPost->setIsAuthorModerator((bool) $this->postArray['isAuthorModerator']);
561 }
562
563 $this->forumPost->insert();
564
565 if (isset($this->postArray['ParentId'], $this->mapping['pos'][$this->postArray['ParentId']])) {
566 $parent_id = (int) $this->mapping['pos'][$this->postArray['ParentId']];
567 } else {
568 $parent_id = 0;
569 }
570
571 if ($parent_id === 0 && (int) $this->postArray['Lft'] > 1) {
572 $parent_id = $this->determineParentFromNestedSet(
573 (int) $this->postArray['Lft'],
574 (int) $this->postArray['Rgt']
575 );
576 }
577
578 $postTreeNodeId = $this->db->nextId('frm_posts_tree');
579 $this->db->insert('frm_posts_tree', [
580 'fpt_pk' => ['integer', $postTreeNodeId],
581 'thr_fk' => ['integer', $this->lastHandledThreadId],
582 'pos_fk' => ['integer', $this->forumPost->getId()],
583 'parent_pos' => ['integer', $parent_id],
584 'lft' => ['integer', $this->postArray['Lft']],
585 'rgt' => ['integer', $this->postArray['Rgt']],
586 'depth' => ['integer', $this->postArray['Depth']],
587 'fpt_date' => ['timestamp', date('Y-m-d H:i:s')]
588 ]);
589
590 $this->mapping['pos'][$this->postArray['Id']] = $this->forumPost->getId();
591 $this->post_tree_structure[] = [
592 'id' => (int) $this->postArray['Id'],
593 'lft' => (int) $this->postArray['Lft'],
594 'rgt' => (int) $this->postArray['Rgt'],
595 'new_id' => $this->forumPost->getId()
596 ];
597 $this->lastHandledPostId = $this->forumPost->getId();
598
599 $media_objects_found = false;
600 foreach ($this->mediaObjects as $mob_attr) {
601 $importfile = $this->getImportDirectory() . '/' . $mob_attr['uri'];
602 if (is_file($importfile)) {
604 basename($importfile),
605 $importfile,
606 false
607 );
608 ilObjMediaObject::_saveUsage($mob->getId(), 'frm:html', $this->forumPost->getId());
609
610 $this->forumPost->setMessage(
611 str_replace(
612 [
613 'src="' . $mob_attr['label'] . '"',
614 'src="' . preg_replace(
615 "/(il)_[\d]+_(mob)_([\d]+)/",
616 '$1_0_$2_$3',
617 $mob_attr['label']
618 ) . '"'
619 ],
620 'src="' . 'il_' . IL_INST_ID . '_mob_' . $mob->getId() . '"',
621 $this->forumPost->getMessage()
622 )
623 );
624 $media_objects_found = true;
625 }
626 }
627
628 if ($media_objects_found) {
629 $this->forumPost->update();
630 }
631 $this->postArray = [];
632 }
633
634 break;
635
636 case 'Content':
637 $propertyValue['content'] = $this->cdata;
638 break;
639
640 case 'Attachment':
641 $filedata = new ilFileDataForum($this->forum->getId(), $this->lastHandledPostId);
642
643 $import_path = $this->contentArray['content'];
644 if ($import_path !== '') {
645 $import_path = $this->getImportDirectory() . '/' . $import_path;
646 $filedata->importPath($import_path, (int) $this->lastHandledPostId);
647 }
648 break;
649 }
650
651 $this->cdata = '';
652 }
653
657 private function getIdAndAliasArray(int $imp_usr_id, string $param = 'import'): array
658 {
659 $where = '';
660 $select = 'SELECT od.obj_id, ud.login FROM object_data od INNER JOIN usr_data ud ON od.obj_id = ud.usr_id';
661 if ($param === 'import') {
662 $where = ' WHERE od.import_id = ' . $this->db->quote(
663 'il_' . $this->import_install_id . '_usr_' . $imp_usr_id,
664 'text'
665 );
666 }
667
668 if ($param === 'user') {
669 $where = ' WHERE ud.usr_id = ' . $this->db->quote(
670 $imp_usr_id,
671 'integer'
672 );
673 }
674
675 $query = $this->db->query($select . $where);
676
677 while ($res = $this->db->fetchAssoc($query)) {
678 break;
679 }
680
681 if ($res) {
682 return [
683 'usr_id' => (int) $res['obj_id'],
684 'usr_alias' => (string) $res['login']
685 ];
686 }
687
688 return [];
689 }
690
694 private function getAnonymousArray(): array
695 {
696 return [
697 'usr_id' => $this->aobject->getId(),
698 'usr_alias' => $this->aobject->getLogin()
699 ];
700 }
701
705 private function getUserIdAndAlias(int $imp_usr_id, string $imp_usr_alias = ''): array
706 {
707 if ($imp_usr_id <= 0) {
708 return [
709 'usr_id' => $imp_usr_id,
710 'usr_alias' => $imp_usr_alias
711 ];
712 }
713
714 if ($this->import_install_id != IL_INST_ID && IL_INST_ID > 0) {
715 // Different installations
716 if (isset($this->user_id_mapping[$imp_usr_id])) {
717 return $this->user_id_mapping[$imp_usr_id];
718 }
719
720 $res = $this->getIdAndAliasArray($imp_usr_id, 'import');
721 if ($res !== []) {
722 $this->user_id_mapping[$imp_usr_id] = $res;
723
724 return $res;
725 }
726
727 $return_value = $this->getAnonymousArray();
728 $this->user_id_mapping[$imp_usr_id] = $return_value;
729
730 return $return_value;
731 }
732
733 if ($this->import_install_id == IL_INST_ID && IL_INST_ID == 0) {
734 // Eventually different installations. We cannot determine it.
735 if (isset($this->user_id_mapping[$imp_usr_id])) {
736 return $this->user_id_mapping[$imp_usr_id];
737 }
738
739 $res = $this->getIdAndAliasArray($imp_usr_id, 'import');
740 if ($res !== []) {
741 $this->user_id_mapping[$imp_usr_id] = $res;
742
743 return $res;
744 }
745
746 if (isset($this->user_id_mapping[$imp_usr_id])) {
747 return $this->user_id_mapping[$imp_usr_id];
748 }
749
750 $res = $this->getIdAndAliasArray($imp_usr_id, 'user');
751 if ($res !== []) {
752 $this->user_id_mapping[$imp_usr_id] = $res;
753
754 return $res;
755 }
756
757 $return_value = $this->getAnonymousArray();
758 $this->user_id_mapping[$imp_usr_id] = $return_value;
759
760 return $return_value;
761 }
762
763 if (isset($this->user_id_mapping[$imp_usr_id])) {
764 return $this->user_id_mapping[$imp_usr_id];
765 }
766
767 $res = $this->getIdAndAliasArray($imp_usr_id, 'user');
768 if ($res !== []) {
769 $this->user_id_mapping[$imp_usr_id] = $res;
770
771 return $res;
772 }
773
774 $return_value = $this->getAnonymousArray();
775 $this->user_id_mapping[$imp_usr_id] = $return_value;
776
777 return $return_value;
778 }
779
780 public function setImportInstallId($id): void
781 {
782 $this->import_install_id = $id;
783 }
784
785 private function getNewForumPk(): int
786 {
787 $query = 'SELECT top_pk FROM frm_data WHERE top_frm_fk = ' . $this->db->quote(
788 $this->forum->getId(),
789 'integer'
790 );
791 $res = $this->db->query($query);
792 $data = $this->db->fetchAssoc($res);
793
794 return (int) $data['top_pk'];
795 }
796
797 public function handlerCharacterData(XMLParser $a_xml_parser, string $a_data): void
798 {
799 if ($a_data !== "\n") {
800 // Replace multiple tabs with one space
801 $a_data = preg_replace("/\t+/", ' ', $a_data);
802
803 $this->cdata .= $a_data;
804 }
805 }
806
811 private function determineParentFromNestedSet(int $lft, int $rgt): int
812 {
813 $parent_id = 0;
814 $closest_span = PHP_INT_MAX;
815
816 foreach ($this->post_tree_structure as $node) {
817 if ($node['lft'] < $lft && $node['rgt'] > $rgt) {
818 // Prefer the nearest ancestor: smallest span while still containing current node
819 $span = $node['rgt'] - $node['lft'];
820 if ($span < $closest_span) {
821 $closest_span = $span;
822 $parent_id = (int) $node['new_id'];
823 }
824 }
825 }
826
827 return $parent_id;
828 }
829}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static getInstance(int $a_obj_id=0)
ILIAS Style Content DomainService $content_style_domain
__construct(private readonly ilObjForum $forum, string $a_xml_data, private readonly ilImportMapping $importMapping)
setSchemaVersion(?string $schema_version)
determineParentFromNestedSet(int $lft, int $rgt)
Find the closest parent using Nested Set values in memory.
handlerCharacterData(XMLParser $a_xml_parser, string $a_data)
handlerBeginTag(XMLParser $a_xml_parser, string $a_name, array $a_attribs)
handlerEndTag(XMLParser $a_xml_parser, string $a_name)
setImportDirectory(?string $a_val)
readonly ilObjUser $aobject
getUserIdAndAlias(int $imp_usr_id, string $imp_usr_alias='')
getIdAndAliasArray(int $imp_usr_id, string $param='import')
readonly ilDBInterface $db
static getInstanceByType(string $type)
static _refreshStatus(int $a_obj_id, ?array $a_users=null)
Class ilObjForum.
static _saveTempFileAsMediaObject(string $name, string $tmp_name, bool $upload=true)
static _saveUsage(int $a_mob_id, string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
Save usage of mob within another container (e.g.
User class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setXMLContent(string $a_xml_content)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
const IL_INST_ID
Definition: constants.php:40
const ANONYMOUS_USER_ID
Definition: constants.php:27
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26
$param
Definition: xapitoken.php:44