LScli :: show : handle form layout (if defined)

This commit is contained in:
Benjamin Renard 2020-05-01 13:05:30 +02:00
parent 448d977f14
commit fa3742c609

View file

@ -1922,18 +1922,45 @@ class LSldapObject {
/**
* CLI helper to show the object info
*
* @param[in] $raw-values bool Show attributes raw values (instead of display ones)
* @param[in] $raw_values bool Show attributes raw values (instead of display ones)
*
* @retval void
**/
public function _cli_show($raw_values) {
public function _cli_show($raw_values=false) {
echo $this -> type_name." (".($this -> dn?$this -> dn:'new').") :\n";
if (is_array($this -> getConfig('LSform.layout'))) {
foreach($this -> getConfig('LSform.layout') as $tab_name => $tab) {
echo " - ".(isset($tab['label'])?$tab['label']:$tab_name)." :\n";
foreach ($tab['args'] as $attr_name) {
$this -> _cli_show_attr($attr_name, $raw_values, " ");
}
echo "\n";
}
}
else {
foreach ($this -> attrs as $attr_name => $attr) {
echo " - $attr_name :";
$values = ($raw_values?$attr->getValue():$attr->getDisplayValue());
$this -> _cli_show_attr($attr_name, $raw_values);
}
}
}
/**
* CLI helper to show the attribute
*
* @param[in] $attr_name string The attribute name
* @param[in] $raw_values bool Show attributes raw values (instead of display ones)
* @param[in] $prefix string Prefix for each line displayed (optional, default: no prefix)
*
* @retval void
**/
public function _cli_show_attr($attr_name, $raw_values=false, $prefix="") {
if (!isset($this -> attrs[$attr_name]))
return;
echo "$prefix - $attr_name :";
$values = ($raw_values?$this -> attrs[$attr_name]->getValue():$this -> attrs[$attr_name]->getDisplayValue());
if (empty($values)) {
echo " empty\n";
continue;
return true;
}
if (!is_array($values)) $values = array($values);
@ -1941,12 +1968,11 @@ class LSldapObject {
for ($i=0; $i < count($values); $i++)
if (strlen($values[$i]) > 70)
$values[$i] = substr($values[$i], 0, 65)."[...]";
echo (count($values) > 1?"\n - ":" ");
echo implode("\n - ", $values);
echo (count($values) > 1?"\n$prefix - ":" ");
echo implode("\n$prefix - ", $values);
echo "\n";
}
}
}
/**
* Error Codes