ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
ilForumXMLParser Class Reference
+ Inheritance diagram for ilForumXMLParser:
+ Collaboration diagram for ilForumXMLParser:

Public Member Functions

 __construct (private readonly ilObjForum $forum, string $a_xml_data, private readonly ilImportMapping $importMapping)
 
 setImportDirectory (?string $a_val)
 
 getImportDirectory ()
 
 getSchemaVersion ()
 
 setSchemaVersion (?string $schema_version)
 
 setHandlers ($a_xml_parser)
 
 handlerBeginTag (XMLParser $a_xml_parser, string $a_name, array $a_attribs)
 
 handlerEndTag (XMLParser $a_xml_parser, string $a_name)
 
 setImportInstallId ($id)
 
 handlerCharacterData (XMLParser $a_xml_parser, string $a_data)
 
- Public Member Functions inherited from ilSaxParser
 __construct (?string $path_to_file='', ?bool $throw_exception=false)
 
 setXMLContent (string $a_xml_content)
 
 getXMLContent ()
 
 getInputType ()
 
 startParsing ()
 stores xml data in array More...
 
 createParser ()
 
 setHandlers ($a_xml_parser)
 
 parse ($a_xml_parser, $a_fp=null)
 

Static Public Attributes

static array $style_map = []
 

Protected Attributes

ILIAS Style Content DomainService $content_style_domain
 
- Protected Attributes inherited from ilSaxParser
ilLanguage $lng = null
 

Private Member Functions

 getIdAndAliasArray (int $imp_usr_id, string $param='import')
 
 getAnonymousArray ()
 
 getUserIdAndAlias (int $imp_usr_id, string $imp_usr_alias='')
 
 getNewForumPk ()
 
 determineParentFromNestedSet (int $lft, int $rgt)
 Find the closest parent using Nested Set values in memory. More...
 

Private Attributes

string $entity = ''
 
array $mapping
 
readonly ilDBInterface $db
 
readonly ilObjUser $aobject
 
 $import_install_id
 
string $importDirectory = null
 
string $schema_version = null
 
string $cdata = ''
 
ilForumTopic $forumThread = null
 
ilForumPost $forumPost = null
 
int $forum_obj_id = null
 
int $frm_last_mapped_top_usr_id = null
 
int $lastHandledForumId = null
 
int $lastHandledThreadId = null
 
int $lastHandledPostId = null
 
int $last_handled_style_id = null
 
array $forumArray = []
 
array $postArray = []
 
array $threadArray = []
 
array $contentArray
 
array $user_id_mapping = []
 
array $mediaObjects = []
 
array $post_tree_structure = []
 

Additional Inherited Members

- Data Fields inherited from ilSaxParser
string $xml_file
 
bool $throw_exception = false
 
- Protected Member Functions inherited from ilSaxParser
 openXMLFile ()
 
 handleError (string $message)
 
 setThrowException (bool $throw_exception)
 

Detailed Description

Definition at line 23 of file class.ilForumXMLParser.php.

Constructor & Destructor Documentation

◆ __construct()

ilForumXMLParser::__construct ( private readonly ilObjForum  $forum,
string  $a_xml_data,
private readonly ilImportMapping  $importMapping 
)

Definition at line 68 of file class.ilForumXMLParser.php.

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 }
User class.
setXMLContent(string $a_xml_content)
const ANONYMOUS_USER_ID
Definition: constants.php:27
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26

References $DIC, ILIAS\GlobalScreen\Provider\__construct(), ANONYMOUS_USER_ID, and ilSaxParser\setXMLContent().

+ Here is the call graph for this function:

Member Function Documentation

◆ determineParentFromNestedSet()

ilForumXMLParser::determineParentFromNestedSet ( int  $lft,
int  $rgt 
)
private

Find the closest parent using Nested Set values in memory.

Returns the new DB id of the parent or 0 if none found.

Definition at line 811 of file class.ilForumXMLParser.php.

811 : 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 }

References ILIAS\Repository\int().

Referenced by handlerEndTag().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAnonymousArray()

ilForumXMLParser::getAnonymousArray ( )
private
Returns
array{usr_id: int, usr_alias: string}

Definition at line 694 of file class.ilForumXMLParser.php.

694 : array
695 {
696 return [
697 'usr_id' => $this->aobject->getId(),
698 'usr_alias' => $this->aobject->getLogin()
699 ];
700 }

Referenced by getUserIdAndAlias().

+ Here is the caller graph for this function:

