ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 "./Services/Xml/classes/class.ilXmlWriter.php";
5 include_once "./Modules/Exercise/classes/class.ilExAssignment.php";
6 
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 
44 
50  var $exercise;
51 
59  function __construct() {
60  // @todo: needs to be revised for multiple assignments per exercise
61  //die ("Needs revision for ILIAS 4.1");
62  parent::__construct();
63  $this->attachFileContents = ilExerciseXMLWriter::$CONTENT_ATTACH_NO;
64  }
65 
72  function setExercise($exercise) {
73  $this->exercise = $exercise;
74  }
75 
82  function setAttachFileContents($attachFileContents) {
83  if ($attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED && ! function_exists ( "gzencode" )) {
84  throw new ilExerciseException ( "Inflating with gzip is not supported", ilExerciseException::$ID_DEFLATE_METHOD_MISMATCH );
85  }
86  if ($attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED && ! function_exists ( "gzcompress" )) {
87  throw new ilExerciseException ( "Inflating with zlib (compress/uncompress) is not supported", ilExerciseException::$ID_DEFLATE_METHOD_MISMATCH );
88  }
89 
90  $this->attachFileContents = $attachFileContents;
91  }
92 
93  function start() {
94  $this->__buildHeader ();
95 
96  $attribs = array ("obj_id" => "il_" . IL_INST_ID . "_exc_" . $this->exercise->getId () );
97 
98  if ($this->exercise->getOwner ())
99  $attribs ["owner"] = "il_" . IL_INST_ID . "_usr_" . $this->exercise->getOwner ();
100 
101  $this->xmlStartTag ( "Exercise", $attribs );
102 
103  //todo: create new dtd for new assignment structure
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 
109 
110  //todo: as a workaround use first assignment for compatibility with old exercise dtd
111  $assignments = ilExAssignment::getAssignmentDataOfExercise ( $this->exercise->getId () );
112 
113  if (count ( $assignments ) > 0) {
114  foreach ( $assignments as $assignment ) {
115  $this->xmlStartTag ("Assignment");
116  $this->xmlElement ( "Instruction", null, $assignment ["instruction"] );
117  $this->xmlElement ( "DueDate", null, $assignment ["deadline"] );
118 
119  $this->handleAssignmentFiles ( $this->exercise->getId (), $assignment ["id"] );
120  if ($this->attachMembers)
121  {
122  $this->handleAssignmentMembers ($this->exercise->getId (), $assignment ["id"]);
123  }
124  $this->xmlEndTag ( "Assignment" );
125  }
126  }
127 
128 
129  $this->xmlEndTag ( "Exercise" );
130  $this->__buildFooter ();
131 
132  return true;
133  }
134 
135  function getXML() {
136  return $this->xmlDumpMem ( FALSE );
137  }
138 
139  function __buildHeader() {
140  $this->xmlSetDtdDef ( "<!DOCTYPE Exercise PUBLIC \"-//ILIAS//DTD ExerciseAdministration//EN\" \"" . ILIAS_HTTP_PATH . "/xml/ilias_exercise_4_4.dtd\">" );
141  $this->xmlSetGenCmt ( "Exercise Object" );
142  $this->xmlHeader ();
143 
144  return true;
145  }
146 
147  function __buildFooter() {
148 
149  }
150 
156  public function setAttachMembers($value) {
157  $this->attachMembers = $value ? true : false;
158  }
159 
166  private function attachMarking($user_id, $assignment_id) {
167 
168  $ass = new ilExAssignment($assignment_id);
169 
170  $amark = $ass->getMemberStatus($user_id)->getMark();
171  $astatus = $ass->getMemberStatus($user_id)->getStatus();
172  $acomment = $ass->getMemberStatus($user_id)->getComment();
173  $anotice = $ass->getMemberStatus($user_id)->getNotice();
174 
175 
176  if ($astatus == "notgraded") {
178  } elseif ($astatus == "failed") {
180  } else {
182  }
183 
184  $this->xmlStartTag ( "Marking", array ("status" => $status ) );
185  $this->xmlElement ( "Mark", null, $amark);
186  $this->xmlElement ( "Notice", null, $anotice );
187  $this->xmlElement ( "Comment", null, $acomment );
188  $this->xmlEndTag ( "Marking" );
189  }
190 
191  private function handleAssignmentFiles($ex_id, $as_id) {
192  $this->xmlStartTag ( "Files" );
193  include_once ("./Modules/Exercise/classes/class.ilFSStorageExercise.php");
194  $storage = new ilFSStorageExercise ( $ex_id, $as_id );
195  $files = $storage->getFiles ();
196 
197  if (count ( $files )) {
198  foreach ( $files as $file ) {
199  $this->xmlStartTag ( "File", array ("size" => $file ["size"] ) );
200  $this->xmlElement ( "Filename", null, $file ["name"] );
201  if ($this->attachFileContents) {
202  $filename = $file ["fullpath"];
203  if (@is_file ( $filename )) {
204  $content = @file_get_contents ( $filename );
205  $attribs = array ("mode" => "PLAIN" );
206  if ($this->attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_ZLIB_ENCODED) {
207  $attribs = array ("mode" => "ZLIB" );
208  $content = gzcompress ( $content, 9 );
209  } elseif ($this->attachFileContents == ilExerciseXMLWriter::$CONTENT_ATTACH_GZIP_ENCODED) {
210  $attribs = array ("mode" => "GZIP" );
211  $content = gzencode ( $content, 9 );
212  }
213  $content = base64_encode ( $content );
214  $this->xmlElement ( "Content", $attribs, $content );
215  }
216  }
217  $this->xmlEndTag ( "File" );
218  }
219  }
220  $this->xmlEndTag ( "Files" );
221  }
222 
229  private function handleAssignmentMembers($ex_id, $assignment_id) {
230  $this->xmlStartTag ( "Members" );
231  include_once ("./Modules/Exercise/classes/class.ilExerciseMembers.php");
232  $members = ilExerciseMembers::_getMembers($ex_id);
233  if (count ( $members )) {
234  foreach ( $members as $member_id ) {
235  $this->xmlStartTag ( "Member", array ("usr_id" => "il_" . IL_INST_ID . "_usr_" . $member_id ) );
236 
237  $name = ilObjUser::_lookupName($member_id);
238 
239  $this->xmlElement("Firstname", array(), $name['firstname']);
240  $this->xmlElement("Lastname", array(), $name['lastname']);
241  $this->xmlElement("Login", array(), $name['login']);
242  $this->attachMarking ( $member_id, $assignment_id);
243  $this->xmlEndTag ( "Member" );
244  }
245  }
246  $this->xmlEndTag ( "Members" );
247  }
248 }
249 
250 ?>
$files
Definition: add-vimline.php:18
static _lookupName($a_user_id)
lookup user name
xmlSetGenCmt($genCmt)
Sets generated comment.
static getAssignmentDataOfExercise($a_exc_id)
Get assignments data of an exercise in an array.
Exercise assignment.
xmlSetDtdDef($dtdDef)
Sets dtd definition.
setAttachMembers($value)
write access to property attchMarkings
handleAssignmentMembers($ex_id, $assignment_id)
create xml for files per assignment
xmlStartTag($tag, $attrs=NULL, $empty=FALSE, $encode=TRUE, $escape=TRUE)
Writes a starttag.
XML writer class.
xmlElement($tag, $attrs=NULL, $data=Null, $encode=TRUE, $escape=TRUE)
Writes a basic element (no children, just textual content)
xmlEndTag($tag)
Writes an endtag.
attachMarking($user_id, $assignment_id)
attach marking tag to member for given assignment
xmlHeader()
Writes xml header public.
setAttachFileContents($attachFileContents)
set attachment content mode
Create styles array
The data for the language used.
setExercise($exercise)
set exercise object
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
static _getMembers($a_obj_id)
xmlDumpMem($format=TRUE)
Returns xml document from memory.
Class to report exception.