Suggestion for pluggable "components" in Moodle

Suggestion for pluggable "components" in Moodle

by John Papaioannou -
Number of replies: 10
This post is about an idea I 've had that would allow Moodle Greater Flexibility Than Even Seen Before(tm). It was cooking for quite some time now, but today I felt the need to explain to Zig why I 've given his feature request the lowest priority and I said it will be "addressed at some point". What follows here is the way I 'd like to see it addressed, and all its implications (where things get really interesting).

It has become apparent that there are some options for the calendar (do admins see all course events? which days are in weekends? and much more, I 'm sure) which don't really fit in the "personal preferences". Hell, even the "personal preferences" were a compromise from my point of view, because there's nothing like them in all of Moodle so they should probably be going into the user profile. But touching the user profile was taboo at the time, and I also didn't want to clutter it. Thus the compromise, for those settings which people would find it impossible to live without.

It's pretty much the same situation again, only on a more esoteric level. We need a configuration panel for the calendar. The logical place would be the administration screen. But does it justify one more entry? Also, the DMS needs some such panel. Does that justify one more entry, considering that it's not even part of the standard install? If it doesn't, it's impossible to provide a version of DMS which is both easy and clean to install plus heavily configurable.

You can see where this is going. IMO we need a way to plug in configuration panels into Moodle. This, and some similar issues, have given birth to a vision of mine (I 've had it for quite some time now, but no time to implement it) of providing facilities for plug-in extensions to Moodle. Much like learning activities, only those would be providing additional core functionality. Let's tentatively call them components.

One aspect of this would be a "configure components" option in the administration panel, giving admins the power to change the way Moodle works. Each component, when installed, would be free to set up its own configuration pages inside that. Calendar problems solved.

Another aspect, not visible to users but I think very useful for programmers, would be placing "notification hooks" in Moodle. In plain English: when "something" happens (a new user account is created, a student enrols in a course, an activity is deleted... almost anything!), Moodle gives a chance to all installed components in turn to respond to the event, possibly by intervening and changing some aspect of what is taking place.

Example 1: If I want to provide "automatic" creation of user folders (or course folders, for that matter) in the DMS, I have to know when a new user has been created and take appropriate action. A notification hook would be ideal for this, which is currently done manually (by running a script).

Example 2: When a user is enrolled in a course, or when he is created, we might want to send him an email with "Welcome and basic instructions" (this in fact happens here at Surrey). Again, a notification hook and you 're set.

Example 3: I said above, "possibly by intervening". Here's a concrete example which you may find interesting. At the time a new user is created, he chooses a username. A "username sanitization" feature might be provided by a component that checks usernames before the user is created, and either strips/converts disallowed characters from them or blocks the process altogether. Of course that component could have its own configuration for the disallowed characters and the type of action it takes, thus removing the need to hack Moodle if you don't like the concept or the way it works.

Example 4: We can design components with "data push" strategies instead of "data pull". "Push" is loads better in any situation where data is written "rarely" but accessed "frequently" (recent activity speedup, anyone?), plus it allows us to write the "display recent activity" code without limiting it to specific types of activity it can display; in fact, without needing it to know anything about what "recent activity" is. The code would be distributed in the components; each would advertise its latest activity and all other components might choose to respond as they see fit.

Example 5 (advanced): Let's take this a bit further. We can allow each component, when installed, to define its own hooks. Other components may, knowing of its existence and the hooks it sets, choose to respond to them (this is in very broad terms, but think of integration and interoperability). Thus, component A and component B might be independent, but when installed at the same time they could still "work together" in some aspect.

I could probably go on for hours selling my case here, but by now everyone should be either convinced or asleep... so I shut up and wait for comments. big grin

If there is positive feedback for this from the hard-core guys, I can start writing APIs so we can get more specific.

Jon
Average of ratings: -
In reply to John Papaioannou

Re: Suggestion for pluggable "components" in Moodle

by Gustav W Delius -

I like your proposal to start writing APIs for this. I think this could be very useful for the future development of Moodle. The main goal in the API should however be simplicity rather than generality.

And while you are at it, perhaps you could write some documentation for the existing APIs thoughtful? By the way, what tools would you use for that? For our JISC project we will have to use UML. Do you have any experience with that?

In reply to Gustav W Delius

Re: Suggestion for pluggable "components" in Moodle

by John Papaioannou -

The "go for simplicity" idea finds me agreeable to a large extent. Martin has always advocated simplicity too, so you can be sure I won't give birth to a monster or anything...

As for the docs: I don't have any experience with UML, or Java for that matter. I 'll probably do it in PHPdoc format.

In reply to John Papaioannou

Re: Suggestion for pluggable "components" in Moodle

by Jurgis Pralgauskis -
well, as much as I understand, things are mooving object way.

1) ArgoUML has ability to generate PHP from UML (and also some commercial plugin to reverse-engineer PHP - i thing worth a look for timesaving devs smile)

2) some portal systems (xoops I know best) try to modularize moodle. though usually they need just quizes. so just a proposal (might be silly, not sure), to have a short talk with their devs and may be some ideas would come up to help port just modules, or they might give some proposals as they have experience with OO.
In reply to John Papaioannou

Re: Suggestion for pluggable "components" in Moodle

by Michael Penney -
Hi Jon, I like so long as basic development remains simple, one of the beauties of Moodle is how easy it is for a teacher to get an idea and implement it. They've done some things like this with Xaraya (hooks), but at the same time it has become hard to code for (at least last time I tried).

One aspect of this would be a "configure components" option in the administration panel, giving admins the power to change the way Moodle works. Each component, when installed, would be free to set up its own configuration pages inside that. Calendar problems solved.

We've done some things like this with blocks, for instance our course program block, it installs as a block, but you only see it as a teacher with editing on.

It would be better though if there were some way to install admin 'modules', modules that only show up in admin. We've added things like our Banner auto enroll functions--these show up in admin of all courses but only to admins, not teachers/ccreators/'students, but they require some new code in core files that make them hard to share and move from one version to another. Admin modules that one dropped in an admin/mods folder and installed like course modules or blocks would be a nice start toward making Moodle more easily customizable.

One issue here is the tug between keeping it simple for small sites and making it robust enough for enterprise/university level sites. Admin mods would help fulfill this, with small few course sites installing just the ones they need while large sites could install database connections, advanded gradebooks, etc.  in a modular fashion.



In reply to Michael Penney

Re: Suggestion for pluggable "components" in Moodle

by John Papaioannou -

That's what I had in mind, too. And your concern about these mods being "difficult to move around" is what drove me in the first place.

I think that the worst evenings I spent in the past year were those where I was trying to get through a CVS update to a Moodle I had made major modifications to. Once for 1.2.x -> 1.3 and once for 1.3.x -> 1.4. I managed to bail out before 1.5 was released though! big grin

In reply to John Papaioannou

Re: Suggestion for pluggable "components" in Moodle

by Mike Churchward -
Picture of Core developers Picture of Plugin developers Picture of Testers
Hi Jon -

I'm intrigued. I've had the same ideas, but haven't been able to turn them into reality. Obviously, creating an object model for Moodle could be a big help.

I think this is an idea who's time has come. The biggest trick will be designing an architecture that supports this without creating a too-complex coding scheme. When that is solved, it should be easy.

Count me in.

mike
In reply to John Papaioannou

Re: Suggestion for pluggable "components" in Moodle

by Bryan Williams -
I like the "component" idea a lot.  If components are distinguished from blocks, in that they would be areas within the center content region that can be programmed for certain tasks (forms, banners, help desk, parents area etc.), it will add a great deal of content management capability to Moodle.  tongueout
In reply to John Papaioannou

Re: Suggestion for pluggable "components" in Moodle

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
I think a small amount of progress has been made as many parts of Moodle are now based on extensible classes and this is progressing. I know there are some detractors that don't like object stuff (Gustav smile ) but resistance is futile evil

However, it only makes things easier up to a point. A lot of what you talk about could be done 'Java style' and generalise everything down to class factories and the like, so you can have anything anywhere. It would be interesting but nobody would understand it anymore. As an aside, that's my big worry about php5 that we will start to pick up the Java 'experts' who like to abstract everything out of existence.

I think the short to medium term goals should be well thought out elegant (elegantly simple that is) object interfaces with properly documented APIs. We should probably be using PHPdoc or whatever it's called.
In reply to Howard Miller

Re: Suggestion for pluggable "components" in Moodle

by Rudy Scott -

I wholeheartedly support this idea.  I think converting the current "formats" setup into modular, extensible classes (more like the blocks and modules are now) would definitely promote innovation.  For example, the subsection module I've worked on periodically would be much easier to maintain if I could simply inherit display functionality from some sort of "topic" or "container" object.  I'm sure other modules could benefit from this as well.

--Rudy

In reply to John Papaioannou

Re: Suggestion for pluggable "components" in Moodle

by Mike Churchward -
Picture of Core developers Picture of Plugin developers Picture of Testers
Well, I just experienced a real-life example of why this is the way to go.

I've been holding off upgrading one of my highly customized Moodle sites, because of the customizations. I was pretty sure it would be a real drain on my energy to go through and reapply all of the necessary customizations to the code, even though I had conciously separated them out as much as possible.

Part of the customization of this site is in the use of categories. Categories are more than just labels on this site - they are entry points to separate Moodle structures. Each category can contain sub-categories and courses like normal, but each category is also a simple course. The category course is a sort-of portal to the levels below, and looks similar to the home page in that it has a description, a news forum and can contain activities.

As part of this, I had created a custom navigation that consisted of separate menus for each category, that listed the categories and courses of that category below it. Each menu was a standard list block, with a title and a list. These groups of menus are context sensitive and adjust to the category that the user is in (they reorder so that the current category is always on top).
The blocks are slightly different than normal blocks in that the title is also a link to the category main page.

Originally, I had to create a custom site index page, a custom category page, and a custom course formats, just to display these menus.

With the new block system, I figured I only had to create a new block type for this navigation, and add it to the pages I needed (index, course, etc). This would work fine, except the standard block interface doesn't allow a linkable header, and this block actually appears as a number of blocks, depending on the number of categories.

The Aha!
Because the block system has been implemented as a class, I wan't restricted to the standard way of doing things. A normal block just provides a 'get_content' method to have it displayed as a block. This wouldn't work for me, so instead, I implemented the parent classes 'print_block' method, replacing it with my code instead. Now my custom block was free to display multiple blocks as a group - and I didn't have to change a line of standard Moodle code!!

Long storey, just to show why this is the way to go. My customizations are now safely stored in their own custom block file, and will continue to work without change after Moodle code updates.

mike