class DolibaseModule extends DolibarrModules (View source)

DolibaseModule class

Known issue: When Dolibase is installed globally, DolibaseModule class will be loaded/included only once on "dolibarr/admin/modules.php" file, but when it's installed internally (in each module) then the class will be included from the first loaded module & in the rest of modules the inclusion will be stopped by the if condition above, otherwise you will get this error: DolibaseModule class already exists.

So the issue here is, if a module with an older version of Dolibase is loaded first & one of your modules requires a new version of this class to work properly, then you may face some errors like: Undefined function or attribute xxx in DolibaseModule class.

Solutions:

  • Use Dolibase module builder (will generate a custom class copy in your module directory).

  • Keep always your modules up-to-date with the latest version of Dolibase (painful solution).

  • Each time you add a function in this class/file, you need to copy & paste it into your module(s) class also.

  • Use namespaces to separate module file(s) from each others (complicated solution, may even not work on Dolibarr).

P.S: This issue affects only DolibaseModule & Widget class & not the other classes of Dolibase.

Properties

array $config
protected array $addons

Methods

__construct($db)

Constructor

loadSettings()

Function called after module configuration.

checkUpdates($langs)

Function to check module updates.

int
init(string $options = '')

Function called when module is enabled.

enableModuleForExternalUsers($module_rights_class)

Enable module for external users

disableModuleForExternalUsers($module_rights_class)

Disable module for external users

setAddons()

Set/Activate addons required by module

int
loadTables()

Create tables, keys and data required by module Files llx_table1.sql, llx_table1.key.sql llx_data.sql with create table, create keys and create data commands must be stored in directory /mymodule/sql/ This function is called by this->init

int
remove(string $options = '')

Function called when module is disabled.

$this
addConstant($name, $value, $desc = '', $type = 'chaine')

Add a constant

$this
addWidget($widget_filename, $note = '', $enabled_by_default_on = 'Home')

Add a widget

$this
addPermission($name, $desc = '', $type = '', $enabled_by_default = 1)

Add a permission

$this
addSubPermission($perm_name, $subperm_name, $desc = '', $type = '', $enabled_by_default = 1)

Add a sub permission

int
generatePermissionID()

Generate an ID for permissions

$this
addTopMenu($name, $title, $url, $perms = '1', $enabled = '1', $position = 100, $target = '')

Add a top menu entry

$this
addLeftMenu($main_menu, $name, $title, $url, $perms = '1', $enabled = '1', $position = 100, $target = '')

Add a left menu entry

$this
addLeftSubMenu($main_menu, $left_menu, $name, $title, $url, $perms = '1', $enabled = '1', $position = 100, $target = '')

Add a left sub menu entry

addMenu($type, $fk_menu, $main_menu, $left_menu, $title, $url, $position, $enabled = '1', $perms = '1', $target = '')

Add a menu

$this
addCssFile($css_filename)

Add a CSS file

$this
addCssFiles($css_files_array)

Add an array of CSS files

$this
addJsFile($js_filename)

Add a JS file

$this
addJsFiles($js_files_array)

Add an array of JS files

$this
enableHook($hook)

Enable a hook

$this
enableHooks($hooks_array)

Enable an array of hooks

$this
enableTriggers()

Enable triggers

$this
addDictionary($table_name, $table_label, $select_fields = 'rowid, label, active', $table_sort = 'label ASC', $fields_to_show = 'label', $fields_to_update = 'label', $fields_to_insert = 'label', $table_pk_field = 'rowid', $fields_help = array())

Add a dictionary

addModulePart($module_part, $value)

Add a module part

$this
activateNumModel($name, $const_prefix = '')

Activate a numbering model

$this
activateDocModel($name, $type = '', $const_prefix = '')

Activate a document model

addCronJob($label, $type, $command = '', $class = '', $object_name = '', $object_method = '', $method_parameters = '', $comment = '', $frequency = 2, $frequency_unit = 3600, $status, $priority)

Add a cron job

$this
addCronCommand($label, $command, $frequency, $frequency_unit, $comment = '', $priority, $status = 1)

Add a cron job using a command

$this
addCronMethod($label, $class, $object_name, $object_method, $method_parameters, $frequency, $frequency_unit, $comment = '', $priority, $status = 1)

Add a cron job using a method

Details

__construct($db)

Constructor

Parameters

$db Database handler

loadSettings()

Function called after module configuration.

protected checkUpdates($langs)

Function to check module updates.

Parameters

$langs Language/translation handler

int init(string $options = '')

Function called when module is enabled.

