Code review: forms/groups/attributes APIs

A bunch of changes made before christmas - could do with a code review.

* Build out api/forms
* Build out api/forms/ID/attributes
* Build out api/forms/ID/groups
* Build out api/forms/ID/groups/ID/attributes
* Behat tests for all this
* Add datetime attribute type (in wiki discussion but not in code before)
* Return URLs in API: for current object, any related objects
* Add foreign keys to SQL schema
* Return errors as JSON not HTML - currently a bit of a hack as we're doing this for everything not just API requests.