ILIAS  release_8 Revision v8.24
ilForumXMLParser Class Reference
+ Inheritance diagram for ilForumXMLParser:
+ Collaboration diagram for ilForumXMLParser:

Public Member Functions

 __construct (ilObjForum $forum, string $a_xml_data, ilImportMapping $importMapping)
 
 setImportDirectory (?string $a_val)
 
 getImportDirectory ()
 
 getSchemaVersion ()
 
 setSchemaVersion (?string $schema_version)
 
 setHandlers ($a_xml_parser)
 
 handlerBeginTag ($a_xml_parser, string $a_name, array $a_attribs)
 
 handlerEndTag ($a_xml_parser, string $a_name)
 
 setImportInstallId ($id)
 
 handlerCharacterData ($a_xml_parser, string $a_data)
 handler for character data More...
 
- 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)
 

Private Member Functions

 getIdAndAliasArray (int $imp_usr_id, string $param='import')
 
 getAnonymousArray ()
 
 getUserIdAndAlias (int $imp_usr_id, string $imp_usr_alias='')
 
 getNewForumPk ()
 

Private Attributes

ilObjForum $forum
 
string $entity = ''
 
array $mapping
 
ilDBInterface $db
 
ilObjUser $aobject
 
 $import_install_id = null
 
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
 
array $forumArray = []
 
array $postArray = []
 
array $threadArray = []
 
array $contentArray
 
array $user_id_mapping = []
 
array $mediaObjects = []
 
ilImportMapping $importMapping
 

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)
 
- Protected Attributes inherited from ilSaxParser
ilLanguage $lng = null
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

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

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

56 {
57 global $DIC;
58
59 $this->db = $DIC->database();
60 $this->aobject = new ilObjUser(ANONYMOUS_USER_ID);
61
62 $this->forum = $forum;
63 $this->importMapping = $importMapping;
64
66
67 $this->setXMLContent('<?xml version="1.0" encoding="utf-8"?>' . $a_xml_data);
68 }
ilImportMapping $importMapping
User class.
setXMLContent(string $a_xml_content)
const ANONYMOUS_USER_ID
Definition: constants.php:27
global $DIC
Definition: feed.php:28
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

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

+ Here is the call graph for this function:

Member Function Documentation

◆ getAnonymousArray()

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

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

664 : array
665 {
666 return [
667 'usr_id' => $this->aobject->getId(),
668 'usr_alias' => $this->aobject->getLogin()
669 ];
670 }

Referenced by getUserIdAndAlias().

+ Here is the caller graph for this function:

◆ getIdAndAliasArray()

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

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

627 : array
628 {
629 $where = '';
630 $select = 'SELECT od.obj_id, ud.login FROM object_data od INNER JOIN usr_data ud ON od.obj_id = ud.usr_id';
631 if ($param === 'import') {
632 $where = ' WHERE od.import_id = ' . $this->db->quote(
633 'il_' . $this->import_install_id . '_usr_' . $imp_usr_id,
634 'text'
635 );
636 }
637
638 if ($param === 'user') {
639 $where = ' WHERE ud.usr_id = ' . $this->db->quote(
640 $imp_usr_id,
641 'integer'
642 );
643 }
644
645 $query = $this->db->query($select . $where);
646
647 while ($res = $this->db->fetchAssoc($query)) {
648 break;
649 }
650
651 if ($res) {
652 return [
653 'usr_id' => (int) $res['obj_id'],
654 'usr_alias' => (string) $res['login']
655 ];
656 }
657
658 return [];
659 }
$res
Definition: ltiservices.php:69
$query
$param
Definition: xapitoken.php:46

References $param, $query, $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 75 of file class.ilForumXMLParser.php.

75 : ?string
76 {
78 }

References $importDirectory.

Referenced by handlerEndTag().

+ Here is the caller graph for this function:

◆ getNewForumPk()

ilForumXMLParser::getNewForumPk ( )
private

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

757 : int
758 {
759 $query = "SELECT top_pk FROM frm_data WHERE top_frm_fk = " . $this->db->quote(
760 $this->forum->getId(),
761 'integer'
762 );
763 $res = $this->db->query($query);
764 $data = $this->db->fetchAssoc($res);
765
766 return (int) $data['top_pk'];
767 }

References $data, $query, and $res.

Referenced by handlerEndTag().

+ Here is the caller graph for this function:

◆ getSchemaVersion()

