Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Moodle 'nder the hood Davo Smith


Published on

Moodle 'nder the hood Davo Smith
Presented at Edinburgh Moodlemoot 2014

  • This makes a lot more sense when you can see the embedded notes:

    1. Davo Smith developer from UK Moodle Partner Synergy Learning;
    I'm also the developer of drag and drop upload and pdf annotation.
    I'm going to try and dismantle, then reassemble a single Moodle page in about 6.5 minutes.

    2. This is the page we're going to dismantle (just an example, made up for this presentation).
    It has the standard Moodle layout
    It has some intro text
    It then has a message to display to all users
    At the bottom is a space for users to type in a new message

    3. It would be nice to imagine that Moodle worked a bit like this - with trained artists at Moodle HQ hand-drawing each page on demand.
    Sadly, it turns out that their arms get too tired after a few hours of this, so, instead, Martin Dougiamas decided to work with a language called PHP

    4. So we start with the most important line of any Moodle page - including 'config.php'
    This sets up the connection to the Moodle database, loads all the main parts of the Moodle code into memory and sorts out important details like which user is accessing the current page.

    5. Next up, we need to figure out where we are on the Moodle site. To do that, we grab the parameters off the end of the URL - using the 'required_param' or 'optional_param' functions.
    In this case - we have the ID of the course module, the activity container, that we are viewing.

    6. Now we load the course module data from the database - this holds details that are needed by all activities in Moodle - which course and course section it belongs to, what group mode it is using, whether or not it is visible.

    7. Next we load the specific data for this activity instance - including the name, the intro text and, in this case the current message to display.
    Much of information comes from the 'settings form' when you create a new activity.

    8. Now we tell Moodle the official URL for the current page - just in case it needs to get back here again later. Here we use the 'moodle_url' class, which fills in the base website address for us. We also use the '$PAGE' object to store this URL in.

    9. Now for a bit of security - here we check if the user is logged in, booting them back to the login screen if they're not. (The URL we set up in the last step is where they'll come back to, once they've logged in.)

    10. We're now logged in - but can we access the page?
    First we need to know what context we're in - so we can work out what permissions the current user has here.
    It could be the system, a category or a course, but in this case it's the activity module called 'This is an example'.

    11. We check the user's capabilities in the context we've just looked up - stopping the page at once, if they don't have permission to be here.

    12. And... we're in. Let's make sure we note the user's details in the logs, before we go any further, so we can check up on them again later, if we need to.

    13. We're nearly ready to start drawing the page for the user - first we have to tell Moodle the title of the page, for the browser title bar, and the heading to put at the top of the content.

    14. Notice how, on the last page, we used 'get_string' instead of writing the name of the plugin - this is the heart of how Moodle is able to be translated into so many different languages: get_string shows the relevant text from the currently selected language.

    15. Let's actually output something now - OUTPUT->header sends out the first part of the webpage - including all the headers, meta data and stylesheets; plus the top part of the page content - right up to where we want our own bits.

    16. Now we output the module 'intro' (or description), followed by a box with the current 'message' that has been typed into the plugin.
    I'll come back to the form in a moment.

    17. Finally we finish off the page by outputting the footer - which, depending on the theme, includes both the block sidebars, the Moodle docs and login/out links and any javascript that didn't need to be sent at the start of the page.

    18. I mentioned the form earlier - there are 3 parts to using a form. Part 1 is to define the form we are going to use - in this case, with one header element, one text area and then an update button.

    19. Part 2: we check to see if anything has been submitted - if it has we process it, save it back into the database, then reload the page so that the update can be seen.

    20. Finally we need to add the form into the output ... and there have it, a Moodle page dismantled and re-assembled in just over 6.5 minutes.
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

Moodle 'nder the hood Davo Smith

  1. 1. Davo Smith @davosmith
  2. 2. Blocks Page heading Intro text Current message Form to update message
  3. 3. ?
  4. 4. context_system context_coursecat context_course context_module
  5. 5. Davo Smith @davosmith