7
edits
(Ajout d'une partie vidéo concernant les extrafields. Not in the language of the page but it's better than nothing or it can help) Tag: 2017 source edit |
(Adding description about "unique" property) |
||
| Line 9: | Line 9: | ||
=Extrafields= | =Extrafields= | ||
Extrafields allow to add others datas to Dolibarr standard database schema. Introduced in version 3.2, extrafields are now implemented in most business objects : | Extrafields allow to add others datas to Dolibarr standard database schema. Introduced in version 3.2, extrafields are now implemented in most business objects<span> </span>: | ||
= Technical implementation = | *Thirdparties & contacts | ||
*Users | |||
*Events | |||
*Proposal | |||
*Customer Invoices | |||
*Orders | |||
*Supplier Proposal | |||
*Supplier Invoices | |||
*Supplier Orders | |||
*Products & services | |||
*Member & member type | |||
*Projects & project tasks (since 3.4) | |||
*Categories | |||
*Expense Report | |||
=Technical implementation= | |||
Each object has its table in database to store values of extrafields. | Each object has its table in database to store values of extrafields. | ||
== Datatables extrafield tables models == | ==Datatables extrafield tables models== | ||
llx_''BaseTableNAme''_extrafields | llx_''BaseTableNAme''_extrafields | ||
| Line 38: | Line 39: | ||
An example of mysql definition file for extrafields implementation on an object : | An example of mysql definition file for extrafields implementation on an object<span> </span>: | ||
create table llx_place_room_extrafields | create table llx_place_room_extrafields | ||
| Line 48: | Line 49: | ||
) ENGINE=innodb; | ) ENGINE=innodb; | ||
= Usage = | The "Unique" property of extrafield create a `UNIQUE INDEX` on this field, forcing objects to have a unique value for their extrafield (two objects cannot have the same value). | ||
== Load class for extrafields == | |||
=Usage= | |||
==Load class for extrafields== | |||
To use extrafields all pages need include | To use extrafields all pages need include | ||
<syntaxhighlight lang="PHP"> | <syntaxhighlight lang="PHP"> | ||
| Line 55: | Line 58: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Load extrafield array in object == | ==Load extrafield array in object== | ||
<syntaxhighlight lang="PHP"> | <syntaxhighlight lang="PHP"> | ||
$extrafields = new ExtraFields($db); | $extrafields = new ExtraFields($db); | ||
| Line 64: | Line 67: | ||
This code must be placed into the class for example into the function "write_file". | This code must be placed into the class for example into the function "write_file". | ||
== Load extrafield into object == | ==Load extrafield into object== | ||
Extrafields are loaded in $object->array_options array. | Extrafields are loaded in $object->array_options array. | ||
| Line 75: | Line 78: | ||
This code must be placed just after the above. | This code must be placed just after the above. | ||
== Display extrafield value into PDF or HTML == | ==Display extrafield value into PDF or HTML== | ||
After load extrafields | After load extrafields | ||
| Line 90: | Line 93: | ||
Where XXX is the code of the extrafields | Where XXX is the code of the extrafields | ||
A dedicated page to show how to integrate extrafileds into PDF can be found there : [[Add Extrafields on PDF Models]] | A dedicated page to show how to integrate extrafileds into PDF can be found there<span> </span>: [[Add Extrafields on PDF Models]] | ||
== Display extrafield value of lines into PDF or HTML == | ==Display extrafield value of lines into PDF or HTML== | ||
After load extrafields | After load extrafields | ||
| Line 108: | Line 111: | ||
== How to change the labels of the columns when using models (propals, etc.) == | ==How to change the labels of the columns when using models (propals, etc.)== | ||
In the PHP code of the model you can change the labels of your extrafield by changing into the function named "_tableau(...)" | In the PHP code of the model you can change the labels of your extrafield by changing into the function named "_tableau(...)" | ||
== Before call $object->create() or $object->update() == | ==Before call $object->create() or $object->update()== | ||
Values of extrafields sent by form need to be retrieve. For doing that, use this method : | Values of extrafields sent by form need to be retrieve. For doing that, use this method<span> </span>: | ||
<syntaxhighlight lang="PHP"> | <syntaxhighlight lang="PHP"> | ||
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); | $ret = $extrafields->setOptionalsFromPost($extralabels,$object); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Inside edit page to display extrafields == | ==Inside edit page to display extrafields== | ||
| Line 129: | Line 132: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Inside view page to display extrafields == | ==Inside view page to display extrafields== | ||
<syntaxhighlight lang="PHP"> | <syntaxhighlight lang="PHP"> | ||
| Line 139: | Line 142: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== After fetch method of this object class == | ==After fetch method of this object class== | ||
<syntaxhighlight lang="PHP"> | <syntaxhighlight lang="PHP"> | ||
require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'); | require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'); | ||
| Line 149: | Line 152: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==After Update method of this object class :== | ==After Update method of this object class<span> </span>:== | ||
<syntaxhighlight lang="PHP"> | <syntaxhighlight lang="PHP"> | ||
// Actions on extra fields (by external module or standard code) | // Actions on extra fields (by external module or standard code) | ||
| Line 170: | Line 173: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== After delete method of this object class == | ==After delete method of this object class== | ||
<syntaxhighlight lang="PHP"> | <syntaxhighlight lang="PHP"> | ||
// Removed extrafields | // Removed extrafields | ||
| Line 187: | Line 190: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==Admin pages == | ==Admin pages== | ||
<syntaxhighlight lang="PHP"> | <syntaxhighlight lang="PHP"> | ||
$elementtype='facture'; //Must be the $table_element of the class that manage extrafield | $elementtype='facture'; //Must be the $table_element of the class that manage extrafield | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=Repair Database = | =Repair Database= | ||
Search and find definition of $listofmodulesextra add the new extrafield declaration | Search and find definition of $listofmodulesextra add the new extrafield declaration | ||
<syntaxhighlight lang="PHP"> | <syntaxhighlight lang="PHP"> | ||
| Line 201: | Line 204: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
= Related videos = | =Related videos= | ||
Extrafields: | Extrafields: | ||
edits