General developer forum

Plugin (grade_report) settings question

 
Picture of André Camacho
Plugin (grade_report) settings question
 

Hi,

I'm working on a gradebook report that generates graphs from grades.
Everything works as expected until now.

My question is :
- I have settings.php file that defines some general settings

I would like to be able to set some of these settings as "default setting" for each course, but also to overwrite this setting for each course.

For example my plugin is activated on a website (setting 1), and then it's by default disabled on every course (setting 2).
I would like to be able to have a setting that is owned by the course and could be changed.
Course1 has setting "activate_on_this_course" = 1, but Course2 has setting "activate_on_this_course" = 0

The main objective is to let teachers that can manage their course gradebook settings activate or deactivate certain features of my report plugin for their own course.

Does anyone have an idea ?
if it's not clear just tell me, i will try to explain it better.

Thanks a lot !

 
Average of ratings: -
Picture of Michael Aherne
Re: Plugin (grade_report) settings question
Core developersParticularly helpful MoodlersPlugin developers

I think you'd need to implement that separately from the plugin settings, similar to how the grader report implements user preferences. Unfortunately, I don't think there's any easy way to do that, so you'll probably have to create your own table to store the course preferences in and create an interface to enable them to be edited.

 
Average of ratings: -
Picture of AL Rachels
Re: Plugin (grade_report) settings question
Core developersParticularly helpful MoodlersPlugin developersTesters

Hi André,

The general "default" settings you apply on the report settings page, will need to be stored as configuration settings in the mdl_config_plugins table. To make it possible for someone to change those defaults when they insert a copy of the report in a course, your "report table" will need to have a field to store the setting also. When you insert your report in a course, it would then need to read the setting in the configuration and display it on the report setup page, with an option to change and save the setting.

As an example, here is a view of the activity configuration defaults page for the HotQuestion activity. Notice the setting outlined in red.


Here is a view of a HotQuestion activity being setup in a course. Notice the default configuration text has been was read read from the saved configuration, but it's wording has been changed slightly to make it fit it's use case in this course.


HTH

 
Average of ratings: -
Picture of André Camacho
Re: Plugin (grade_report) settings question
 

Thanks for both your replies.

I understood that admin settings are saved somewhere, and for the rest we need to use a database table to save my settings. The most used is the table for plugin options.

Problem is my plugin doesn't write in database (only read) so I would like to try to get it working without saving data in database.

I saw this paragraph (cf. screenshot joined) in documentation. Is it something I could use ?

- Default option fixed in admin
- Overwrite option somewhere else


 
Average of ratings: -
Picture of Michael Aherne
Re: Plugin (grade_report) settings question
Core developersParticularly helpful MoodlersPlugin developers

Yes, you could use lockable settings if you want, but you still need to implement the override in your grade report manually. In the example in the documentation you show, it's for default settings for assignments, but the assignment module still has to manage writing the overridden values to the database when an assignment is created. I can't see any way to do what you're trying to do without writing to the database.

 
Average of ratings: -
Picture of André Camacho
Re: Plugin (grade_report) settings question
 

Thanks for your reply !

I'm ok with writing in the database, I'm just looking for the best way to do it.
I mean, for example, the "global" settings that I have for my plugin (in site administration) were very easy to create and do probably save in database these settings no ?

So what I'm looking is for the easiest/cleanest way and best place to store that information.

As the "plugin" I wrote is a gradebook_report I found this :

https://docs.moodle.org/33/en/Gradebook_report_settings

Can a "plugin" save course (specific) settings (with a default value) to the same place the gradebook report settings are saved ?

And If yes, how should I do it ? Enter information manually or is there a function like for global settings ?

ie : $settings->add(new admin_setting_configcheckbox( .. )); adds a setting in setting page, and managed all the storing data in database part.

Finally I would like to say thanks again to have read my topic and replied until now smile

Thanks a lot

 
Average of ratings: -
Picture of Michael Aherne
Re: Plugin (grade_report) settings question
Core developersParticularly helpful MoodlersPlugin developers

No, it can't be done. Sorry if I haven't been clear but that's what I've been trying to say all along!

 
Average of ratings: -
Picture of André Camacho
Re: Plugin (grade_report) settings question
 

Ok, sorry if I didn't get it before.

Thanks a lot for your help !

 
Average of ratings: Useful (1)