dolibarr 19.0.4
modulebuilder.lib.php File Reference

Set of function for modulebuilder management. More...

Go to the source code of this file.

Functions

 rebuildObjectClass ($destdir, $module, $objectname, $newmask, $readdir='', $addfieldentry=array(), $delfieldentry='')
 Regenerate files .class.php.
 
 rebuildObjectSql ($destdir, $module, $objectname, $newmask, $readdir='', $object=null, $moduletype='external')
 Save data into a memory area shared by all users, all sessions on server.
 
 dolGetListOfObjectClasses ($destdir)
 Get list of existing objects from directory.
 
 checkExistComment ($file, $number)
 function for check if comment begin an end exist in modMyModule class
 
 deletePerms ($file)
 Delete all permissions.
 
 compareFirstValue ($a, $b)
 Compare two value.
 
 reWriteAllPermissions ($file, $permissions, $key, $right, $objectname, $module, $action)
 Rewriting all permissions after any actions.
 
 parsePropertyString ($string)
 Converts a formatted properties string into an associative array.
 
 writePropsInAsciiDoc ($file, $objectname, $destfile)
 Write all properties of the object in AsciiDoc format.
 
 deletePropsAndPermsFromDoc ($file, $objectname)
 Delete property and permissions from documentation ascii file if we delete an object.
 
 getFromFile ($file, $start, $end)
 Search a string and return all lines needed from file.
 
 writePermsInAsciiDoc ($file, $destfile)
 Write all permissions of each object in AsciiDoc format.
 
 addObjectsToApiFile ($file, $objects, $modulename)
 Add Object in ModuleApi File.
 
 removeObjectFromApiFile ($file, $objectname, $modulename)
 Remove Object variables and methods from API_Module File.
 
 reWriteAllMenus ($file, $menus, $menuWantTo, $key, $action)
 
 updateDictionaryInFile ($module, $file, $dicts)
 Updates a dictionary in a module descriptor file.
 
 createNewDictionnary ($modulename, $file, $namedic, $dictionnaires=null)
 Creates a new dictionary table.
 
 writeApiUrlsInDoc ($file_api, $file_doc)
 Generate Urls and add them to documentaion module.
 
 countItemsInDirectory ($path, $type=1)
 count directories or files in modulebuilder folder
 

Detailed Description

Set of function for modulebuilder management.

Definition in file modulebuilder.lib.php.

Function Documentation

◆ addObjectsToApiFile()

addObjectsToApiFile ( $file,
$objects,
$modulename )

Add Object in ModuleApi File.

Parameters
string$filepath of file
array$objectsarray of objects in the module
string$modulenamename of module
Returns
int 1 if OK, -1 if KO

Definition at line 943 of file modulebuilder.lib.php.

References dolReplaceInFile(), and getFromFile().

◆ checkExistComment()

checkExistComment ( $file,
$number )

function for check if comment begin an end exist in modMyModule class

Parameters
string$filefilename or path
int$number0 = For Menus,1 = For permissions, 2 = For Dictionaries
Returns
int 1 if OK , -1 if KO

Definition at line 465 of file modulebuilder.lib.php.

◆ compareFirstValue()

compareFirstValue ( $a,
$b )

Compare two value.

Parameters
int | string$avalue 1
int | string$bvalue 2
Returns
int less 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal.

Definition at line 525 of file modulebuilder.lib.php.

◆ countItemsInDirectory()

countItemsInDirectory ( $path,
$type = 1 )

count directories or files in modulebuilder folder

Parameters
string$pathpath of directory
int$typetype of file 1= file,2=directory
Returns
int|bool

Definition at line 1342 of file modulebuilder.lib.php.

◆ createNewDictionnary()

createNewDictionnary ( $modulename,
$file,
$namedic,
$dictionnaires = null )

Creates a new dictionary table.

for creating a new dictionary table in Dolibarr. It generates the necessary SQL code to define the table structure, including columns such as 'rowid', 'code', 'label', 'position', 'use_default', 'active', etc. The table name is constructed based on the provided $namedic parameter.

Parameters
string$modulenameThe lowercase name of the module for which the dictionary table is being created.
string$fileThe file path to the Dolibarr module builder file where the dictionaries are defined.
string$namedicThe name of the dictionary, which will also be used as the base for the table name.
array | null$dictionnairesAn optional array containing pre-existing dictionary data, including 'tabname', 'tablib', 'tabsql', etc.
Returns
void

Definition at line 1205 of file modulebuilder.lib.php.

References dol_print_error(), setEventMessages(), and updateDictionaryInFile().

◆ deletePerms()

deletePerms ( $file)

Delete all permissions.

Parameters
string$filefile with path
Returns
void

Definition at line 492 of file modulebuilder.lib.php.

References dolReplaceInFile().

Referenced by reWriteAllPermissions().

◆ deletePropsAndPermsFromDoc()

deletePropsAndPermsFromDoc ( $file,
$objectname )

Delete property and permissions from documentation ascii file if we delete an object.

Parameters
string$filefile or path
string$objectnamename of object wants to deleted
Returns
void

Definition at line 802 of file modulebuilder.lib.php.

References dol_is_file().

◆ dolGetListOfObjectClasses()

dolGetListOfObjectClasses ( $destdir)

Get list of existing objects from directory.

Parameters
string$destdirDirectory
Returns
array|int Return integer <=0 if KO, array if OK

Definition at line 434 of file modulebuilder.lib.php.

References dol_dir_list().

◆ getFromFile()

getFromFile ( $file,
$start,
$end )

Search a string and return all lines needed from file.

Parameters
string$filefile for searching
string$startstart line if exist
string$endend line if exist
Returns
string return the content needed

Definition at line 831 of file modulebuilder.lib.php.

Referenced by addObjectsToApiFile(), removeObjectFromApiFile(), reWriteAllMenus(), updateDictionaryInFile(), writeApiUrlsInDoc(), and writePermsInAsciiDoc().

◆ parsePropertyString()

parsePropertyString ( $string)

Converts a formatted properties string into an associative array.

Parameters
string$stringThe formatted properties string.
Returns
array The resulting associative array.

Definition at line 658 of file modulebuilder.lib.php.

References parsePropertyString().

Referenced by parsePropertyString(), and writePropsInAsciiDoc().

◆ rebuildObjectClass()

rebuildObjectClass ( $destdir,
$module,
$objectname,
$newmask,
$readdir = '',
$addfieldentry = array(),
$delfieldentry = '' )

Regenerate files .class.php.

Parameters
string$destdirDirectory
string$moduleModule name
string$objectnameName of object
string$newmaskNew mask
string$readdirDirectory source (use $destdir when not defined)
string$addfieldentryArray of 1 field entry to add array('key'=>,'type'=>,''label'=>,'visible'=>,'enabled'=>,'position'=>,'notnull'=>','index'=>,'searchall'=>,'comment'=>,'help'=>,'isameasure')
string$delfieldentryId of field to remove
Returns
int|object Return integer <=0 if KO, Object if OK
See also
rebuildObjectSql()

Definition at line 38 of file modulebuilder.lib.php.

References dol_copy(), dol_escape_js(), dol_escape_php(), dol_is_file(), dol_mkdir(), dol_osencode(), dol_print_error(), dol_sort_array(), dolChmod(), and setEventMessages().

◆ rebuildObjectSql()

rebuildObjectSql ( $destdir,
$module,
$objectname,
$newmask,
$readdir = '',
$object = null,
$moduletype = 'external' )

Save data into a memory area shared by all users, all sessions on server.

Parameters
string$destdirDirectory
string$moduleModule name
string$objectnameName of object
string$newmaskNew mask
string$readdirDirectory source (use $destdir when not defined)
Object$objectIf object was already loaded/known, it is pass to avoid another include and new.
string$moduletype'external' or 'internal'
Returns
int Return integer <=0 if KO, >0 if OK
See also
rebuildObjectClass()

Definition at line 256 of file modulebuilder.lib.php.

References dol_copy(), dol_is_file(), dol_mkdir(), dol_osencode(), dolChmod(), and setEventMessages().

◆ removeObjectFromApiFile()

removeObjectFromApiFile ( $file,
$objectname,
$modulename )

Remove Object variables and methods from API_Module File.

Parameters
string$filefile api module
string$objectnamename of object whant to remove
string$modulenamename of module
Returns
int 1 if OK, -1 if KO

Definition at line 1002 of file modulebuilder.lib.php.

References dolReplaceInFile(), and getFromFile().

◆ reWriteAllMenus()

reWriteAllMenus ( $file,
$menus,
$menuWantTo,
$key,
$action )
Parameters
string$filepath of filename
mixed$menusall menus for module
mixed | null$menuWantTomenu get for do actions
int | null$keykey for the concerned menu
int$actionfor specify what action (0 = delete, 1 = add, 2 = update, -1 = when delete object)
Returns
int 1 if OK, -1 if KO

Definition at line 1050 of file modulebuilder.lib.php.

References dolReplaceInFile(), and getFromFile().

◆ reWriteAllPermissions()

reWriteAllPermissions ( $file,
$permissions,
$key,
$right,
$objectname,
$module,
$action )

Rewriting all permissions after any actions.

Parameters
string$filefilename or path
array$permissionspermissions existing in file
int | null$keykey for permission needed
array | null$right$right to update or add
string | null$objectnamename of object
string | null$modulename of module
int$action0 for delete, 1 for add, 2 for update, -1 when delete object completly, -2 for generate rights after add
Returns
int 1 if OK,-1 if KO

Definition at line 540 of file modulebuilder.lib.php.

References deletePerms(), and dolReplaceInFile().

◆ updateDictionaryInFile()

updateDictionaryInFile ( $module,
$file,
$dicts )

Updates a dictionary in a module descriptor file.

Parameters
string$moduleThe name of the module.
string$fileThe path to the module descriptor file.
array$dictsThe dictionary data to be updated.
Returns
int Returns the number of replacements made in the file.

Definition at line 1149 of file modulebuilder.lib.php.

References dolReplaceInFile(), and getFromFile().

Referenced by createNewDictionnary().

◆ writeApiUrlsInDoc()

writeApiUrlsInDoc ( $file_api,
$file_doc )

Generate Urls and add them to documentaion module.

Parameters
string$file_apifilename or path of api
string$file_docfilename or path of documentation
Returns
int -1 if KO, 1 if OK, 0 if nothing change

Definition at line 1285 of file modulebuilder.lib.php.

References dol_is_file(), dolReplaceInFile(), and getFromFile().

◆ writePermsInAsciiDoc()

writePermsInAsciiDoc ( $file,
$destfile )

Write all permissions of each object in AsciiDoc format.

Parameters
string$filepath of the class
string$destfilefile where write table of permissions
Returns
int 1 if OK, -1 if KO

Definition at line 859 of file modulebuilder.lib.php.

References dolReplaceInFile(), and getFromFile().

◆ writePropsInAsciiDoc()

writePropsInAsciiDoc ( $file,
$objectname,
$destfile )

Write all properties of the object in AsciiDoc format.

Parameters
string$filepath of the class
string$objectnamename of the objectClass
string$destfilefile where write table of properties
Returns
int 1 if OK, -1 if KO

Definition at line 704 of file modulebuilder.lib.php.

References dolReplaceInFile(), and parsePropertyString().