ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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
 
- 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...
 
 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 45 of file class.ilExerciseXMLParser.php.

References $exercise, $obj_id, ILIAS\GlobalScreen\Provider\__construct(), ilExAssignment\getAssignmentDataOfExercise(), ilObject\getId(), and ilSaxParser\setXMLContent().

49  {
50  // @todo: needs to be revised for multiple assignments per exercise
51 
53 
54  $this->exercise = $exercise;
55  // get all assignments and choose first one if exists, otherwise create
56  $assignments = ilExAssignment::getAssignmentDataOfExercise($exercise->getId());
57  if (count($assignments) > 0) {
58  $this->assignment = new ilExAssignment($assignments [0]["id"]);
59  } else {
60  $this->assignment = new ilExAssignment();
61  $this->assignment->setExerciseId($exercise->getId());
62  $this->assignment->save();
63  }
64 
65  $this->setXMLContent($a_xml_data);
66  $this->obj_id = $obj_id;
67  $this->result = false;
68  }
Exercise assignment.
static getAssignmentDataOfExercise(int $a_exc_id)
__construct(Container $dic, ilPlugin $plugin)
setXMLContent(string $a_xml_content)
+ Here is the call graph for this function:

Member Function Documentation

◆ getAssignment()

ilExerciseXMLParser::getAssignment ( )

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

References $assignment.

264  {
265  return $this->assignment;
266  }
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 85 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().

Referenced by setHandlers().

85  : void
86  {
87  $a_attribs = $this->trimAndStripAttribs($a_attribs);
88  switch ($a_name) {
89  case 'Exercise':
90  if (isset($a_attribs["obj_id"])) {
91  $read_obj_id = ilUtil::__extractId($a_attribs["obj_id"], IL_INST_ID);
92  if ($this->obj_id != -1 && (int) $read_obj_id != -1 && $this->obj_id !== (int) $read_obj_id) {
93  throw new ilExerciseException("Object IDs (xml $read_obj_id and argument " . $this->obj_id . ") do not match!", ilExerciseException::$ID_MISMATCH);
94  }
95  }
96  break;
97  case 'Member':
98  $this->usr_action = $a_attribs["action"];
99  $this->usr_id = (int) ilUtil::__extractId($a_attribs["usr_id"], IL_INST_ID);
100  break;
101 
102  case 'File':
103  $this->file_action = $a_attribs["action"];
104  break;
105  case 'Content':
107  if ($a_attribs["mode"] == "GZIP") {
108  if (!function_exists("gzdecode")) {
109  throw new ilExerciseException("Deflating with gzip is not supported", ilExerciseException::$ID_DEFLATE_METHOD_MISMATCH);
110  }
111 
113  } elseif ($a_attribs["mode"] == "ZLIB") {
114  if (!function_exists("gzuncompress")) {
115  throw new ilExerciseException("Deflating with zlib (compress/uncompress) is not supported", ilExerciseException::$ID_DEFLATE_METHOD_MISMATCH);
116  }
117 
119  }
120  break;
121  case 'Marking':
122  $this->status = $a_attribs["status"];
123  if ($this->status == ilExerciseXMLWriter::$STATUS_NOT_GRADED) {
124  $this->status = "notgraded";
125  } elseif ($this->status == ilExerciseXMLWriter::$STATUS_PASSED) {
126  $this->status = "passed";
127  } else {
128  $this->status = "failed";
129  }
130  break;
131  }
132  }
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:
+ Here is the caller 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 194 of file class.ilExerciseXMLParser.php.

Referenced by setHandlers().

194  : void
195  {
196  if ($a_data != "\n") {
197  $this->cdata .= $a_data;
198  }
199  }
+ Here is the caller graph for this function:

◆ 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 142 of file class.ilExerciseXMLParser.php.

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

Referenced by setHandlers().

142  : void
143  {
144  switch ($a_name) {
145  case 'Exercise':
146  $this->result = true;
147  break;
148  case 'Title':
149  $this->exercise->setTitle($this->trimAndStrip((string) $this->cdata));
150  $this->assignment->setTitle($this->trimAndStrip((string) $this->cdata));
151  break;
152  case 'Description':
153  $this->exercise->setDescription($this->trimAndStrip((string) $this->cdata));
154  break;
155  case 'Instruction':
156  $this->assignment->setInstruction($this->trimAndStrip((string) $this->cdata));
157  break;
158  case 'DueDate':
159  $this->assignment->setDeadLine($this->trimAndStrip((string) $this->cdata));
160  break;
161  case 'Member':
162  $this->updateMember($this->usr_id, $this->usr_action);
163  // update marking after update member.
164  $this->updateMarking($this->usr_id);
165  break;
166  case 'Filename':
167  $this->file_name = $this->trimAndStrip((string) $this->cdata);
168  break;
169  case 'Content':
170  $this->file_content = $this->trimAndStrip((string) $this->cdata);
171  break;
172  case 'Comment':
173  $this->comment = $this->trimAndStrip((string) $this->cdata);
174  break;
175  case 'Notice':
176  $this->notice = $this->trimAndStrip((string) $this->cdata);
177  break;
178  case 'Mark':
179  $this->mark = $this->trimAndStrip((string) $this->cdata);
180  break;
181  case 'Marking':
182  // see Member end tag
183  break;
184  }
185  $this->cdata = '';
186  }
updateMember(int $user_id, string $action)
update member object according to given action
comment()
description: > Example for rendring a comment glyph.
Definition: comment.php:41
updateMarking(int $usr_id)
update marking of member
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setHandlers()

ilExerciseXMLParser::setHandlers (   $a_xml_parser)

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

References handlerBeginTag(), handlerCharacterData(), and handlerEndTag().

71  : void
72  {
73  xml_set_element_handler($a_xml_parser, $this->handlerBeginTag(...), $this->handlerEndTag(...));
74  xml_set_character_data_handler($a_xml_parser, $this->handlerCharacterData(...));
75  }
handlerEndTag($a_xml_parser, string $a_name)
handler for end of element
handlerBeginTag($a_xml_parser, string $a_name, array $a_attribs)
handler for begin of element
handlerCharacterData($a_xml_parser, string $a_data)
handler for character data
+ Here is the call graph for this function:

◆ 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 228 of file class.ilExerciseXMLParser.php.

References ilSaxParser\startParsing().

228  : bool
229  {
230  $this->startParsing();
231  return $this->result > 0;
232  }
startParsing()
stores xml data in array
+ Here is the call graph for this function:

◆ trimAndStrip()

ilExerciseXMLParser::trimAndStrip ( string  $input)
protected

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

References ilUtil\stripSlashes().

Referenced by handlerEndTag(), and trimAndStripAttribs().

277  : string
278  {
279  return ilUtil::stripSlashes(trim($input));
280  }
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 268 of file class.ilExerciseXMLParser.php.

References trimAndStrip().

Referenced by handlerBeginTag().

268  : array
269  {
270  $ret = [];
271  foreach ($attribs as $k => $v) {
272  $ret[$k] = $this->trimAndStrip((string) $v);
273  }
274  return $ret;
275  }
+ Here is the call graph for this function:
+ 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 239 of file class.ilExerciseXMLParser.php.

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

Referenced by handlerEndTag().

239  : void
240  {
241  $member_status = $this->assignment->getMemberStatus($usr_id);
242  if (isset($this->mark)) {
243  $member_status->setMark(ilUtil::stripSlashes($this->mark));
244  }
245  if (isset($this->comment)) {
246  $member_status->setComment(ilUtil::stripSlashes($this->comment));
247  }
248  if (isset($this->status)) {
249  $member_status->setStatus(ilUtil::stripSlashes($this->status));
250  }
251  if (isset($this->notice)) {
252  $member_status->setNotice(ilUtil::stripSlashes($this->notice));
253  }
254  $member_status->update();
255 
256  // reset variables
257  $this->mark = null;
258  $this->status = null;
259  $this->notice = null;
260  $this->comment = null;
261  }
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
comment()
description: > Example for rendring a comment glyph.
Definition: comment.php:41
+ 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 205 of file class.ilExerciseXMLParser.php.

Referenced by handlerEndTag().

205  : void
206  {
207  if (!is_int($user_id) || $user_id <= 0) {
208  return;
209  }
210  $memberObject = new ilExerciseMembers($this->exercise);
211 
212  if ($action == "Attach" && !$memberObject->isAssigned($user_id)) {
213  $memberObject->assignMember($user_id);
214  }
215 
216  if ($action == "Detach" && $memberObject->isAssigned($user_id)) {
217  $memberObject->deassignMember($user_id);
218  }
219  }
+ 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().

◆ $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().

◆ $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.

◆ $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: