31,003
edits
mNo edit summary Tag: 2017 source edit |
mNo edit summary Tag: 2017 source edit |
||
| Line 51: | Line 51: | ||
== Load class for extrafields == | == Load class for extrafields == | ||
To use extrafields all pages need include | To use extrafields all pages need include | ||
< | <syntaxhighlight lang="PHP"> | ||
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; | require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; | ||
</ | </syntaxhighlight> | ||
== Load extrafield array in object == | == Load extrafield array in object == | ||
< | <syntaxhighlight lang="PHP"> | ||
$extrafields = new ExtraFields($db); | $extrafields = new ExtraFields($db); | ||
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); | $extralabels=$extrafields->fetch_name_optionals_label($object->table_element); | ||
</ | </syntaxhighlight> | ||
$extralabels will be an array with code and label of extrafields. | $extralabels will be an array with code and label of extrafields. | ||
| Line 68: | Line 68: | ||
Extrafields are loaded in $object->array_options array. | Extrafields are loaded in $object->array_options array. | ||
< | <syntaxhighlight lang="PHP"> | ||
$object->fetch($rowid); | $object->fetch($rowid); | ||
$object->fetch_optionals($rowid,$extralabels); | $object->fetch_optionals($rowid,$extralabels); | ||
</ | </syntaxhighlight> | ||
This code must be placed just after the above. | This code must be placed just after the above. | ||
| Line 79: | Line 79: | ||
HTML Exemple | HTML Exemple | ||
< | <syntaxhighlight lang="PHP"> | ||
print $object->array_options ['options_XXX']; | print $object->array_options ['options_XXX']; | ||
</ | </syntaxhighlight> | ||
Where XXX is the code of the extrafields | Where XXX is the code of the extrafields | ||
PDF example | PDF example | ||
< | <syntaxhighlight lang="PHP"> | ||
$pdf->MultiCell (0,5, $outputlangs->convToOutputCharset($object->array_options ['options_XXX']),0,'L'); ) | $pdf->MultiCell (0,5, $outputlangs->convToOutputCharset($object->array_options ['options_XXX']),0,'L'); ) | ||
</ | </syntaxhighlight> | ||
Where XXX is the code of the extrafields | Where XXX is the code of the extrafields | ||
| Line 96: | Line 96: | ||
HTML Exemple | HTML Exemple | ||
< | <syntaxhighlight lang="PHP"> | ||
print $object->lines[$i]->array_options['options_XXX']; | print $object->lines[$i]->array_options['options_XXX']; | ||
</ | </syntaxhighlight> | ||
Where XXX is the code of the extrafields | Where XXX is the code of the extrafields | ||
PDF example | PDF example | ||
< | <syntaxhighlight lang="PHP"> | ||
$pdf->MultiCell (0,5, $outputlangs->convToOutputCharset($object->lines[$i]->array_options['options_XXX']),0,'L'); | $pdf->MultiCell (0,5, $outputlangs->convToOutputCharset($object->lines[$i]->array_options['options_XXX']),0,'L'); | ||
</ | </syntaxhighlight> | ||
Where XXX is the code of the extrafields | Where XXX is the code of the extrafields | ||
| Line 114: | Line 114: | ||
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 : | ||
< | <syntaxhighlight lang="PHP"> | ||
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); | $ret = $extrafields->setOptionalsFromPost($extralabels,$object); | ||
</ | </syntaxhighlight> | ||
== Inside edit page to display extrafields == | == Inside edit page to display extrafields == | ||
< | <syntaxhighlight lang="PHP"> | ||
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook | $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook | ||
if (empty($reshook) && ! empty($extrafields->attribute_label)) | if (empty($reshook) && ! empty($extrafields->attribute_label)) | ||
| Line 127: | Line 127: | ||
print $object->showOptionals($extrafields,'edit'); | print $object->showOptionals($extrafields,'edit'); | ||
} | } | ||
</ | </syntaxhighlight> | ||
== Inside view page to display extrafields == | == Inside view page to display extrafields == | ||
< | <syntaxhighlight lang="PHP"> | ||
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook | $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook | ||
if (empty($reshook) && ! empty($extrafields->attribute_label)) | if (empty($reshook) && ! empty($extrafields->attribute_label)) | ||
| Line 137: | Line 137: | ||
print $object->showOptionals($extrafields); | print $object->showOptionals($extrafields); | ||
} | } | ||
</ | </syntaxhighlight> | ||
== After fetch method of this object class == | == After fetch method of this object class == | ||
< | <syntaxhighlight lang="PHP"> | ||
require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'); | require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'); | ||
$extrafields=new ExtraFields($this->db); | $extrafields=new ExtraFields($this->db); | ||
| Line 147: | Line 147: | ||
$this->fetch_optionals($this->id,$extralabels); | $this->fetch_optionals($this->id,$extralabels); | ||
} | } | ||
</ | </syntaxhighlight> | ||
==After Update method of this object class :== | ==After Update method of this object class :== | ||
< | <syntaxhighlight lang="PHP"> | ||
// Actions on extra fields (by external module or standard code) | // Actions on extra fields (by external module or standard code) | ||
// FIXME le hook fait double emploi avec le trigger !! | // FIXME le hook fait double emploi avec le trigger !! | ||
| Line 168: | Line 168: | ||
} | } | ||
else if ($reshook < 0) $error++; | else if ($reshook < 0) $error++; | ||
</ | </syntaxhighlight> | ||
== After delete method of this object class == | == After delete method of this object class == | ||
< | <syntaxhighlight lang="PHP"> | ||
// Removed extrafields | // Removed extrafields | ||
if (! $error) | if (! $error) | ||
| Line 185: | Line 185: | ||
} | } | ||
} | } | ||
</ | </syntaxhighlight> | ||
==Admin pages == | ==Admin pages == | ||
< | <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> | ||
=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"> | ||
$listofmodulesextra=array('societe'=>'societe','adherent'=>'adherent','product'=>'product', | $listofmodulesextra=array('societe'=>'societe','adherent'=>'adherent','product'=>'product', | ||
'socpeople'=>'socpeople', 'commande'=>'commande', 'facture'=>'facture', | 'socpeople'=>'socpeople', 'commande'=>'commande', 'facture'=>'facture', | ||
'commande_fournisseur'=>'commande_fournisseur', 'actioncomm'=>'actioncomm', | 'commande_fournisseur'=>'commande_fournisseur', 'actioncomm'=>'actioncomm', | ||
'adherent_type'=>'adherent_type','user'=>'user','projet'=>'projet', 'projet_task'=>'projet_task'); | 'adherent_type'=>'adherent_type','user'=>'user','projet'=>'projet', 'projet_task'=>'projet_task'); | ||
</ | </syntaxhighlight> | ||