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

Detailed Description

Set of function for modulebuilder management.

Definition in file modulebuilder.lib.php.

Function Documentation

◆ addObjectsToApiFile()

addObjectsToApiFile (   $srcfile,
  $file,
  $objects,
  $modulename 
)

Add Object in ModuleApi File.

Parameters
string$srcfileSource file to use as example
string$filePath of modified file
string[]$objectsArray of objects in the module
string$modulenameName of module
Returns
int<-1,1> Return 1 if OK, -1 if KO

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

◆ checkExistComment()

checkExistComment (   $file,
  $number 
)

Function to check if comment BEGIN and END exists 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 469 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 546 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 1433 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<string,string|array<string,int|string>>$dictionnaires An optional array containing pre-existing dictionary data, including 'tabname', 'tablib', 'tabsql', etc.
Returns
int<-1,-1>|void Return int < 0 if error, return nothing on success

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

◆ deletePerms()

deletePerms (   $file)

Delete all permissions.

Parameters
string$filefile with path
Returns
void

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

◆ 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 824 of file modulebuilder.lib.php.

◆ 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 436 of file modulebuilder.lib.php.

References dol_dir_list().

◆ getFromFile()

getFromFile (   $file,
  $start,
  $end,
  $excludestart = '',
  $includese = 0 
)

Search a string and return all lines needed from file.

Does not include line $start nor $end

Parameters
string$filefile for searching
string$startstart line if exist
string$endend line if exist
string$excludestartIgnore if start line is $excludestart
int$includeseInclude start and end line
Returns
string Return the lines between first line with $start and $end. "" if not found.

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

◆ parsePropertyString()

parsePropertyString (   $string)

Converts a formatted properties string into an associative array.

Parameters
string$stringThe formatted properties string.
Returns
array<string,bool|int|float|string|mixed[]> The resulting associative array.

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

◆ 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)
array{}|array{name:string,key:string,type:string,label:string,picot?:string,enabled:int<0,1>,notnull:int<0,1>,position:int,visible:int,noteditable?:int<0,1>,alwayseditable?:int<0,1>,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int<0,1>,css?:string,cssview?:string,csslist?:string,help?:string,showoncombobox?:int<0,1>,disabled?:int<0,1>,autofocusoncreate?:int<0,1>,arrayofkeyval?:array<string,string>,validate?:int<0,1>,comment?:string}$addfieldentry Array of 1 field entry to add
string$delfieldentryId of field to remove
Returns
int<-7,-1>|CommonObject Return integer <=0 if KO, Object if OK
See also
rebuildObjectSql()

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

◆ 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 258 of file modulebuilder.lib.php.

◆ removeObjectFromApiFile()

removeObjectFromApiFile (   $file,
  $objects,
  $objectname 
)

Remove Object variables and methods from API_Module File.

Parameters
string$fileFile api module
string[]$objectsArray of objects in the module
string$objectnameName of object want to remove
Returns
int<-1,1> 1 if OK, -1 if KO

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

◆ reWriteAllMenus()

reWriteAllMenus (   $file,
  $menus,
  $menuWantTo,
  $key,
  $action 
)
Parameters
string$filepath of filename
array<int,array{commentgroup:string,fk_menu:string,type:string,titre:string,mainmenu:string,leftmenu:string,url:string,langs:string,position:int,enabled:int,perms:string,target:string,user:int}>$menus all menus for module
mixed | null$menuWantTomenu get for do actions
int | null$keykey for the concerned menu
int<-1,2>$action for specify what action (0 = delete perm, 1 = add perm, 2 = update perm, -1 = when we delete object)
Returns
int<-1,1> 1 if OK, -1 if KO

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

◆ reWriteAllPermissions()

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

Rewriting all permissions after any actions.

Parameters
string$filefilename or path
array<int,string[]>$permissions permissions existing in file
int | null$keykey for permission needed
array{0:string,1:string}|null$right $right to update or add
string | null$objectnamename of object
string | null$modulename of module
int<-2,2>$action 0 for delete, 1 for add, 2 for update, -1 when delete object completely, -2 for generate rights after add
Returns
int<-1,1> 1 if OK,-1 if KO

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

◆ 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<string,string|array<string,int|string>>$dicts The dictionary data to be updated.
Returns
int Returns the number of replacements made in the file.
Parameters
bool | int | string$val
Returns
string|int
Parameters
string$val
Returns
string

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

◆ writeApiUrlsInDoc()

writeApiUrlsInDoc (   $file_api,
  $file_doc 
)

Generate Urls and add them to documentation module.

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

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

◆ 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,1> 1 if OK, -1 if KO

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

◆ 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 726 of file modulebuilder.lib.php.