LCMS Difference Engine
From Dokeos
Contents |
Introduction
The LCMS version of Dokeos offers the possibility to compare different object versions. This page will provide some basic insight into the logic behind the code, as well as a general overview of the functionality and it's possible uses.
Background
The basis of the LCMS Difference Engine is a PERL module called "Algorithm::Diff" which allows the user to compare two given arrays of strings. Implementations of this very same module seem to be common throughout all packages which implement the comparison of texts, e.g. PEAR and MediaWiki. A basic implementation of this algorithm in PHP by Geoffrey T. Dairiki was used for the LCMS. We however did implement several changes to fine-tune the system for usage in the Dokeos LCMS environment.
Logic / The Difference Engine
Given that there is an infinite number of possible learning object types with a large variety of possible , it was deemed necessary to implement a structure that would allow the comparison of all these type-specific properties.
e.g. A link does not only contain a description, it also contains an url, which may change from one version to the next. A calendar event contains dates which may change, etc etc.
To make this possible a basic Learning Object Difference class was implemented which simply compares a learning object's description from one version to the next. This basic class can then be extended by each Learning Object type to compare additional properties of the learning objects in question.
At this point the Learning Object Difference object contains the actual difference and both versions of an object. When asked to return the difference it will return an array of Difference Engine Operation objects. Each object contains 2 arrays, one for each version that was passed to the difference engine.
The possible Difference Engine Operation object types are:
- Difference Engine Operation: Copy
This type indicates the text contained within did not change from one version to the next. The original and final array are therefore, literally copies of one another. - Difference Engine Operation: Change
When a user replaces several words within a paragraph of, for example, an object's description, or he adds a line, the difference engine will detect this as a change. - Difference Engine Operation: Add
If text is added in between of two existing sections, an Add Operation object is added to the Difference. The array will be empty for either the original or the final array of the Add object. - Difference Engine Operation: Delete
If a portion of the ext is deleted, a Delete Operation object is added to the difference. The array will be empty for either the original or the final array of the Delete object.
The following screenshot illustrates the default colour coding associated with the different Difference Operations. These colours can of course be changed by tweaking the associated css file.
Functionality
Practically speaking, one never directly asks the Difference Engine to compare two versions. As explained above we implemented a Learning Object Difference class to facilitate comparing object versions. To further smoothen things out, one needs not even directly communicate with this class. One can simply ask every learning object version to get it's difference with any other given version of that same object.
When so requested, a new Learning Object Difference object is created, which knows both versions of the object. This object is then passed back to the requester of the difference. The object can then used to get the actual difference array containing all changes, additions, deletes and copies.
The array like formatting of the difference(see above) however, is not the most practical way of showing the difference to the end-user. To this end a special Display class was added for each object type, following the same layout as the learning object and learning object difference itself. That is: one Learning Object Difference Display class which can be extended by each and every type of learning object. In this case to alter the visual presentation of the differences between both versions. As one might guess, this is not at all unlike the relation between a Learning Object and a Learning Object Display. so, like Learning Object Display, Learning Object Difference Display returns a full html representation of the given difference.
This way one should be able to easily implement different ways of showing differences for different object types.
e.g. The visual representation of the differences between two announcements:
Notice the difference is displayed side by side in two columns.
The system administrator however wanted links to be displayed vertically, using two rows, instead of two colums.
The different ways of displaying these object types, was achieved by overriding the get_diff_as_html() in Link Difference Display




