This manual is deprecated. Please visit https://groupoffice.readthedocs.io for the latest documentation. |
Difference between revisions of "Global settings manager"
(Created page with "'''Use of global settings in modules''' Groupoffice has a global config that is stored in the table 'go_settings' in the database. It is possible to add and remove settings to t...") |
|||
Line 5: | Line 5: | ||
Database Table overview: | Database Table overview: | ||
− | + | {| | |
− | + | userid||int(11)||required||default: 0|- | |
− | + | |name||varchar(50)||required|||- | |
− | + | |value||text||not required||default: NULL|} | |
(note: The primary key is set on 'userid' and 'name') | (note: The primary key is set on 'userid' and 'name') |
Revision as of 13:01, 5 January 2011
Use of global settings in modules
Groupoffice has a global config that is stored in the table 'go_settings' in the database. It is possible to add and remove settings to the global config for your own created module.
Database Table overview:
name | varchar(50) | required | - | value | text | not required | }
(note: The primary key is set on 'userid' and 'name')
get_setting(Template:Setting name, Template:User id) With this function you receive the value of a setting. Template:Setting name is the name of the setting where you want the value from and is always required. Template:User id is the id of the user for which the setting is accessible, the default value is: 0, so it is accessible for every user in the system. This variable is not required. get_settings(Template:User id) With this function you can receive all the settings at once. Template:User id is the id of the user for which the setting is accessible, the default value is: 0, so it is accessible for every user in the system. This variable is not required. save_setting(Template:Setting name, Template:Setting value, Template:User id) With this function you can save a new setting or edit the value of an existing setting. Template:Setting name is the name of the setting that you want to save or edit, this is always required. Template:Setting value is the value of the setting that you want to save or edit, this is always required. Template:User id is the id of the user for which the setting is accessible, the default value is: 0, so it is accessible for every user in the system. This variable is not required. delete_setting( Template:Setting name ) With this function you can delete the whole setting. Template:Setting name is the name of the setting where you want to delete, this is always required. Usage of the above functions with the global config class: global $GO_CONFIG; To get a setting: $setting = $GO_CONFIG->get_setting('Template:Setting name'); To get all settings: $settings[] = $GO_CONFIG->get_settings('Template:User id(optional)'); To save a (new)setting: $GO_CONFIG->save_setting('Template:Setting name,Template:Setting value,Template:User id(optional)'); To delete a setting: $GO_CONFIG->delete_setting('Template:Setting name'); (note: The “global $GO_CONFIG” call is needed to load the global config into the used function or class)
1: In the module that you have created add the following file: GlobalSettings.js 2: Add the following contents to the GlobalSettings.js file: This file creates and shows the form that is showed on the 'Settings' tab. GO.moduleManager.on('moduleconstructed',function(mm,moduleName,panel){ if(moduleName=='settings'){ var fieldset =new Ext.form.FieldSet({ title:'Calendar', items:{ xtype:'textfield', name:'calendar_name_template', fieldLabel:'Template', width: 300 } }); panel.add(fieldset); } }); (note: for example we add a fieldset with the title 'Calendar' and with one textfield item 'calendar_name_template')
(note: To see how the event listeners work go tho the wiki section 'Event handling' on the 'developer' tab.) http://www.group-office.com/wiki/Event_handling 4: Add the static functions that are triggered by the even to the same file: In the function load_global_settings you can specify the settings that needs to be loaded into the class so they can be used. The function save_global_settings is needed for the settings module to save the settings that are changed by the administrator on the 'Settings' tab. public static function load_global_settings(&$response) { global $GO_CONFIG; $response['data']['calendar_name_template']=$GO_CONFIG->get_setting('calendar_name_template'); if(!$response['data']['calendar_name_template']) $response['data']['calendar_name_template']='{first_name} {middle_name} {last_name}'; } public static function save_global_settings(&$response) { global $GO_CONFIG; $GO_CONFIG->save_setting('calendar_name_template', $_POST['calendar_name_template']); } |