You are here

Validating solution correctness

21 January, 2016 - 14:46

When the whole process of defining XML document template is finished, new activity can be utilized by course participants in the same way as all predefined in the MOODLE platform objects and is accessible in a list of participant's tasks. Window of the XML activity includes tree elements (Figure 2.7): task contents, text area for its solution and Check structure button, which starts a procedure of verifying a correctness of a solution.

media/image7.png
Figure 2.7 View of a XML course participant's window 
 

This procedure, included in logic of the view.php file, is based on data inserted to the Tag_templates table and similarly, begins with splitting solution into substrings. Because a base for this partitioning is the symbol of a new line, the requirement ending each tag and value by this character has to be fulfilled. For each substring a level is calculated, which, subsequently, is compared with the level defined for a related tag in a template. In case of detecting a difference participant receives an appropriate message (Figure 2.8). At the end of the process, an existence of a corresponding opening and closing tags is checked. A proper solution is acknowledged with a suitable notification (Figure 2.9).

media/image8.png
Figure 2.8 View of a participant's window with a badly prepared solution 
 
media/image9.png
Figure 2.9 View of a participant's window with a properly prepared solution 
 

Independently, every analyzed element is remembered in Solutions table. A row of this table includes task number, tag, its level in a structure defined by a participant and user identifier assigned to her/him. Owing to that, a teacher is able to analyze the result of a participant's work. Additionally, a new row, containing data on task and a participant solving it, is added to Grades table. If a solution is acceptable, the passed column is checked in this record. In other case column named attempt is incremented. The number of possible attempts is defined by a teacher in a task configuration window, through the additional element introduced into the mod_form.php file (Figure 2.10):

$mform->addElement('text','attempts_number',get_string('attempts','xml'));

media/image10.png
Figure 2.10 The attempts_number text element visible in the teacher's window