Your SlideShare is downloading. ×
0
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Zen and the Art of Claroline Module Development
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Zen and the Art of Claroline Module Development

5,811

Published on

Or: How I Learned to Stop …

Or: How I Learned to Stop
Worrying and Love
Creating Claroline
Modules

by Frédéric Minne
Institut de pédagogie universitaire et des
multimédias
UCL - Belgique

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
5,811
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
106
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • Transcript

    • 1. Zen and the Art of Claroline Module Development <ul><ul><li>Or: How I Learned to Stop Worrying and Love Creating Claroline Modules </li></ul></ul>Frédéric Minne Institut de pédagogie universitaire et des multimédias UCL - Belgique
    • 2. Goal of this talk <ul><li>Take a look at the module architecture of Claroline </li></ul><ul><li>Explain how to create a Module using the Claroline Module API </li></ul><ul><li>See how module development can be made simpler using the embed.lib </li></ul><ul><li>Take a look at the future and improvements of Claroline modules </li></ul>
    • 3. Modules in Claroline <ul><ul><li>Modules mean modularity </li></ul></ul>
    • 4. Why modules in Claroline ? <ul><li>To enhance Claroline modularity </li></ul><ul><ul><li>To decouple the kernel and the tools (development and release) </li></ul></ul><ul><ul><li>To allow building « à la carte » Claroline distributions </li></ul></ul><ul><ul><li>To make upgrade simpler </li></ul></ul><ul><ul><li>To help the distribution of home-made tools </li></ul></ul><ul><li>To help developers to create new tools </li></ul>
    • 5. What is a Claroline Module ? (functional view) <ul><li>A business unit that could be </li></ul><ul><ul><li>An applet </li></ul></ul><ul><ul><ul><li>Adds some functionnalities to existing pages </li></ul></ul></ul><ul><ul><ul><li>Displays output in reserved zone called docks </li></ul></ul></ul><ul><ul><li>A (course) tool </li></ul></ul><ul><ul><ul><li>A bigger piece of script that adds a new tool to Claroline </li></ul></ul></ul><ul><ul><ul><li>Could be accessed through the tool list of a course </li></ul></ul></ul>
    • 6. What is a Claroline Module ? (technical view) <ul><li>A package containing a set of files </li></ul><ul><ul><li>Some are mandatory </li></ul></ul><ul><ul><ul><li>manifest.xml , describes the module </li></ul></ul></ul><ul><ul><ul><li>entry.php , the entry point of the module </li></ul></ul></ul><ul><ul><li>Other are optional </li></ul></ul><ul><ul><ul><li>Setup files </li></ul></ul></ul><ul><ul><ul><li>Configurations </li></ul></ul></ul><ul><ul><ul><li>Libraries </li></ul></ul></ul><ul><ul><ul><li>Icons and Style sheets </li></ul></ul></ul><ul><ul><ul><li>... </li></ul></ul></ul>
    • 7. Creating Modules for Claroline <ul><ul><li>A (not so) short tutorial </li></ul></ul>
    • 8. The (mandatory) « Hello World » Module <ul><ul><li>Content of entry.php : </li></ul></ul><ul><ul><li><?php </li></ul></ul><ul><ul><li>// Module identifier (aka Module Label) </li></ul></ul><ul><ul><li>$tlabelReq = 'HELLO'; </li></ul></ul><ul><ul><li>// Include Claroline Kernel </li></ul></ul><ul><ul><li>require dirname(__FILE__) . '/../../claroline' </li></ul></ul><ul><ul><li>. '/inc/claro_init_global.inc.php'; </li></ul></ul><ul><ul><li>// Business logic </li></ul></ul><ul><ul><li>$sayhello = &quot;hello world&quot;; </li></ul></ul><ul><ul><li>// Include Claroline header and banner </li></ul></ul><ul><ul><li>require get_path('includePath') </li></ul></ul><ul><ul><li>. '/claro_init_header.inc.php'; </li></ul></ul><ul><ul><li>// Display </li></ul></ul><ul><ul><li>echo $sayhello; </li></ul></ul><ul><ul><li>// Include Claroline footer </li></ul></ul><ul><ul><li>require get_path('includePath') </li></ul></ul><ul><ul><li>. '/claro_init_footer.inc.php'; </li></ul></ul><ul><ul><li>?> </li></ul></ul>
    • 9. How does this script work ?
    • 10. How does this script work ? <ul><li>First the script initialises and call the Claroline Kernel to set session variables, check access rights, load libraries, load lang and config... </li></ul><ul><li>Then the script executes its business logic to produce the data that will be used in display </li></ul><ul><li>The Kernel is called to display Claroline header and banner </li></ul><ul><li>The script displays its output </li></ul><ul><li>The Kernel is called to display Claroline footer </li></ul>
    • 11. Write the module manifest (1) <ul><li>The module manifest contains the data needed to install and run the module </li></ul><ul><li>Mandatory data are : </li></ul><ul><ul><li>Module Label, module unique identifier </li></ul></ul><ul><ul><ul><li>« HELLO » here (Upper case) </li></ul></ul></ul><ul><ul><li>Module Type, applet or tool </li></ul></ul><ul><ul><ul><li>« tool » here </li></ul></ul></ul><ul><ul><li>Module Name, </li></ul></ul><ul><ul><ul><li>« Hello World » </li></ul></ul></ul>
    • 12. Write the module manifest (2) <ul><li>Other optional data could be added </li></ul><ul><ul><li>Module description </li></ul></ul><ul><ul><li>Module author data (website, email,...) </li></ul></ul><ul><ul><li>Module version </li></ul></ul><ul><ul><li>Module dependencies </li></ul></ul><ul><ul><li>Module license </li></ul></ul><ul><li>The manifest is written in XML </li></ul>
    • 13. Write the module manifest (3) <ul><ul><li>The content of manifest.xml : </li></ul></ul><ul><ul><li><module> </li></ul></ul><ul><ul><li>< label > HELLO </ label > </li></ul></ul><ul><ul><li>< name > Hello World </ name > </li></ul></ul><ul><ul><li>< type > tool </ type > </li></ul></ul><ul><ul><li>< description > a really useful tool </ description > </li></ul></ul><ul><ul><li>< version > 0.1 </ version > </li></ul></ul><ul><ul><li>< author > </li></ul></ul><ul><ul><li>< name > Me </ name > </li></ul></ul><ul><ul><li>< email > [email_address] </ email > </li></ul></ul><ul><ul><li>< web > http://me.mydomain.net/HELLO </ web > </li></ul></ul><ul><ul><li></ author > </li></ul></ul><ul><ul><li></module> </li></ul></ul>
    • 14. Let's make the package and install the tool (with a demo) <ul><li>Create a zip archive hello_tool.zip containing </li></ul><ul><ul><li>entry.php </li></ul></ul><ul><ul><li>manifest.xml </li></ul></ul><ul><li>Go to Administration > Platform > Modules </li></ul><ul><li>Click the 'Install module' link and choose the hello_tool.zip package </li></ul><ul><li>Activate the module </li></ul><ul><li>Test the module in a course </li></ul>
    • 15. It's Alive, Alive !!!! (The Mad Claroline Developer)
    • 16. Write your first applet <ul><li>An applet is a small piece of code </li></ul><ul><ul><li>But some applets could have an associated tool-like script </li></ul></ul><ul><li>Applets can output some data in reserved zones called docks </li></ul><ul><ul><li>the manifest SHOULD include the definition of a default dock </li></ul></ul><ul><li>Applets use a buffer to generate their output </li></ul>
    • 17. The « Hello World » Applet <ul><ul><li>Content of entry.php: </li></ul></ul><ul><ul><li><?php </li></ul></ul><ul><ul><li>$out = '<p>Hello World !</p>'; </li></ul></ul><ul><ul><li>$claro_buffer->append( $out ); </li></ul></ul><ul><ul><li>?> </li></ul></ul><ul><ul><li>Content of manifest.xml: </li></ul></ul><ul><ul><li><module> </li></ul></ul><ul><ul><li>< label > ALOHA </ label > </li></ul></ul><ul><ul><li>< name > Hello World </ name > </li></ul></ul><ul><ul><li>< description > Hello Applet </ description > </li></ul></ul><ul><ul><li>< type > applet </ type > </li></ul></ul><ul><ul><li>< default_dock > userBannerRight </ default_dock > </li></ul></ul><ul><ul><li></module> </li></ul></ul>
    • 18. Let's test this tremendous applet (with a demo) <ul><li>Create a zip archive hello_applet.zip containing </li></ul><ul><ul><li>entry.php </li></ul></ul><ul><ul><li>manifest.xml </li></ul></ul><ul><li>Go to Administration > Platform > Modules </li></ul><ul><li>Click the 'Install module' link and choose the hello_tool.zip package </li></ul><ul><li>Activate the module </li></ul><ul><li>The text « Hello World ! » appears in user banner </li></ul>
    • 19. It's Alive, Alive !!!! (The Return of the Mad Claroline Developer)
    • 20. Using Claroline API to enhance the « Hello World » tool (1) <ul><li>We want to personalize the message for each user </li></ul><ul><li>We will use Claroline API functions to </li></ul><ul><ul><li>Control the tool workflow </li></ul></ul><ul><ul><li>l10n / i18n messages using get_lang </li></ul></ul><ul><ul><li>Retrieve user data </li></ul></ul><ul><ul><li>... </li></ul></ul>
    • 21. Using Claroline API to enhance the « Hello World » tool (2) <ul><ul><li>New version of the business logic in entry.php: </li></ul></ul><ul><ul><li>// Business logic </li></ul></ul><ul><ul><li>if ( claro_is_user_authenticated () ) </li></ul></ul><ul><ul><li>{ </li></ul></ul><ul><ul><li>$sayhello = </li></ul></ul><ul><ul><li>get_lang ( &quot; Hello %firstName% %lastName% ! &quot; </li></ul></ul><ul><ul><li>, array ( ' %firstName% ' => </li></ul></ul><ul><ul><li> claro_get_current_user_data ('firstName'), ' %lastName% ' => </li></ul></ul><ul><ul><li> claro_get_current_user_data ('lastName') ) </li></ul></ul><ul><ul><li>); </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><li>else </li></ul></ul><ul><ul><li>{ </li></ul></ul><ul><ul><li>$sayhello = get_lang ( &quot; Hello dear visitor ! &quot; ); </li></ul></ul><ul><ul><li>} </li></ul></ul>
    • 22. It's Alive, Alive !!!! (Oh no, not the Mad Claroline Developer again)
    • 23. Let's use the database to store data about users <ul><li>Display the last date a user access to our module </li></ul><ul><li>Need to </li></ul><ul><ul><li>Create the database using the module setup scripts </li></ul></ul><ul><ul><li>Use the module API to access the database tables </li></ul></ul><ul><ul><li>Store and retrieve the data using Claroline SQL functions to show the last script access date to a registered user </li></ul></ul>
    • 24. The module setup scripts <ul><li>The module setup contains : </li></ul><ul><ul><li>Main database SQL setup scripts : </li></ul></ul><ul><ul><ul><li>install.sql : sql script run at module install, typically for database tables creation </li></ul></ul></ul><ul><ul><ul><li>uninstall.sql : sql script run at module uninstall, typically for tables deletion </li></ul></ul></ul><ul><ul><li>Course database SQL setup scripts run : </li></ul></ul><ul><ul><ul><li>course_install.sql : to install the module in a course </li></ul></ul></ul><ul><ul><ul><li>course_uninstall.sql : run at course deletion </li></ul></ul></ul>
    • 25. Main database SQL setup script for the « Hello World ! » module <ul><ul><li>Create a table using install.sql : </li></ul></ul><ul><ul><li>CREATE TABLE IF NOT EXISTS </li></ul></ul><ul><ul><li>` __CL_MAIN__ hello_user_access` ( </li></ul></ul><ul><ul><li>userId int(11) unsigned not null, </li></ul></ul><ul><ul><li>accessDate timestamp not null default now(), </li></ul></ul><ul><ul><li>primary key (userId) </li></ul></ul><ul><ul><li>); </li></ul></ul><ul><ul><li>Drop the table with uninstall.sql: </li></ul></ul><ul><ul><li>DROP TABLE IF EXISTS </li></ul></ul><ul><ul><li>` __CL_MAIN__ hello_user_access` ; </li></ul></ul>
    • 26. Let's add database access code and test the module <ul><li>Use get_module_main_tbl to get the module table names </li></ul><ul><li>Use claro_sql_query to create or update the last access date associated with the current user </li></ul><ul><li>Use claro_sql_query to get the last access date associated with the current user </li></ul>
    • 27. It's Alive, Alive !!!! (The revenge of the Mad Claroline Developer)
    • 28. Using course databases instead of main (central) databases <ul><li>Write course setup scripts : </li></ul><ul><ul><li>course_install.sql </li></ul></ul><ul><ul><li>course_uninstall.sql </li></ul></ul><ul><ul><li>using __CL_COURSE__ instead of __CL_MAIN__ </li></ul></ul><ul><li>Call install_module_in_course </li></ul><ul><ul><li>module label of the current module </li></ul></ul><ul><ul><li>claro_get_current_course_id() </li></ul></ul><ul><li>Use get_module_course_tbl instead of get_module_main_tbl </li></ul>
    • 29. Differences between main and course databases <ul><li>Main databases : </li></ul><ul><ul><li>Setup scripts executed only once </li></ul></ul><ul><ul><li>Data are shared over the platform </li></ul></ul><ul><ul><li>You have to store course informations </li></ul></ul><ul><li>Course databases : </li></ul><ul><ul><li>Install script executed at each access to the module, uninstall script executed at course deletion </li></ul></ul><ul><ul><li>Data are « private » to a course, not shared </li></ul></ul><ul><ul><li>Course information stored in database schema </li></ul></ul>
    • 30. Embed your script output <ul><ul><li>And make your scripts code simpler with embed.lib </li></ul></ul>
    • 31. Embedding your script output : Why ? <ul><li>No more need to include header and footer </li></ul><ul><li>Make display options </li></ul><ul><ul><li>Simpler to control </li></ul></ul><ul><ul><li>Easier to understand </li></ul></ul><ul><li>Make your source code clearer </li></ul><ul><li>Easily convert an existing script into a Claroline module </li></ul>
    • 32. Embedding your script output : How ? <ul><li>Use embed.lib that provides </li></ul><ul><ul><li>function claro_embed, to embed script output in Claroline </li></ul></ul><ul><ul><li>class ClaroScriptEmbed, OOP version with methods to add extra element and control display </li></ul></ul><ul><li>Use a buffer to store your script output </li></ul><ul><ul><li>A buffer string variable </li></ul></ul><ul><ul><li>PHP output buffering functions </li></ul></ul><ul><li>Pass the buffer contents to the function/object </li></ul>
    • 33. Use embed.lib in our module entry point <ul><ul><li>Content of entry.php : </li></ul></ul><ul><ul><li><?php </li></ul></ul><ul><ul><li>// Module identifier (aka Module Label) </li></ul></ul><ul><ul><li>$tlabelReq = 'HELLO'; </li></ul></ul><ul><ul><li>// Include Claroline Kernel </li></ul></ul><ul><ul><li>require dirname(__FILE__) . '/../../claroline' </li></ul></ul><ul><ul><li>. '/inc/claro_init_global.inc.php'; </li></ul></ul><ul><ul><li>// Include embed.lib </li></ul></ul><ul><ul><li>require get_path('includePath') </li></ul></ul><ul><ul><li>. '/lib/embed.lib.php'; </li></ul></ul><ul><ul><li>// Business logic </li></ul></ul><ul><ul><li>[...] </li></ul></ul><ul><ul><li>// Script output </li></ul></ul><ul><ul><li>claro_embed( $sayhello ); </li></ul></ul><ul><ul><li>?> </li></ul></ul>
    • 34. It's Alive, Alive !!!! (Demo time with the Mad Claroline Developer)
    • 35. The Future of Claroline Modules <ul><ul><li>Let's take a look at some potential improvements in the Claroline module architecture </li></ul></ul>
    • 36. New and enhanced module types <ul><li>Enhance current module types </li></ul><ul><ul><li>Group tools </li></ul></ul><ul><ul><li>Allow applet contextualization </li></ul></ul><ul><li>Add new module types </li></ul><ul><ul><li>Shared libraries and drivers </li></ul></ul><ul><ul><li>Administration, platform and other tools that run outside a course </li></ul></ul><ul><ul><li>Languages, Themes and Wysiwyg editors </li></ul></ul>
    • 37. Improved module setup <ul><li>Dependency checking and enforcement </li></ul><ul><li>Version management and upgrade </li></ul><ul><li>Developer-friendly </li></ul><ul><li>Kernel safe mode (no modules loaded) in case of platform crash </li></ul><ul><li>Course install by Kernel not by hand </li></ul><ul><li>Module reinstallation </li></ul><ul><li>Split file uninstallation from data deletion </li></ul>
    • 38. Tools to make developers happy <ul><li>Enhanced debugging facilities </li></ul><ul><li>New embedding classes for HTML Frames and Framesets (already in 1.9), for Applets (decorators)... </li></ul><ul><li>Module packager </li></ul><ul><li>Manifest generator </li></ul><ul><li>Unit test integration </li></ul>
    • 39. Questions and (maybe) answers
    • 40. Contact E-mail : [email_address] Jabber : [email_address] On Claroline Forums or IRC Channel

    ×