676
edits
mNo edit summary Tag: 2017 source edit |
Tag: 2017 source edit |
||
| Line 72: | Line 72: | ||
=Tips= | =Tips= | ||
== Computed Fields== | == Computed Fields== | ||
You can enter here a formula using other properties of object or any PHP coding to get a dynamic computed value. You can use any PHP compatible formulas including the "?" condition operator, and following global object: '''$db, $conf, $langs, $mysoc, $user, $object'''. | |||
'''WARNING''': Only some properties of $object may be available. If you need a properties not loaded, just fetch yourself the object into your formula like in the second example. | |||
Using a computed field means you can't enter yourself any value from interface. Also, if there is a syntax error, the formula may return nothing. | |||
===Example of formula:=== | |||
<code>$object->id < 10 ? round($object->id / 2, 2): ($object->id + 2 * $user->id) * (int) substr($mysoc->zip, 1, 2)</code> | |||
===Example to reload object=== | |||
<code>(($reloadedobj = new Societe($db)) && ($reloadedobj->fetchNoCompute($obj->id ? $obj->id: ($obj->rowid ? $obj->rowid: $object->id)) > 0)) ? $reloadedobj->array_options['options_extrafieldkey'] * $reloadedobj->capital / 5: '-1'</code> | |||
===Other example of formula to force load of object and its parent object:=== | |||
<code>(($reloadedobj = new Task($db)) && ($reloadedobj->fetchNoCompute($object->id) > 0) && ($secondloadedobj = new Project($db)) && ($secondloadedobj->fetchNoCompute($reloadedobj->fk_project) > 0)) ? $secondloadedobj->ref: 'Parent project not found'</code> | |||
== Visibility== | == Visibility== | ||
<code>(($c = new Categorie($db)) && ($cats = $c->containing($object->id, Categorie::TYPE_PRODUCT))&& (in_array('mycategory',$cats ))) ? 1 : 0</code> | <code>(($c = new Categorie($db)) && ($cats = $c->containing($object->id, Categorie::TYPE_PRODUCT))&& (in_array('mycategory',$cats ))) ? 1 : 0</code> | ||
edits