ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilExerciseXMLParser Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Inheritance diagram for ilExerciseXMLParser:
+ Collaboration diagram for ilExerciseXMLParser:

Public Member Functions

 __construct (ilObjExercise $exercise, string $a_xml_data, int $obj_id=-1)
 
 setHandlers ($a_xml_parser)
 
 handlerBeginTag ($a_xml_parser, string $a_name, array $a_attribs)
 handler for begin of element More...
 
 handlerEndTag ($a_xml_parser, string $a_name)
 handler for end of element More...
 
 handlerCharacterData ($a_xml_parser, string $a_data)
 handler for character data More...
 
 start ()
 starts parsing an changes object by side effect. More...
 
 getAssignment ()
 
- Public Member Functions inherited from ilSaxParser
 __construct (?string $path_to_file='', ?bool $throw_exception=false)
 
 setXMLContent (string $a_xml_content)
 
 getXMLContent ()
 
 getInputType ()
 
 startParsing ()
 stores xml data in array More...
 
 createParser ()
 
 setHandlers ($a_xml_parser)
 
 parse ($a_xml_parser, $a_fp=null)
 

Data Fields

ilObjExercise $exercise
 
int $obj_id
 
bool $result
 
int $mode
 
ilExAssignment $assignment
 
ilFSStorageExercise $storage
 
- Data Fields inherited from ilSaxParser
string $xml_file
 
bool $throw_exception = false
 

Static Public Attributes

static int $CONTENT_NOT_COMPRESSED = 0
 
static int $CONTENT_GZ_COMPRESSED = 1
 
static int $CONTENT_ZLIB_COMPRESSED = 2
 

Protected Member Functions

 trimAndStripAttribs (array $attribs)
 
 trimAndStrip (string $input)
 
- Protected Member Functions inherited from ilSaxParser
 openXMLFile ()
 
 handleError (string $message)
 
 setThrowException (bool $throw_exception)
 

Protected Attributes

string $cdata
 
string $mark
 
string $notice
 
string $comment
 
string $file_content
 
string $file_name
 
string $status
 
string $file_action
 
int $usr_id
 
string $usr_action
 
- Protected Attributes inherited from ilSaxParser
ilLanguage $lng = null
 

Private Member Functions

 updateMember (int $user_id, string $action)
 update member object according to given action More...
 
 updateFile (string $filename, string $b64encodedContent, string $action)
 update file according to filename More...
 
 updateMarking (int $usr_id)
 update marking of member More...
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Exercise XML Parser which completes/updates a given exercise by an xml string.

Author
Roland Küstermann rolan.nosp@m.d@ku.nosp@m.ester.nosp@m.mann.nosp@m..com

Definition at line 23 of file class.ilExerciseXMLParser.php.

Constructor & Destructor Documentation

◆ __construct()

ilExerciseXMLParser::__construct ( ilObjExercise  $exercise,
string  $a_xml_data,
int  $obj_id = -1 
)

Definition at line 46 of file class.ilExerciseXMLParser.php.

References $exercise, $obj_id, ILIAS\MetaData\Repository\Validation\Data\__construct(), ilFSStorageExercise\create(), ilExAssignment\getAssignmentDataOfExercise(), ilObject\getId(), and ilSaxParser\setXMLContent().

50  {
51  // @todo: needs to be revised for multiple assignments per exercise
52 
54 
55  $this->exercise = $exercise;
56  // get all assignments and choose first one if exists, otherwise create
57  $assignments = ilExAssignment::getAssignmentDataOfExercise($exercise->getId());
58  if (count($assignments) > 0) {
59  $this->assignment = new ilExAssignment($assignments [0]["id"]);
60  } else {
61  $this->assignment = new ilExAssignment();
62  $this->assignment->setExerciseId($exercise->getId());
63  $this->assignment->save();
64  }
65 
66  $this->storage = new ilFSStorageExercise($this->exercise->getId(), $this->assignment->getId());
67  $this->storage->create();
68  $this->storage->init();
69 
70  $this->setXMLContent($a_xml_data);
71  $this->obj_id = $obj_id;
72  $this->result = false;
73  }
Exercise assignment.
static getAssignmentDataOfExercise(int $a_exc_id)
__construct(VocabulariesInterface $vocabularies)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setXMLContent(string $a_xml_content)
+ Here is the call graph for this function:

Member Function Documentation

◆ getAssignment()

ilExerciseXMLParser::getAssignment ( )

Definition at line 305 of file class.ilExerciseXMLParser.php.