ilForumXMLParser::getSchemaVersion ( )

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

80 : ?string
81 {
83 }

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
Parameters
int$imp_usr_id
string$imp_usr_alias
Returns
array{usr_id: int, usr_alias: string}

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

677 : array
678 {
679 if (!($imp_usr_id > 0)) {
680 return [
681 'usr_id' => $imp_usr_id,
682 'usr_alias' => $imp_usr_alias
683 ];
684 }
685
686 if ($this->import_install_id != IL_INST_ID && IL_INST_ID > 0) {
687 // Different installations
688 if (isset($this->user_id_mapping[$imp_usr_id])) {
689 return $this->user_id_mapping[$imp_usr_id];
690 }
691
692 $res = $this->getIdAndAliasArray($imp_usr_id, 'import');
693 if ($res !== []) {
694 $this->user_id_mapping[$imp_usr_id] = $res;
695
696 return $res;
697 }
698
699 $return_value = $this->getAnonymousArray();
700 $this->user_id_mapping[$imp_usr_id] = $return_value;
701
702 return $return_value;
703 }
704
705 if ($this->import_install_id == IL_INST_ID && IL_INST_ID == 0) {
706 // Eventually different installations. We cannot determine it.
707 if (isset($this->user_id_mapping[$imp_usr_id])) {
708 return $this->user_id_mapping[$imp_usr_id];
709 }
710
711 $res = $this->getIdAndAliasArray($imp_usr_id, 'import');
712 if ($res !== []) {
713 $this->user_id_mapping[$imp_usr_id] = $res;
714
715 return $res;
716 }
717
718 if (isset($this->user_id_mapping[$imp_usr_id])) {
719 return $this->user_id_mapping[$imp_usr_id];
720 }
721
722 $res = $this->getIdAndAliasArray($imp_usr_id, 'user');
723 if ($res !== []) {
724 $this->user_id_mapping[$imp_usr_id] = $res;
725
726 return $res;
727 }
728
729 $return_value = $this->getAnonymousArray();
730 $this->user_id_mapping[$imp_usr_id] = $return_value;
731
732 return $return_value;
733 }
734
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, 'user');
740 if ($res !== []) {
741 $this->user_id_mapping[$imp_usr_id] = $res;
742
743 return $res;
744 }
745
746 $return_value = $this->getAnonymousArray();
747 $this->user_id_mapping[$imp_usr_id] = $return_value;
748
749 return $return_value;
750 }
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 (   $a_xml_parser,
string  $a_name,
array  $a_attribs 
)
Parameters
XMLParser | resource$a_xml_parser
string$a_name
array$a_attribs
Returns
void

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

103 : void
104 {
105 switch ($a_name) {
106 case 'Forum':
107 $this->entity = 'forum';
108 $this->forumArray = [];
109 break;
110
111 case 'Thread':
112 $this->entity = 'thread';
113 $this->threadArray = [];
114 break;
115
116 case 'Post':
117 $this->entity = 'post';
118 $this->postArray = [];
119 $this->mediaObjects = [];
120 break;
121
122 case 'Content':
123 $this->entity = 'content';
124 $this->contentArray = [
125 'content' => ''
126 ];
127 break;
128
129 case 'MediaObject':
130 $this->mediaObjects[] = $a_attribs;
131 break;
132 }
133 }

◆ handlerCharacterData()

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

handler for character data

Parameters
XMLParser | resource$a_xml_parserxml parser
string$a_datacharacter data

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

774 : void
775 {
776 if ($a_data !== "\n") {
777 // Replace multiple tabs with one space
778 $a_data = preg_replace("/\t+/", " ", $a_data);
779
780 $this->cdata .= $a_data;
781 }
782 }

◆ handlerEndTag()

ilForumXMLParser::handlerEndTag (   $a_xml_parser,
string  $a_name 
)
Parameters
XMLParser | resource$a_xml_parser
string$a_name
Returns
void

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

