ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilExerciseXMLWriter.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  +-----------------------------------------------------------------------------+
5  | ILIAS open source |
6  +-----------------------------------------------------------------------------+
7  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
8  | |
9  | This program is free software; you can redistribute it and/or |
10  | modify it under the terms of the GNU General Public License |
11  | as published by the Free Software Foundation; either version 2 |
12  | of the License, or (at your option) any later version. |
13  | |
14  | This program is distributed in the hope that it will be useful, |
15  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
16  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17  | GNU General Public License for more details. |
18  | |
19  | You should have received a copy of the GNU General Public License |
20  | along with this program; if not, write to the Free Software |
21  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22  +-----------------------------------------------------------------------------+
23 */
24 
40 include_once "./classes/class.ilXmlWriter.php";
41 
43 {
44 
45  static $CONTENT_ATTACH_NO = 0;
49 
50  static $STATUS_NOT_GRADED = "NOT_GRADED";
51  static $STATUS_PASSED = "PASSED";
52  static $STATUS_FAILED = "FAILED";
59 
60 
67 
73  var $exercise;
74 
83  {
85  $this->attachFileContents = ilExerciseXMLWriter::$CONTENT_ATTACH_NO;
86  }
87 
88 
89  function setExercise(& $exercise)
90  {
91  $this->exercise = & $exercise;
92  }
93 
101  {
102  if ($attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED && !function_exists("gzencode"))
103  {
104  throw new ilExerciseException("Inflating with gzip is not supported", ilExerciseException::$ID_DEFLATE_METHOD_MISMATCH);
105  }
106  if ($attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED && !function_exists("gzcompress"))
107  {
108  throw new ilExerciseException("Inflating with zlib (compress/uncompress) is not supported", ilExerciseException::$ID_DEFLATE_METHOD_MISMATCH);
109  }
110 
111  $this->attachFileContents = $attachFileContents;
112  }
113 
114 
115  function start()
116  {
117  $this->__buildHeader();
118 
119  $attribs =array ("obj_id" => "il_".IL_INST_ID."_exc_".$this->exercise->getId());
120 
121  if ($this->exercise->getOwner())
122  $attribs["owner"] = "il_".IL_INST_ID."_usr_".$this->exercise->getOwner();
123 
124  $this->xmlStartTag("Exercise", $attribs);
125 
126  $this->xmlElement("Title", null,$this->exercise->getTitle());
127  $this->xmlElement("Description", null,$this->exercise->getDescription());
128  $this->xmlElement("Instruction", null,$this->exercise->getInstruction());
129  $this->xmlElement("DueDate", null,$this->exercise->getTimestamp());
130  $this->xmlStartTag("Files");
131 
135  $exerciseFileData = $this->exercise->file_obj;
136  $files = $exerciseFileData->getFiles();
137  if (count($files))
138  {
139  foreach ($files as $file)
140  {
141  $this->xmlStartTag("File", array ("size" => $file["size"] ));
142  $this->xmlElement("Filename", null, $file["name"]);
143  if ($this->attachFileContents)
144  {
145  $filename = $file["fullpath"];
146  if (@is_file($filename))
147  {
148  $content = @file_get_contents($filename);
149  $attribs = array ("mode"=>"PLAIN");
150  if ($this->attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED)
151  {
152  $attribs = array ("mode"=>"ZLIB");
153  $content = gzcompress($content, 9);
154  }
155  elseif ($this->attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED)
156  {
157  $attribs = array ("mode"=>"GZIP");
158  $content = gzencode($content, 9);
159  }
160  $content = base64_encode($content);
161  $this->xmlElement("Content",$attribs, $content);
162  }
163  }
164  $this->xmlEndTag("File");
165  }
166  }
167  $this->xmlEndTag("Files");
168  if ($this->attachMembers)
169  {
170  $this->xmlStartTag("Members");
171  $members = $this->exercise->getMemberListData();
172  if (count($members))
173  {
174  foreach ($members as $member)
175  {
176  $this->xmlStartTag("Member",
177  array ("usr_id" => "il_".IL_INST_ID."_usr_".$member["usr_id"]));
178  $this->attachMarking ($member);
179  $this->xmlEndTag("Member");
180  }
181  }
182  $this->xmlEndTag("Members");
183  }
184 
185 
186  $this->xmlEndTag("Exercise");
187  $this->__buildFooter();
188 
189  return true;
190  }
191 
192  function getXML()
193  {
194  return $this->xmlDumpMem(FALSE);
195  }
196 
197 
198  function __buildHeader()
199  {
200  $this->xmlSetDtdDef("<!DOCTYPE Exercise PUBLIC \"-//ILIAS//DTD ExerciseAdministration//EN\" \"".ILIAS_HTTP_PATH."/xml/ilias_exercise_3_10.dtd\">");
201  $this->xmlSetGenCmt("Exercise Object");
202  $this->xmlHeader();
203 
204  return true;
205  }
206 
207  function __buildFooter()
208  {
209 
210  }
211 
217  public function setAttachMembers ($value) {
218  $this->attachMembers = $value ? true : false;
219  }
220 
226  private function attachMarking ($a_member)
227  {
228  include_once 'Services/Tracking/classes/class.ilLPMarks.php';
229 
230  $marks = new ilLPMarks($this->exercise->getId(), $a_member["usr_id"]);
231  if ($a_member["status"] == "notgraded")
232  {
234  } elseif ($a_member["status"] == "failed")
235  {
237  } else
238  {
240  }
241  $this->xmlStartTag("Marking", array (
242  "status" => $status
243  ));
244  $this->xmlElement("Mark", null, $marks->getMark());
245  $this->xmlElement("Notice", null, $a_member["notice"]);
246  $this->xmlElement("Comment", null, $marks->getComment());
247  $this->xmlEndTag("Marking");
248  }
249 
250 }
251 
252 
253 ?>