dolibarr 18.0.6
ExtraFields Class Reference

Class to manage standard extra fields. More...

Collaboration diagram for ExtraFields:

Public Member Functions

 __construct ($db)
 Constructor.
 
 addExtraField ($attrname, $label, $type, $pos, $size, $elementtype, $unique=0, $required=0, $default_value='', $param='', $alwayseditable=0, $perms='', $list='-1', $help='', $computed='', $entity='', $langfile='', $enabled='1', $totalizable=0, $printable=0, $moreparams=array())
 Add a new extra field parameter.
 
 delete ($attrname, $elementtype='member')
 Delete an optional attribute.
 
 update ($attrname, $label, $type, $length, $elementtype, $unique=0, $required=0, $pos=0, $param='', $alwayseditable=0, $perms='', $list='', $help='', $default='', $computed='', $entity='', $langfile='', $enabled='1', $totalizable=0, $printable=0, $moreparams=array())
 Modify type of a personalized attribute.
 
 fetch_name_optionals_label ($elementtype, $forceload=false)
 Load the array of extrafields defintion $this->attributes.
 
 showInputField ($key, $value, $moreparam='', $keysuffix='', $keyprefix='', $morecss='', $objectid=0, $extrafieldsobjectkey='', $mode=0)
 Return HTML string to put an input field into a page Code very similar with showInputField of common object.
 
 showOutputField ($key, $value, $moreparam='', $extrafieldsobjectkey='', $outputlangs=null)
 Return HTML string to put an output field into a page.
 
 getAlignFlag ($key, $extrafieldsobjectkey='')
 Return the CSS to use for this extrafield into list.
 
 showSeparator ($key, $object, $colspan=2, $display_type='card', $mode='')
 Return HTML string to print separator extrafield.
 
 setOptionalsFromPost ($extralabels, &$object, $onlykey='', $todefaultifmissing=0)
 Fill array_options property of object by extrafields value (using for data sent by forms)
 
 getOptionalsFromPost ($extrafieldsobjectkey, $keyprefix='', $keysuffix='')
 return array_options array of data of extrafields value of object sent by a search form
 

Private Member Functions

 create ($attrname, $type='varchar', $length=255, $elementtype='member', $unique=0, $required=0, $default_value='', $param='', $perms='', $list='0', $computed='', $help='', $moreparams=array())
 Add a new optional attribute.
 
 create_label ($attrname, $label='', $type='', $pos=0, $size=0, $elementtype='member', $unique=0, $required=0, $param='', $alwayseditable=0, $perms='', $list='-1', $help='', $default='', $computed='', $entity='', $langfile='', $enabled='1', $totalizable=0, $printable=0, $moreparams=array())
 Add description of a new optional attribute.
 
 delete_label ($attrname, $elementtype='member')
 Delete description of an optional attribute.
 
 update_label ($attrname, $label, $type, $size, $elementtype, $unique=0, $required=0, $pos=0, $param='', $alwayseditable=0, $perms='', $list='0', $help='', $default='', $computed='', $entity='', $langfile='', $enabled='1', $totalizable=0, $printable=0, $moreparams=array())
 Modify description of personalized attribute.
 

Detailed Description

Class to manage standard extra fields.

Definition at line 39 of file extrafields.class.php.

Constructor & Destructor Documentation

◆ __construct()

ExtraFields::__construct ( $db)

Constructor.

Parameters
DoliDB$dbDatabase handler

Definition at line 106 of file extrafields.class.php.

Member Function Documentation

◆ addExtraField()

ExtraFields::addExtraField ( $attrname,
$label,
$type,
$pos,
$size,
$elementtype,
$unique = 0,
$required = 0,
$default_value = '',
$param = '',
$alwayseditable = 0,
$perms = '',
$list = '-1',
$help = '',
$computed = '',
$entity = '',
$langfile = '',
$enabled = '1',
$totalizable = 0,
$printable = 0,
$moreparams = array() )

Add a new extra field parameter.

Parameters
string$attrnameCode of attribute
string$labellabel of attribute
string$typeType of attribute ('boolean','int','varchar','text','html','date','datetime','price', 'pricecy', 'phone','mail','password','url','select','checkbox','separate',...)
int$posPosition of attribute
string$sizeSize/length definition of attribute ('5', '24,8', ...). For float, it contains 2 numeric separated with a comma.
string$elementtypeElement type. Same value than object->table_element (Example 'member', 'product', 'thirdparty', ...)
int$uniqueIs field unique or not
int$requiredIs field required or not
string$default_valueDefaulted value (In database. use the default_value feature for default value on screen. Example: '', '0', 'null', 'avalue')
array | string$paramParams for field (ex for select list : array('options' => array(value'=>'label of option')) )
int$alwayseditableIs attribute always editable regardless of the document status
string$permsPermission to check
string$listVisibility ('0'=never visible, '1'=visible on list+forms, '2'=list only, '3'=form only or 'eval string')
string$helpText with help tooltip
string$computedComputed value
string$entityEntity of extrafields (for multicompany modules)
string$langfileLanguage file
string$enabledCondition to have the field enabled or not
int$totalizableIs a measure. Must show a total on lists
int$printableIs extrafield displayed on PDF
array$moreparamsMore parameters. Example: array('css'=>, 'csslist'=>Css on list, 'cssview'=>...)
Returns
int <=0 if KO, >0 if OK

Definition at line 140 of file extrafields.class.php.

References create(), and create_label().

◆ create()

ExtraFields::create ( $attrname,
$type = 'varchar',
$length = 255,
$elementtype = 'member',
$unique = 0,
$required = 0,
$default_value = '',
$param = '',
$perms = '',
$list = '0',
$computed = '',
$help = '',
$moreparams = array() )
private

Add a new optional attribute.

This is a private method. For public method, use addExtraField.

Parameters
string$attrnamecode of attribute
int$typeType of attribute ('boolean', 'int', 'varchar', 'text', 'html', 'date', 'datetime','price','pricecy','phone','mail','password','url','select','checkbox', ...)
string$lengthSize/length of attribute ('5', '24,8', ...)
string$elementtypeElement type ('member', 'product', 'thirdparty', 'contact', ...)
int$uniqueIs field unique or not
int$requiredIs field required or not
string$default_valueDefault value for field (in database)
array$paramParams for field (ex for select list : array('options'=>array('value'=>'label of option'))
string$permsPermission
string$listInto list view by default
string$computedComputed value
string$helpHelp on tooltip
array$moreparamsMore parameters. Example: array('css'=>, 'csslist'=>, 'cssview'=>...)
Returns
int <=0 if KO, >0 if OK

Definition at line 202 of file extrafields.class.php.

Referenced by addExtraField().

◆ create_label()

ExtraFields::create_label ( $attrname,
$label = '',
$type = '',
$pos = 0,
$size = 0,
$elementtype = 'member',
$unique = 0,
$required = 0,
$param = '',
$alwayseditable = 0,
$perms = '',
$list = '-1',
$help = '',
$default = '',
$computed = '',
$entity = '',
$langfile = '',
$enabled = '1',
$totalizable = 0,
$printable = 0,
$moreparams = array() )
private

Add description of a new optional attribute.

Parameters
string$attrnamecode of attribute
string$labellabel of attribute
int$typeType of attribute ('int', 'varchar', 'text', 'html', 'date', 'datetime', 'float')
int$posPosition of attribute
string$sizeSize/length of attribute ('5', '24,8', ...)
string$elementtypeElement type ('member', 'product', 'thirdparty', ...)
int$uniqueIs field unique or not
int$requiredIs field required or not
array | string$paramParams for field (ex for select list : array('options' => array(value'=>'label of option')) )
int$alwayseditableIs attribute always editable regardless of the document status
string$permsPermission to check
string$listVisibily
string$helpHelp on tooltip
string$defaultDefault value (in database. use the default_value feature for default value on screen).
string$computedComputed value
string$entityEntity of extrafields
string$langfileLanguage file
string$enabledCondition to have the field enabled or not
int$totalizableIs a measure. Must show a total on lists
int$printableIs extrafield displayed on PDF
array$moreparamsMore parameters. Example: array('css'=>, 'csslist'=>, 'cssview'=>...)
Returns
int <=0 if KO, >0 if OK
Exceptions
Exception

Definition at line 306 of file extrafields.class.php.

References dol_now(), and dol_syslog().

Referenced by addExtraField().

◆ delete()

ExtraFields::delete ( $attrname,
$elementtype = 'member' )

Delete an optional attribute.

Parameters
string$attrnameCode of attribute to delete
string$elementtypeElement type ('member', 'product', 'thirdparty', 'contact', ...)
Returns
int < 0 if KO, 0 if nothing is done, 1 if OK

Definition at line 438 of file extrafields.class.php.

References delete_label().

◆ delete_label()

ExtraFields::delete_label ( $attrname,
$elementtype = 'member' )
private

Delete description of an optional attribute.

Parameters
string$attrnameCode of attribute to delete
string$elementtypeElement type ('member', 'product', 'thirdparty', ...)
Returns
int < 0 if KO, 0 if nothing is done, 1 if OK

Definition at line 496 of file extrafields.class.php.

References dol_print_error(), and dol_syslog().

Referenced by delete().

◆ fetch_name_optionals_label()

ExtraFields::fetch_name_optionals_label ( $elementtype,
$forceload = false )

Load the array of extrafields defintion $this->attributes.

Parameters
string$elementtypeType of element ('all' = all or $object->table_element like 'adherent', 'commande', 'thirdparty', 'facture', 'propal', 'product', ...).
boolean$forceloadForce load of extra fields whatever is status of cache.
Returns
array Array of attributes keys+label for all extra fields.

Definition at line 833 of file extrafields.class.php.

References dol_syslog(), and jsonOrUnserialize().

◆ getAlignFlag()

ExtraFields::getAlignFlag ( $key,
$extrafieldsobjectkey = '' )

Return the CSS to use for this extrafield into list.

Parameters
string$keyKey of attribute
string$extrafieldsobjectkeyIf defined, use the new method to get extrafields data
Returns
string Formated value

Definition at line 1941 of file extrafields.class.php.

◆ getOptionalsFromPost()

ExtraFields::getOptionalsFromPost ( $extrafieldsobjectkey,
$keyprefix = '',
$keysuffix = '' )

return array_options array of data of extrafields value of object sent by a search form

Parameters
array | string$extrafieldsobjectkeyarray of extrafields (old usage) or value of object->table_element (new usage)
string$keyprefixPrefix string to add into name and id of field (can be used to avoid duplicate names)
string$keysuffixSuffix string to add into name and id of field (can be used to avoid duplicate names)
Returns
array|int array_options set or 0 if no value

Definition at line 2234 of file extrafields.class.php.

References dol_htmlcleanlastbr(), dol_mktime(), GETPOST(), GETPOSTISARRAY(), and price2num().

◆ setOptionalsFromPost()

ExtraFields::setOptionalsFromPost ( $extralabels,
& $object,
$onlykey = '',
$todefaultifmissing = 0 )

Fill array_options property of object by extrafields value (using for data sent by forms)

Parameters
array | null$extralabelsDeprecated (old $array of extrafields, now set this to null)
object$objectObject
string$onlykeyOnly some keys are filled: 'string' => When we make update of only one extrafield ($action = 'update_extras'), calling page can set this to avoid to have other extrafields being reset. '@GETPOSTISSET' => When we make update of several extrafields ($action = 'update'), calling page can set this to avoid to have fields not into POST being reset.
int$todefaultifmissing1=Set value to the default value in database if value is mandatory and missing
Returns
int 1 if array_options set, 0 if no value, -1 if error (field required missing for example)

Definition at line 2080 of file extrafields.class.php.

References dol_eval(), dol_mktime(), GETPOST(), price2num(), and setEventMessages().

◆ showInputField()

ExtraFields::showInputField ( $key,
$value,
$moreparam = '',
$keysuffix = '',
$keyprefix = '',
$morecss = '',
$objectid = 0,
$extrafieldsobjectkey = '',
$mode = 0 )

Return HTML string to put an input field into a page Code very similar with showInputField of common object.

Parameters
string$keyKey of attribute
string | array$valuePreselected value to show (for date type it must be in timestamp format, for amount or price it must be a php numeric value); for dates in filter mode, a range array('start'=><timestamp>, 'end'=><timestamp>) should be provided
string$moreparamTo add more parameters on html input tag
string$keysuffixPrefix string to add after name and id of field (can be used to avoid duplicate names)
string$keyprefixSuffix string to add before name and id of field (can be used to avoid duplicate names)
string$morecssMore css (to defined size of field. Old behaviour: may also be a numeric)
int$objectidCurrent object id
string$extrafieldsobjectkeyThe key to use to store retreived data (for example $object->table_element)
string$mode1=Used for search filters
Returns
string

Definition at line 940 of file extrafields.class.php.

References ajax_combobox(), dol_escape_htmltag(), dol_eval(), dol_syslog(), and price().

◆ showOutputField()

ExtraFields::showOutputField ( $key,
$value,
$moreparam = '',
$extrafieldsobjectkey = '',
$outputlangs = null )

Return HTML string to put an output field into a page.

Parameters
string$keyKey of attribute
string$valueValue to show
string$moreparamTo add more parameters on html input tag (only checkbox use html input for output rendering)
string$extrafieldsobjectkeyRequired (for example $object->table_element).
Translate$outputlangsOutput language
Returns
string Formated value

Definition at line 1588 of file extrafields.class.php.

References dol_eval(), dol_print_date(), dol_print_email(), dol_print_ip(), dol_print_phone(), dol_print_url(), dol_syslog(), dol_trunc(), img_object(), and price().

◆ showSeparator()

ExtraFields::showSeparator ( $key,
$object,
$colspan = 2,
$display_type = 'card',
$mode = '' )

Return HTML string to print separator extrafield.

Parameters
string$keyKey of attribute
object$objectObject
int$colspanValue of colspan to use (it must includes the first column with title)
string$display_type"card" for form display, "line" for document line display (extrafields on propal line, order line, etc...)
string$modeShow output ('view') or input ('create' or 'edit') for extrafield
Returns
string HTML code with line for separator

Definition at line 1981 of file extrafields.class.php.

References GETPOST().

◆ update()

ExtraFields::update ( $attrname,
$label,
$type,
$length,
$elementtype,
$unique = 0,
$required = 0,
$pos = 0,
$param = '',
$alwayseditable = 0,
$perms = '',
$list = '',
$help = '',
$default = '',
$computed = '',
$entity = '',
$langfile = '',
$enabled = '1',
$totalizable = 0,
$printable = 0,
$moreparams = array() )

Modify type of a personalized attribute.

Parameters
string$attrnameName of attribute
string$labelLabel of attribute
string$typeType of attribute ('boolean', 'int', 'varchar', 'text', 'html', 'date', 'datetime','price','phone','mail','password','url','select','checkbox', ...)
int$lengthLength of attribute
string$elementtypeElement type ('member', 'product', 'thirdparty', 'contact', ...)
int$uniqueIs field unique or not
int$requiredIs field required or not
int$posPosition of attribute
array$paramParams for field (ex for select list : array('options' => array(value'=>'label of option')) )
int$alwayseditableIs attribute always editable regardless of the document status
string$permsPermission to check
string$listVisibility
string$helpHelp on tooltip
string$defaultDefault value (in database. use the default_value feature for default value on screen).
string$computedComputed value
string$entityEntity of extrafields
string$langfileLanguage file
string$enabledCondition to have the field enabled or not
int$totalizableIs extrafield totalizable on list
int$printableIs extrafield displayed on PDF
array$moreparamsMore parameters. Example: array('css'=>, 'csslist'=>, 'cssview'=>...)
Returns
int >0 if OK, <=0 if KO
Exceptions
Exception

Definition at line 554 of file extrafields.class.php.

References dol_syslog(), and update_label().

◆ update_label()

ExtraFields::update_label ( $attrname,
$label,
$type,
$size,
$elementtype,
$unique = 0,
$required = 0,
$pos = 0,
$param = '',
$alwayseditable = 0,
$perms = '',
$list = '0',
$help = '',
$default = '',
$computed = '',
$entity = '',
$langfile = '',
$enabled = '1',
$totalizable = 0,
$printable = 0,
$moreparams = array() )
private

Modify description of personalized attribute.

Parameters
string$attrnameName of attribute
string$labelLabel of attribute
string$typeType of attribute
int$sizeLength of attribute
string$elementtypeElement type ('member', 'product', 'thirdparty', ...)
int$uniqueIs field unique or not
int$requiredIs field required or not
int$posPosition of attribute
array$paramParams for field (ex for select list : array('options' => array(value'=>'label of option')) )
int$alwayseditableIs attribute always editable regardless of the document status
string$permsPermission to check
string$listVisiblity
string$helpHelp on tooltip.
string$defaultDefault value (in database. use the default_value feature for default value on screen).
string$computedComputed value
string$entityEntity of extrafields
string$langfileLanguage file
string$enabledCondition to have the field enabled or not
int$totalizableIs extrafield totalizable on list
int$printableIs extrafield displayed on PDF
array$moreparamsMore parameters. Example: array('css'=>, 'csslist'=>, 'cssview'=>...)
Returns
int <=0 if KO, >0 if OK
Exceptions
Exception

Definition at line 679 of file extrafields.class.php.

References dol_now(), dol_print_error(), and dol_syslog().

Referenced by update().


The documentation for this class was generated from the following file: