ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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 if ($this->last_handled_style_id) {
367 self::$style_map[$this->last_handled_style_id][] = $newObjProp->getObjId();
368 $this->last_handled_style_id = null;
369 }
370
371 $this->forumArray = [];
372 }
373 break;
374
375 case 'Thread':
376 $update_str = null;
377 if ($this->lastHandledPostId !== 0) {
378 $update_str = implode('#', [
379 (string) $this->lastHandledForumId,
380 (string) $this->lastHandledThreadId,
381 (string) $this->lastHandledPostId
382 ]);
383 }
384
385 $this->db->manipulateF(
386 'UPDATE frm_threads SET thr_last_post = %s WHERE thr_pk = %s',
387 ['text', 'integer'],
388 [$update_str, $this->lastHandledThreadId]
389 );
390 break;
391
392 case 'Subject':
393 $propertyValue['Subject'] = $this->cdata;
394 break;
395
396 case 'Alias':
397 $propertyValue['Alias'] = $this->cdata;
398 break;
399
400 case 'Sticky':
401 $propertyValue['Sticky'] = $this->cdata;
402 break;
403
404 case 'MarkModeratorPosts':
405 $propertyValue['MarkModeratorPosts'] = $this->cdata;
406 break;
407
408 case 'Closed':
409 $propertyValue['Closed'] = $this->cdata;
410
411 if ($this->entity === 'thread' && $this->lastHandledForumId && $this->threadArray !== []) {
412 $this->forumThread = new ilForumTopic();
413 $this->forumThread->setId((int) $this->threadArray['Id']);
414 $this->forumThread->setForumId($this->lastHandledForumId);
415 $this->forumThread->setSubject(
416 ilUtil::stripSlashes((string) ($this->threadArray['Subject'] ?? ''))
417 );
418 $this->forumThread->setSticky((bool) ($this->threadArray['Sticky'] ?? false));
419 $this->forumThread->setClosed((bool) ($this->threadArray['Closed'] ?? false));
420
421 $this->forumThread->setImportName(
422 isset($this->threadArray['ImportName']) ?
423 ilUtil::stripSlashes($this->threadArray['ImportName']) :
424 null
425 );
426 $this->forumThread->setCreateDate($this->threadArray['CreateDate']);
427 $this->forumThread->setChangeDate($this->threadArray['UpdateDate']);
428
429 $usr_data = $this->getUserIdAndAlias(
430 (int) ($this->threadArray['UserId'] ?? 0),
431 ilUtil::stripSlashes((string) ($this->threadArray['Alias'] ?? ''))
432 );
433
434 $this->forumThread->setDisplayUserId($usr_data['usr_id']);
435 $this->forumThread->setUserAlias($usr_data['usr_alias']);
436
437 if (version_compare($this->getSchemaVersion(), '4.5.0', '<=')) {
438 $this->threadArray['AuthorId'] = $this->threadArray['UserId'];
439 }
440
441 $author_id_data = $this->getUserIdAndAlias(
442 (int) ($this->threadArray['AuthorId'] ?? 0)
443 );
444 $this->forumThread->setThrAuthorId($author_id_data['usr_id']);
445
446 $this->forumThread->insert();
447
448 $this->mapping['thr'][$this->threadArray['Id']] = $this->forumThread->getId();
449 $this->lastHandledThreadId = $this->forumThread->getId();
450 $this->threadArray = [];
451 }
452 break;
453
454 case 'Post':
455 break;
456
457 case 'Censorship':
458 $propertyValue['Censorship'] = $this->cdata;
459 break;
460
461 case 'CensorshipMessage':
462 $propertyValue['CensorshipMessage'] = $this->cdata;
463 break;
464
465 case 'Notification':
466 $propertyValue['Notification'] = $this->cdata;
467 break;
468
469 case 'ImportName':
470 $propertyValue['ImportName'] = $this->cdata;
471 break;
472
473 case 'Status':
474 $propertyValue['Status'] = $this->cdata;
475 break;
476
477 case 'Message':
478 $propertyValue['Message'] = $this->cdata;
479 break;
480
481 case 'Lft':
482 $propertyValue['Lft'] = $this->cdata;
483 break;
484
485 case 'Rgt':
486 $propertyValue['Rgt'] = $this->cdata;
487 break;
488
489 case 'Depth':
490 $propertyValue['Depth'] = $this->cdata;
491 break;
492
493 case 'ParentId':
494 $propertyValue['ParentId'] = $this->cdata;
495
496 if (
497 $this->entity === 'post' &&
498 $this->lastHandledForumId &&
499 $this->postArray !== [] &&
500 $this->forumThread &&
501 $this->lastHandledThreadId
502 ) {
503 $this->forumPost = new ilForumPost();
504 $this->forumPost->setThread($this->forumThread);
505
506 $this->forumPost->setId((int) $this->postArray['Id']);
507 $this->forumPost->setCensorship((bool) ($this->postArray['Censorship'] ?? false));
508 $this->forumPost->setCensorshipComment(
509 ilUtil::stripSlashes((string) ($this->postArray['CensorshipMessage'] ?? ''))
510 );
511 $this->forumPost->setNotification((bool) ($this->postArray['Notification'] ?? false));
512 $this->forumPost->setStatus((bool) ($this->postArray['Status'] ?? false));
513 $purifier = ilHtmlPurifierFactory::getInstanceByType('frm_post');
514 $this->forumPost->setMessage($purifier->purify((string) ($this->postArray['Message'] ?? '')));
515 $this->forumPost->setSubject(ilUtil::stripSlashes((string) ($this->postArray['Subject'] ?? '')));
516 $this->forumPost->setLft((int) $this->postArray['Lft']);
517 $this->forumPost->setRgt((int) $this->postArray['Rgt']);
518 $this->forumPost->setDepth((int) $this->postArray['Depth']);
519 $this->forumPost->setParentId((int) $this->postArray['ParentId']);
520 $this->forumPost->setThreadId($this->lastHandledThreadId);
521 $this->forumPost->setForumId($this->lastHandledForumId);
522
523 $this->forumPost->setImportName(
524 isset($this->postArray['ImportName']) ?
525 ilUtil::stripSlashes($this->postArray['ImportName']) :
526 null
527 );
528 $this->forumPost->setCreateDate($this->postArray['CreateDate']);
529 $this->forumPost->setChangeDate($this->postArray['UpdateDate']);
530
531 $usr_data = $this->getUserIdAndAlias(
532 (int) ($this->postArray['UserId'] ?? 0),
533 ilUtil::stripSlashes((string) ($this->postArray['Alias'] ?? ''))
534 );
535 $update_usr_data = $this->getUserIdAndAlias(
536 (int) ($this->postArray['UpdateUserId'] ?? 0)
537 );
538 $this->forumPost->setDisplayUserId($usr_data['usr_id']);
539 $this->forumPost->setUserAlias($usr_data['usr_alias']);
540 $this->forumPost->setUpdateUserId($update_usr_data['usr_id']);
541
542 if (version_compare($this->getSchemaVersion(), '4.5.0', '<=')) {
543 $this->postArray['AuthorId'] = $this->postArray['UserId'];
544 }
545 $author_id_data = $this->getUserIdAndAlias(
546 (int) ($this->postArray['AuthorId'] ?? 0)
547 );
548 $this->forumPost->setPosAuthorId((int) $author_id_data['usr_id']);
549
550 if (isset($this->postArray['isAuthorModerator']) && strtoupper($this->postArray['isAuthorModerator']) === 'NULL') {
551 $this->forumPost->setIsAuthorModerator(false);
552 } else {
553 $this->forumPost->setIsAuthorModerator((bool) $this->postArray['isAuthorModerator']);
554 }
555
556 $this->forumPost->insert();
557
558 if (isset($this->postArray['ParentId'], $this->mapping['pos'][$this->postArray['ParentId']])) {
559 $parent_id = (int) $this->mapping['pos'][$this->postArray['ParentId']];
560 } else {
561 $parent_id = 0;
562 }
563
564 if ($parent_id === 0 && (int) $this->postArray['Lft'] > 1) {
565 $parent_id = $this->determineParentFromNestedSet(
566 (int) $this->postArray['Lft'],
567 (int) $this->postArray['Rgt']
568 );
569 }
570
571 $postTreeNodeId = $this->db->nextId('frm_posts_tree');
572 $this->db->insert('frm_posts_tree', [
573 'fpt_pk' => ['integer', $postTreeNodeId],
574 'thr_fk' => ['integer', $this->lastHandledThreadId],
575 'pos_fk' => ['integer', $this->forumPost->getId()],
576 'parent_pos' => ['integer', $parent_id],
577 'lft' => ['integer', $this->postArray['Lft']],
578 'rgt' => ['integer', $this->postArray['Rgt']],
579 'depth' => ['integer', $this->postArray['Depth']],
580 'fpt_date' => ['timestamp', date('Y-m-d H:i:s')]
581 ]);
582
583 $this->mapping['pos'][$this->postArray['Id']] = $this->forumPost->getId();
584 $this->post_tree_structure[] = [
585 'id' => (int) $this->postArray['Id'],
586 'lft' => (int) $this->postArray['Lft'],
587 'rgt' => (int) $this->postArray['Rgt'],
588 'new_id' => $this->forumPost->getId()
589 ];
590 $this->lastHandledPostId = $this->forumPost->getId();
591
592 $media_objects_found = false;
593 foreach ($this->mediaObjects as $mob_attr) {
594 $importfile = $this->getImportDirectory() . '/' . $mob_attr['uri'];
595 if (is_file($importfile)) {
597 basename($importfile),
598 $importfile,
599 false
600 );
601 ilObjMediaObject::_saveUsage($mob->getId(), 'frm:html', $this->forumPost->getId());
602
603 $this->forumPost->setMessage(
604 str_replace(
605 [
606 'src="' . $mob_attr['label'] . '"',
607 'src="' . preg_replace(
608 "/(il)_[\d]+_(mob)_([\d]+)/",
609 '$1_0_$2_$3',
610 $mob_attr['label']
611 ) . '"'
612 ],
613 'src="' . 'il_' . IL_INST_ID . '_mob_' . $mob->getId() . '"',
614 $this->forumPost->getMessage()
615 )
616 );
617 $media_objects_found = true;
618 }
619 }
620
621 if ($media_objects_found) {
622 $this->forumPost->update();
623 }
624 $this->postArray = [];
625 }
626
627 break;
628
629 case 'Content':
630 $propertyValue['content'] = $this->cdata;
631 break;
632
633 case 'Attachment':
634 $filedata = new ilFileDataForum($this->forum->getId(), $this->lastHandledPostId);
635
636 $import_path = $this->contentArray['content'];
637 if ($import_path !== '') {
638 $import_path = $this->getImportDirectory() . '/' . $import_path;
639 $filedata->importPath($import_path, (int) $this->lastHandledPostId);
640 }
641 break;
642 }
643
644 $this->cdata = '';
645 }
646
650 private function getIdAndAliasArray(int $imp_usr_id, string $param = 'import'): array
651 {
652 $where = '';
653 $select = 'SELECT od.obj_id, ud.login FROM object_data od INNER JOIN usr_data ud ON od.obj_id = ud.usr_id';
654 if ($param === 'import') {
655 $where = ' WHERE od.import_id = ' . $this->db->quote(
656 'il_' . $this->import_install_id . '_usr_' . $imp_usr_id,
657 'text'
658 );
659 }
660
661 if ($param === 'user') {
662 $where = ' WHERE ud.usr_id = ' . $this->db->quote(
663 $imp_usr_id,
664 'integer'
665 );
666 }
667
668 $query = $this->db->query($select . $where);
669
670 while ($res = $this->db->fetchAssoc($query)) {
671 break;
672 }
673
674 if ($res) {
675 return [
676 'usr_id' => (int) $res['obj_id'],
677 'usr_alias' => (string) $res['login']
678 ];
679 }
680
681 return [];
682 }
683
687 private function getAnonymousArray(): array
688 {
689 return [
690 'usr_id' => $this->aobject->getId(),
691 'usr_alias' => $this->aobject->getLogin()
692 ];
693 }
694
698 private function getUserIdAndAlias(int $imp_usr_id, string $imp_usr_alias = ''): array
699 {
700 if ($imp_usr_id <= 0) {
701 return [
702 'usr_id' => $imp_usr_id,
703 'usr_alias' => $imp_usr_alias
704 ];
705 }
706
707 if ($this->import_install_id != IL_INST_ID && IL_INST_ID > 0) {
708 // Different installations
709 if (isset($this->user_id_mapping[$imp_usr_id])) {
710 return $this->user_id_mapping[$imp_usr_id];
711 }
712
713 $res = $this->getIdAndAliasArray($imp_usr_id, 'import');
714 if ($res !== []) {
715 $this->user_id_mapping[$imp_usr_id] = $res;
716
717 return $res;
718 }
719
720 $return_value = $this->getAnonymousArray();
721 $this->user_id_mapping[$imp_usr_id] = $return_value;
722
723 return $return_value;
724 }
725
726 if ($this->import_install_id == IL_INST_ID && IL_INST_ID == 0) {
727 // Eventually different installations. We cannot determine it.
728 if (isset($this->user_id_mapping[$imp_usr_id])) {
729 return $this->user_id_mapping[$imp_usr_id];
730 }
731
732 $res = $this->getIdAndAliasArray($imp_usr_id, 'import');
733 if ($res !== []) {
734 $this->user_id_mapping[$imp_usr_id] = $res;
735
736 return $res;
737 }
738
739 if (isset($this->user_id_mapping[$imp_usr_id])) {
740 return $this->user_id_mapping[$imp_usr_id];
741 }
742
743 $res = $this->getIdAndAliasArray($imp_usr_id, 'user');
744 if ($res !== []) {
745 $this->user_id_mapping[$imp_usr_id] = $res;
746
747 return $res;
748 }
749
750 $return_value = $this->getAnonymousArray();
751 $this->user_id_mapping[$imp_usr_id] = $return_value;
752
753 return $return_value;
754 }
755
756 if (isset($this->user_id_mapping[$imp_usr_id])) {
757 return $this->user_id_mapping[$imp_usr_id];
758 }
759
760 $res = $this->getIdAndAliasArray($imp_usr_id, 'user');
761 if ($res !== []) {
762 $this->user_id_mapping[$imp_usr_id] = $res;
763
764 return $res;
765 }
766
767 $return_value = $this->getAnonymousArray();
768 $this->user_id_mapping[$imp_usr_id] = $return_value;
769
770 return $return_value;
771 }
772
773 public function setImportInstallId($id): void
774 {
775 $this->import_install_id = $id;
776 }
777
778 private function getNewForumPk(): int
779 {
780 $query = 'SELECT top_pk FROM frm_data WHERE top_frm_fk = ' . $this->db->quote(
781 $this->forum->getId(),
782 'integer'
783 );
784 $res = $this->db->query($query);
785 $data = $this->db->fetchAssoc($res);
786
787 return (int) $data['top_pk'];
788 }
789
790 public function handlerCharacterData(XMLParser $a_xml_parser, string $a_data): void
791 {
792 if ($a_data !== "\n") {
793 // Replace multiple tabs with one space
794 $a_data = preg_replace("/\t+/", ' ', $a_data);
795
796 $this->cdata .= $a_data;
797 }
798 }
799
804 private function determineParentFromNestedSet(int $lft, int $rgt): int
805 {
806 $parent_id = 0;
807 $closest_span = PHP_INT_MAX;
808
809 foreach ($this->post_tree_structure as $node) {
810 if ($node['lft'] < $lft && $node['rgt'] > $rgt) {
811 // Prefer the nearest ancestor: smallest span while still containing current node
812 $span = $node['rgt'] - $node['lft'];
813 if ($span < $closest_span) {
814 $closest_span = $span;
815 $parent_id = (int) $node['new_id'];
816 }
817 }
818 }
819
820 return $parent_id;
821 }
822}
$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