I propose evolution of the function jsonDumObj from api/index.php.
function jsonDumpObj($obj, $included=false) {
$res="";
foreach($obj as $fld=>$val) {
if (is_object($val)) {
if ($res!="") { $res.=", ";}
$res.=jsonDumpObj($val, true);
} else if (substr($fld,0,1)=='_'
or $obj->isAttributeSetToField($fld, 'hidden')
or $included and ($fld=='id' or $fld=='refType' or $fld=='refId' or $fld=='refName'
or $fld=='handled' or $fld=='done' or $fld=='idle' or $fld=='cancelled') ) {
// Nothing
} else {
if ($fld=='name' && property_exists($obj, '_isNameTranslatable') && $obj->_isNameTranslatable) { $val=i18n($val); }
if ($res!="") { $res.=", ";}
$res.='"' . htmlEncode($fld) . '":"' . htmlEncodeJson($val) . '"';
if (substr($fld,0,2)=='id' and strlen($fld)>2) {
$idclass=substr($fld,2);
if (strtoupper(substr($idclass,0,1))==substr($idclass,0,1) and property_exists($idclass, 'name')) {
$res.=", ";
$val2=SqlList::getNameFromId($idclass, $val);
if (property_exists($idclass, '_isNameTranslatable') && $idclass->_isNameTranslatable) { $val2=i18n($val2); }
$res.='"name' . $idclass . '":"' . htmlEncodeJson($val2) . '"';
}
}
}
}
if (property_exists($obj, 'refId') && property_exists($obj, 'refType') && !property_exists($obj, 'refName') &&
$obj->refId!="" and $obj->refType!="") {
$idclass=$obj->refType;
if (strtoupper(substr($idclass,0,1))==substr($idclass,0,1) and property_exists($idclass, 'name')) {
$res.=", ";
$res.='"refName":"' . htmlEncodeJson(SqlList::getNameFromId($idclass, $obj->refId)) . '"';
}
}
return $res;
}