Custom Course Fields: New Module (MDL-18319)

Custom Course Fields: New Module (MDL-18319)

by Sanket Sharma -
Number of replies: 12

Hi,

I just finished writing some code that lets users add custom fields to a course - just like the custom fields for a user. I also customized the custom reporting module to let a user choose and report on any of those fields and create reports as he or she may wish.

Now, what I would like to know is how do I contribute it back to the community? I see there is an issue open at http://tracker.moodle.org/browse/MDL-18319

I'm however not sure if I have adhered to all moodle code guidelines and if I my code is of that great quality. But I'm willing to work on it and submit a patch that adheres to guidlines, architecture and standards.

So, where do I begin? I basically looked at the code and tables for custom user fields, copied it, and made changes wherever necessary. This did induce some duplication of code in following directories

 

MOODLE_HOME/user/profile

MOODLE_HOME/user/profile/field

MOODLE_HOME/user/profile/field/checkbox

MOODLE_HOME/user/profile/field/datetime

MOODLE_HOME/user/profile/field/menu

MOODLE_HOME/user/profile/field/text

MOODLE_HOME/user/profile/field/textarea

I renamed some of the class to avoid naming confict but I don't think thats a good idea. My first thought was to reuse the classes for user profile but they have been named in way that imply they are specific to custom user fields. Not sure, maybe you guys can enlighten me?

So the question is, is it okay to duplicate code in this module or maybe I should re-use the 'custom user field' classes or maye re-work both the modules with generic names?

I'll really appreciate any help and guidance in this regard

 

 

Average of ratings: -
In reply to Sanket Sharma

Re: Custom Course Fields: New Module (MDL-18319)

by Nadav Kavalerchik -
Picture of Core developers Picture of Plugin developers Picture of Testers Picture of Translators

So useful!

I would LOVE to see this integrated into Moodle and hope similar code be added to Modules so Teachers can add Descriptive Meta Data to Modules and Resources which will help them search and retirve them back from archived courses. and even enable other Teachers from the same system or other systems search for OER inside Moodle.

In reply to Sanket Sharma

Re: Custom Course Fields: New Module (MDL-18319)

by amit janghu -

Here is the link that can help you. Guidelines for contributed code.  If you would like your code to be tested and reviewed, please create your account at tracker.moodle.org and create a separate issue and add the code or add your code to already made issue.  Go through this style guide to check your code. Recently I have also started working on the same issue, so if you'll add the code soon I'll test it for you. 

In reply to amit janghu

Re: Custom Course Fields: New Module (MDL-18319)

by Sanket Sharma -

Hi Amit, Thank you for the links and information. I'll quickly fix my code where to adhere to the guidelines and will try and post the code by weekend.

In reply to Sanket Sharma

Re: Custom Course Fields: New Module (MDL-18319)

by amit janghu -

Hi Sanket, I recently found few links which I think would be of your use if you are creating a new plugin/module for adding course fields. Here is the link for the new module template https://github.com/moodlehq/moodle-mod_newmodule. You can downlaod it and make changes in the template also, otherwise you can use the same framework which is explained here. http://docs.moodle.org/dev/NEWMODULE_Documentation. These file are mandatory for building activity modules. you can check this out in \mod directory also. 

In reply to amit janghu

Re: Custom Course Fields: New Module (MDL-18319)

by Sanket Sharma -

I am now wondering if it would not be a better idea to merge this with the course module itself - like the way its done for user custom fields? Its not a separate module, but resides with the "user" folder in root directory?

What do you think?

In reply to Sanket Sharma

Re: Custom Course Fields: New Module (MDL-18319)

by amit janghu -

Yes, it's a good idea to begin with and check people response on your added functionality but modifying the code directly and adding folder elsewhere apart from plugin folder creates problem during updation of moodle version. Hence, people preferably use plugins to add functionality to moodle.   

In reply to Sanket Sharma

Re: Custom Course Fields: New Module (MDL-18319)

by amit janghu -

I am extremely sorry !! I thought of something else. yeah, you are completely  right !!

In reply to Sanket Sharma

Re: Custom Course Fields: New Module (MDL-18319)

by paddy ward -

I was wondering how you were going with this, Sanket? I am very keen to be able to add custom menus to themes at the course level and even allow teachers to create their own at this level. Please let me know when you have an idea of when your code might be available, and keep up the great work!

In reply to Sanket Sharma

Re: Custom Course Fields: New Module (MDL-18319)

by Jay Knight -

This sounds like it's exactly what we need... Can a plugin even accomplish this?  Being built in would be even better.  I'm willing to give it a stab if someone more knowlegable of the existing code and structure could give me some direction of how this should work.

In reply to Sanket Sharma

Re: Custom Course Fields: New Module (MDL-18319)

by Sanket Sharma -

Hi,

Apologies for the dealyed response. I've added a patch for this one. I've tested it with Moodle 2.2 

You can download the patch from here - http://tracker.moodle.org/browse/MDL-18319

You'll have to download the latest code and apply this patch before you install. The patch includes XML for creating database as well.

Look forward to your feedback and comments!

In reply to Sanket Sharma

Re: Custom Course Fields: New Module (MDL-18319)

by stuti bhavsar -

Hi Sanket,

I have created my custom plugin. I want to add an additional field in add/edit course page. It is possible editing the edit_form.php file of the course. But I want to add the field when the plugin gets installed.

Can you please suggest how to add the field using plugin?