class DolibarrModules (View source)

Class DolibarrModules

Parent class for module descriptor class files

Constants

URL_FOR_BLACKLISTED_MODULES

KEY_ID

KEY_LABEL

KEY_TYPE

KEY_DEFAULT

KEY_FIRST_LEVEL

KEY_SECOND_LEVEL

KEY_MODULE

KEY_ENABLED

Properties

DoliDB $db
int $numero
string $editor_name
string $editor_url
$editor_squarred_logo
$family
$familyinfo
string $module_position
string $name
string[] $dirs
array<array{file?: string, note?: string, enabledbydefaulton: string, 1?: string}> $boxes
array<array{0: string, 1: string, 2: string|int, 3: string, 4?: int<0, 1>, 5?: string, 6?: int<0, 1>}> $const
array<array{entity?: int, label?: string, jobtype?: string, class?: string, objectname?: string, method?: string, command?: string, parameters?: string, md5params?: string, comment?: string, frequency?: int, unitfrequency?: int, priority?: int, datestart?: int, dateend?: int, datenextrun?: string, status?: int, maxrun?: int, libname?: string, test?: string|bool}> $cronjobs
array<int, array<int<0, 7>, string|int>> $rights
int<0, 1> $rights_admin_allowed
string $rights_class
array<array{commentgroup?: string, mainmenu: string, leftmenu: string, langs: string, enabled: int|string, target: string, titre: string, user: int, fk_menu: string, fk_parent: string, url: string, position: int, positionfull: int|string, perms: string, type: string}>|int<1, 1> $menu
array{triggers?: int<0, 1>, login?: int<0, 1>, substitutions?: int<0, 1>, menus?: int<0, 1>, theme?: int<0, 1>, tpl?: int<0, 1>, barcode?: int<0, 1>, models?: int<0, 1>, printing?: int<0, 1>, css?: string[], js?: string[], hooks?: array{data?: string[], entity?: string}, moduleforexternal?: int<0, 1>, websitetemplates?: int<0, 1>, contactelement?: int<0, 1>} $module_parts
string $error
string[] $errors
string $version
string $lastVersion

Module last version

bool $needUpdate

true indicate this module need update

string $description
string Since: 4.0.0 HTML content supported.
$descriptionlong
array{}|array{langs: string, tabname: string[], tablib: string[], tabsql: string[], tabsqlsort: string[], tabfield: string[], tabfieldvalue: string[], tabfieldinsert: string[], tabrowid: string[], tabcond: array<bool|int<0, 1>>, tabhelp: array<array<string, string>>} $dictionaries
array<string|array{data: string, entity: int}> $tabs
string[] $export_code
string[] $export_label
string[] $export_icon
string[] $export_enabled
array<array<array{string, string}>> $export_permission
array<array<string, string>> $export_fields_array
array<array<string, string>> $export_TypeFields_array
array<array<string, string>> $export_entities_array
array<array<string, string>> $export_aggregate_array
array<array<string, string>> $export_examplevalues_array
array<array<string, string>> $export_help_array
array<array<array{rule: string, file: string, classfile: string, class: string, method: string, method_params: string[]}>>|array<array<string, string>> $export_special_array
array<int, array<string, string|string[]>> $export_dependencies_array
string[] $export_sql_start
string[] $export_sql_end
string[] $export_sql_order
string $import_code
string[] $import_label
string[] $import_icon
array<array<string, string>> $import_entities_array
array<array<string, string>> $import_tables_array
array<array<string, string>> $import_tables_creator_array
array<array<string, string>> $import_fields_array
array<array<string, string>> $import_fieldshidden_array
array<array<array<string, string>>> $import_convertvalue_array
array<array<string, string>> $import_regex_array
array<array<string, string>> $import_examplevalues_array
array<array<string, string>> $import_updatekeys_array
array<int, array<int, string>> $import_run_sql_after_array
array<array<string, string>> $import_TypeFields_array
array<array<string, string>> $import_help_array
string $const_name
bool $always_enabled
bool $disabled
array<string, string> $automatic_activation
int $core_enabled
string $picto
string[]|string $config_page_url
$depends
$requiredby
$conflictwith
null|string[] $langfiles
array<string, mixed> $warnings_activation
array<string, mixed> $warnings_activation_ext
array<string, string> $warnings_unactivation
null|int[] $phpmin
null|int[] $phpmax
null|int[] $need_dolibarr_version
int[] $max_dolibarr_version
int<0, 1> $need_javascript_ajax
bool $enabled_bydefault
bool|int<0, 1> $hidden
string $url_last_version

