ILIAS  release_8 Revision v8.24
class.ilForumXMLWriter.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
32{
33 public ?int $forum_id = 0;
34 private ?string $target_dir_relative;
35 private ?string $target_dir_absolute;
36
37 public function __construct()
38 {
40 }
41
42 public function setForumId(int $id): void
43 {
44 $this->forum_id = $id;
45 }
46
47 public function setFileTargetDirectories(string $a_rel, string $a_abs): void
48 {
49 $this->target_dir_relative = $a_rel;
50 $this->target_dir_absolute = $a_abs;
51 }
52
53 public function start(): bool
54 {
55 global $DIC;
56 $ilDB = $DIC->database();
57
58 ilFileUtils::makeDir($this->target_dir_absolute . "/objects");
59
60 $query_frm = '
61 SELECT *
62 FROM object_data od
63 INNER JOIN frm_data
64 ON top_frm_fk = od.obj_id
65 LEFT JOIN frm_settings fs
66 ON fs.obj_id = od.obj_id
67 WHERE od.obj_id = ' . $ilDB->quote($this->forum_id, 'integer');
68
69 $res = $ilDB->query($query_frm);
70 $row = $ilDB->fetchObject($res);
71
72 $this->xmlStartTag("Forum", null);
73
74 $this->xmlElement("Id", null, (int) $row->top_pk);
75 $this->xmlElement("ObjId", null, (int) $row->obj_id);
76 $this->xmlElement("Title", null, $row->title);
77 $this->xmlElement("Description", null, $row->description);
78 $this->xmlElement("DefaultView", null, (int) $row->default_view);
79 $this->xmlElement("Pseudonyms", null, (int) $row->anonymized);
80 $this->xmlElement("Statistics", null, (int) $row->statistics_enabled);
81 $this->xmlElement("ThreadRatings", null, (int) $row->thread_rating);
82 $this->xmlElement("Sorting", null, (int) $row->thread_sorting);
83 $this->xmlElement("MarkModeratorPosts", null, (int) $row->mark_mod_posts);
84 $this->xmlElement("PostingActivation", null, (int) $row->post_activation);
85 $this->xmlElement("PresetSubject", null, (int) $row->preset_subject);
86 $this->xmlElement("PresetRe", null, (int) $row->add_re_subject);
87 $this->xmlElement("NotificationType", null, $row->notification_type);
88 $this->xmlElement("NotificationEvents", null, (int) $row->interested_events);
89 $this->xmlElement("ForceNotification", null, (int) $row->admin_force_noti);
90 $this->xmlElement("ToggleNotification", null, (int) $row->user_toggle_noti);
91 $this->xmlElement("LastPost", null, $row->top_last_post);
92 $this->xmlElement("Moderator", null, (int) $row->top_mods);
93 $this->xmlElement("CreateDate", null, $row->top_date);
94 $this->xmlElement("UpdateDate", null, $row->top_update);
95 $this->xmlElement("FileUpload", null, (int) $row->file_upload_allowed);
96 $this->xmlElement("UpdateUserId", null, $row->update_user);
97 $this->xmlElement("UserId", null, (int) $row->top_usr_id);
98
99 $query_thr = "SELECT frm_threads.* " .
100 " FROM frm_threads " .
101 " INNER JOIN frm_data ON top_pk = thr_top_fk " .
102 'WHERE top_frm_fk = ' . $ilDB->quote($this->forum_id, 'integer');
103
104 $res = $ilDB->query($query_thr);
105
106 while ($row = $ilDB->fetchObject($res)) {
107 $this->xmlStartTag("Thread");
108
109 $this->xmlElement("Id", null, (int) $row->thr_pk);
110 $this->xmlElement("Subject", null, $row->thr_subject);
111 $this->xmlElement("UserId", null, (int) $row->thr_display_user_id);
112 $this->xmlElement("AuthorId", null, (int) $row->thr_author_id);
113 $this->xmlElement("Alias", null, $row->thr_usr_alias);
114 $this->xmlElement("LastPost", null, $row->thr_last_post);
115 $this->xmlElement("CreateDate", null, $row->thr_date);
116 $this->xmlElement("UpdateDate", null, $row->thr_date);
117 $this->xmlElement("ImportName", null, $row->import_name);
118 $this->xmlElement("Sticky", null, (int) $row->is_sticky);
119 $this->xmlElement("OrderSequenceIndex", null, (int) $row->thread_sorting);
120 $this->xmlElement("Closed", null, (int) $row->is_closed);
121
122 $query = 'SELECT frm_posts.*, frm_posts_tree.*
123 FROM frm_posts
124 INNER JOIN frm_data
125 ON top_pk = pos_top_fk
126 INNER JOIN frm_posts_tree
127 ON pos_fk = pos_pk
128 WHERE pos_thr_fk = ' . $ilDB->quote($row->thr_pk, 'integer') . ' ';
129 $query .= " ORDER BY frm_posts_tree.lft ASC";
130 $resPosts = $ilDB->query($query);
131
132 while ($rowPost = $ilDB->fetchObject($resPosts)) {
133 $this->xmlStartTag("Post");
134 $this->xmlElement("Id", null, (int) $rowPost->pos_pk);
135 $this->xmlElement("UserId", null, (int) $rowPost->pos_display_user_id);
136 $this->xmlElement("AuthorId", null, (int) $rowPost->pos_author_id);
137 $this->xmlElement("Alias", null, $rowPost->pos_usr_alias);
138 $this->xmlElement("Subject", null, $rowPost->pos_subject);
139 $this->xmlElement("CreateDate", null, $rowPost->pos_date);
140 $this->xmlElement("UpdateDate", null, $rowPost->pos_update);
141 $this->xmlElement("UpdateUserId", null, (int) $rowPost->update_user);
142 $this->xmlElement("Censorship", null, (int) $rowPost->pos_cens);
143 $this->xmlElement("CensorshipMessage", null, $rowPost->pos_cens_com);
144 $this->xmlElement("Notification", null, $rowPost->notify);
145 $this->xmlElement("ImportName", null, $rowPost->import_name);
146 $this->xmlElement("Status", null, (int) $rowPost->pos_status);
147 $this->xmlElement("Message", null, ilRTE::_replaceMediaObjectImageSrc($rowPost->pos_message, 0));
148
149 if ($rowPost->is_author_moderator === null) {
150 $is_moderator_string = 'NULL';
151 } else {
152 $is_moderator_string = (string) $rowPost->is_author_moderator;
153 }
154
155 $this->xmlElement("isAuthorModerator", null, $is_moderator_string);
156
157 $media_exists = false;
158 $mobs = ilObjMediaObject::_getMobsOfObject('frm:html', (int) $rowPost->pos_pk);
159 foreach ($mobs as $mob) {
160 $moblabel = "il_" . IL_INST_ID . "_mob_" . $mob;
161 if (ilObjMediaObject::_exists($mob)) {
162 if (!$media_exists) {
163 $this->xmlStartTag("MessageMediaObjects");
164 $media_exists = true;
165 }
166
167 $mob_obj = new ilObjMediaObject($mob);
168 $imgattrs = [
169 "label" => $moblabel,
170 "uri" => $this->target_dir_relative . "/objects/" . "il_" . IL_INST_ID . "_mob_" . $mob . "/" . $mob_obj->getTitle()
171 ];
172
173 $this->xmlElement("MediaObject", $imgattrs, null);
174 $mob_obj->exportFiles($this->target_dir_absolute);
175 }
176 }
177 if ($media_exists) {
178 $this->xmlEndTag("MessageMediaObjects");
179 }
180
181 $this->xmlElement("Lft", null, (int) $rowPost->lft);
182 $this->xmlElement("Rgt", null, (int) $rowPost->rgt);
183 $this->xmlElement("Depth", null, (int) $rowPost->depth);
184 $this->xmlElement("ParentId", null, (int) $rowPost->parent_pos);
185
186 $tmp_file_obj = new ilFileDataForum(
187 (int) $this->forum_id,
188 (int) $rowPost->pos_pk
189 );
190
191 if (count($tmp_file_obj->getFilesOfPost())) {
192 foreach ($tmp_file_obj->getFilesOfPost() as $file) {
193 $this->xmlStartTag("Attachment");
194
195 copy($file['path'], $this->target_dir_absolute . "/" . basename($file['path']));
196 $content = $this->target_dir_relative . "/" . basename($file['path']);
197 $this->xmlElement("Content", null, $content);
198
199 $this->xmlEndTag("Attachment");
200 }
201 }
202
203 $this->xmlEndTag("Post");
204 }
205 $this->xmlEndTag("Thread");
206 }
207 $this->xmlEndTag("Forum");
208
209 return true;
210 }
211
212 public function getXML(): string
213 {
214 // Replace ascii code 11 characters because of problems with xml sax parser
215 return str_replace('&#11;', '', $this->xmlDumpMem(false));
216 }
217}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This class handles all operations on files for the forum object.
static makeDir(string $a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
XML writer class Class to simplify manual writing of xml documents.
setFileTargetDirectories(string $a_rel, string $a_abs)
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
static _getMobsOfObject(string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
static _replaceMediaObjectImageSrc(string $a_text, int $a_direction=0, string $nic='')
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
xmlEndTag(string $tag)
Writes an endtag.
xmlDumpMem(bool $format=true)
Returns xml document from memory.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
const IL_INST_ID
Definition: constants.php:40
global $DIC
Definition: feed.php:28
$mobs
Definition: imgupload.php:70
$res
Definition: ltiservices.php:69
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$query