Where to start Moodle API?

Where to start Moodle API?

by Daniele Filipe -
Number of replies: 4

Hello Moodle Community,


I am new to PHP and new to the Moodle code, however, I am not new to programming. Moodle is a big program and trying to understand everything at once is daunting. 

My question is, where can I start to get the best understanding of Moodle and how it works?

I've looked at the architecture, Core APIs (this was where I started getting stuck, especially looking at the $PAGE API), coding guidelines and I understand how Moodle works from a user's point of view. 

The main issue I am having with especially is finding where the code is located in Moodle. For example, the $PAGE API mentions all the functionality it has, however it doesn't specify where in the code the $PAGE API is implemented. How can I find this out for any API?

Daniele

Average of ratings: -
In reply to Daniele Filipe

Re: Where to start Moodle API?

by Андрей Тюфтин -

hi Daniel. You said - Moodle was one large program. Try to understand - don't even try) I would start to understand Moodle with the database, with its structure..the Main elements of user interaction and Moodle are elements of the course (plugins). For a General view on this site enough information on their device..and of course a basic knowledge of php and html are required) 

this is my opinion, but I may be wrong in that..

good luck

Average of ratings: Useful (1)
In reply to Daniele Filipe

Re: Where to start Moodle API?

by Fred Riley -

Hi Daniele

I'm in a similar position to yourself, coming fresh to Moodle development from a programming and e-learning background. It is an enormous and insanely complex system, so in my case I've found it simpler to concentrate on specific tasks and learn from those, rather than trying to integrate all of the APIs in my mind.

I started with the Block and Theme tutorials on Moodle Docs, and that enabled me to gain a small foothold in Moodle territory from where I could venture tentatively into the dense jungles beyond. This is my personal learning style - others might prefer a different way of approaching the Moodle Monster, and I'll be interested in other responses to your question.

It's best, in my view, to concentrate on specific development tasks in Moodle and to adapt existing work - being an Open Source system, Moodle is very well suited to this 'adapt and reuse' approach. As a colleague of mine put it: "forget about full anatomy of the Moodle Monster, just learn how to give it a manicure".

What I've found extremely useful is to install a copy of Moodle on localhost, to run under XAMPP. If you've not done this already, I'd advise it.

Fred

Average of ratings: Useful (1)
In reply to Daniele Filipe

Re: Where to start Moodle API?

by David Mudrák -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators

What helped me when I started with Moodle development was setting up my editor/IDE so that it allows to quickly jump to a function definition and back. Then, when trying to understand a particular area of the code, I just opened the script I saw in the address bar (such as /course/view.php?id=42) and started to study it line by line - just as the PHP does itself. It mostly works for all the code.

Some exceptions that you need to get familar with are those global objects created by the core setup - such as $DB, $PAGE or $OUTPUT. For these, grepping the code in lib/dml/moodle_database.php, lib/pagelib.php and lib/outputrenderers.php respectively may be a good start.

In reply to Daniele Filipe

Re: Where to start Moodle API?

by Andrew Lyons -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi Daniele,

Good question, thanks for posting.

For me personally when I started to learn Moodle I started as others have suggested with implementing a new module, block, or report. I asked others for good examples of similar existing plugins to see how they were structured.

Moodle has been around for many years and so you have to be careful which module to pick. For example, the forum code is some of the oldest and hasn't (yet) been updated to use renderers and renderables. It also doesn't meet much of the coding style and has some very complex sections of code. Similarly, although the quiz is extremely well written and maintained, and has a fair amount of good documentation, it's probably not a good one to start with (sorry Tim Hunt) because it's an extremely complicated module. If you're looking to write a new module, you'd do well to look at the workshop and assignment plugins.

Also, as David says, make use of your tools. I personally don't use an IDE (I use ViM), but I'm at one with the editor, and I have made sure to learn as much as possible of Git too. I know that I can do things like quickly use git grep to find where a function is defined (sometimes quicker than some IDEs can do so), or use git blame to find out where a line of code originated from so as to understand it's original intent.

Another thing you can do is to look at the unit tests. For the most part, our unit tests are fairly new (certainly in comparison to some parts of the code), and mostly follow the current coding style guidelines.

Hope that this helps,

Andrew

Average of ratings: Useful (2)