The main purpose of this plugin is to demonstrate usage of advanced coding techniques available in recent Moodle versions. Most notably:For this post, I will install and examine the code with the goal of learning better how to use these concepts.
- Rendering HTML output via Mustache templates.
- AJAX based workflow of the elementary CRUD operations.
- Organising JS into AMD modules.
- Organising external functions into traits.
- Low-level access to the database via persistent models.
- Using exporters for handling the data structures in rendering and AJAX.
While I have been a plugin developer for many years, I have not been able to keep up with all of the latest techniques to enhance the plugins I maintain. I am personally really interested in getting better with AJAX and AMD, as many of my plugins could benefit from these features. I have already experimented and released code with renderers and Mustache templates (see the series beginning here), so I won't go deep into those unless I see something new.
To begin, I fork David's repository into my own Github repository. This gives me place to install and play with the code. Once I have a local copy, I load it into my IDE (I use PhpStorm) and take a look at the code.
I search the development documentation on Moodledocs, and find this function referred to on the "jQuery pre2.9" page. So, it must be a function that has remained even with the new AMD module addition. I think I may want to look for the AMD Module documentation first.
By default this function simply permits the user to dock the block if it is dockable.
In any case, the function passes the arguments:
Getting back to the function of the plugin, the main block get_content function, is a very simple function that does two things: gets a list of todo items, and outputs them on the screen. The technique uses one technique I'm familiar with, templates, and two I am unfamiliar with, Moodle persistents and Moodle exporters.
This is what I am seeing in get_content:
This code uses the persistent class, which appears to be a new technique to manage database data using CRUD techniques. It will be interesting to learn why this exists and when it should be used.// Load the list of persistent todo item models from the database. $items = block_todo\item::get_my_todo_items();
This code uses exporter class and appears to be a technique to manage data passed in and out of web service functions, used by external applications and AJAX.// Prepare the exporter of the todo items list. $list = new block_todo\external\list_exporter([ 'instanceid' => $this->instance->id , ], [ 'items' => $items, 'context' => $this->context ,]);
This code is using a Mustache template to display the block content and utilizes the exporter class to send the data rather than renderers defined for the plugin, as I am used to. Again, I will need to discover why this technique is used.// Render the list using a template and exported data. $this->content->text = $OUTPUT->render_from_template('block_todo/content', $list->export($OUTPUT));
I have some concepts to learn, so I install the block just to see what it does and how it works. After adding it to my dashboard page, I play with it, and see that it is as advertises, a simple "To Do" list.
Next post, I will start my functional learning.
Welcome to J.T. Casino - JamBaseReplyDelete
Welcome to J.T. 수원 출장마사지 Casino. Enjoy a $1000 welcome bonus 구리 출장안마 with our Welcome Bonus! 춘천 출장마사지 It gives you a 경산 출장마사지 $1000 free 화성 출장안마 play!
Moodle has a number of core APIs that provide tools for Moodle scripts. They are essential when writing Moodle plugins.ReplyDelete
Visit here https://rubioscustomironwork.com/ for Iron Gates Repair Services in Northridge CA.
Excellent series all parts are really wonderful.ReplyDelete
For availing the best realtors service in Santa Monica CA you must contact to one of the best company in CA.