140 : void
141 {
142 $this->cdata = trim($this->cdata);
143 $property = strtolower($this->entity) . 'Array';
144
145 if (!property_exists($this, $property)) {
146 return;
147 }
148
149 $propertyValue = &$this->{$property};
150
151 switch ($a_name) {
152 case 'Forum':
153 $query_num_posts = "SELECT COUNT(pos_pk) cnt FROM frm_posts WHERE pos_top_fk = " . $this->db->quote(
154 $this->lastHandledForumId,
155 'integer'
156 );
157 $res_pos = $this->db->query($query_num_posts);
158 $data_pos = $this->db->fetchAssoc($res_pos);
159 $num_posts = (int) $data_pos['cnt'];
160
161 $query_num_threads = "SELECT COUNT(thr_pk) cnt FROM frm_threads WHERE thr_top_fk = " . $this->db->quote(
162 $this->lastHandledForumId,
163 'integer'
164 );
165 $res_thr = $this->db->query($query_num_threads);
166 $data_thr = $this->db->fetchAssoc($res_thr);
167 $num_threads = (int) $data_thr['cnt'];
168
169 $update_str = null;
170 if ($this->lastHandledPostId !== 0) {
171 $update_str = implode('#', [
172 (string) $this->lastHandledForumId,
173 (string) $this->lastHandledThreadId,
174 (string) $this->lastHandledPostId
175 ]);
176 }
177
178 $this->db->manipulateF(
179 "UPDATE frm_data
180 SET top_last_post = %s,
181 top_num_posts = %s,
182 top_num_threads = %s,
183 top_usr_id = %s
184 WHERE top_frm_fk = %s",
185 ['text', 'integer', 'integer', 'integer', 'integer'],
186 [$update_str, $num_posts, $num_threads, $this->frm_last_mapped_top_usr_id, $this->forum_obj_id]
187 );
188
189 ilLPStatusWrapper::_refreshStatus($this->forum->getId());
190 break;
191
192 case 'Id':
193 $propertyValue['Id'] = $this->cdata;
194 break;
195
196 case 'StyleId':
197 $x['StyleId'] = $this->cdata;
198 break;
199
200 case 'ObjId':
201 $propertyValue['ObjId'] = $this->cdata;
202 break;
203
204 case 'Title':
205 $propertyValue['Title'] = $this->cdata;
206 break;
207
208 case 'Description':
209 $propertyValue['Description'] = $this->cdata;
210 break;
211
212 case 'DefaultView':
213 $propertyValue['DefaultView'] = $this->cdata;
214 break;
215
216 case 'Pseudonyms':
217 $propertyValue['Pseudonyms'] = $this->cdata;
218 break;
219
220 case 'Statistics':
221 $propertyValue['Statistics'] = $this->cdata;
222 break;
223
224 case 'ThreadRatings':
225 $propertyValue['ThreadRatings'] = $this->cdata;
226 break;
227
228 case 'PostingActivation':
229 $propertyValue['PostingActivation'] = $this->cdata;
230 break;
231
232 case 'PresetSubject':
233 $propertyValue['PresetSubject'] = $this->cdata;
234 break;
235
236 case 'PresetRe':
237 $propertyValue['PresetRe'] = $this->cdata;
238 break;
239
240 case 'NotificationType':
241 $propertyValue['NotificationType'] = $this->cdata;
242 break;
243
244 case 'NotificationEvents':
245 $propertyValue['NotificationEvents'] = $this->cdata;
246 break;
247
248 case 'ForceNotification':
249 $propertyValue['ForceNotification'] = $this->cdata;
250 break;
251
252 case 'ToggleNotification':
253 $propertyValue['ToggleNotification'] = $this->cdata;
254 break;
255
256 case 'LastPost':
257 $propertyValue['LastPost'] = $this->cdata;
258 break;
259
260 case 'Moderator':
261 $propertyValue['Moderator'] = $this->cdata;
262 break;
263
264 case 'CreateDate':
265 $propertyValue['CreateDate'] = $this->cdata;
266 break;
267
268 case 'UpdateDate':
269 $propertyValue['UpdateDate'] = $this->cdata;
270 break;
271
272 case 'FileUpload':
273 $propertyValue['FileUpload'] = $this->cdata;
274 break;
275
276 case 'UpdateUserId':
277 $propertyValue['UpdateUserId'] = $this->cdata;
278 break;
279
280 case 'AuthorId':
281 $propertyValue['AuthorId'] = $this->cdata;
282 break;
283 case 'isAuthorModerator':
284 $propertyValue['isAuthorModerator'] = $this->cdata;
285 break;
286
287 case 'UserId':
288 $propertyValue['UserId'] = $this->cdata;
289 if ($this->entity === 'forum' && $this->forumArray !== []) {
291 // createSettings accesses superglobal $_GET array, which can cause problems
292 // with public_notifications of block settings
293 $this->forum->createSettings();
294
295 $forum_array = $this->getUserIdAndAlias(
296 (int) ($this->forumArray['UserId'] ?? 0),
297 ''
298 );
299 $this->frm_last_mapped_top_usr_id = $forum_array['usr_id'];
300
301 $update_forum_array = $this->getUserIdAndAlias(
302 (int) ($this->forumArray['UpdateUserId'] ?? 0),
303 ''
304 );
305 // Store old user id
306 // Manipulate user object
307 // changed smeyer 28.7.16: the session id is not manipulated
308 // anymore. Instead the user is passwd ilObjForum::update()
309 $this->forum->setTitle(ilUtil::stripSlashes((string) ($this->forumArray["Title"] ?? '')));
310 $this->forum->setDescription(ilUtil::stripSlashes((string) ($this->forumArray["Description"] ?? '')));
311 $this->forum->update();
312 $this->forum->updateMoficationUserId($update_forum_array['usr_id']);
313
314 $newObjProp = ilForumProperties::getInstance($this->forum->getId());
315 $newObjProp->setDefaultView((int) ($this->forumArray['DefaultView'] ?? ilForumProperties::VIEW_TREE));
316 $newObjProp->setAnonymisation((bool) ($this->forumArray['Pseudonyms'] ?? false));
317 $newObjProp->setStatisticsStatus((bool) ($this->forumArray['Statistics'] ?? false));
318 $newObjProp->setIsThreadRatingEnabled((bool) ($this->forumArray['ThreadRatings'] ?? false));
319 $newObjProp->setPostActivation((bool) ($this->forumArray['PostingActivation'] ?? false));
320 $newObjProp->setPresetSubject((bool) ($this->forumArray['PresetSubject'] ?? false));
321 $newObjProp->setAddReSubject((bool) ($this->forumArray['PresetRe'] ?? false));
322 $newObjProp->setNotificationType((string) ($this->forumArray['NotificationType'] ?: 'all_users'));
323 $newObjProp->setInterestedEvents((int) ($this->forumArray['NotificationEvents'] ?? 0));
324 $newObjProp->setAdminForceNoti((bool) ($this->forumArray['ForceNotification'] ?? false));
325 $newObjProp->setUserToggleNoti((bool) ($this->forumArray['ToggleNotification'] ?? false));
326 $newObjProp->setFileUploadAllowed((bool) ($this->forumArray['FileUpload'] ?? false));
327 $newObjProp->setThreadSorting((int) ($this->forumArray['Sorting'] ?? ilForumProperties::THREAD_SORTING_DEFAULT));
328 $newObjProp->setMarkModeratorPosts((bool) ($this->forumArray['MarkModeratorPosts'] ?? false));
329 $newObjProp->update();
330
331 $id = $this->getNewForumPk();
332 $this->forum_obj_id = $newObjProp->getObjId();
333 $this->mapping['frm'][$this->forumArray['Id']] = $id;
334 $this->lastHandledForumId = $id;
335
336 $this->importMapping->addMapping(
337 'Services/COPage',
338 'pg',
339 'frm:' . $this->forumArray['ObjId'],
340 'frm:' . $this->forum->getId()
341 );
342
343 $this->forumArray = [];
344 }
345 break;
346
347 case 'Thread':
348 $update_str = null;
349 if ($this->lastHandledPostId !== 0) {
350 $update_str = implode('#', [
351 (string) $this->lastHandledForumId,
352 (string) $this->lastHandledThreadId,
353 (string) $this->lastHandledPostId
354 ]);
355 }
356
357 $this->db->manipulateF(
358 "UPDATE frm_threads SET thr_last_post = %s WHERE thr_pk = %s",
359 ['text', 'integer'],
360 [$update_str, $this->lastHandledThreadId]
361 );
362 break;
363
364 case 'Subject':
365 $propertyValue['Subject'] = $this->cdata;
366 break;
367
368 case 'Alias':
369 $propertyValue['Alias'] = $this->cdata;
370 break;
371
372 case 'Sticky':
373 $propertyValue['Sticky'] = $this->cdata;
374 break;
375
376 case 'OrderSequenceIndex':
377 $propertyValue['OrderSequenceIndex'] = $this->cdata;
378 break;
379
380 case 'Sorting':
381 $propertyValue['Sorting'] = $this->cdata;
382 break;
383
384 case 'MarkModeratorPosts':
385 $propertyValue['MarkModeratorPosts'] = $this->cdata;
386 break;
387
388 case 'Closed':
389 $propertyValue['Closed'] = $this->cdata;
390
391 if ($this->entity === 'thread' && $this->lastHandledForumId && $this->threadArray !== []) {
392 $this->forumThread = new ilForumTopic();
393 $this->forumThread->setId((int) ($this->threadArray['Id'] ?? 0));
394 $this->forumThread->setForumId($this->lastHandledForumId);
395 $this->forumThread->setSubject(ilUtil::stripSlashes((string) ($this->threadArray['Subject'] ?? '')));
396 $this->forumThread->setSticky((bool) ($this->threadArray['Sticky'] ?? false));
397 $this->forumThread->setOrderSequenceIndex((int) ($this->threadArray['OrderSequenceIndex'] ?? 0));
398 $this->forumThread->setClosed((bool) ($this->threadArray['Closed'] ?? false));
399
400 $this->forumThread->setImportName(
401 isset($this->threadArray['ImportName']) ?
402 ilUtil::stripSlashes($this->threadArray['ImportName']) :
403 null
404 );
405 $this->forumThread->setCreateDate($this->threadArray['CreateDate']);
406 $this->forumThread->setChangeDate($this->threadArray['UpdateDate']);
407
408 $usr_data = $this->getUserIdAndAlias(
409 (int) ($this->threadArray['UserId'] ?? 0),
410 ilUtil::stripSlashes((string) ($this->threadArray['Alias'] ?? ''))
411 );
412
413 $this->forumThread->setDisplayUserId($usr_data['usr_id']);
414 $this->forumThread->setUserAlias($usr_data['usr_alias']);
415
416 if (version_compare($this->getSchemaVersion(), '4.5.0', '<=')) {
417 $this->threadArray['AuthorId'] = $this->threadArray['UserId'];
418 }
419
420 $author_id_data = $this->getUserIdAndAlias(
421 (int) ($this->threadArray['AuthorId'] ?? 0)
422 );
423 $this->forumThread->setThrAuthorId($author_id_data['usr_id']);
424
425 $this->forumThread->insert();
426
427 $this->mapping['thr'][$this->threadArray['Id']] = $this->forumThread->getId();
428 $this->lastHandledThreadId = $this->forumThread->getId();
429 $this->threadArray = [];
430 }
431 break;
432
433 case 'Post':
434 break;
435
436 case 'Censorship':
437 $propertyValue['Censorship'] = $this->cdata;
438 break;
439
440 case 'CensorshipMessage':
441 $propertyValue['CensorshipMessage'] = $this->cdata;
442 break;
443
444 case 'Notification':
445 $propertyValue['Notification'] = $this->cdata;
446 break;
447
448 case 'ImportName':
449 $propertyValue['ImportName'] = $this->cdata;
450 break;
451
452 case 'Status':
453 $propertyValue['Status'] = $this->cdata;
454 break;
455
456 case 'Message':
457 $propertyValue['Message'] = $this->cdata;
458 break;
459
460 case 'Lft':
461 $propertyValue['Lft'] = $this->cdata;
462 break;
463
464 case 'Rgt':
465 $propertyValue['Rgt'] = $this->cdata;
466 break;
467
468 case 'Depth':
469 $propertyValue['Depth'] = $this->cdata;
470 break;
471
472 case 'ParentId':
473 $propertyValue['ParentId'] = $this->cdata;
474
475 if (
476 $this->entity === 'post' &&
477 $this->lastHandledForumId &&
478 $this->postArray !== [] &&
479 $this->forumThread &&
480 $this->lastHandledThreadId
481 ) {
482 $this->forumPost = new ilForumPost();
483 $this->forumPost->setThread($this->forumThread);
484
485 $this->forumPost->setId((int) $this->postArray['Id']);
486 $this->forumPost->setCensorship((bool) ($this->postArray['Censorship'] ?? false));
487 $this->forumPost->setCensorshipComment(
488 ilUtil::stripSlashes((string) ($this->postArray['CensorshipMessage'] ?? ''))
489 );
490 $this->forumPost->setNotification((bool) ($this->postArray['Notification'] ?? false));
491 $this->forumPost->setStatus((bool) ($this->postArray['Status'] ?? false));
492 $purifier = ilHtmlPurifierFactory::getInstanceByType('frm_post');
493 $this->forumPost->setMessage($purifier->purify((string) ($this->postArray['Message'] ?? '')));
494 $this->forumPost->setSubject(ilUtil::stripSlashes((string) ($this->postArray['Subject'] ?? '')));
495 $this->forumPost->setLft((int) $this->postArray['Lft']);
496 $this->forumPost->setRgt((int) $this->postArray['Rgt']);
497 $this->forumPost->setDepth((int) $this->postArray['Depth']);
498 $this->forumPost->setParentId((int) $this->postArray['ParentId']);
499 $this->forumPost->setThreadId($this->lastHandledThreadId);
500 $this->forumPost->setForumId($this->lastHandledForumId);
501
502 $this->forumPost->setImportName(
503 isset($this->postArray['ImportName']) ?
504 ilUtil::stripSlashes($this->postArray['ImportName']) :
505 null
506 );
507 $this->forumPost->setCreateDate($this->postArray['CreateDate']);
508 $this->forumPost->setChangeDate($this->postArray['UpdateDate']);
509
510 $usr_data = $this->getUserIdAndAlias(
511 (int) ($this->postArray['UserId'] ?? 0),
512 ilUtil::stripSlashes((string) ($this->postArray['Alias'] ?? ''))
513 );
514 $update_usr_data = $this->getUserIdAndAlias(
515 (int) ($this->postArray['UpdateUserId'] ?? 0)
516 );
517 $this->forumPost->setDisplayUserId($usr_data['usr_id']);
518 $this->forumPost->setUserAlias($usr_data['usr_alias']);
519 $this->forumPost->setUpdateUserId($update_usr_data['usr_id']);
520
521 if (version_compare($this->getSchemaVersion(), '4.5.0', '<=')) {
522 $this->postArray['AuthorId'] = $this->postArray['UserId'];
523 }
524 $author_id_data = $this->getUserIdAndAlias(
525 (int) ($this->postArray['AuthorId'] ?? 0)
526 );
527 $this->forumPost->setPosAuthorId((int) $author_id_data['usr_id']);
528
529 if (isset($this->postArray['isAuthorModerator']) && $this->postArray['isAuthorModerator'] === 'NULL') {
530 $this->forumPost->setIsAuthorModerator(false);
531 } else {
532 $this->forumPost->setIsAuthorModerator((bool) $this->postArray['isAuthorModerator']);
533 }
534
535 $this->forumPost->insert();
536
537 if (isset($this->postArray['ParentId'], $this->mapping['pos'][$this->postArray['ParentId']])) {
538 $parentId = (int) $this->mapping['pos'][$this->postArray['ParentId']];
539 } else {
540 $parentId = 0;
541 }
542
543 $postTreeNodeId = $this->db->nextId('frm_posts_tree');
544 $this->db->insert('frm_posts_tree', [
545 'fpt_pk' => ['integer', $postTreeNodeId],
546 'thr_fk' => ['integer', $this->lastHandledThreadId],
547 'pos_fk' => ['integer', $this->forumPost->getId()],
548 'parent_pos' => ['integer', $parentId],
549 'lft' => ['integer', $this->postArray['Lft']],
550 'rgt' => ['integer', $this->postArray['Rgt']],
551 'depth' => ['integer', $this->postArray['Depth']],
552 'fpt_date' => ['timestamp', date('Y-m-d H:i:s')]
553 ]);
554
555 $this->mapping['pos'][($this->postArray['Id'] ?? 0)] = $this->forumPost->getId();
556 $this->lastHandledPostId = $this->forumPost->getId();
557
558 $media_objects_found = false;
559 foreach ($this->mediaObjects as $mob_attr) {
560 $importfile = $this->getImportDirectory() . '/' . $mob_attr['uri'];
561 if (is_file($importfile)) {
563 basename($importfile),
564 $importfile,
565 false
566 );
567 ilObjMediaObject::_saveUsage($mob->getId(), "frm:html", $this->forumPost->getId());
568
569 $this->forumPost->setMessage(
570 str_replace(
571 [
572 "src=\"" . $mob_attr["label"] . "\"",
573 "src=\"" . preg_replace(
574 "/(il)_[\d]+_(mob)_([\d]+)/",
575 "$1_0_$2_$3",
576 $mob_attr["label"]
577 ) . "\""
578 ],
579 "src=\"" . "il_" . IL_INST_ID . "_mob_" . $mob->getId() . "\"",
580 $this->forumPost->getMessage()
581 )
582 );
583 $media_objects_found = true;
584 }
585 }
586
587 if ($media_objects_found) {
588 $this->forumPost->update();
589 }
590 $this->postArray = [];
591 }
592
593 break;
594
595 case 'Content':
596 $propertyValue['content'] = $this->cdata;
597 break;
598
599 case 'Attachment':
600 $filedata = new ilFileDataForum($this->forum->getId(), $this->lastHandledPostId);
601
602 $importPath = $this->contentArray['content'];
603
604 if ($importPath !== '') {
605 $importPath = $this->getImportDirectory() . '/' . $importPath;
606
607 $newFilename = preg_replace(
608 "/^\d+_\d+(_.*)/ms",
609 $this->forum->getId() . "_" . $this->lastHandledPostId . "$1",
610 basename($importPath)
611 );
612 $path = $filedata->getForumPath();
613 $newPath = $path . '/' . $newFilename;
614 @copy($importPath, $newPath);
615 }
616 break;
617 }
618
619 $this->cdata = '';
620 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This class handles all operations on files for the forum object.
static getInstance(int $a_obj_id=0)
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)
Create new media object and update page in db and return new media object.
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="")
$path
Definition: ltiservices.php:32

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

