This manual is deprecated. Please visit https://groupoffice.readthedocs.io for the latest documentation.

Difference between revisions of "Global settings manager"

From Group-Office Groupware and CRM Documentation
Jump to: navigation, search
 
(21 intermediate revisions by the same user not shown)
Line 1: Line 1:
'''Use of global settings in modules'''
+
=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.
 
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:
+
==Database Table overview:==
 
{|
 
{|
 
|<u>userid</u>
 
|<u>userid</u>
Line 22: Line 22:
 
<font style='font-size:8px; font-weight:bold;'>(note: The primary key is set on 'userid' and 'name')</font>
 
<font style='font-size:8px; font-weight:bold;'>(note: The primary key is set on 'userid' and 'name')</font>
  
 +
==Global config:==
 +
 +
===Functions:===
 
Use of the global config can be done easily with the following functions of the global config class:
 
Use of the global config can be done easily with the following functions of the global config class:
 
 
 
<b>get_setting(<nowiki>{{setting_name}}</nowiki>, <nowiki>{{user_id}}</nowiki>)</b><br>
 
<b>get_setting(<nowiki>{{setting_name}}</nowiki>, <nowiki>{{user_id}}</nowiki>)</b><br>
 
With this function you receive the value of a setting.
 
With this function you receive the value of a setting.
<nowiki>{{setting_name}}</nowiki> is the name of the setting where you want the value from and is always required.<br>
+
{|
<nowiki>{{user_id}}</nowiki> 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.
+
|<nowiki>{{setting_name}}</nowiki>
 +
|is the name of the setting where you want the value from and is always required.
 +
|-
 +
|<nowiki>{{user_id}}</nowiki>
 +
|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.
 +
|}
  
 
<b>get_settings(<nowiki>{{user_id}}</nowiki>)</b><br>
 
<b>get_settings(<nowiki>{{user_id}}</nowiki>)</b><br>
 
With this function you can receive all the settings at once.
 
With this function you can receive all the settings at once.
<nowiki>{{user_id}}</nowiki> 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.
+
{|
 +
|<nowiki>{{user_id}}</nowiki>
 +
|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.
 +
|}
  
 
<b>save_setting(<nowiki>{{setting_name}}</nowiki>, <nowiki>{{setting_value}}</nowiki>, <nowiki>{{user_id}}</nowiki>)</b><br>
 
<b>save_setting(<nowiki>{{setting_name}}</nowiki>, <nowiki>{{setting_value}}</nowiki>, <nowiki>{{user_id}}</nowiki>)</b><br>
 
With this function you can save a new setting or edit the value of an existing setting.
 
With this function you can save a new setting or edit the value of an existing setting.
<nowiki>{{setting_name}}</nowiki> is the name of the setting that you want to save or edit, this is always required.<br>
+
{|
<nowiki>{{setting_value}}</nowiki> is the value of the setting that you want to save or edit, this is always required.<br>
+
|<nowiki>{{setting_name}}</nowiki>
<nowiki>{{user_id}}</nowiki> 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.
+
|is the name of the setting that you want to save or edit, this is always required.
 +
|-
 +
|<nowiki>{{setting_value}}</nowiki>
 +
|is the value of the setting that you want to save or edit, this is always required.
 +
|-
 +
|<nowiki>{{user_id}}</nowiki>
 +
|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.
 +
|}
  
 
<b>delete_setting( <nowiki>{{setting_name}}</nowiki> )</b><br>
 
<b>delete_setting( <nowiki>{{setting_name}}</nowiki> )</b><br>
With this function you can delete the whole setting.
+
With this function you can delete the whole setting.<br>
<nowiki>{{setting_name}}</nowiki> is the name of the setting where you want to delete, this is always required.
+
{|
 +
|<nowiki>{{setting_name}}</nowiki>
 +
|is the name of the setting where you want to delete, this is always required.
 +
|}
 +
 
 +
===Usage:===
 
Usage of the above functions with the global config class:<br>
 
Usage of the above functions with the global config class:<br>
<code>global $GO_CONFIG;</code>
 
  
 
To get a setting:<br>
 
To get a setting:<br>
<code>$setting = $GO_CONFIG->get_setting('<nowiki>{{setting_name}}</nowiki>');</code>
+
<pre>$setting = GO::config()->get_setting('<nowiki>{{setting_name}}</nowiki>');</pre>
 
 
 
To get all settings:<br>
 
To get all settings:<br>
<code>$settings[] = $GO_CONFIG->get_settings('<nowiki>{{user_id(optional)}}</nowiki>');</code>
+
<pre>$settings[] = GO::config()->get_settings('<nowiki>{{user_id(optional)}}</nowiki>');</pre>
 
 
 
To save a (new)setting:<br>
 
To save a (new)setting:<br>
<code>$GO_CONFIG->save_setting('<nowiki>{{setting_name}}</nowiki>,<nowiki>{{setting_value}}</nowiki>,<nowiki>{{user_id(optional)}}</nowiki>');</code>
+
<pre>GO::config()->save_setting('<nowiki>{{setting_name}}</nowiki>,<nowiki>{{setting_value}}</nowiki>,<nowiki>{{user_id(optional)}}</nowiki>');</pre>
 
 
 
To delete a setting:<br>
 
To delete a setting:<br>
<code>$GO_CONFIG->delete_setting('<nowiki>{{setting_name}}</nowiki>');</code>
+
<pre>GO::config()->delete_setting('<nowiki>{{setting_name}}</nowiki>');</pre>
+
 
<font style='font-size:8px; font-weight:bold;'>(note: The “global $GO_CONFIG” call is needed to load the global config into the used function or class)</font>
+
==Add settings for own module:==
  
 
In groupoffice, the administrator can access the 'Settings' tab in the startmenu. From the 'Settings' tab the administrator can easily manage the global settings of groupoffice that are made visible. By default the settings are not visible on this tab. The settings need to be added by hand in the source code of the module from which the settings are. To achieve this you need to do a couple of things.
 
In groupoffice, the administrator can access the 'Settings' tab in the startmenu. From the 'Settings' tab the administrator can easily manage the global settings of groupoffice that are made visible. By default the settings are not visible on this tab. The settings need to be added by hand in the source code of the module from which the settings are. To achieve this you need to do a couple of things.
Line 63: Line 85:
 
1. In the module that you have created add the following file: GlobalSettings.js
 
1. In the module that you have created add the following file: GlobalSettings.js
  
2. Add the following contents to the GlobalSettings.js file:
+
2. Add the following contents to the GlobalSettings.js file:<br>
This file creates and shows the form that is showed on the 'Settings' tab.
+
This file creates and shows the form that is showed on the 'Settings' tab.
 
+
<pre>
<br><code>GO.moduleManager.on('moduleconstructed',function(mm,moduleName,panel){
+
GO.moduleManager.on('moduleconstructed',function(mm,moduleName,panel){
  if(moduleName=='settings'){
+
  if(moduleName=='settings'){
    var fieldset =new Ext.form.FieldSet({
+
    var fieldset =new Ext.form.FieldSet({
      title:'Calendar',
+
      title:'Calendar',
      items:{
+
      items:{
        xtype:'textfield',
+
        xtype:'textfield',
        name:'calendar_name_template',
+
        name:'calendar_name_template',
        fieldLabel:'Template',
+
fieldLabel:'Template',
        width: 300
+
width: 300
    }
+
      }
  });
+
    });
  panel.add(fieldset);
+
  panel.add(fieldset);
  }
+
  }
});</code>
+
});
 +
</pre>
  
 
<font style='font-size:8px; font-weight:bold;'>(note: for example we add a fieldset with the title 'Calendar' and with one textfield item 'calendar_name_template')</font>
 
<font style='font-size:8px; font-weight:bold;'>(note: for example we add a fieldset with the title 'Calendar' and with one textfield item 'calendar_name_template')</font>
  
 +
[[File:Settingpanel.jpg|border|900px]]
  
 
3. In the class where you want to use the data you need to add the following event listeners:
 
3. In the class where you want to use the data you need to add the following event listeners:
<br><code>$events->add_listener('load_global_settings', __FILE__, '{{module_name}}','load_global_settings');
+
<pre>
$events->add_listener('save_global_settings', __FILE__, '{{module_name}}','save_global_settings');</code>
+
$events->add_listener('load_global_settings', __FILE__, '{{module_name}}','load_global_settings');<br>
 
+
$events->add_listener('save_global_settings', __FILE__, '{{module_name}}','save_global_settings');
(note: To see how the event listeners work go tho the wiki section 'Event handling' on the 'developer' tab.)
+
</pre>
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.
+
<font style='font-size:8px; font-weight:bold;'>(note: To see how the event listeners work go tho the wiki section '[[Event handling]]')</font>
  
<br><code>public static function load_global_settings(&$response)
+
4. Add the static functions that are triggered by the even to the same file:<br>
{
+
In the function load_global_settings you can specify the settings that needs to be loaded into the class so they can be used.
  global $GO_CONFIG;
+
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.
  $response['data']['calendar_name_template']=$GO_CONFIG->get_setting('calendar_name_template');
+
<pre>
 +
public static function load_global_settings(&$response)
 +
{
 +
  $response['data']['calendar_name_template']=GO::config()->get_setting('calendar_name_template');
 
 
  if(!$response['data']['calendar_name_template'])
+
  if(!$response['data']['calendar_name_template'])
    $response['data']['calendar_name_template']='{first_name} {middle_name} {last_name}';
+
    $response['data']['calendar_name_template']='{first_name} {middle_name} {last_name}';
}
+
}
  
public static function save_global_settings(&$response)
+
public static function save_global_settings(&$response)
{
+
{
  global $GO_CONFIG;
+
  GO::config()->->save_setting('calendar_name_template', $_POST['calendar_name_template']);
  $GO_CONFIG->save_setting('calendar_name_template', $_POST['calendar_name_template']);
+
}
}</code>
+
</pre>

Latest revision as of 10:05, 26 July 2012

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:

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')

Global config:

Functions:

Use of the global config can be done easily with the following functions of the global config class:

get_setting({{setting_name}}, {{user_id}})
With this function you receive the value of a setting.

{{setting_name}} is the name of the setting where you want the value from and is always required.
{{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({{user_id}})
With this function you can receive all the settings at once.

{{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({{setting_name}}, {{setting_value}}, {{user_id}})
With this function you can save a new setting or edit the value of an existing setting.

{{setting_name}} is the name of the setting that you want to save or edit, this is always required.
{{setting_value}} is the value of the setting that you want to save or edit, this is always required.
{{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( {{setting_name}} )
With this function you can delete the whole setting.

{{setting_name}} is the name of the setting where you want to delete, this is always required.

Usage:

Usage of the above functions with the global config class:

To get a setting:

$setting = GO::config()->get_setting('{{setting_name}}');

To get all settings:

$settings[] = GO::config()->get_settings('{{user_id(optional)}}');

To save a (new)setting:

GO::config()->save_setting('{{setting_name}},{{setting_value}},{{user_id(optional)}}');

To delete a setting:

GO::config()->delete_setting('{{setting_name}}');

Add settings for own module:

In groupoffice, the administrator can access the 'Settings' tab in the startmenu. From the 'Settings' tab the administrator can easily manage the global settings of groupoffice that are made visible. By default the settings are not visible on this tab. The settings need to be added by hand in the source code of the module from which the settings are. To achieve this you need to do a couple of things.

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')

Settingpanel.jpg

3. In the class where you want to use the data you need to add the following event listeners:

$events->add_listener('load_global_settings', __FILE__, '{{module_name}}','load_global_settings');<br>
$events->add_listener('save_global_settings', __FILE__, '{{module_name}}','save_global_settings');

(note: To see how the event listeners work go tho the wiki section '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)
{
  $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)
{
  GO::config()->->save_setting('calendar_name_template', $_POST['calendar_name_template']);
}