40
Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Mahara Development for Moodle Developers Penny Leach <[email protected]> MoodleMoot Barcelona October 24 2008 Penny Leach <[email protected]> MoodleMoot Barcelona Mahara Development for Moodle Developers

Mahara Development for Moodle Developers

Embed Size (px)

DESCRIPTION

Workshop by Penny Leach at the MoodleMoot Barcelona 2008 on 24 October 2008

Citation preview

Page 1: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

Mahara Development for Moodle Developers

Penny Leach <[email protected]>

MoodleMoot Barcelona

October 24 2008

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 2: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

1 IntroductionWhere the similarities come fromMahara’s General approach

2 Key SimilaritiesDML & XMLDBUpgradesLanguage Packsconfig.php

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 3: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

3 Key DifferencesDatabaseInput and OutputError handling and debuggingMiscellaneous differences

4 Other main componentsSignalling

5 Plugin TypesIntroduction to PluginsArtefact PluginsOther PluginsThemes

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 4: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

6 Code flow layout

7 A typical Mahara Page

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 5: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

1 IntroductionWhere the similarities come fromMahara’s General approach

2 Key Similarities

3 Key Differences

4 Other main components

5 Plugin Types

6 Code flow layout

7 A typical Mahara Page

8 Lets write some code!

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 6: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

Where the similarities come from

History

• A very rushed first 3 months• A lot of code taken from Moodle by me• Over time we diverged and broke compatibility

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 7: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

Mahara’s General approach

General approach

• PHP5 from the start• Much stricter approach• Much more OO and later PHP features.• For example, plugin definitions are all abstract classes

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 8: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

1 Introduction

2 Key SimilaritiesDML & XMLDBUpgradesLanguage Packsconfig.php

3 Key Differences

4 Other main components

5 Plugin Types

6 Code flow layout

7 A typical Mahara Page

8 Lets write some code!

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 9: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

DML & XMLDB

DDL & XMLDB

• No UI to generate XML or upgrade PHP• Learn the API and write it yourself• Learn the XML and write it yourself• Offset by removal of NEXT/PREV checking• Added some changes back into Moodle early on

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 10: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

Upgrades

Upgrades

• version.php and database version number• db/upgrade.php and db/install.xml as usual• Upgrades require administrative login• disablelogin & minupgradefrom

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 11: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

Language Packs

Language Packs

• get string

• $string array of keys to values• Use of sprintf and %s rather than eval and $a

• Slightly different get string function contract (variablearguments rather than one mixed argument)

• Helpfiles are more often automatically detected based onform element, page and section

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 12: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

config.php

config.php

• Very similar beginning - db details• docroot is detected• dataroot the same• wwwroot optional (detected but not perfect)

• Then divergence begins• One big difference:

• config.php• config-dist.php• config-defaults.php

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 13: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

1 Introduction

2 Key Similarities

3 Key DifferencesDatabaseInput and OutputError handling and debuggingMiscellaneous differences

4 Other main components

5 Plugin Types

6 Code flow layout

7 A typical Mahara Page

8 Lets write some code!

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 14: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

Database

DML

• Same starting point but a few divergences:• Prepared statements and placeholders (select * from{table} where field = ?)

• No get records anymore, get records array andget records assoc instead

• Some function contracts changed to suit $values arraybetween $sql and other things like $limit

• 138 lines of diff in grep function between Moodle andMahara but really it’s not that different

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 15: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

Database

More DB differences

• Referential Integrity - there in XMLDB but disabled inMoodle for now

• Proper date fields rather than integers• Much more use of transactions• No magic id field on every table

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 16: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

Input and Output

Forms

• Completely different to Moodle, they were developed aboutthe same time

• Pieforms, written by a Mahara developer, Nigel.• Maintained as a separate library on sourceforge• Array based form definitions with callback functions• Much simpler than QuickForms and easier to customise

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 17: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

Input and Output

Parameter Input

• Completely different approach• Moodle will clean parameters to match rules• Mahara will reject anything that doesn’t match• Moodle:

• $id = required param(’id’, PARAM INT);• $id = optional param(’id’, 0, PARAM INT);

• Mahara:• $id = param integer(’id’);• $id = param integer(’id’, 0);

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 18: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

Error handling and debugging

Error handling and debugging

• Exceptions from the start• Throw specifically, catch generally in most cases• Clearly defined Exception hierarchy, which defines the