◆ getIdAndAliasArray()

ilForumXMLParser::getIdAndAliasArray ( int  $imp_usr_id,
string  $param = 'import' 
)
private
Returns
array|array{usr_id: int, usr_alias: string}

Definition at line 657 of file class.ilForumXMLParser.php.

657 : 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 }
$res
Definition: ltiservices.php:69
$param
Definition: xapitoken.php:44

References $param, $res, and ILIAS\Repository\int().

Referenced by getUserIdAndAlias().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getImportDirectory()

ilForumXMLParser::getImportDirectory ( )

Definition at line 92 of file class.ilForumXMLParser.php.

92 : ?string
93 {
95 }

References $importDirectory.

Referenced by handlerEndTag().

+ Here is the caller graph for this function:

◆ getNewForumPk()

ilForumXMLParser::getNewForumPk ( )
private

Definition at line 785 of file class.ilForumXMLParser.php.

785 : 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 }

References $data, and $res.

Referenced by handlerEndTag().

+ Here is the caller graph for this function:

◆ getSchemaVersion()

ilForumXMLParser::getSchemaVersion ( )

Definition at line 97 of file class.ilForumXMLParser.php.

97 : ?string
98 {
100 }

References $schema_version.

Referenced by handlerEndTag().

+ Here is the caller graph for this function:

◆ getUserIdAndAlias()

ilForumXMLParser::getUserIdAndAlias ( int  $imp_usr_id,
string  $imp_usr_alias = '' 
)
private
Returns
array{usr_id: int, usr_alias: string}

Definition at line 705 of file class.ilForumXMLParser.php.

705 : 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 }
getIdAndAliasArray(int $imp_usr_id, string $param='import')
const IL_INST_ID
Definition: constants.php:40

References $res, getAnonymousArray(), getIdAndAliasArray(), and IL_INST_ID.

Referenced by handlerEndTag().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handlerBeginTag()

ilForumXMLParser::handlerBeginTag ( XMLParser  $a_xml_parser,
string  $a_name,
array  $a_attribs 
)

Definition at line 123 of file class.ilForumXMLParser.php.

123 : 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 }

References ILIAS\Repository\int().

Referenced by setHandlers().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handlerCharacterData()

ilForumXMLParser::handlerCharacterData ( XMLParser  $a_xml_parser,
string  $a_data 
)

Definition at line 797 of file class.ilForumXMLParser.php.

797 : 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 }

Referenced by setHandlers().

+ Here is the caller graph for this function:

◆ handlerEndTag()

ilForumXMLParser::handlerEndTag ( XMLParser  $a_xml_parser,
string  $a_name 
)

Definition at line 160 of file class.ilForumXMLParser.php.

160 : 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 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static getInstance(int $a_obj_id=0)
determineParentFromNestedSet(int $lft, int $rgt)
Find the closest parent using Nested Set values in memory.
getUserIdAndAlias(int $imp_usr_id, string $imp_usr_alias='')
static getInstanceByType(string $type)
static _refreshStatus(int $a_obj_id, ?array $a_users=null)
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.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")

References $cdata, $id, $last_handled_style_id, ilLPStatusWrapper\_refreshStatus(), ilObjMediaObject\_saveTempFileAsMediaObject(), ilObjMediaObject\_saveUsage(), determineParentFromNestedSet(), getImportDirectory(), ilForumProperties\getInstance(), ilHtmlPurifierFactory\getInstanceByType(), getNewForumPk(), getSchemaVersion(), getUserIdAndAlias(), IL_INST_ID, ILIAS\Repository\int(), ilUtil\stripSlashes(), and ilForumProperties\VIEW_TREE.

Referenced by setHandlers().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setHandlers()

ilForumXMLParser::setHandlers (   $a_xml_parser)
Parameters
XMLParser | resource$a_xml_parser
Returns
void

Reimplemented from ilSaxParser.

Definition at line 107 of file class.ilForumXMLParser.php.

107 : 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 }
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)

References handlerBeginTag(), handlerCharacterData(), and handlerEndTag().

+ Here is the call graph for this function:

◆ setImportDirectory()

ilForumXMLParser::setImportDirectory ( ?string  $a_val)

Definition at line 87 of file class.ilForumXMLParser.php.

87 : void
88 {
89 $this->importDirectory = $a_val;
90 }

◆ setImportInstallId()

ilForumXMLParser::setImportInstallId (   $id)

Definition at line 780 of file class.ilForumXMLParser.php.

