Generic "custom fields" mechanism

Generic "custom fields" mechanism

by Allegre Guillaume -
Number of replies: 14
Hello,

We are facing the need to add custom fields (metadata) to courses, like what Moodle does on users custom fields. This is a requirement of a French university, and the code will be open to the community.

We are aware of the existence of a similar patch by Sanket Sharma:
http://tracker.moodle.org/browse/MDL-18319
http://moodle.org/mod/forum/discuss.php?d=193820
But we think it would be more useful (and technically cleaner) if designed as a generic mechanism, potentially usable on many objects (eg resources, activities, cohorts...). So we plan to develop such a generic mechanism, then we'll add the UI that handles these metadata for courses.

Basically, the idea is to take the user custom fields code and structure to an abstract "object" level. The 3 tables user_info_category, user_info_field and user_info_data would be somewhat renamed as custom_info_*, with an additional "object" reference field in custom_info_category.

This feature has to modify a core part of Moodle (even if not the most internal). If this feature was in a roadmap, we could follow what was planned, if anyone has pointers on this. We are also interested in any suggestion. We believe this feature would be a useful enhancement to Moodle.
Average of ratings: -
In reply to Allegre Guillaume

Re: Generic "custom fields" mechanism

by Hubert Chathi -

Remote-Learner's ELIS platform has a mechanism for attaching custom fields onto any Moodle context (although AFAIK, the interface only allowed fields on ELIS's custom contexts).  https://github.com/remotelearner/elis.base/tree/elis2

(Disclaimer: I used to work for Remote-Learner.)

In reply to Hubert Chathi

Re: Generic "custom fields" mechanism

by Allegre Guillaume -

Thanks for this reference.

Maybe I am wrong, but reading the documentation for ELIS, it seems that ELIS depends on Alfresco, which is far beyond our scope.

Nevertheless, there is maybe means to have compatible custom metadata, between ELIS and pure-Moodle. Do you know some requirements which would help to attain this goal ?

In reply to Allegre Guillaume

Re: Generic "custom fields" mechanism

by Hubert Chathi -

ELIS has several components, and one of them in Alfresco, but Alfresco is not required for the other parts.  I'm not sure, though, how much the actual code will be useful to you -- it depends on an internal database class, which builds on top of Moodle's database classes.  But you may be able to use some of the concepts from it, such as the database schema.  It's mostly based on Moodle's database custom user profile field tables, but has some additions.

In reply to Allegre Guillaume

Re: Generic "custom fields" mechanism

by Séverin Terrier -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

Hi,

Good idea : generic custom fields would certainly be useful smile

Séverin

In reply to Allegre Guillaume

Re: Generic "custom fields" mechanism

by Simon Coggins -

We've implemented course custom fields in Totara, you can have a look at https://demo.totaralms.com/ log in as demoadmin/demoadmin, then visit Manage Courses > Custom Fields. We've also added some new field types such as date/time fields.

It's written in a reasonably generic way as we also use the same code in our hierarchies. Our approach was to have separate tables for each "type" of custom field (e.g. mdl_course_info_*), rather than an extra field in a single table. It's not currently integrated with user custom fields and would require some work to integrate into moodle. 

The demo is currently running 1.9 but this code has been ported to 2.2. We are happy to share what we have if it would be useful.

Simon

Average of ratings: Useful (4)
In reply to Simon Coggins

Re: Generic "custom fields" mechanism

by Matus Mlynarcik -

Could you share the code? It will be very useful!

 

thanks

In reply to Matus Mlynarcik

Re: Generic "custom fields" mechanism

by Mark Aberdour -

Ditto, it would be good to see the custom code if you can share thanks smile

In reply to Mark Aberdour

Re: Generic "custom fields" mechanism

by Simon Coggins -

Hi,

Sorry for the delay. It turns out that the code isn't quite as nicely abstracted as I thought, so it will take a little work to get it up and running.

Here's a zip with the following:

  • totara/customfield: This is the bulk of the code. It's implemented as a custom "totara" module but should be easy enough to put somewhere else
  • course_custom_field.patch: a patch to apply the required changes to course editing. This probably won't apply cleanly because of other changes we have in that file but it should show what needs to be added
  • custom_field_install.xml: a snippet of an XML file showing the tables that are needed.

There's no code in there for actually displaying the fields anywhere at the moment but the functions are there in each custom field class.

If there are any references to 'types' or 'hierachies' that's Totara specific code that should be removed. Ideally I think each "subject" should have it's own class too to make it easier to extend - e.g. something like custom_field_type_course extends custom_field_type_base { }.

Simon

Average of ratings: Useful (2)
In reply to Simon Coggins

Re: Generic "custom fields" mechanism

by srihari g -

Hi Simon Coggins

   Where i want to install this folder.I trying to install using "local plugin" but it is showing is not correct path to do it.Please reply me to my mail id gsrihari.1990@gmail.com. 

In reply to Simon Coggins

Re: Generic "custom fields" mechanism

by Ralph Blakeslee -

Simon,

This looks great!  Have you thought of adding the ability to list selected items from the custom course fields on the course description page?  In other words, if you create a custom field called CEU's (or contact hours) you might want to have that listed in the course description, say under the instructor's name.  

Ralph

In reply to Ralph Blakeslee

Re: Generic "custom fields" mechanism

by Simon Coggins -

Hi,

Yes that would make sense - each custom field type has a display function called "display_item_data()" so it's pretty easy to output the field contents.

Simon

In reply to Allegre Guillaume

Re: Generic "custom fields" mechanism

by Allegre Guillaume -

Finally, this generic mechanism has been implemented, mostly by my workfellow François Gannaz.

You can see the tracker ticket : http://tracker.moodle.org/browse/MDL-34634
 where you can find the git repository and in-depth explaination.

All feedbacks are welcome, here or on the tracker.

In reply to Allegre Guillaume

Re: Generic "custom fields" mechanism

by Maxim Vetryakov -

Well guys. I see this feature developement is dead. I need it so much...