The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. It also creates data directories

Parameters

string $options Options when enabling module ('', 'noboxes')

Return Value

int 1 if OK, 0 if KO

protected enableModuleForExternalUsers($module_rights_class)

Enable module for external users

Parameters

$module_rights_class Module rights class

protected disableModuleForExternalUsers($module_rights_class)

Disable module for external users

Parameters

$module_rights_class Module rights class

protected setAddons()

Set/Activate addons required by module

protected int loadTables()

Create tables, keys and data required by module Files llx_table1.sql, llx_table1.key.sql llx_data.sql with create table, create keys and create data commands must be stored in directory /mymodule/sql/ This function is called by this->init

Return Value

int <=0 if KO, >0 if OK

int remove(string $options = '')

Function called when module is disabled.

Remove from database constants, boxes and permissions from Dolibarr database. Data directories are not deleted

Parameters

string $options Options when enabling module ('', 'noboxes')

Return Value

int 1 if OK, 0 if KO

$this addConstant($name, $value, $desc = '', $type = 'chaine')

Add a constant

Parameters

$name constant name
$value constant value
$desc constant description / note
$type constant type

Return Value

$this

$this addWidget($widget_filename, $note = '', $enabled_by_default_on = 'Home')

Add a widget

Parameters

$widget_filename widget filename
$note widget note
$enabled_by_default_on where to enable the widget by default

Return Value

$this

$this addPermission($name, $desc = '', $type = '', $enabled_by_default = 1)

Add a permission

Parameters

$name permission name
$desc permission description
$type permission type: 'r', 'c', 'm', 'd'
$enabled_by_default enable the permission by default for all users

Return Value

$this

$this addSubPermission($perm_name, $subperm_name, $desc = '', $type = '', $enabled_by_default = 1)

Add a sub permission

Parameters

$perm_name permission name
$subperm_name sub permission name
$desc permission description
$type permission type: 'r', 'c', 'm', 'd'
$enabled_by_default enable the permission by default for all users

Return Value

$this

protected int generatePermissionID()

Generate an ID for permissions

Return Value

int permission ID

$this addTopMenu($name, $title, $url, $perms = '1', $enabled = '1', $position = 100, $target = '')

Add a top menu entry

Parameters

$name menu name (should be the same as the module folder name, & the same as the menu picture file *.png)
$title menu title
$url target page url
$perms should anyone see & use the menu or use conditions like '$user->rights->monmodule->level1->level2'
$enabled should the menu be always enabled or use conditions like '$conf->monmodule->enabled'
$position menu position
$target menu target, leave empty or use '_blank' to open in a new window / tab

Return Value

$this

$this addLeftMenu($main_menu, $name, $title, $url, $perms = '1', $enabled = '1', $position = 100, $target = '')

Add a left menu entry

Parameters

$main_menu main/top menu name where to insert
$name menu name (codename for further use)
$title menu title
$url target page url
$perms should anyone see & use the menu or use conditions like '$user->rights->monmodule->level1->level2'
$enabled should the menu be always enabled or use conditions like '$conf->monmodule->enabled'
$position menu position
$target menu target, leave empty or use '_blank' to open in a new window / tab

Return Value

$this

$this addLeftSubMenu($main_menu, $left_menu, $name, $title, $url, $perms = '1', $enabled = '1', $position = 100, $target = '')

Add a left sub menu entry

Parameters

$main_menu main/top menu name where to insert
$left_menu left menu name where to insert
$name menu name (codename for further use)
$title menu title
$url target page url
$perms should anyone see & use the menu or use conditions like '$user->rights->monmodule->level1->level2'
$enabled should the menu be always enabled or use conditions like '$conf->monmodule->enabled'
$position menu position
$target menu target, leave empty or use '_blank' to open in a new window / tab

Return Value

$this

protected addMenu($type, $fk_menu, $main_menu, $left_menu, $title, $url, $position, $enabled = '1', $perms = '1', $target = '')

Add a menu

Parameters

$type menu type 'top' or 'left'
$fk_menu where to insert menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode of parent menu
$main_menu main/top menu name
$left_menu left menu name
$title menu title
$url target page url
$position menu position
$enabled define condition to show or hide menu entry. Use '$conf->monmodule->enabled' if entry must be visible if module is enabled.
$perms use 'perms'=>'$user->rights->monmodule->level1->level2' if you want your menu with a permission rules
$target menu target, leave empty or use '_blank' to open in a new window / tab

$this addCssFile($css_filename)

Add a CSS file

Parameters

$css_filename css filename

Return Value

