Now, I've finished the sequence diagrams. Push "read more" to see the diagrams of each operation I've implemented. All comments and explanations are made into the diagram itself:
Featured content
Well, I've finished doing the class diagram for the plugin I developed for Moodle:
Explanations
Previously in moodle existed a class called Moodleform. This class is intended to be subclassed, as it works as a template for all forms in Moodle. So I subclassed it in order to make my own form for OpenSyllabus plugin. The functions (all their sequence diagrams will be posted in my next post) I needed to redefine were:
- definition(): this operation is called by the constructor and builds the form with the fields you define on it
- definition_after_data: for making some validations or instructions after data is submitted.
- getFileValue(): this operation retrieves the name of the uploaded file.
- validation(): this operation makes some validations before the form is accepted. In my case, as I only had to make a prototype, I redefined it empty.
- add_action_buttons(): adds the "submit" and cancel buttons to the form.
As I said, I will provide sequence diagrams later. Once I defined the form, now only we must bind this form to our Main process and the logics of our problem is finished. It's easy to understand, it isn't?
It is well known that one of my preferred fields in computer enginering world is software enginering. I love read and make UML diagrams, because it is an easier way to understand and make programs than following a methodology properly called "eXtreme Programming" (consists on programming inside out).
Indeed, it's easier understanding a 1-sheet diagram where you see a box with some letters inside and some arrows than "public class TEXT { A b; B a; etc etc;}". Learning process about how a program/project works is done extremely faster. And that is why I prefer reading some UML diagrams than reading code.
However in my PFC, Moodle lacks about a good UML documentation in order to make programmers to work easier. That has disappointed me a bit, because I expected I would apply all my software enginering knowledgement and improve my skill in that field. I made the OpenSyllabus prototype (and learn how to do it) with some file examples of Moodle project.
I will propose to Marc (or Pigui) that in my next work in DFWiki refactoring I want to document in UML all my work (if possible). I feel ready to do it and I've leant some basic PHP, enough to do a good job (and, of course, understood Moodle modules, format course, blocks, thinking about the ID substitution, it should not be too much hard but it requires spending some time...).
My objective about this proposition is having a deeper knowledgement about Software Enginering and working methodology. In order to achieve that, I was preparing my PC to make nice class diagrams and sequence diagrams.
The "Free Software Market" about UML isn't too much good. I've tested some programs and very few ones completed my needs:
- ArgoUML: It lacks of a very intuitive interface and some basic functionalities that I find vital, and it doesn't allow me to do things in the way I want (bad class diagrams, bad sequence diagrams)
- Violet: It is not updated to UML2, so I couldn't do some stuff like fragments in sequence diagrams
- UMLet: It would be really good if it had a simple, but very necessary tool: a ZOOM!
- BoUML: You can't do constructors in sequence diagrams.
So, after some research, I found 2 programs which fit on my needs:
SDedit: Probably the best sequence diagram editor I've ever seen. It is not a WYSIWYG editor like the others, you have to know some easy-to-use code (read the program's help) to make sequence diagrams. You type a simple code, and the diagram is drawn while you're doing that. Once you are used to it, the sequence diagram production speeds up in a considerable way, and the diagrams it makes are really nice.
As it is not a WYSIWYG program, it introduces us to a new philosophy: Dragging&dropping, mouse moves... it's rather slower than simply typing some short lines with keyboard. I leant this concept and idea, and I find it well-builded in empirical demonstrations. I, for instance, I can make sequence diagrams fastly. With a "drawing" (WYSIWYG) editor I spend more time. I can assure you this.
Dia: SDedit is a program that has sense: Sequence diagrams are just this, sequential. They can be builded and all drawn objects can have a fixed position in the diagram and it will be well shown; in class diagrams it's not possible to do that (or it is really harder), because you can position your items and classes in many ways and are all pretty or more understandable.
I was looking for a program to design class diagrams as I design sequence diagrams in SDedit, by code; nevertheless, for the reasons explained above, I have not find any program such that (or I'm so stupid that I am not able to find it), so I had to give up and use a decent WYSIWYG editor. I found Dia for this, it's a great program, similar to Visio, it allows me to do very nice class diagrams in UML. It is far better than all described above, but by default it doesn't allow to create associative classes (it's not a huge problem but it could be good to have them), and last time I tried it, after forcing a bit the program capabilities, I recived a Segmentation Fault, loosing my time. It was not very happy, but I will give him a new try.
Well, today I've been working on how to make 'foo' blocks and modules.
Making blocks has been quite easy because in moodle wiki there is a very well explained page about how to make blocks for Moodle: link to the page. I upload the block I've programmed so anyone can see 'in life' the progress:
As you can see, making a block in Moodle it's very easy. But making modules... it's rather harder than blocks. There isn't documentation as good as blocks, and the template they give you it's a bit confusing, specially for the database managing.
While trying to learn how can I program a foo module, I think I've learnt accidentally how I can manage databases in Moodle. For the module, I need to create a database table in one of the files of module, but I don't know where and how... I expect that the following libraries I've found will be useful to me:
In the lib folder of Moodle, there is 2 libraries: ddllib.php and dmllib.php. The first one contains functions to alter the main structure of the database (create and alter tables, for instance). The second one is used to access data (like inserting new rows, retrieve values, delete values, etc).
Let's follow working on it... I've not finished yet :)
Well, today I've started classes at UPC again (finally, I just wanted it :D), and after my first class in "Web Application System Design" and looking for my scolarship holder table (OMG, it was an enormous and dirty table, but I've cleaned it; I hope I will find it as clean as I left it tomorrow), I met Marc.
The objective of the meeting was to show him the OpenSyllabus integration in Moodle prototype I made and "look for" more work.
After Marc took a look into my work, he noticed something he didn't like: Lesson outlines (see image) are all wikis (1 wiki per lesson). This was the unique way I found to solve a problem:
- Marc wanted me to make only 1 wiki, and the lesson outlines were mere links to a wiki page from that wiki. The problem is that links are stored in the Moodle course XML files as static links.
- These links have a number parameter, the wiki identifier. (For example, ID 10). When restoring a course, moodle assigns a different ID automatically to the new modules of the course, so the wiki will have probably another ID different than 10. But the lesson outline link has the ID 10 as parameter!!! (static link).
So, what can I do now? Well, Marc told me that I have to find the way to change the ID of these links to redirect to the current wiki ID. How can I do this?
As a first requirement, I can make an abstraction:
- First, I have to found, in the restoring process, where the new wiki ID is given and restored.
- Then, after the piece of code I found before, I have to retrieve the new ID value.
- Then, I have to locate the code where the link resources are restored.
- Finally, I have to modify every link that will be restored in the previous founded code, retrieving the current link direction, and modifying the id parameter to the previous retrieved ID value from wiki.
I hope it won't be so hard to perform, however Marc's purposes for this piece of work are merely for my own learning and education.
Marc has explained to me that I will work on DFWiki code refactoring (lot of work is coming OMG), so as a training he demanded me to program a "foo" (example) Moodle format course, Moodle module and a Moodle block. This job has priority for me over the "ID" job explained previously.
In Moodle wiki I remember founding something related with that (some module/block/course format templates), so I'm going to take a look immediately.
Ok guys, let's work!
Once I've programmed the PHP part of the prototype, I had to program the other part of the project: the XSLT file.
Let's go back for a while; the main purpose of the project is, having a syllabi (OpenSyllabus XML course file), I have to make a moodle course automatically according to that syllabi.
Moodle courses can be saved as XML files and be restored with that XML file. With this premise, and knowing that syllabi are also XML files, we can see that we need to transform in some way the syllabi into a Moodle course. The way for doing it is called XSLT (eXtensible StyleSheet Language Tranform).
The process for making the XSL file:
- First, having a syllabi example, I've made manually a Moodle course.
- Then, I've stored the XML file into my computer to work with it (making a backup of the course). Now, the objective is to transform the syllabi XML file into a Moodle XML course file with the aid of XSLT language.
(in the previous entry of my blog I wrote about the PHP part and his relantionship with XSLT part).
I never did any XSL transformation or programmed a XSL file, and I needed learning some advanced XSL features immediatelly not recommended for a newbie who wants to learn XSL as a hobby :). Also I had to adapt the xsl syntax to moodle, because Moodle needs "special" considerations:
- Moodle xml files have very separated parts in the document. However, some parts have a very close relationship, and this relation can only be linked with an Identifier. But this identifier needs to be independent of the XML syllabi, so after some heavy research, the XSL function I needed for this was "generate-id" (this function generates a unique ID for a node, ideal for the lesson bucle).
- I didn't know why Moodle, after the point 1 application, gave me errors didn't allow me to create a course. The explanation was that generate-id generates an id like "id7623472". Moodle only reads numbers, not strings!, so I have to discard the "id" string with "substring" xsl function.
- In bucles, I needed incremental variables (aka i++ :)). Nevertheless, "variable" xsl element doesn't allow changing his first assigned value (OMG, problem!), because XSL is a declarative language, not a procedural one like C++ or PHP. The first and valid approach I found to solve this problem was the "number" xsl element. In a bucle, it makes something like a counter, from 1 to N being N the number of iterations. I found it a rustic and 'vaste' method, but valid for my purposes :)
After all these ones, and spending some time, finally I've finished the XSL file and it works perfectly. But this XSL file is built over a syllabi prototype, not over a final version, so I will have to modify it a lot when I recive it.
Now, I've finished all my work on OpenSyllabus integration prototype for Moodlemoot for now until "new external requirements" (probably they will arrive soon).
As you can see, in my blog entries I'm writing about XML files and other kind of resources, but I don't put any example to allow you understanding me clearly. Once I finish the project I will upload all those files and will modify all posts adding to them the mentioned ones (or until my teacher tells me that it could be good to upload them while they are in process).
Finally, the requirements for OpenSyllabus integration into Moodle are clearly defined. The main purpose: having a Syllabi (an OpenSyllabus XML file), Moodle has to process this XML file by means of an XSL file, which transforms the original Osyl XML file into a Moodle XML course file, and then process it to have a new Moodle course ready for being used.
However, I only have two more weeks to finish the work (all must be ready soon for Moodlemoot).
The main abstraction (God heavens, I love this word!) is (the main tasks):
- Create a new administration option, called 'Import OpenSyllabus course'.
- That option will link to a Moodle Form, where the administrator will be able to upload an XML file.
- Once the user has selected an Osyl XML file, and he submits it, the file is uploaded.
- After that, the uploaded file will be parsed with an XSL parser, who will transform the original XML into another Moodle readable XML course file.
- In order to reuse some original Moodle code (concretely the course restoration code) the output XML file needs to be zipped.
- Once the file has been zipped, now is the time to invoke the restoration process with the zipped file as parameter.
Until here, all seems to be tidy and clear. Yes, it is. This is the main specification however, I've found some personal problems (the design, how can I made it? how can I implement it?):
- I've no idea about PHP (I'm a pure Java developer, I've never touched PHP).
- How can I add a new link (which points to the import form) in the Moodle admin block?
- How can I create a form for allowing a user to upload a file compatible with Moodle?
- How can I retrieve the file? And the name of the file?
- How can I store a file into an specific folder in PHP?
- How can I process a XML file with an XSL parser with my XSL file to transform it into another XML file in PHP?
- How can I zip files in PHP?
- How can I reuse the restore implementation?
Well, all these questions have their proper answer. But where can I find the answers and understand them? Afortunately I've already found them, however, it has not been easy:
- Or I'm stupid and I can't find it, or Moodle lacks of a good developer documentation (such as complete class diagrams, specifications, sequence diagrams, proper explanations...). It only has an API over hundreds of files composing Moodle (omg, finding something has been really hard).
- I'm tired of searching concrete functions among the API files. Is the Moodle API useful or useless? Can I do my job with brute programming? Or has someone implemented what I need yet?
After some days of desperate study:
- PHP is an Object Oriented language, so a port from Java should not be too difficult. PHP is rather different than Java, however it has some similarities (like classes, attributes...), so with some practice, learning PHP should be easier (in fact, I believe I know now PHP and now I can program better than some time ago)
I've found the admin block is implemented in admin/settings. I've located my option link in courses.php file:
$ADMIN->add('courses', new admin_externalpage('osylimp', get_string('osylimp', 'admin'), $CFG->wwwroot . '/course/osyl.php'));
Moodle has a superclass for forms, called moodleform (located at lib/formslib.php). Using a form example (edit_form.php located in course folder), I've created a new subclass, called syllabi_import_form.
But the form example doesn't have a field for uploading files. How can I make one? After lot of websearching and coffees, I've found that I can add a line into the definition function of my new class:
$mform->addElement('file','syllabi', 'XML course file','maxlength="150" size="20"');
There were lots of similar lines in the document, however, replacing the first parameter with 'file' I've created a field for uploading files.
For retrieving the file value, exists a moodle function for forms: getElementValue. Passing as parameter the name of the file, it will retrieve the value entered by the user. Nevertheless, the value returned by getElementValue for the file field was an array. Arrays in PHP are rather different than Java:
For expressing an array, in Java we use this expression: namevariable[integer]. In PHP, is something similar, but different. Arrays can be used in many ways, like hash tables, priority queues, stacks... so you can use also strings into the [], and mapping a key to a value in the array. See PHP documentation for further explanation.
Finally, I could retrieve the name of the file :)
- For retrieving the file and store it, Moodle forms have a method for storing into an specific path all files the user wants to upload: "save_files".
There are lots of XSL parser for PHP: the most interesting I found was Sablotron. However, I couldn't get it working, so I've used the built-in XSLT parser (libxslt library). In PHP documentation about XSL I've found some functions to get it working. This is the main procedure:
$xp = new XSLTProcessor(); //First we create a XSLT process
$xsl = new DomDocument; //Then, we must load an XSL file
$xsl->load('../OsylCourse.xsl');
$xp->importStylesheet($xsl); //After that, we must import the XSL file
//to the XSLT process
$xml_doc = new DomDocument; //now we have to load the XML file
$xml_doc->load($CFG->dataroot.'/3/backupdata/'.$file['name']);
/*finally, we have to apply the transformation to the document and
save it to a file*/
if ($xml_out = $xp->transformToDOC($xml_doc)) {
$xml_out->save($CFG->dataroot.'/3/backupdata/moodle.xml');
} else {
trigger_error('XSL transformation failed.', E_USER_ERROR);
}Zipping a file is quite easy:
$zip = new ZipArchive(); //First we create an instance of a Zip file
/*Then, with open system call we create a zip file*/
if ($zip->open($CFG->dataroot.'/3/backupdata/course.zip', ZIPARCHIVE::CREATE)!==TRUE) {
exit("cannot open");
}
//Add as many files as you want (also directories)
$zip->addFile($CFG->dataroot.'/3/backupdata/moodle.xml', 'moodle.xml');
//Close the zip file
$zip->close();
For further information see PHP Documentation for ZIP.
- Reuse the restoration code is easy. Simply pass as a parameter the recently zipped file.
Well, that's all for now. However, there are plenty of bugs. For now, I'm only making a functional prototype for Moodlemoot... Doing things well requires time :)
The FIBer Talks
About
-
I'm using this blog as logbook for my PFC
Who is Davigetto?
Blog Archive
-
▼
2008
(37)
-
▼
September
(7)
- Sequence diagram about OpenSyllabus integration in...
- Class diagram about OpenSyllabus integration in Mo...
- The importance of UML in the software programming ...
- Blocks, modules and discovers
- 15th September: Meeting with Marc Alier: the IDea
- Next round: The XSLT part
- Next round: Implementing the OpenSyllabus integrat...
-
▼
September
(7)
Labels
- Computer (8)
- database (1)
- Diary Life (1)
- General (6)
- Information Systems (1)
- Me quejo (2)
- Miscelanea (1)
- moodle (4)
- opensyllabus (1)
- Personal (7)
- PFC (26)
- php (2)
- Poetry (6)
- restore (1)
- Testing (1)
- Web (1)
- xml (1)
- xslt (2)
- zip (1)