References $assignment.

306  {
307  return $this->assignment;
308  }
Exercise assignment.

◆ handlerBeginTag()

ilExerciseXMLParser::handlerBeginTag (   $a_xml_parser,
string  $a_name,
array  $a_attribs 
)

handler for begin of element

Parameters
resource$a_xml_parserxml parser
string$a_nameelement name
array$a_attribselement attributes array
Exceptions
ilExerciseExceptionwhen obj id != - 1 and if it it does not match the id in the xml

Definition at line 91 of file class.ilExerciseXMLParser.php.

References $CONTENT_GZ_COMPRESSED, $CONTENT_NOT_COMPRESSED, $CONTENT_ZLIB_COMPRESSED, ilExerciseException\$ID_DEFLATE_METHOD_MISMATCH, ilExerciseException\$ID_MISMATCH, ilExerciseXMLWriter\$STATUS_NOT_GRADED, ilExerciseXMLWriter\$STATUS_PASSED, ilUtil\__extractId(), IL_INST_ID, ILIAS\Repository\int(), and trimAndStripAttribs().

91  : void
92  {
93  $a_attribs = $this->trimAndStripAttribs($a_attribs);
94  switch ($a_name) {
95  case 'Exercise':
96  if (isset($a_attribs["obj_id"])) {
97  $read_obj_id = ilUtil::__extractId($a_attribs["obj_id"], IL_INST_ID);
98  if ($this->obj_id != -1 && (int) $read_obj_id != -1 && $this->obj_id !== (int) $read_obj_id) {
99  throw new ilExerciseException("Object IDs (xml $read_obj_id and argument " . $this->obj_id . ") do not match!", ilExerciseException::$ID_MISMATCH);
100  }
101  }
102  break;
103  case 'Member':
104  $this->usr_action = $a_attribs["action"];
105  $this->usr_id = (int) ilUtil::__extractId($a_attribs["usr_id"], IL_INST_ID);
106  break;
107 
108  case 'File':
109  $this->file_action = $a_attribs["action"];
110  break;
111  case 'Content':
113  if ($a_attribs["mode"] == "GZIP") {
114  if (!function_exists("gzdecode")) {
115  throw new ilExerciseException("Deflating with gzip is not supported", ilExerciseException::$ID_DEFLATE_METHOD_MISMATCH);
116  }
117 
119  } elseif ($a_attribs["mode"] == "ZLIB") {
120  if (!function_exists("gzuncompress")) {
121  throw new ilExerciseException("Deflating with zlib (compress/uncompress) is not supported", ilExerciseException::$ID_DEFLATE_METHOD_MISMATCH);
122  }
123 
125  }
126  break;
127  case 'Marking':
128  $this->status = $a_attribs["status"];
129  if ($this->status == ilExerciseXMLWriter::$STATUS_NOT_GRADED) {
130  $this->status = "notgraded";
131  } elseif ($this->status == ilExerciseXMLWriter::$STATUS_PASSED) {
132  $this->status = "passed";
133  } else {
134  $this->status = "failed";
135  }
136  break;
137  }
138  }
const IL_INST_ID
Definition: constants.php:40
static __extractId(string $ilias_id, int $inst_id)
extract ref id from role title, e.g.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:

◆ handlerCharacterData()

ilExerciseXMLParser::handlerCharacterData (   $a_xml_parser,
string  $a_data 
)

handler for character data

Parameters
resource$a_xml_parserxml parser
string$a_datacharacter data

Definition at line 203 of file class.ilExerciseXMLParser.php.

203  : void
204  {
205  if ($a_data != "\n") {
206  $this->cdata .= $a_data;
207  }
208  }

◆ handlerEndTag()

ilExerciseXMLParser::handlerEndTag (   $a_xml_parser,
string  $a_name 
)

handler for end of element

Parameters
resource$a_xml_parserxml parser
string$a_nameelement name

Definition at line 148 of file class.ilExerciseXMLParser.php.

References ILIAS\UI\examples\Symbol\Glyph\Comment\comment(), trimAndStrip(), updateFile(), updateMarking(), and updateMember().

148  : void
149  {
150  switch ($a_name) {
151  case 'Exercise':
152  $this->result = true;
153  break;
154  case 'Title':
155  $this->exercise->setTitle($this->trimAndStrip((string) $this->cdata));
156  $this->assignment->setTitle($this->trimAndStrip((string) $this->cdata));
157  break;
158  case 'Description':
159  $this->exercise->setDescription($this->trimAndStrip((string) $this->cdata));
160  break;
161  case 'Instruction':
162  $this->assignment->setInstruction($this->trimAndStrip((string) $this->cdata));
163  break;
164  case 'DueDate':
165  $this->assignment->setDeadLine($this->trimAndStrip((string) $this->cdata));
166  break;
167  case 'Member':
168  $this->updateMember($this->usr_id, $this->usr_action);
169  // update marking after update member.
170  $this->updateMarking($this->usr_id);
171  break;
172  case 'Filename':
173  $this->file_name = $this->trimAndStrip((string) $this->cdata);
174  break;
175  case 'Content':
176  $this->file_content = $this->trimAndStrip((string) $this->cdata);
177  break;
178  case 'File':
179  $this->updateFile($this->file_name, $this->file_content, $this->file_action);
180  break;
181  case 'Comment':
182  $this->comment = $this->trimAndStrip((string) $this->cdata);
183  break;
184  case 'Notice':
185  $this->notice = $this->trimAndStrip((string) $this->cdata);
186  break;
187  case 'Mark':
188  $this->mark = $this->trimAndStrip((string) $this->cdata);
189  break;
190  case 'Marking':
191  // see Member end tag
192  break;
193  }
194  $this->cdata = '';
195  }
updateMember(int $user_id, string $action)
update member object according to given action
updateFile(string $filename, string $b64encodedContent, string $action)
update file according to filename
updateMarking(int $usr_id)
update marking of member
+ Here is the call graph for this function:

◆ setHandlers()

ilExerciseXMLParser::setHandlers (   $a_xml_parser)

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

76  : void
77  {
78  xml_set_object($a_xml_parser, $this);
79  xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
80  xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
81  }

◆ start()

ilExerciseXMLParser::start ( )

starts parsing an changes object by side effect.

Exceptions
ilExerciseExceptionwhen obj id != - 1 and if it it does not match the id in the xml
Returns
boolean true, if no errors happend.

Definition at line 270 of file class.ilExerciseXMLParser.php.

References ilSaxParser\startParsing().

270  : bool
271  {
272  $this->startParsing();
273  return $this->result > 0;
274  }
startParsing()
stores xml data in array
+ Here is the call graph for this function:

◆ trimAndStrip()

ilExerciseXMLParser::trimAndStrip ( string  $input)
protected

Definition at line 319 of file class.ilExerciseXMLParser.php.

References ilUtil\stripSlashes().

Referenced by handlerEndTag(), and trimAndStripAttribs().

319  : string
320  {
321  return ilUtil::stripSlashes(trim($input));
322  }
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ trimAndStripAttribs()

ilExerciseXMLParser::trimAndStripAttribs ( array  $attribs)
protected

Definition at line 310 of file class.ilExerciseXMLParser.php.

References trimAndStrip().

Referenced by handlerBeginTag().

310  : array
311  {
312  $ret = [];
313  foreach ($attribs as $k => $v) {
314  $ret[$k] = $this->trimAndStrip((string) $v);
315  }
316  return $ret;
317  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updateFile()

ilExerciseXMLParser::updateFile ( string  $filename,
string  $b64encodedContent,
string  $action 
)
private

update file according to filename

Parameters
string$filename
string$contentbase 64 encoded string
string$actioncan be Attach or Detach

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

References $CONTENT_GZ_COMPRESSED, $CONTENT_ZLIB_COMPRESSED, and $filename.

Referenced by handlerEndTag().

241  : void {
242  if (strlen($filename) == 0) {
243  return;
244  }
245  $filename = $this->storage->getAbsolutePath() . "/" . $filename;
246 
247  if ($action == "Attach") {
248  $content = base64_decode($b64encodedContent);
249  if ($this->mode == ilExerciseXMLParser::$CONTENT_GZ_COMPRESSED) {
250  $content = gzdecode($content);
251  } elseif ($this->mode == ilExerciseXMLParser::$CONTENT_ZLIB_COMPRESSED) {
252  $content = gzuncompress($content);
253  }
254 
255  //echo $filename;
256  //$this->storage->writeToFile($content, $filename);
257  }
258  if ($action == "Detach") {
259  //$this->storage->deleteFile($filename);
260  }
261  }
$filename
Definition: buildRTE.php:78
+ Here is the caller graph for this function:

◆ updateMarking()

ilExerciseXMLParser::updateMarking ( int  $usr_id)
private

update marking of member

Parameters
int$usr_id

Definition at line 281 of file class.ilExerciseXMLParser.php.

References ILIAS\UI\examples\Symbol\Glyph\Comment\comment(), and ilUtil\stripSlashes().

Referenced by handlerEndTag().

281  : void
282  {
283  $member_status = $this->assignment->getMemberStatus($usr_id);
284  if (isset($this->mark)) {
285  $member_status->setMark(ilUtil::stripSlashes($this->mark));
286  }
287  if (isset($this->comment)) {
288  $member_status->setComment(ilUtil::stripSlashes($this->comment));
289  }
290  if (isset($this->status)) {
291  $member_status->setStatus(ilUtil::stripSlashes($this->status));
292  }
293  if (isset($this->notice)) {
294  $member_status->setNotice(ilUtil::stripSlashes($this->notice));
295  }
296  $member_status->update();
297 
298  // reset variables
299  $this->mark = null;
300  $this->status = null;
301  $this->notice = null;
302  $this->comment = null;
303  }
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updateMember()

ilExerciseXMLParser::updateMember ( int  $user_id,
string  $action 
)
private

update member object according to given action

Definition at line 214 of file class.ilExerciseXMLParser.php.

Referenced by handlerEndTag().

214  : void
215  {
216  if (!is_int($user_id) || $user_id <= 0) {
217  return;
218  }
219  $memberObject = new ilExerciseMembers($this->exercise);
220 
221  if ($action == "Attach" && !$memberObject->isAssigned($user_id)) {
222  $memberObject->assignMember($user_id);
223  }
224 
225  if ($action == "Detach" && $memberObject->isAssigned($user_id)) {
226  $memberObject->deassignMember($user_id);
227  }
228  }
Class ilExerciseMembers.
+ Here is the caller graph for this function:

Field Documentation

◆ $assignment

ilExAssignment ilExerciseXMLParser::$assignment

Definition at line 43 of file class.ilExerciseXMLParser.php.

Referenced by getAssignment().

◆ $cdata

string ilExerciseXMLParser::$cdata
protected

Definition at line 28 of file class.ilExerciseXMLParser.php.

◆ $comment

string ilExerciseXMLParser::$comment
protected

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

◆ $CONTENT_GZ_COMPRESSED

int ilExerciseXMLParser::$CONTENT_GZ_COMPRESSED = 1
static

Definition at line 26 of file class.ilExerciseXMLParser.php.

Referenced by handlerBeginTag(), and updateFile().

◆ $CONTENT_NOT_COMPRESSED

int ilExerciseXMLParser::$CONTENT_NOT_COMPRESSED = 0
static

Definition at line 25 of file class.ilExerciseXMLParser.php.

Referenced by handlerBeginTag().

◆ $CONTENT_ZLIB_COMPRESSED

int ilExerciseXMLParser::$CONTENT_ZLIB_COMPRESSED = 2
static

Definition at line 27 of file class.ilExerciseXMLParser.php.

Referenced by handlerBeginTag(), and updateFile().

◆ $exercise

ilObjExercise ilExerciseXMLParser::$exercise

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

Referenced by __construct().

◆ $file_action

string ilExerciseXMLParser::$file_action
protected

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

◆ $file_content

string ilExerciseXMLParser::$file_content
protected

Definition at line 32 of file class.ilExerciseXMLParser.php.

◆ $file_name

string ilExerciseXMLParser::$file_name
protected

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

◆ $mark

string ilExerciseXMLParser::$mark
protected

Definition at line 29 of file class.ilExerciseXMLParser.php.

◆ $mode

int ilExerciseXMLParser::$mode

Definition at line 42 of file class.ilExerciseXMLParser.php.

◆ $notice

string ilExerciseXMLParser::$notice
protected

Definition at line 30 of file class.ilExerciseXMLParser.php.

◆ $obj_id

int ilExerciseXMLParser::$obj_id

Definition at line 40 of file class.ilExerciseXMLParser.php.

Referenced by __construct().

◆ $result

bool ilExerciseXMLParser::$result

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

◆ $status

string ilExerciseXMLParser::$status
protected

Definition at line 34 of file class.ilExerciseXMLParser.php.

◆ $storage

ilFSStorageExercise ilExerciseXMLParser::$storage

Definition at line 44 of file class.ilExerciseXMLParser.php.

◆ $usr_action

string ilExerciseXMLParser::$usr_action
protected

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

◆ $usr_id

int ilExerciseXMLParser::$usr_id
protected

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


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