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
190 break;
191
192 case 'Id':
194 break;
195
196 case 'StyleId':
198 break;
199
200 case 'ObjId':
202 break;
203
204 case 'Title':
206 break;
207
208 case 'Description':
210 break;
211
212 case 'DefaultView':
214 break;
215
216 case 'Pseudonyms':
218 break;
219
220 case 'Statistics':
222 break;
223
224 case 'ThreadRatings':
226 break;
227
228 case 'PostingActivation':
230 break;
231
232 case 'PresetSubject':
234 break;
235
236 case 'PresetRe':
238 break;
239
240 case 'NotificationType':
242 break;
243
244 case 'NotificationEvents':
246 break;
247
248 case 'ForceNotification':
250 break;
251
252 case 'ToggleNotification':
254 break;
255
256 case 'LastPost':
258 break;
259
260 case 'Moderator':
262 break;
263
264 case 'CreateDate':
266 break;
267
268 case 'UpdateDate':
270 break;
271
272 case 'FileUpload':
274 break;
275
276 case 'UpdateUserId':
278 break;
279
280 case 'AuthorId':
282 break;
283 case 'isAuthorModerator':
285 break;
286
287 case 'UserId':
289 if ($this->entity === 'forum' && $this->forumArray !== []) {
291
292
293 $this->forum->createSettings();
294
296 (int) ($this->forumArray['UserId'] ?? 0),
297 ''
298 );
299 $this->frm_last_mapped_top_usr_id = $forum_array['usr_id'];
300
302 (int) ($this->forumArray['UpdateUserId'] ?? 0),
303 ''
304 );
305
306
307
308
310 $this->forum->setDescription(
ilUtil::stripSlashes((
string) ($this->forumArray[
"Description"] ??
'')));
311 $this->forum->update();
312 $this->forum->updateMoficationUserId($update_forum_array['usr_id']);
313
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));
328 $newObjProp->setMarkModeratorPosts((bool) ($this->forumArray['MarkModeratorPosts'] ?? false));
329 $newObjProp->update();
330
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':
366 break;
367
368 case 'Alias':
370 break;
371
372 case 'Sticky':
374 break;
375
376 case 'OrderSequenceIndex':
378 break;
379
380 case 'Sorting':
382 break;
383
384 case 'MarkModeratorPosts':
386 break;
387
388 case 'Closed':
390
391 if ($this->entity === 'thread' && $this->lastHandledForumId && $this->threadArray !== []) {
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']) ?
403 null
404 );
405 $this->forumThread->setCreateDate($this->threadArray['CreateDate']);
406 $this->forumThread->setChangeDate($this->threadArray['UpdateDate']);
407
409 (int) ($this->threadArray['UserId'] ?? 0),
411 );
412
413 $this->forumThread->setDisplayUserId($usr_data['usr_id']);
414 $this->forumThread->setUserAlias($usr_data['usr_alias']);
415
417 $this->threadArray['AuthorId'] = $this->threadArray['UserId'];
418 }
419
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':
438 break;
439
440 case 'CensorshipMessage':
442 break;
443
444 case 'Notification':
446 break;
447
448 case 'ImportName':
450 break;
451
452 case 'Status':
454 break;
455
456 case 'Message':
458 break;
459
460 case 'Lft':
462 break;
463
464 case 'Rgt':
466 break;
467
468 case 'Depth':
470 break;
471
472 case 'ParentId':
474
475 if (
476 $this->entity === 'post' &&
477 $this->lastHandledForumId &&
478 $this->postArray !== [] &&
479 $this->forumThread &&
480 $this->lastHandledThreadId
481 ) {
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(
489 );
490 $this->forumPost->setNotification((bool) ($this->postArray['Notification'] ?? false));
491 $this->forumPost->setStatus((bool) ($this->postArray['Status'] ?? false));
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']) ?
505 null
506 );
507 $this->forumPost->setCreateDate($this->postArray['CreateDate']);
508 $this->forumPost->setChangeDate($this->postArray['UpdateDate']);
509
511 (int) ($this->postArray['UserId'] ?? 0),
513 );
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
522 $this->postArray['AuthorId'] = $this->postArray['UserId'];
523 }
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) {
561 if (is_file($importfile)) {
563 basename($importfile),
564 $importfile,
565 false
566 );
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':
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 !== '') {
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
This class handles all operations on files for the forum object.
const THREAD_SORTING_DEFAULT
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 stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")