ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilExerciseXMLWriter.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once "./classes/class.ilXmlWriter.php";
5 
21 {
22 
23  static $CONTENT_ATTACH_NO = 0;
27 
28  static $STATUS_NOT_GRADED = "NOT_GRADED";
29  static $STATUS_PASSED = "PASSED";
30  static $STATUS_FAILED = "FAILED";
37 
38 
45 
51  var $exercise;
52 
61  {
63  $this->attachFileContents = ilExerciseXMLWriter::$CONTENT_ATTACH_NO;
64  }
65 
66 
67  function setExercise(& $exercise)
68  {
69  $this->exercise = & $exercise;
70  }
71 
79  {
80  if ($attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED && !function_exists("gzencode"))
81  {
82  throw new ilExerciseException("Inflating with gzip is not supported", ilExerciseException::$ID_DEFLATE_METHOD_MISMATCH);
83  }
84  if ($attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED && !function_exists("gzcompress"))
85  {
86  throw new ilExerciseException("Inflating with zlib (compress/uncompress) is not supported", ilExerciseException::$ID_DEFLATE_METHOD_MISMATCH);
87  }
88 
89  $this->attachFileContents = $attachFileContents;
90  }
91 
92 
93  function start()
94  {
95  $this->__buildHeader();
96 
97  $attribs =array ("obj_id" => "il_".IL_INST_ID."_exc_".$this->exercise->getId());
98 
99  if ($this->exercise->getOwner())
100  $attribs["owner"] = "il_".IL_INST_ID."_usr_".$this->exercise->getOwner();
101 
102  $this->xmlStartTag("Exercise", $attribs);
103 
104  $this->xmlElement("Title", null,$this->exercise->getTitle());
105  $this->xmlElement("Description", null,$this->exercise->getDescription());
106  $this->xmlElement("Instruction", null,$this->exercise->getInstruction());
107  $this->xmlElement("DueDate", null,$this->exercise->getTimestamp());
108  $this->xmlStartTag("Files");
109 
113  $exerciseFileData = $this->exercise->file_obj;
114  $files = $exerciseFileData->getFiles();
115  if (count($files))
116  {
117  foreach ($files as $file)
118  {
119  $this->xmlStartTag("File", array ("size" => $file["size"] ));
120  $this->xmlElement("Filename", null, $file["name"]);
121  if ($this->attachFileContents)
122  {
123  $filename = $file["fullpath"];
124  if (@is_file($filename))
125  {
126  $content = @file_get_contents($filename);
127  $attribs = array ("mode"=>"PLAIN");
128  if ($this->attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED)
129  {
130  $attribs = array ("mode"=>"ZLIB");
131  $content = gzcompress($content, 9);
132  }
133  elseif ($this->attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED)
134  {
135  $attribs = array ("mode"=>"GZIP");
136  $content = gzencode($content, 9);
137  }
138  $content = base64_encode($content);
139  $this->xmlElement("Content",$attribs, $content);
140  }
141  }
142  $this->xmlEndTag("File");
143  }
144  }
145  $this->xmlEndTag("Files");
146  if ($this->attachMembers)
147  {
148  $this->xmlStartTag("Members");
149  $members = $this->exercise->getMemberListData();
150  if (count($members))
151  {
152  foreach ($members as $member)
153  {
154  $this->xmlStartTag("Member",
155  array ("usr_id" => "il_".IL_INST_ID."_usr_".$member["usr_id"]));
156  $this->attachMarking ($member);
157  $this->xmlEndTag("Member");
158  }
159  }
160  $this->xmlEndTag("Members");
161  }
162 
163 
164  $this->xmlEndTag("Exercise");
165  $this->__buildFooter();
166 
167  return true;
168  }
169 
170  function getXML()
171  {
172  return $this->xmlDumpMem(FALSE);
173  }
174 
175 
176  function __buildHeader()
177  {
178  $this->xmlSetDtdDef("<!DOCTYPE Exercise PUBLIC \"-//ILIAS//DTD ExerciseAdministration//EN\" \"".ILIAS_HTTP_PATH."/xml/ilias_exercise_3_10.dtd\">");
179  $this->xmlSetGenCmt("Exercise Object");
180  $this->xmlHeader();
181 
182  return true;
183  }
184 
185  function __buildFooter()
186  {
187 
188  }
189 
195  public function setAttachMembers ($value) {
196  $this->attachMembers = $value ? true : false;
197  }
198 
204  private function attachMarking ($a_member)
205  {
206  include_once 'Services/Tracking/classes/class.ilLPMarks.php';
207 
208  $marks = new ilLPMarks($this->exercise->getId(), $a_member["usr_id"]);
209  if ($a_member["status"] == "notgraded")
210  {
212  } elseif ($a_member["status"] == "failed")
213  {
215  } else
216  {
218  }
219  $this->xmlStartTag("Marking", array (
220  "status" => $status
221  ));
222  $this->xmlElement("Mark", null, $marks->getMark());
223  $this->xmlElement("Notice", null, $a_member["notice"]);
224  $this->xmlElement("Comment", null, $marks->getComment());
225  $this->xmlEndTag("Marking");
226  }
227 
228 }
229 
230 
231 ?>