780 : void
781 {
782 $this->import_install_id = $id;
783 }

References $id.

◆ setSchemaVersion()

ilForumXMLParser::setSchemaVersion ( ?string  $schema_version)

Definition at line 102 of file class.ilForumXMLParser.php.

102 : void
103 {
104 $this->schema_version = $schema_version;
105 }

References $schema_version.

Field Documentation

◆ $aobject

readonly ilObjUser ilForumXMLParser::$aobject
private

Definition at line 37 of file class.ilForumXMLParser.php.

◆ $cdata

string ilForumXMLParser::$cdata = ''
private

Definition at line 42 of file class.ilForumXMLParser.php.

Referenced by handlerEndTag().

◆ $content_style_domain

ILIAS Style Content DomainService ilForumXMLParser::$content_style_domain
protected

Definition at line 60 of file class.ilForumXMLParser.php.

◆ $contentArray

array ilForumXMLParser::$contentArray
private
Initial value:
= [
'content' => ''
]

Definition at line 55 of file class.ilForumXMLParser.php.

◆ $db

readonly ilDBInterface ilForumXMLParser::$db
private

Definition at line 36 of file class.ilForumXMLParser.php.

◆ $entity

string ilForumXMLParser::$entity = ''
private

Definition at line 30 of file class.ilForumXMLParser.php.

◆ $forum_obj_id

int ilForumXMLParser::$forum_obj_id = null
private

Definition at line 46 of file class.ilForumXMLParser.php.

◆ $forumArray

array ilForumXMLParser::$forumArray = []
private

Definition at line 52 of file class.ilForumXMLParser.php.

◆ $forumPost

ilForumPost ilForumXMLParser::$forumPost = null
private

Definition at line 45 of file class.ilForumXMLParser.php.

◆ $forumThread

ilForumTopic ilForumXMLParser::$forumThread = null
private

Definition at line 44 of file class.ilForumXMLParser.php.

◆ $frm_last_mapped_top_usr_id

int ilForumXMLParser::$frm_last_mapped_top_usr_id = null
private

Definition at line 47 of file class.ilForumXMLParser.php.

◆ $import_install_id

ilForumXMLParser::$import_install_id
private

Definition at line 39 of file class.ilForumXMLParser.php.

◆ $importDirectory

string ilForumXMLParser::$importDirectory = null
private

Definition at line 40 of file class.ilForumXMLParser.php.

Referenced by getImportDirectory().

◆ $last_handled_style_id

int ilForumXMLParser::$last_handled_style_id = null
private

Definition at line 51 of file class.ilForumXMLParser.php.

Referenced by handlerEndTag().

◆ $lastHandledForumId

int ilForumXMLParser::$lastHandledForumId = null
private

Definition at line 48 of file class.ilForumXMLParser.php.

◆ $lastHandledPostId

int ilForumXMLParser::$lastHandledPostId = null
private

Definition at line 50 of file class.ilForumXMLParser.php.

◆ $lastHandledThreadId

int ilForumXMLParser::$lastHandledThreadId = null
private

Definition at line 49 of file class.ilForumXMLParser.php.

◆ $mapping

array ilForumXMLParser::$mapping
private
Initial value:
= [
'frm' => [],
'thr' => [],
'pos' => []
]

Definition at line 31 of file class.ilForumXMLParser.php.

◆ $mediaObjects

array ilForumXMLParser::$mediaObjects = []
private

Definition at line 59 of file class.ilForumXMLParser.php.

◆ $post_tree_structure

array ilForumXMLParser::$post_tree_structure = []
private

Definition at line 65 of file class.ilForumXMLParser.php.

◆ $postArray

array ilForumXMLParser::$postArray = []
private

Definition at line 53 of file class.ilForumXMLParser.php.

◆ $schema_version

string ilForumXMLParser::$schema_version = null
private

Definition at line 41 of file class.ilForumXMLParser.php.

Referenced by getSchemaVersion(), and setSchemaVersion().

◆ $style_map

array ilForumXMLParser::$style_map = []
static

Definition at line 28 of file class.ilForumXMLParser.php.

Referenced by ilForumImporter\finalProcessing().

◆ $threadArray

array ilForumXMLParser::$threadArray = []
private

Definition at line 54 of file class.ilForumXMLParser.php.

◆ $user_id_mapping

array ilForumXMLParser::$user_id_mapping = []
private

Definition at line 58 of file class.ilForumXMLParser.php.


The documentation for this class was generated from the following file: