Ray Morris による投稿

Maybe for the same reason it does this:

WHERE id LIKE '$id'

instead of this:

WHERE id=$id

Sorry, I just thought it was interesting that after your five years working with Moodle, the lack of a unique index in the DB was what you thought was wonky. 

It's totally dependant on you, your background, and mostly whether you see things as individual cases, or your brain automatically generalizes.

Moodle is big though - 1.1 million lines of code or so, so there's a lot to learn.  For reference, that's three times as many code lines as Apache, if you've ever written an Apache module.  The API is pretty big.  Like writing Apache modules, you can pretty quickly learn to do it "wrong", like writing your own SQL queries, then you learn to do it "right", calling get_record().

I've had people working for me, with many years of experience and a CS degree, who would NEVER be able to write a decent plugin.  I came to Moodle with fifteen years of experience writing modules for other systems and was authoring working Moodle modules, simple ones, within a few days.

The thing is, my brain generalizes.  I write modules.  I already knew how to write modules.  The only thing that changed is those modules now use the Moodle names for the functions as opposed to the Apache names, the Wordpress names, or the kernel names.  For some people, writing a Moodle module, an Apache module, or a kernel module is all the same thing.  Those people will have no trouble learning the Moodle framework.   You may be one of those people if you find yourself accidentally using two or three different programming languages in the same file.  C, Perl, PHP, Bourne shell - it's all the same for some of us, so we forget which language we're writing in.

 

If you're the other type, the type of person who doesn't confuse PHP syntax verus Perl versus C versus JavaScript, you've got a big job ahead.  If you had to learn javascript seperately from other languages you already knew, you'll have to learn Moodle programming from scratch as well.

 

So that other modules can more easily get the list of users online and to reduce duplication of code, I think it would be good for the Online Users block to place get_users_online() in externallib.php.  In that way, other modules like the forum could simply call get_users_online().  

Describing the function in services.php would make it also available as a web service. 

This would not effect the operation of the block at all - it would only make the information available to other blocks which choose to call the function. Everything would still work exactly the same as it already does if you don't add another module which takes advantage of the newly available function.

I'd be glad to make these adjustments to make the function available.

Right now, the block consists basically of one big function which first gets the list, then generates HTML to display it. To make the list available via a function call, I'll seperate those two tasks into two seperate functions - one to retrieve and filter the list, the other to generate HTML for display.