ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
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 $attributes = [];
98
99 $style = $this->content_style_domain->styleForObjId((int) $row->obj_id);
100 if ($style->getEffectiveStyleId() > 0) {
101 $attributes['Style'] = $style->getEffectiveStyleId();
102 }
103
104 $this->xmlStartTag('Forum', $attributes);
105
106 $this->xmlElement('Id', null, (int) $row->top_pk);
107 $this->xmlElement('ObjId', null, (int) $row->obj_id);
108 $this->xmlElement('Title', null, $row->title);
109 $this->xmlElement('Description', null, $row->description);
110 $this->xmlElement('DefaultView', null, (int) $row->default_view);
111 $this->xmlElement('Pseudonyms', null, (int) $row->anonymized);
112 $this->xmlElement('Statistics', null, (int) $row->statistics_enabled);
113 $this->xmlElement('ThreadRatings', null, (int) $row->thread_rating);
114 $this->xmlElement('MarkModeratorPosts', null, (int) $row->mark_mod_posts);
115 $this->xmlElement('PostingActivation', null, (int) $row->post_activation);
116 $this->xmlElement('PresetSubject', null, (int) $row->preset_subject);
117 $this->xmlElement('PresetRe', null, (int) $row->add_re_subject);
118 $this->xmlElement('NotificationType', null, $row->notification_type);
119 $this->xmlElement('NotificationEvents', null, (int) $row->interested_events);
120 $this->xmlElement('ForceNotification', null, (int) $row->admin_force_noti);
121 $this->xmlElement('ToggleNotification', null, (int) $row->user_toggle_noti);
122 $this->xmlElement('LastPost', null, $row->top_last_post);
123 $this->xmlElement('Moderator', null, (int) $row->top_mods);
124 $this->xmlElement('CreateDate', null, $row->top_date);
125 $this->xmlElement('UpdateDate', null, $row->top_update);
126 $this->xmlElement('FileUpload', null, (int) $row->file_upload_allowed);
127 $this->xmlElement('UpdateUserId', null, $row->update_user);
128 $this->xmlElement('UserId', null, (int) $row->top_usr_id);
129
130 $query_thr = 'SELECT frm_threads.* ' .
131 ' FROM frm_threads ' .
132 ' INNER JOIN frm_data ON top_pk = thr_top_fk ' .
133 'WHERE top_frm_fk = ' . $ilDB->quote($this->forum_id, 'integer');
134
135 $res = $ilDB->query($query_thr);
136
137 while ($row = $ilDB->fetchObject($res)) {
138 $this->xmlStartTag('Thread');
139
140 $this->xmlElement('Id', null, (int) $row->thr_pk);
141 $this->xmlElement('Subject', null, $row->thr_subject);
142 $this->xmlElement('UserId', null, (int) $row->thr_display_user_id);
143 $this->xmlElement('AuthorId', null, (int) $row->thr_author_id);
144 $this->xmlElement('Alias', null, $row->thr_usr_alias);
145 $this->xmlElement('LastPost', null, $row->thr_last_post);
146 $this->xmlElement('CreateDate', null, $row->thr_date);
147 $this->xmlElement('UpdateDate', null, $row->thr_date);
148 $this->xmlElement('ImportName', null, $row->import_name);
149 $this->xmlElement('Sticky', null, (int) $row->is_sticky);
150 $this->xmlElement('Closed', null, (int) $row->is_closed);
151
152 $query = 'SELECT frm_posts.*, frm_posts_tree.*
153 FROM frm_posts
154 INNER JOIN frm_data
155 ON top_pk = pos_top_fk
156 INNER JOIN frm_posts_tree
157 ON pos_fk = pos_pk
158 WHERE pos_thr_fk = ' . $ilDB->quote($row->thr_pk, 'integer') . ' ';
159 $query .= ' ORDER BY frm_posts_tree.lft ASC';
160 $resPosts = $ilDB->query($query);
161
162 while ($rowPost = $ilDB->fetchObject($resPosts)) {
163 $this->xmlStartTag('Post');
164 $this->xmlElement('Id', null, (int) $rowPost->pos_pk);
165 $this->xmlElement('UserId', null, (int) $rowPost->pos_display_user_id);
166 $this->xmlElement('AuthorId', null, (int) $rowPost->pos_author_id);
167 $this->xmlElement('Alias', null, $rowPost->pos_usr_alias);
168 $this->xmlElement('Subject', null, $rowPost->pos_subject);
169 $this->xmlElement('CreateDate', null, $rowPost->pos_date);
170 $this->xmlElement('UpdateDate', null, $rowPost->pos_update);
171 $this->xmlElement('UpdateUserId', null, (int) $rowPost->update_user);
172 $this->xmlElement('Censorship', null, (int) $rowPost->pos_cens);
173 $this->xmlElement('CensorshipMessage', null, $rowPost->pos_cens_com);
174 $this->xmlElement('Notification', null, $rowPost->notify);
175 $this->xmlElement('ImportName', null, $rowPost->import_name);
176 $this->xmlElement('Status', null, (int) $rowPost->pos_status);
177 $this->xmlElement('Message', null, ilRTE::_replaceMediaObjectImageSrc($rowPost->pos_message, 0));
178
179 if ($rowPost->is_author_moderator === null) {
180 $is_moderator_string = 'NULL';
181 } else {
182 $is_moderator_string = (string) $rowPost->is_author_moderator;
183 }
184
185 $this->xmlElement('isAuthorModerator', null, $is_moderator_string);
186
187 $media_exists = false;
188 $mobs = ilObjMediaObject::_getMobsOfObject('frm:html', (int) $rowPost->pos_pk);
189 foreach ($mobs as $mob) {
190 $moblabel = 'il_' . IL_INST_ID . '_mob_' . $mob;
191 if (ilObjMediaObject::_exists($mob)) {
192 if (!$media_exists) {
193 $this->xmlStartTag('MessageMediaObjects');
194 $media_exists = true;
195 }
196
197 $mob_obj = new ilObjMediaObject($mob);
198 $imgattrs = [
199 'label' => $moblabel,
200 'uri' => $this->relative_component_path . '/' . self::LEGACY_RESOURCE_SUB_DIRECTORY . '/objects/' . 'il_' . IL_INST_ID . '_mob_' . $mob . '/' . $mob_obj->getTitle()
201 ];
202
203 $this->xmlElement('MediaObject', $imgattrs, null);
204 $mob_obj->exportFiles($this->getComponentPath() . '/' . self::LEGACY_RESOURCE_SUB_DIRECTORY);
205 }
206 }
207 if ($media_exists) {
208 $this->xmlEndTag('MessageMediaObjects');
209 }
210
211 $this->xmlElement('Lft', null, (int) $rowPost->lft);
212 $this->xmlElement('Rgt', null, (int) $rowPost->rgt);
213 $this->xmlElement('Depth', null, (int) $rowPost->depth);
214 $this->xmlElement('ParentId', null, (int) $rowPost->parent_pos);
215
216 $tmp_file_obj = new ilFileDataForum(
217 (int) $this->forum_id,
218 (int) $rowPost->pos_pk
219 );
220
221 foreach ($tmp_file_obj->getFilesOfPost() as $file) {
222 $this->xmlStartTag('Attachment');
223 copy($file['path'], $this->getComponentPath() . '/' . self::LEGACY_RESOURCE_SUB_DIRECTORY . '/' . basename($file['name']));
224 $relative_path = $this->relative_component_path . '/' . self::LEGACY_RESOURCE_SUB_DIRECTORY . '/' . basename($file['name']);
225 $this->xmlElement('Content', null, $relative_path);
226
227 $this->xmlEndTag('Attachment');
228 }
229
230 $this->xmlEndTag('Post');
231 }
232 $this->xmlEndTag('Thread');
233 }
234 $this->xmlEndTag('Forum');
235
236 return true;
237 }
238
239 public function getXML(): string
240 {
241 // Replace ascii code 11 characters because of problems with xml sax parser
242 return str_replace('&#11;', '', $this->xmlDumpMem(false));
243 }
244}
$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|false $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