Methods

__construct(DoliDB $db)

Constructor. Define names, constants, directories, boxes, permissions

int
_init(array<array{sql: string, ignoreerror: int<0, 1>}>|string[] $array_sql, string $options = '')

Enables a module.

int
_remove(string[] $array_sql, string $options = '')

Disable function. Deletes the module constants and boxes from the database.

string
getName()

Gives the translated module name if translation exists in admin.lang or into language files of module.

string
getDesc(int<0, 1> $foruseinpopupdesc = 0)

Gives the translated module description if translation exists in admin.lang or the default module description

string
getDescLong()

Gives the long description of a module. First check README-la_LA.md then README.md If no markdown files found, it returns translated value of the key ->descriptionlong.

string
getDescLongReadmeFound()

Return path of file if a README file was found.

string
getChangeLog()

Gives the changelog. First check ChangeLog-la_LA.md then ChangeLog.md

string
getPublisher()

Gives the publisher name

string
getPublisherUrl()

Gives the publisher url

string
getVersion(int $translated = 1)

Gives module version (translated if param $translated is on) For 'experimental' modules, gives 'experimental' translation For 'dolibarr' modules, gives Dolibarr version

string
getModulePosition()

Gives the module position

string
isCoreOrExternalModule()

Tells if module is core or external.

string[]
getLangFilesArray()

Gives module related language files list

string
getExportDatasetLabel(int $r)

Gives translated label of an export dataset

string
getImportDatasetLabel(int $r)

Gives translated label of an import dataset

int|string
getLastActivationDate()

Gives the last date of activation

array{}|array{authorid: int|"", ip: string, lastactivationdate: int|"", lastactivationversion: string}
getLastActivationInfo()

Gives the last author of activation

int
_active()

Insert constants for module activation

int
_unactive()

Module deactivation

int<0, 1>
_load_tables(string $reldir, string $onlywithsuffix = '')

Create tables and keys required by module:

  • Files table.sql or table-module.sql with create table instructions
  • Then table.key.sql or table-module.key.sql with create keys instructions
  • Then data_xxx.sql (usually provided by external modules only)
  • Then update_xxx.sql (usually provided by external modules only) Files must be stored in subdirectory 'tables' or 'data' into directory $reldir (Example: '/install/mysql/' or '/module/sql/') This function may also be called by :
  • _load_tables('/install/mysql/', 'modulename') into the this->init() of core module descriptors.

int
insert_boxes(string $option = '')

Adds boxes

int
delete_boxes()

Removes boxes

int
insert_cronjobs()

Adds cronjobs

int
delete_cronjobs()

Removes boxes

int
delete_tabs()

Removes tabs

int
insert_tabs()

Adds tabs

int
insert_const()

Adds constants

int
delete_const()

Removes constants tagged 'deleteonunactive'

int
insert_permissions(int<0, 1> $reinitadminperms = 0, ?int $force_entity = null, int<0, 1> $notrigger = 0)

Adds access rights

int
delete_permissions()

Removes access rights

int
insert_menus()

Adds menu entries

int
delete_menus()

Removes menu entries

int
create_dirs()

Creates directories

int
insert_dirs(string $name, string $dir)

Adds directories definitions

int
delete_dirs()

Removes directories

int
insert_module_parts()

Save configuration for generic features.

int
delete_module_parts()

Removes generic parts

int
init(string $options = '')

Function called when module is enabled.

int
remove(string $options = '')

Function called when module is disabled.

string
getKanbanView(string $codeenabledisable = '', string $codetoconfig = '')

Return Kanban view of a module

int
checkForUpdate()

Check for module update.

int|string
checkForCompliance(string $nametocheck = '')

Check for module compliance with Dolibarr rules and law If a module is reported by this function,it is surely a malware. Delete it as soon as possible.

void
declareNewDictionary(array{name: string, lib: string, sql: string, sqlsort: string, field: string, fieldvalue: string, fieldinsert: string, rowid: string, cond: bool, help: array<string, string>, fieldcheck?: null} $dictionaryArray, string $langs = '')

Helper method to declare dictionaries one at a time (rather than declaring dictionaries property by property).

Details

__construct(DoliDB $db)

Constructor. Define names, constants, directories, boxes, permissions

Parameters

DoliDB $db

Database handler

protected int _init(array<array{sql: string, ignoreerror: int<0, 1>}>|string[] $array_sql, string $options = '')

Enables a module.

Inserts all information into database.

Parameters

array<array{sql: string, ignoreerror: int<0, 1>}>|string[] $array_sql

SQL requests to be executed when enabling module

string $options

String with options when disabling module:

  • 'noboxes' = Do all actions except for actions related to widgets/boxes
  • 'newboxdefonly' = Do all actions but for widgets/boxes we only insert their declaration and we do not change widgets activation or position

Return Value

int

1 if OK, 0 if KO

protected int _remove(string[] $array_sql, string $options = '')

Disable function. Deletes the module constants and boxes from the database.

Parameters

string[] $array_sql

SQL requests to be executed when module is disabled

string $options

Options when disabling module:

Return Value

int

1 if OK, 0 if KO

string getName()

Gives the translated module name if translation exists in admin.lang or into language files of module.

Otherwise return the module key name.

Return Value

string

Translated module name

string getDesc(int<0, 1> $foruseinpopupdesc = 0)

Gives the translated module description if translation exists in admin.lang or the default module description

Parameters

int<0, 1> $foruseinpopupdesc

If 1, we return a short description for use into popup window

Return Value

string

Translated module description

string getDescLong()

Gives the long description of a module. First check README-la_LA.md then README.md If no markdown files found, it returns translated value of the key ->descriptionlong.

Return Value

string

Long description of a module from README.md of from property.

string getDescLongReadmeFound()

Return path of file if a README file was found.

Return Value

string

Path of file if a README file was found.

string getChangeLog()

Gives the changelog. First check ChangeLog-la_LA.md then ChangeLog.md

Return Value

string

Content of ChangeLog

string getPublisher()

Gives the publisher name

Return Value

string

Publisher name

string getPublisherUrl()

Gives the publisher url

Return Value

string

Publisher url

string getVersion(int $translated = 1)

Gives module version (translated if param $translated is on) For 'experimental' modules, gives 'experimental' translation For 'dolibarr' modules, gives Dolibarr version

Parameters

int $translated

1=Special version keys are translated, 0=Special version keys are not translated

Return Value

string

Module version

string getModulePosition()

Gives the module position

Return Value

string

Module position (an external module should never return a value lower than 100000. 1-100000 are reserved for core)

string isCoreOrExternalModule()

Tells if module is core or external.

Version = 'dolibarr', 'dolibarr_deprecated', 'experimental' and 'development' means core modules

Return Value

string

'core', 'external' or 'unknown'

string[] getLangFilesArray()

Gives module related language files list

Return Value

string[]

Language files list

string getExportDatasetLabel(int $r)

Gives translated label of an export dataset

Parameters

int $r

Dataset index

Return Value

string

Translated databaset label

string getImportDatasetLabel(int $r)

Gives translated label of an import dataset

Parameters

int $r

Dataset index

Return Value

string

Translated dataset label

int|string getLastActivationDate()

Gives the last date of activation

Return Value

int|string

Date of last activation or '' if module was never activated

array{}|array{authorid: int|"", ip: string, lastactivationdate: int|"", lastactivationversion: string} getLastActivationInfo()

Gives the last author of activation

Return Value

array{}|array{authorid: int|"", ip: string, lastactivationdate: int|"", lastactivationversion: string}

Array array('authorid'=>Id of last activation user, 'lastactivationdate'=>Date of last activation)

protected int _active()

Insert constants for module activation

Return Value

int

Error count (0 if OK)

protected int _unactive()

Module deactivation

Return Value

int

Error count (0 if OK)

protected int<0, 1> _load_tables(string $reldir, string $onlywithsuffix = '')

Create tables and keys required by module:

  • Files table.sql or table-module.sql with create table instructions
  • Then table.key.sql or table-module.key.sql with create keys instructions
  • Then data_xxx.sql (usually provided by external modules only)
  • Then update_xxx.sql (usually provided by external modules only) Files must be stored in subdirectory 'tables' or 'data' into directory $reldir (Example: '/install/mysql/' or '/module/sql/') This function may also be called by :
  • _load_tables('/install/mysql/', 'modulename') into the this->init() of core module descriptors.

  • _load_tables('/mymodule/sql/') into the this->init() of external module descriptors.

Parameters

string $reldir

Relative directory where to scan files. Example: '/install/mysql/' or '/module/sql/'

string $onlywithsuffix

Only with the defined suffix

Return Value

int<0, 1>

Return integer <=0 if KO, >0 if OK

int insert_boxes(string $option = '')

Adds boxes

Parameters

string $option

Options when disabling module ('newboxdefonly'=insert only boxes definition)

Return Value

int

Error count (0 if OK)

int delete_boxes()

