class modProduct extends DolibarrModules (View source)

Class descriptor of Product module

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 from  DolibarrModules
int $numero from  DolibarrModules
string $editor_name from  DolibarrModules
string $editor_url from  DolibarrModules
$editor_squarred_logo from  DolibarrModules
$family from  DolibarrModules
$familyinfo from  DolibarrModules
string $module_position from  DolibarrModules
string $name from  DolibarrModules
string[] $dirs from  DolibarrModules
array<array{file?: string, note?: string, enabledbydefaulton: string, 1?: string}> $boxes from  DolibarrModules
array<array{0: string, 1: string, 2: string|int, 3: string, 4?: int<0, 1>, 5?: string, 6?: int<0, 1>}> $const from  DolibarrModules
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 from  DolibarrModules
array<int, array<int<0, 7>, string|int>> $rights from  DolibarrModules
int<0, 1> $rights_admin_allowed from  DolibarrModules
string $rights_class from  DolibarrModules
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 from  DolibarrModules
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 from  DolibarrModules
string $error from  DolibarrModules
string[] $errors from  DolibarrModules
string $version from  DolibarrModules
string $lastVersion

Module last version

from  DolibarrModules
bool $needUpdate

true indicate this module need update

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

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

@param DoliDB $db Database handler

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 add 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