+ Here is the call graph for this function:

◆ setHandlers()

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

Reimplemented from ilSaxParser.

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

90 : void
91 {
92 xml_set_object($a_xml_parser, $this);
93 xml_set_element_handler($a_xml_parser, [$this, 'handlerBeginTag'], [$this, 'handlerEndTag']);
94 xml_set_character_data_handler($a_xml_parser, [$this, 'handlerCharacterData']);
95 }

◆ setImportDirectory()

ilForumXMLParser::setImportDirectory ( ?string  $a_val)

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

70 : void
71 {
72 $this->importDirectory = $a_val;
73 }

◆ setImportInstallId()

ilForumXMLParser::setImportInstallId (   $id)

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

752 : void
753 {
754 $this->import_install_id = $id;
755 }

References $id.

◆ setSchemaVersion()

ilForumXMLParser::setSchemaVersion ( ?string  $schema_version)

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

85 : void
86 {
87 $this->schema_version = $schema_version;
88 }

References $schema_version.

Field Documentation

◆ $aobject

ilObjUser ilForumXMLParser::$aobject
private

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

◆ $cdata

string ilForumXMLParser::$cdata = ''
private

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

Referenced by handlerEndTag().

◆ $contentArray

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

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

◆ $db

ilDBInterface ilForumXMLParser::$db
private

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

◆ $entity

string ilForumXMLParser::$entity = ''
private

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

◆ $forum

ilObjForum ilForumXMLParser::$forum
private

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

Referenced by __construct().

◆ $forum_obj_id

int ilForumXMLParser::$forum_obj_id = null
private

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

◆ $forumArray

array ilForumXMLParser::$forumArray = []
private

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

◆ $forumPost

ilForumPost ilForumXMLParser::$forumPost = null
private

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

◆ $forumThread

ilForumTopic ilForumXMLParser::$forumThread = null
private

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

◆ $frm_last_mapped_top_usr_id

int ilForumXMLParser::$frm_last_mapped_top_usr_id = null
private

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

◆ $import_install_id

ilForumXMLParser::$import_install_id = null
private

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

◆ $importDirectory

string ilForumXMLParser::$importDirectory = null
private

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

Referenced by getImportDirectory().

◆ $importMapping

ilImportMapping ilForumXMLParser::$importMapping
private

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

Referenced by __construct().

◆ $lastHandledForumId

int ilForumXMLParser::$lastHandledForumId = null
private

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

◆ $lastHandledPostId

int ilForumXMLParser::$lastHandledPostId = null
private

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

◆ $lastHandledThreadId

int ilForumXMLParser::$lastHandledThreadId = null
private

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

◆ $mapping

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

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

◆ $mediaObjects

array ilForumXMLParser::$mediaObjects = []
private

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

◆ $postArray

array ilForumXMLParser::$postArray = []
private

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

◆ $schema_version

string ilForumXMLParser::$schema_version = null
private

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

Referenced by getSchemaVersion(), and setSchemaVersion().

◆ $threadArray

array ilForumXMLParser::$threadArray = []
private

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

◆ $user_id_mapping

array ilForumXMLParser::$user_id_mapping = []
private

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


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