ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilForumXMLWriter.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
32{
33 private const string LEGACY_RESOURCE_SUB_DIRECTORY = 'expDir_1';
34
35 public ?int $forum_id = 0;
36 private ?string $relative_component_path = null;
37 private ?string $absolute_root_export_path = null;
38
39 private readonly \ILIAS\Style\Content\DomainService $content_style_domain;
40
41 public function __construct(
42 string $version = '1.0',
43 string $outEnc = 'utf-8',
44 string $inEnc = 'utf-8'
45 ) {
46 global $DIC;
47
49
50 $this->content_style_domain = $DIC
51 ->contentStyle()
52 ->domain();
53 }
54
55 public function setForumId(int $id): void
56 {
57 $this->forum_id = $id;
58 }
59
60 public function setFileTargetDirectories(string $a_rel, string $a_abs): void
61 {
62 $path = str_replace('\\', '/', $a_rel);
63 $segments = explode('/', $path);
64 array_shift($segments);
65 $a_rel = implode('/', $segments);
66
67 $this->relative_component_path = $a_rel;
68 $this->absolute_root_export_path = rtrim($a_abs, '/');
69 }
70
71 public function getComponentPath(): string
72 {
73 return $this->absolute_root_export_path . '/' . $this->relative_component_path;
74 }
75
76 public function start(): bool
77 {
78 global $DIC;
79 $ilDB = $DIC->database();
80
82 ilFileUtils::makeDir($this->getComponentPath() . '/' . self::LEGACY_RESOURCE_SUB_DIRECTORY);
83 ilFileUtils::makeDir($this->getComponentPath() . '/' . self::LEGACY_RESOURCE_SUB_DIRECTORY . '/objects');
84
85 $query_frm = '
86 SELECT *
87 FROM object_data od
88 INNER JOIN frm_data
89 ON top_frm_fk = od.obj_id
90 LEFT JOIN frm_settings fs
91 ON fs.obj_id = od.obj_id
92 WHERE od.obj_id = ' . $ilDB->quote($this->forum_id, 'integer');
93
94 $res = $ilDB->query($query_frm);
95 $row = $ilDB->fetchObject($res);
96
97 $style = $this->content_style_domain->styleForObjId((int) $row->obj_id);
98 $attributes = [
99 'Style' => $style->getStyleId()
100 ];
101
102 $this->xmlStartTag('Forum', $attributes);
103
104 $this->xmlElement('Id', null, (int) $row->top_pk);
105 $this->xmlElement('ObjId', null, (int) $row->obj_id);
106 $this->xmlElement('Title', null, $row->title);
107 $this->xmlElement('Description', null, $row->description);
108 $this->xmlElement('DefaultView', null, (int) $row->default_view);
109 $this->xmlElement('Pseudonyms', null, (int) $row->anonymized);
110 $this->xmlElement('Statistics', null, (int) $row->statistics_enabled);
111 $this->xmlElement('ThreadRatings', null, (int) $row->thread_rating);
112 $this->xmlElement('MarkModeratorPosts', null, (int) $row->mark_mod_posts);
113 $this->xmlElement('PostingActivation', null, (int) $row->post_activation);
114 $this->xmlElement('PresetSubject', null, (int) $row->preset_subject);
115 $this->xmlElement('PresetRe', null, (int) $row->add_re_subject);
116 $this->xmlElement('NotificationType', null, $row->notification_type);
117 $this->xmlElement('NotificationEvents', null, (int) $row->interested_events);
118 $this->xmlElement('ForceNotification', null, (int) $row->admin_force_noti);
119 $this->xmlElement('ToggleNotification', null, (int) $row->user_toggle_noti);
120 $this->xmlElement('LastPost', null, $row->top_last_post);
121 $this->xmlElement('Moderator', null, (int) $row->top_mods);
122 $this->xmlElement('CreateDate', null, $row->top_date);
123 $this->xmlElement('UpdateDate', null, $row->top_update);
124 $this->xmlElement('FileUpload', null, (int) $row->file_upload_allowed);
125 $this->xmlElement('UpdateUserId', null, $row->update_user);
126 $this->xmlElement('UserId', null, (int) $row->top_usr_id);
127
128 $query_thr = 'SELECT frm_threads.* ' .
129 ' FROM frm_threads ' .
130 ' INNER JOIN frm_data ON top_pk = thr_top_fk ' .
131 'WHERE top_frm_fk = ' . $ilDB->quote($this->forum_id, 'integer');
132
133 $res = $ilDB->query($query_thr);
134
135 while ($row = $ilDB->fetchObject($res)) {
136 $this->xmlStartTag('Thread');
137
138 $this->xmlElement('Id', null, (int) $row->thr_pk);
139 $this->xmlElement('Subject', null, $row->thr_subject);
140 $this->xmlElement('UserId', null, (int) $row->thr_display_user_id);
141 $this->xmlElement('AuthorId', null, (int) $row->thr_author_id);
142 $this->xmlElement('Alias', null, $row->thr_usr_alias);
143 $this->xmlElement('LastPost', null, $row->thr_last_post);
144 $this->xmlElement('CreateDate', null, $row->thr_date);
145 $this->xmlElement('UpdateDate', null, $row->thr_date);
146 $this->xmlElement('ImportName', null, $row->import_name);
147 $this->xmlElement('Sticky', null, (int) $row->is_sticky);
148 $this->xmlElement('Closed', null, (int) $row->is_closed);
149
150 $query = 'SELECT frm_posts.*, frm_posts_tree.*
151 FROM frm_posts
152 INNER JOIN frm_data
153 ON top_pk = pos_top_fk
154 INNER JOIN frm_posts_tree
155 ON pos_fk = pos_pk
156 WHERE pos_thr_fk = ' . $ilDB->quote($row->thr_pk, 'integer') . ' ';
157 $query .= ' ORDER BY frm_posts_tree.lft ASC';
158 $resPosts = $ilDB->query($query);
159
160 while ($rowPost = $ilDB->fetchObject($resPosts)) {
161 $this->xmlStartTag('Post');
162 $this->xmlElement('Id', null, (int) $rowPost->pos_pk);
163 $this->xmlElement('UserId', null, (int) $rowPost->pos_display_user_id);
164 $this->xmlElement('AuthorId', null, (int) $rowPost->pos_author_id);
165 $this->xmlElement('Alias', null, $rowPost->pos_usr_alias);
166 $this->xmlElement('Subject', null, $rowPost->pos_subject);
167 $this->xmlElement('CreateDate', null, $rowPost->pos_date);
168 $this->xmlElement('UpdateDate', null, $rowPost->pos_update);
169 $this->xmlElement('UpdateUserId', null, (int) $rowPost->update_user);
170 $this->xmlElement('Censorship', null, (int) $rowPost->pos_cens);
171 $this->xmlElement('CensorshipMessage', null, $rowPost->pos_cens_com);
172 $this->xmlElement('Notification', null, $rowPost->notify);
173 $this->xmlElement('ImportName', null, $rowPost->import_name);
174 $this->xmlElement('Status', null, (int) $rowPost->pos_status);
175 $this->xmlElement('Message', null, ilRTE::_replaceMediaObjectImageSrc($rowPost->pos_message, 0));
176
177 if ($rowPost->is_author_moderator === null) {
178 $is_moderator_string = 'NULL';
179 } else {
180 $is_moderator_string = (string) $rowPost->is_author_moderator;
181 }
182
183 $this->xmlElement('isAuthorModerator', null, $is_moderator_string);
184
185 $media_exists = false;
186 $mobs = ilObjMediaObject::_getMobsOfObject('frm:html', (int) $rowPost->pos_pk);
187 foreach ($mobs as $mob) {
188 $moblabel = 'il_' . IL_INST_ID . '_mob_' . $mob;
189 if (ilObjMediaObject::_exists($mob)) {
190 if (!$media_exists) {
191 $this->xmlStartTag('MessageMediaObjects');
192 $media_exists = true;
193 }
194
195 $mob_obj = new ilObjMediaObject($mob);
196 $imgattrs = [
197 'label' => $moblabel,
198 'uri' => $this->relative_component_path . '/' . self::LEGACY_RESOURCE_SUB_DIRECTORY . '/objects/' . 'il_' . IL_INST_ID . '_mob_' . $mob . '/' . $mob_obj->getTitle()
199 ];
200
201 $this->xmlElement('MediaObject', $imgattrs, null);
202 $mob_obj->exportFiles($this->getComponentPath() . '/' . self::LEGACY_RESOURCE_SUB_DIRECTORY);
203 }
204 }
205 if ($media_exists) {
206 $this->xmlEndTag('MessageMediaObjects');
207 }
208
209 $this->xmlElement('Lft', null, (int) $rowPost->lft);
210 $this->xmlElement('Rgt', null, (int) $rowPost->rgt);
211 $this->xmlElement('Depth', null, (int) $rowPost->depth);
212 $this->xmlElement('ParentId', null, (int) $rowPost->parent_pos);
213
214 $tmp_file_obj = new ilFileDataForum(
215 (int) $this->forum_id,
216 (int) $rowPost->pos_pk
217 );
218
219 foreach ($tmp_file_obj->getFilesOfPost() as $file) {
220 $this->xmlStartTag('Attachment');
221 copy($file['path'], $this->getComponentPath() . '/' . self::LEGACY_RESOURCE_SUB_DIRECTORY . '/' . basename($file['name']));
222 $relative_path = $this->relative_component_path . '/' . self::LEGACY_RESOURCE_SUB_DIRECTORY . '/' . basename($file['name']);
223 $this->xmlElement('Content', null, $relative_path);
224
225 $this->xmlEndTag('Attachment');
226 }
227
228 $this->xmlEndTag('Post');
229 }
230 $this->xmlEndTag('Thread');
231 }
232 $this->xmlEndTag('Forum');
233
234 return true;
235 }
236
237 public function getXML(): string
238 {
239 // Replace ascii code 11 characters because of problems with xml sax parser
240 return str_replace('&#11;', '', $this->xmlDumpMem(false));
241 }
242}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
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.
readonly ILIAS Style Content DomainService $content_style_domain
setFileTargetDirectories(string $a_rel, string $a_abs)
const string LEGACY_RESOURCE_SUB_DIRECTORY
__construct(string $version='1.0', string $outEnc='utf-8', string $inEnc='utf-8')
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
$path
Definition: ltiservices.php:30
$res
Definition: ltiservices.php:69
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26