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