ILIAS  trunk Revision v11.0_alpha-1866-gfa368f7776e
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilForumXMLWriter Class Reference

XML writer class Class to simplify manual writing of xml documents. More...

+ Inheritance diagram for ilForumXMLWriter:
+ Collaboration diagram for ilForumXMLWriter:

Public Member Functions

 __construct (string $version='1.0', string $outEnc='utf-8', string $inEnc='utf-8')
 
 setForumId (int $id)
 
 setFileTargetDirectories (string $a_rel, string $a_abs)
 
 getComponentPath ()
 
 start ()
 
 getXML ()
 
- Public Member Functions inherited from ilXmlWriter
 __construct (string $version="1.0", string $outEnc="utf-8", string $inEnc="utf-8")
 
 xmlSetDtdDef (string $dtdDef)
 Sets dtd definition. More...
 
 xmlSetGenCmt (string $genCmt)
 Sets generated comment. More...
 
 xmlFormatData (string $data)
 Indents text for better reading. More...
 
 xmlHeader ()
 Writes xml header. More...
 
 xmlStartTag (string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
 Writes a starttag. More...
 
 xmlEndTag (string $tag)
 Writes an endtag. More...
 
 xmlData (string $data, bool $encode=true, bool $escape=true)
 Writes data. More...
 
 xmlElement (string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
 Writes a basic element (no children, just textual content) More...
 
 xmlDumpFile (string $file, bool $format=true)
 Dumps xml document from memory into a file. More...
 
 xmlDumpMem (bool $format=true)
 Returns xml document from memory. More...
 
 appendXML (string $a_str)
 append xml string to document More...
 
 xmlClear ()
 clears xmlStr More...
 

Data Fields

int $forum_id = 0
 

Private Attributes

const LEGACY_RESOURCE_SUB_DIRECTORY = 'expDir_1'
 
string $relative_component_path = null
 
string $absolute_root_export_path = null
 
readonly ILIAS Style Content DomainService $content_style_domain
 

Detailed Description

XML writer class Class to simplify manual writing of xml documents.

It only supports writing xml sequentially, because the xml document is saved in a string with no additional structure information. The author is responsible for well-formedness and validity of the xml document.

Author
Andreas Kordosz (akord.nosp@m.osz@.nosp@m.datab.nosp@m.ay.d.nosp@m.e) \

Definition at line 31 of file class.ilForumXMLWriter.php.

Constructor & Destructor Documentation

◆ __construct()

ilForumXMLWriter::__construct ( string  $version = '1.0',
string  $outEnc = 'utf-8',
string  $inEnc = 'utf-8' 
)

Definition at line 41 of file class.ilForumXMLWriter.php.

References $DIC, ilXmlWriter\$inEnc, ilXmlWriter\$outEnc, ilXmlWriter\$version, and ILIAS\GlobalScreen\Provider\__construct().

45  {
46  global $DIC;
47 
49 
50  $this->content_style_domain = $DIC
51  ->contentStyle()
52  ->domain();
53  }
global $DIC
Definition: shib_login.php:22
__construct(Container $dic, ilPlugin $plugin)
+ Here is the call graph for this function:

Member Function Documentation

◆ getComponentPath()

ilForumXMLWriter::getComponentPath ( )

Definition at line 71 of file class.ilForumXMLWriter.php.

References $relative_component_path.

Referenced by start().

71  : string
72  {
73  return $this->absolute_root_export_path . '/' . $this->relative_component_path;
74  }
+ Here is the caller graph for this function:

◆ getXML()

ilForumXMLWriter::getXML ( )

Definition at line 237 of file class.ilForumXMLWriter.php.

References ilXmlWriter\xmlDumpMem().

237  : string
238  {
239  // Replace ascii code 11 characters because of problems with xml sax parser
240  return str_replace('', '', $this->xmlDumpMem(false));
241  }
xmlDumpMem(bool $format=true)
Returns xml document from memory.
+ Here is the call graph for this function:

◆ setFileTargetDirectories()

ilForumXMLWriter::setFileTargetDirectories ( string  $a_rel,
string  $a_abs 
)

Definition at line 60 of file class.ilForumXMLWriter.php.

References $path.

60  : 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  }
$path
Definition: ltiservices.php:29

◆ setForumId()

ilForumXMLWriter::setForumId ( int  $id)

Definition at line 55 of file class.ilForumXMLWriter.php.

References $id.

55  : void
56  {
57  $this->forum_id = $id;
58  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

◆ start()

ilForumXMLWriter::start ( )

Definition at line 76 of file class.ilForumXMLWriter.php.

References $DIC, $ilDB, $res, ilObjMediaObject\_exists(), ilObjMediaObject\_getMobsOfObject(), ilRTE\_replaceMediaObjectImageSrc(), getComponentPath(), IL_INST_ID, ilFileUtils\makeDir(), ilFileUtils\makeDirParents(), null, ilXmlWriter\xmlElement(), ilXmlWriter\xmlEndTag(), and ilXmlWriter\xmlStartTag().

76  : 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  }
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...
$res
Definition: ltiservices.php:66
const IL_INST_ID
Definition: constants.php:40
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
xmlEndTag(string $tag)
Writes an endtag.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
global $DIC
Definition: shib_login.php:22
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="-")
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)
static makeDir(string $a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
+ Here is the call graph for this function:

Field Documentation

◆ $absolute_root_export_path

string ilForumXMLWriter::$absolute_root_export_path = null
private

Definition at line 37 of file class.ilForumXMLWriter.php.

◆ $content_style_domain

readonly ILIAS Style Content DomainService ilForumXMLWriter::$content_style_domain
private

Definition at line 39 of file class.ilForumXMLWriter.php.

◆ $forum_id

int ilForumXMLWriter::$forum_id = 0

Definition at line 35 of file class.ilForumXMLWriter.php.

◆ $relative_component_path

string ilForumXMLWriter::$relative_component_path = null
private

Definition at line 36 of file class.ilForumXMLWriter.php.

Referenced by getComponentPath().

◆ LEGACY_RESOURCE_SUB_DIRECTORY

const ilForumXMLWriter::LEGACY_RESOURCE_SUB_DIRECTORY = 'expDir_1'
private

Definition at line 33 of file class.ilForumXMLWriter.php.


The documentation for this class was generated from the following file: