Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

AJAX marking block

From MoodleDocs
Revision as of 00:24, 25 February 2010 by Matt Gibson (talk | contribs) (Began page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This page outlines the internal architecture of the AJAX marking block and how to extend it for new types of assignment.

Architecture

The block has a server side section of code written in PHP and a client side in javascript. The client is based on the YUI treeview widget and sends asynchronous messages to the server to retrieve the data which becomes the nodes of the tree. Each time a node is clicked to expand it, a new message is sent, with the response data parsed and made into the new sub-nodes.

HTML fallback

To aid accessibility, the block starts by loading a very basic HTML version so that if javascript is turned off either in the browser or the user's preferences, the block is still usable. This HTML version is normally not visible as the javascript acts to hide it immediately if possible.

File structure

The main lib.php file acts as a base class which holds most of the useful functions. This is extended through inheritance when either ajax.php is accessed (each time an asynchronous request is sent) or html_list.php, providing an object which automatically collects submitted POST data and outputs the desired code once instantiated.

The javascript.js file...

Plugins

The block is designed to allow new assessment types to be added dynamically. Rach new type will need to provide two files: modulename_grading.php and modulename_grading.js, whic can be placed either in the /block/ajax_marking folder or in the /mod/modulename folder.

To see how these work, take the assignment_grading files as examples.

PHP

The php file will need the following functions as a minimum:

Javascript

The javascript file will need to use the YAHOO.ajax_marking_block.modulename namespace and will have to add the following functions: