Difference between revisions of "Extrafields"

From Dolibarr ERP CRM Wiki
Jump to navigation Jump to search
Line 25: Line 25:
 
)
 
)
  
[[Display page have to include :]]
+
==Display page have to include :==
 
<source lang="php">
 
<source lang="php">
 
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
 
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
 
</source>
 
</source>
  
[[Load extrafield array in object :]]
+
==Load extrafield array in object :==
 
<source lang="php">
 
<source lang="php">
 
$extrafields = new ExtraFields($db);
 
$extrafields = new ExtraFields($db);
Line 36: Line 36:
 
</source>
 
</source>
  
[[Load extrafield into object :]]
+
==Load extrafield into object :==
 
<source lang="php">
 
<source lang="php">
 
''$object''->fetch($rowid);
 
''$object''->fetch($rowid);
Line 47: Line 47:
 
</source>
 
</source>
  
[[Inside edit page to display extrafields :]]
+
==Inside edit page to display extrafields :==
 
<source lang="php">
 
<source lang="php">
 
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$act,$action);    // Note that $action and $object may have been modified by hook
 
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$act,$action);    // Note that $action and $object may have been modified by hook
Line 56: Line 56:
 
</source>
 
</source>
  
[[Inside view page to display extrafields :]]
+
==Inside view page to display extrafields :==
 
<source lang="php">
 
<source lang="php">
 
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$act,$action);    // Note that $action and $object may have been modified by hook
 
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$act,$action);    // Note that $action and $object may have been modified by hook

Revision as of 02:43, 20 April 2013

Extrafields

Extrafields allow to add others datas to Dolibarr standard database schema. Introduced in version 3.2, extrafields are now implemented in businesses object :

  • Thirdparties & contacts & users
  • Events
  • Customer Invoices
  • Proposal
  • Products & services
  • Member & member type
  • Orders
  • Projects & project tasks (since 3.4)

Technical implementation

Each object have his table in database to store values of extrafields.

Datatables extrafield tables models is : llx_BaseTableNAme_extrafields (

 rowid                     integer AUTO_INCREMENT PRIMARY KEY,
 tms                       timestamp,
 fk_object                 integer NOT NULL,
 import_key                varchar(14)

)

Display page have to include :

require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';

Load extrafield array in object :

$extrafields = new ExtraFields($db);
$extralabels=$extrafields->fetch_name_optionals_label('''ObjectClassName''');

Load extrafield into object :

''$object''->fetch($rowid);
''$object''->fetch_optionals($rowid,$extralabels);

[[Before call $object->create or $object->delete :]]

$ret = $extrafields->setOptionalsFromPost($extralabels,''$object'');

Inside edit page to display extrafields :

$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$act,$action);    // Note that $action and $object may have been modified by hook
if (empty($reshook) && ! empty($extrafields->attribute_label))
{
      print ''$object''->showOptionals($extrafields,'edit');
}

Inside view page to display extrafields :

$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$act,$action);    // Note that $action and $object may have been modified by hook
if (empty($reshook) && ! empty($extrafields->attribute_label))
{
      print ''$object''->showOptionals($extrafields);
}