ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilForumXMLWriter.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once "./Services/Xml/classes/class.ilXmlWriter.php";
6 include_once "./Modules/Forum/classes/class.ilFileDataForum.php";
7 
23 {
24  var $forum_id = null;
25 
33  public function __construct()
34  {
36  }
37 
38 
39  function setForumId($id)
40  {
41  $this->forum_id = $id;
42  }
43 
44 
51  function setFileTargetDirectories($a_rel, $a_abs)
52  {
53  $this->target_dir_relative = $a_rel;
54  $this->target_dir_absolute = $a_abs;
55  }
56 
57  function start()
58  {
59  global $ilDB;
60 
61  $query_frm = 'SELECT * FROM frm_settings fs '.
62  'JOIN object_data od ON fs.obj_id = od.obj_id '.
63  'JOIN frm_data ON top_frm_fk = od.obj_id '.
64  'WHERE fs.obj_id = '.$ilDB->quote($this->forum_id, 'integer');
65 
66  $res = $ilDB->query($query_frm);
67 
68  while( $row = $res->fetchRow(DB_FETCHMODE_OBJECT) )
69  {
70  break;
71  }
72 
73  $this->xmlStartTag("Forum", null);
74 
75  $this->xmlElement("Id", null, (int)$row->top_pk);
76  $this->xmlElement("ObjId", null, (int)$row->obj_id);
77  $this->xmlElement("Title", null, $row->title);
78  $this->xmlElement("Description", null, $row->description);
79  $this->xmlElement("DefaultView", null, (int)$row->default_view);
80  $this->xmlElement("Pseudonyms", null, (int)$row->anonymized);
81  $this->xmlElement("Statistics", null, (int)$row->statistics_enabled);
82  $this->xmlElement("PostingActivation", null, (int)$row->post_activation);
83  $this->xmlElement("PresetSubject", null, (int)$row->preset_subject);
84  $this->xmlElement("PresetRe", null, (int)$row->add_re_subject);
85  $this->xmlElement("NotificationType", null, $row->notification_type);
86  $this->xmlElement("ForceNotification", null, (int)$row->admin_force_noti);
87  $this->xmlElement("ToggleNotification", null, (int)$row->user_toggle_noti);
88  $this->xmlElement("LastPost", null, $row->top_last_post);
89  $this->xmlElement("Moderator", null, (int)$row->top_mods);
90  $this->xmlElement("CreateDate", null, $row->top_date);
91  $this->xmlElement("UpdateDate", null, $row->top_update);
92  $this->xmlElement("UpdateUserId", null, $row->update_user);
93  $this->xmlElement("UserId", null, (int)$row->top_usr_id);
94 
95  $query_thr = "SELECT frm_threads.* ".
96  " FROM frm_threads ".
97  " INNER JOIN frm_data ON top_pk = thr_top_fk ".
98  'WHERE top_frm_fk = '.$ilDB->quote($this->forum_id, 'integer');
99 
100  $res = $ilDB->query($query_thr);
101 
102  while( $row = $ilDB->fetchObject($res) )
103  {
104  $this->xmlStartTag("Thread");
105 
106  $this->xmlElement("Id", null, (int)$row->thr_pk);
107  $this->xmlElement("Subject", null, $row->thr_subject);
108  $this->xmlElement("UserId", null, (int)$row->thr_usr_id);
109  $this->xmlElement("Alias", null, $row->thr_usr_alias);
110  $this->xmlElement("LastPost", null, $row->thr_last_post);
111  $this->xmlElement("CreateDate", null, $row->thr_date);
112  $this->xmlElement("UpdateDate", null, $row->thr_date);
113  $this->xmlElement("ImportName", null, $row->import_name);
114  $this->xmlElement("Sticky", null, (int)$row->is_sticky);
115  $this->xmlElement("Closed", null, (int)$row->is_closed);
116 
117  $query = 'SELECT frm_posts.*, frm_posts_tree.*
118  FROM frm_posts
119  INNER JOIN frm_data
120  ON top_pk = pos_top_fk
121  INNER JOIN frm_posts_tree
122  ON pos_fk = pos_pk
123  WHERE pos_thr_fk = '.$ilDB->quote($row->thr_pk, 'integer').' ';
124  $query .= " ORDER BY frm_posts_tree.lft ASC";
125  $resPosts = $ilDB->query($query);
126 
127  $lastDepth = null;
128  while( $rowPost = $ilDB->fetchObject($resPosts) )
129  {
130  /*
131  // Used for nested postings
132  if( $rowPost->depth < $lastDepth )
133  {
134  for( $i = $rowPost->depth; $i <= $lastDepth; $i++ )
135  {
136  $this->xmlEndTag("Post");
137  }
138  }*/
139 
140  $this->xmlStartTag("Post");
141  $this->xmlElement("Id", null, (int)$rowPost->pos_pk);
142  $this->xmlElement("UserId", null, (int)$rowPost->pos_usr_id);
143  $this->xmlElement("Alias", null, $rowPost->pos_usr_alias);
144  $this->xmlElement("Subject", null, $rowPost->pos_subject);
145  $this->xmlElement("CreateDate", null, $rowPost->pos_date);
146  $this->xmlElement("UpdateDate", null, $rowPost->pos_update);
147  $this->xmlElement("UpdateUserId", null, (int)$rowPost->update_user);
148  $this->xmlElement("Censorship", null, (int)$rowPost->pos_cens);
149  $this->xmlElement("CensorshipMessage", null, $rowPost->pos_cens_com);
150  $this->xmlElement("Notification", null, $rowPost->notify);
151  $this->xmlElement("ImportName", null, $rowPost->import_name);
152  $this->xmlElement("Status", null, (int)$rowPost->pos_status);
153  $this->xmlElement("Message", null, $rowPost->pos_message);
154  $this->xmlElement("Lft", null, (int)$rowPost->lft);
155  $this->xmlElement("Rgt", null, (int)$rowPost->rgt);
156  $this->xmlElement("Depth", null, (int)$rowPost->depth);
157  $this->xmlElement("ParentId", null, (int)$rowPost->parent_pos);
158 
159  $tmp_file_obj = new ilFileDataForum(
160  $this->forum_id, $rowPost->pos_pk
161  );
162 
163  $set = array();
164  if ( count($tmp_file_obj->getFilesOfPost()) )
165  {
166  foreach ($tmp_file_obj->getFilesOfPost() as $file)
167  {
168  $this->xmlStartTag("Attachment");
169 
170  copy($file['path'], $this->target_dir_absolute."/".basename($file['path']));
171  $content = $this->target_dir_relative."/".basename($file['path']);
172  $this->xmlElement("Content", null, $content);
173 
174 
175  /* $thumb = $tmp_file_obj->getThumbFilename($file);
176  if($thumb)
177  {
178  copy($tmp_file_obj->getThumbPath().'/'.$thumb, $this->target_dir_absolute."/".$thumb);
179  $contentThumb = $this->target_dir_relative."/".$thumb;
180  $this->xmlElement("ContentThumbnail", null, $contentThumb);
181  }*/
182  ++$i;
183  $this->xmlEndTag("Attachment");
184  }
185  }
186 
187  //Used for nested postings
188  //$lastDepth = $rowPost->depth;
189 
190  $this->xmlEndTag("Post");
191  }
192  /*
193  // Used for nested postings
194  if( $lastDepth )
195  {
196  for( $i = 1; $i <= $lastDepth ; $i++ )
197  {
198  $this->xmlEndTag("Post");
199  }
200 
201  $lastDepth = null;
202  }*/
203  $this->xmlEndTag("Thread");
204  }
205  $this->xmlEndTag("Forum");
206 
207  return true;
208  }
209 
210  function getXML()
211  {
212  // Replace ascii code 11 characters because of problems with xml sax parser
213  return str_replace('&#11;', '', $this->xmlDumpMem(false));
214  }
215 
216 }
217 
218 ?>