439
edits
(Init Module_CustomFields_Cases) |
(Adding one example case thank's to manub) |
||
| Line 1: | Line 1: | ||
This page lists a compilation of concrete, practical examples uses of CustomFields and of its various features. | |||
If you had an experience with CustomFields, you can also add here your case as an example for others to get inspired. | |||
= Conditions on fields selection = | |||
conditions 3 types: static (view on only prospect), semi-dynamic (static table but based on the value of another field/customfield, like manub/rossy), dynamic (based on another subfield of a field of the current module, like mermoz) | |||
= Overloading functions = | |||
The goal is to show two custom fields on the Third-Party module: one which gives the zone (secteur) of the third-party (Isere, Alpes du sud, Haute-Savoie...) and the other which gives relative to the zone the list of all the ski resorts (station_a) inside the selected zone. | |||
We have one table '''llx_k_station''' (rowid, station (char50), secteur(char50)) which contains the following: | |||
<pre> | |||
1,les 2 alpes,isère | |||
2,chamrousse,isère | |||
3,alpe d'huez,isère | |||
4,vars,alpes du sud | |||
5,risoul,alpes du sud | |||
etc... | |||
</pre> | |||
In CustomFields's admin panel, we create two custom fields: | |||
1-secteur: returns the list of all zones - type DropdownBox: enum('- Aucun','Alpes du Sud','export','Haute-Savoie','Isère', etc...) | |||
2-station_a: returns the list of all ski resorts - type constraint on '''llx_k_station''' | |||
Here is the code to put in customfields_fields_extend.lib.php that will allow to show only the ski resorts corresponding to the selected zone: | |||
<source lang="php"> | |||
function customfields_field_editview_societe_station_a (&$currentmodule, &$object, &$parameters, &$action, &$user, &$idvar, &$rightok, &$customfields, &$field, &$name, &$value) { | |||
global $db; // allow to access database functions | |||
$sql="SELECT llx_k_station.station, llx_k_station.rowid FROM llx_societe_customfields INNER JOIN llx_k_station ON llx_societe_customfields.Secteur = llx_k_station.secteur WHERE llx_societe_customfields.fk_societe=".$object->id; | |||
$result=$db->query($sql); | |||
if ($result) { | |||
$num = $db->num_rows($result); | |||
$i = 0; | |||
$myarray = array(); | |||
while ($i < $num) | |||
{ | |||
$obj = $db->fetch_object($result); | |||
$myarray []=array('id'=>$obj->rowid, 'value'=>$obj->station); | |||
$i++; | |||
} | |||
$value = $myarray; | |||
$db->free($result); | |||
} | |||
} | |||
</source> | |||
Thank's to manub for giving this case. | |||
edits