$this

$this addCssFiles($css_files_array)

Add an array of CSS files

Parameters

$css_files_array css files array

Return Value

$this

$this addJsFile($js_filename)

Add a JS file

Parameters

$js_filename javascript filename

Return Value

$this

$this addJsFiles($js_files_array)

Add an array of JS files

Parameters

$js_files_array javascript files array

Return Value

$this

$this enableHook($hook)

Enable a hook

Parameters

$hook dolibarr hook name: 'toprightmenu', 'main', ...

Return Value

$this

$this enableHooks($hooks_array)

Enable an array of hooks

Parameters

$hooks_array hooks array

Return Value

$this

$this enableTriggers()

Enable triggers

Return Value

$this

$this addDictionary($table_name, $table_label, $select_fields = 'rowid, label, active', $table_sort = 'label ASC', $fields_to_show = 'label', $fields_to_update = 'label', $fields_to_insert = 'label', $table_pk_field = 'rowid', $fields_help = array())

Add a dictionary

Parameters

$table_name table name without prefix
$table_label table label
$select_fields select statement fields, e.: 'rowid, code, label, active'
$table_sort sort field & order, e.: 'label ASC'
$fields_to_show fields to show on dict page (no spaces), e.: 'code,label'
$fields_to_update fields to update on dict page (no spaces), e.: 'code,label'
$fields_to_insert fields to insert on dict page (no spaces), e.: 'code,label'
$table_pk_field table primary key field
$fields_help fields help summary or link, e.: array('code' => 'summary..', 'label' => 'summary..')

Return Value

$this

protected addModulePart($module_part, $value)

Add a module part

Parameters

$module_part module part: 'hooks', 'css', 'js'
$value module part value (could be a css or js filenames, a hook, etc)

$this activateNumModel($name, $const_prefix = '')

Activate a numbering model

Parameters

$name numbering model name
$const_prefix numbering model constant prefix

Return Value

$this

$this activateDocModel($name, $type = '', $const_prefix = '')

Activate a document model

Parameters

$name document model name
$type document model type
$const_prefix document model constant prefix

Return Value

$this

protected addCronJob($label, $type, $command = '', $class = '', $object_name = '', $object_method = '', $method_parameters = '', $comment = '', $frequency = 2, $frequency_unit = 3600, $status, $priority)

Add a cron job

Parameters

$label Job label
$type Job type, possible values: 'command', 'method'
$command Job shell command (if $type = 'command')
$class Job class (if $type = 'method'), e.: '/mymodule/class/myobject.class.php'
$object_name Object name (if $type = 'method'), e.: 'MyObject'
$object_method Object method (if $type = 'method'), e.: 'doScheduledJob'
$method_parameters Method parameters (if $type = 'method'), e.: 'param1, param2'
$comment Job comment
$frequency Job frequency or execution time, e.: 2 (if $frequency_unit = 3600 it will be considered as every 2 hours)
$frequency_unit Job frequency unit, e.: 3600 (1 hour), 360024 (1 day), 360024*7 (1 week)
$status Job status at module installation: 0 = disabled, 1 = enabled
$priority Job priority (number from 0 to 100)

$this addCronCommand($label, $command, $frequency, $frequency_unit, $comment = '', $priority, $status = 1)

Add a cron job using a command

Parameters

$label Job label
$command Job shell command
$frequency Job frequency or execution time, e.: 2 (if $frequency_unit = 3600 it will be considered as every 2 hours)
$frequency_unit Job frequency unit, e.: 3600 (1 hour), 360024 (1 day), 360024*7 (1 week)
$comment Job comment
$priority Job priority (number from 0 to 100)
$status Job status at module installation: 0 = disabled, 1 = enabled

Return Value

$this

$this addCronMethod($label, $class, $object_name, $object_method, $method_parameters, $frequency, $frequency_unit, $comment = '', $priority, $status = 1)

Add a cron job using a method

Parameters

$label Job label
$class Job class, e.: '/mymodule/class/myobject.class.php'
$object_name Object name, e.: 'MyObject'
$object_method Object method, e.: 'doScheduledJob'
$method_parameters Method parameters, e.: 'param1, param2'
$frequency Job frequency or execution time, e.: 2 (if $frequency_unit = 3600 it will be considered as every 2 hours)
$frequency_unit Job frequency unit, e.: 3600 (1 hour), 360024 (1 day), 360024*7 (1 week)
$comment Job comment
$priority Job priority (number from 0 to 100)
$status Job status at module installation: 0 = disabled, 1 = enabled

Return Value

$this