Removes boxes

Return Value

int

Error count (0 if OK)

int insert_cronjobs()

Adds cronjobs

Return Value

int

Error count (0 if OK)

int delete_cronjobs()

Removes boxes

Return Value

int

Error count (0 if OK)

int delete_tabs()

Removes tabs

Return Value

int

Error count (0 if OK)

int insert_tabs()

Adds tabs

Return Value

int

Error count (0 if ok)

int insert_const()

Adds constants

Return Value

int

Error count (0 if OK)

int delete_const()

Removes constants tagged 'deleteonunactive'

Return Value

int

Return integer <0 if KO, 0 if OK

int insert_permissions(int<0, 1> $reinitadminperms = 0, ?int $force_entity = null, int<0, 1> $notrigger = 0)

Adds access rights

Parameters

int<0, 1> $reinitadminperms

If 1, we also grant them to all admin users

?int $force_entity

Force current entity

int<0, 1> $notrigger

1=Does not execute triggers, 0= execute triggers

Return Value

int

Error count (0 if OK)

int delete_permissions()

Removes access rights

Return Value

int

Error count (0 if OK)

int insert_menus()

Adds menu entries

Return Value

int

Error count (0 if OK)

int delete_menus()

Removes menu entries

Return Value

int

Error count (0 if OK)

int create_dirs()

Creates directories

Return Value

int

Error count (0 if OK)

int insert_dirs(string $name, string $dir)

Adds directories definitions

Parameters

string $name Name
string $dir Directory

Return Value

int

Error count (0 if OK)

int delete_dirs()

Removes directories

Return Value

int

Error count (0 if OK)

int insert_module_parts()

Save configuration for generic features.

This also generate website templates if the module provide some.

Return Value

int

Error count (0 if OK)

int delete_module_parts()

Removes generic parts

Return Value

int

Error count (0 if OK)

int init(string $options = '')

Function called when module is enabled.

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

Parameters

string $options

Options when enabling module ('', 'newboxdefonly', 'noboxes', 'menuonly') 'noboxes' = Do not insert boxes 'newboxdefonly' = For boxes, insert def of boxes only and not boxes activation

Return Value

int

1 if OK, 0 if KO

int remove(string $options = '')

Function called when module is disabled.

The remove() function removes tabs, constants, boxes, permissions and menus from Dolibarr database. Data directories are not deleted

Parameters

string $options

Options when enabling module ('', 'noboxes', 'newboxdefonly')

Return Value

int

1 if OK, 0 if KO

string getKanbanView(string $codeenabledisable = '', string $codetoconfig = '')

Return Kanban view of a module

Parameters

string $codeenabledisable

HTML code for button to enable/disable module

string $codetoconfig

HTML code to go to config page

Return Value

string

HTML code of Kanban view

int checkForUpdate()

Check for module update.

Get URL content of $this->url_last_version and set $this->lastVersion and$this->needUpdate TODO Store result in DB. TODO Add a cron task to monitor for updates.

Return Value

int

Return integer <0 if Error, 0 == no update needed, >0 if need update

int|string checkForCompliance(string $nametocheck = '')

Check for module compliance with Dolibarr rules and law If a module is reported by this function,it is surely a malware. Delete it as soon as possible.

Parameters

string $nametocheck

Name to check

Return Value

int|string

Return integer <0 if Error, 0 == not compliant, 'string' with message if module not compliant

protected void declareNewDictionary(array{name: string, lib: string, sql: string, sqlsort: string, field: string, fieldvalue: string, fieldinsert: string, rowid: string, cond: bool, help: array<string, string>, fieldcheck?: null} $dictionaryArray, string $langs = '')

Helper method to declare dictionaries one at a time (rather than declaring dictionaries property by property).

Parameters

array{name: string, lib: string, sql: string, sqlsort: string, field: string, fieldvalue: string, fieldinsert: string, rowid: string, cond: bool, help: array<string, string>, fieldcheck?: null} $dictionaryArray

Array describing one dictionary. Keys are: 'name', table name (without prefix) 'lib', dictionary label 'sql', query for select 'sqlsort', sort order 'field', comma-separated list of fields to select 'fieldvalue', list of columns used for editing existing rows 'fieldinsert', list of columns used for inserting new rows 'rowid', name of the technical ID (primary key) column, usually 'rowid' 'cond', condition for the dictionary to be shown / active 'help', optional array of translation keys by column for tooltips 'fieldcheck' (appears to be unused)

string $langs

Optional translation file to include (appears to be unused)

Return Value

void