handling of errors• Logging targets (screen/logs), could be more later (eg

email to developers)• Logging levels: debug, warn, environment

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 19: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

Miscellaneous differences

Cron

• Proper scheduler• Database example

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 20: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

Miscellaneous differences

Miscellaneous differences

• less use of globals - get config rather than global $CFG• Contentious - use of Smarty for templates• Mochikit rather than YUI

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 21: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

1 Introduction

2 Key Similarities

3 Key Differences

4 Other main componentsSignalling

5 Plugin Types

6 Code flow layout

7 A typical Mahara Page

8 Lets write some code!

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 22: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

Signalling

Event handling

• Similar to Moodle• handle event

• Core throws events, plugins can subscribe• They register which events they want at install/upgrade• Processed at cron

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 23: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

Signalling

Activity handling

• Like events, but for user activity• Eg, feedback on a view• activity occurred

• Notifies all relevant users

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 24: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

1 Introduction

2 Key Similarities

3 Key Differences

4 Other main components

5 Plugin TypesIntroduction to PluginsArtefact PluginsOther PluginsThemes

6 Code flow layout

7 A typical Mahara Page

8 Lets write some code!

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 25: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

Introduction to Plugins

Introduction to Plugins

• Registers at installation time:• Cronjobs• Event subscriptions

• Also exports config form• Exactly the same way to install and upgrade as Moodle

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 26: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

Introduction to Plugins

The Plugin base class

• get cron

• get event subscriptions

• postinst

• has config

• get activity types

• Subtypes can enforce their own abstract methods

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 27: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

Artefact Plugins

Artefact

• Richest plugin type• Two new classes

• PluginArtefact• get artefact types

• get block types

• get plugin name

• menu items

• group tabs

• ArtefactType• get icon

• is singular

• public feedback allowed

• has config

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 28: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

Artefact Plugins

More on Artefacts

• Generally plugins will write a new ArtefactType base class• Example: artefact plugin Foo will make PluginArtefactFoo

and ArtefactTypeFoo• For each artefact type that get artefact types returns,

ArtefactTypeFoo subclass• Should be fairly obvious that the API is quite flexible

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 29: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

Other Plugins

Blocktype

• Blocktypes define how artefacts are displayed in a view• Probably the most simple Mahara plugin• We’ll have a go at writing one this afternoon• Bound to either an artefact plugin or ’system’ level

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 30: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

Other Plugins

Blocktype classes

• New subclass: PluginBlocktype extends Plugin

• single only

• get title

• get description

• get categories

• get viewtypes

• render instance

• artefactchooser element

• ... more

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 31: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

Other Plugins

Notification

• PluginNotification extends Plugin

• one new method: notify user

• Current: internal messages, email, emaildigest• Could be: jabber plugin, for example

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 32: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

Other Plugins

Interaction

• Used for adding things like Forums to Groups• Two new subclass:• PluginInteraction extends Plugin

• instance config form• instance config save

• InteractionInstance• get plugin• interaction remove user

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 33: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

Other Plugins

Other plugins

• Authentication - internal, ldap, xmlrpc (MNET), imap• Search - internal (sql), solr• Grouptype - standard, course

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 34: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

Themes

Themes

• theme directory contains:• config.php - parent theme, theme name• static - stylesheets, images• templates - smarty templates

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 35: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

1 Introduction

2 Key Similarities

3 Key Differences

4 Other main components

5 Plugin Types

6 Code flow layout

7 A typical Mahara Page

8 Lets write some code!

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 36: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

Layout

• Switch to code

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 37: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

1 Introduction

2 Key Similarities

3 Key Differences

4 Other main components

5 Plugin Types

6 Code flow layout

7 A typical Mahara Page

8 Lets write some code!

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 38: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

A typical Mahara Page

• Switch to code

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 39: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

1 Introduction

2 Key Similarities

3 Key Differences

4 Other main components

5 Plugin Types

6 Code flow layout

7 A typical Mahara Page

8 Lets write some code!Ideas?

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers

Page 40: Mahara Development for Moodle Developers

Introduction Key Similarities Key Differences Other main components Plugin Types Code flow layout A typical Mahara Page Lets write some code!

Ideas?

Ideas?

• Themes• Blocktypes

• Twitter• Last.fm• Dopplr• Facebook• Flickr

Penny Leach <[email protected]> MoodleMoot Barcelona

Mahara Development for Moodle Developers