Extrafields: Difference between revisions

Jump to navigation Jump to search
m
no edit summary
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  
<source 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';
</source>
</syntaxhighlight>


== Load extrafield array in object ==
== Load extrafield array in object ==
<source lang="php">
<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);
</source>
</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.


<source lang="php">
<syntaxhighlight lang="PHP">
$object->fetch($rowid);
$object->fetch($rowid);
$object->fetch_optionals($rowid,$extralabels);
$object->fetch_optionals($rowid,$extralabels);
</source>
</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
<source lang="php">
<syntaxhighlight lang="PHP">
print $object->array_options ['options_XXX'];
print $object->array_options ['options_XXX'];
</source>
</syntaxhighlight>
Where XXX is the code of the extrafields
Where XXX is the code of the extrafields


PDF example
PDF example
<source lang="php">
<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'); )
</source>
</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
<source lang="php">
<syntaxhighlight lang="PHP">
print $object->lines[$i]->array_options['options_XXX'];
print $object->lines[$i]->array_options['options_XXX'];
</source>
</syntaxhighlight>
Where XXX is the code of the extrafields
Where XXX is the code of the extrafields


PDF example
PDF example
<source lang="php">
<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');
</source>
</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 :
<source lang="php">
<syntaxhighlight lang="PHP">
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
</source>
</syntaxhighlight>


== Inside edit page to display extrafields ==
== Inside edit page to display extrafields ==




<source lang="php">
<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');
}
}
</source>
</syntaxhighlight>


== Inside view page to display extrafields ==
== Inside view page to display extrafields ==


<source lang="php">
<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);
}
}
</source>
</syntaxhighlight>


== After fetch method of this object class ==
== After fetch method of this object class ==
<source 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');
$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);
}
}
</source>
</syntaxhighlight>


==After Update method of this object class :==
==After Update method of this object class :==
<source 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)
// 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++;
</source>
</syntaxhighlight>


== After delete method of this object class ==
== After delete method of this object class ==
<source lang="php">
<syntaxhighlight lang="PHP">
// Removed extrafields
// Removed extrafields
if (! $error)
if (! $error)
Line 185: Line 185:
   }
   }
}
}
</source>
</syntaxhighlight>


==Admin pages ==
==Admin pages ==
<source 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
</source>
</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
<source lang="php">
<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');
</source>
</syntaxhighlight>

Navigation menu