Use defined tree constants instead of strings

This commit is contained in:
nathangray 2019-11-14 13:52:00 -07:00
parent 9f32f8115d
commit 94a9290776

View File

@ -14,6 +14,7 @@ use EGroupware\Api;
use EGroupware\Api\Link; use EGroupware\Api\Link;
use EGroupware\Api\Egw; use EGroupware\Api\Egw;
use EGroupware\Api\Etemplate; use EGroupware\Api\Etemplate;
use EGroupware\Api\Etemplate\Widget\Tree;
/** /**
* UI for admin * UI for admin
@ -418,7 +419,7 @@ class admin_ui
*/ */
public static function tree_data($root = '/') public static function tree_data($root = '/')
{ {
$tree = array('id' => $root === '/' ? 0 : $root, 'item' => array(), 'child' => 1); $tree = array(Tree::ID => $root === '/' ? 0 : $root, Tree::CHILDREN => array(), 'child' => 1);
if ($root == '/') if ($root == '/')
{ {
@ -438,32 +439,32 @@ class admin_ui
'link' => $data, 'link' => $data,
); );
} }
if (empty($data['text'])) $data['text'] = $text; if (empty($data[Tree::LABEL])) $data[Tree::LABEL] = $text;
if (empty($data['id'])) if (empty($data[Tree::ID]))
{ {
$data['id'] = $root.($app == 'admin' ? 'admin' : 'apps/'.$app).'/'; $data['id'] = $root.($app == 'admin' ? 'admin' : 'apps/'.$app).'/';
$matches = null; $matches = null;
if (preg_match_all('/(menuaction|load)=([^&]+)/', $data['link'], $matches)) if (preg_match_all('/(menuaction|load)=([^&]+)/', $data['link'], $matches))
{ {
$data['id'] .= $matches[2][(int)array_search('load', $matches[1])]; $data[Tree::ID] .= $matches[2][(int)array_search('load', $matches[1])];
} }
} }
if (!empty($data['icon'])) if (!empty($data['icon']))
{ {
$icon = Etemplate\Widget\Tree::imagePath($data['icon']); $icon = Etemplate\Widget\Tree::imagePath($data['icon']);
if ($data['child'] || $data['item']) if ($data['child'] || $data[Tree::CHILDREN])
{ {
$data['im1'] = $data['im2'] = $icon; $data[Tree::IMAGE_FOLDER_OPEN] = $data[Tree::IMAGE_FOLDER_CLOSED] = $icon;
} }
else else
{ {
$data['im0'] = $icon; $data[Tree::IMAGE_LEAF] = $icon;
} }
} }
unset($data['icon']); unset($data['icon']);
$parent =& $tree['item']; $parent =& $tree[Tree::CHILDREN];
$parts = explode('/', $data['id']); $parts = explode('/', $data[Tree::ID]);
if ($data['id'][0] == '/') array_shift($parts); // remove root if ($data[Tree::ID][0] == '/') array_shift($parts); // remove root
array_pop($parts); array_pop($parts);
$path = ''; $path = '';
foreach($parts as $part) foreach($parts as $part)
@ -474,23 +475,23 @@ class admin_ui
$icon = Etemplate\Widget\Tree::imagePath($part == 'apps' ? Api\Image::find('api', 'home') : $icon = Etemplate\Widget\Tree::imagePath($part == 'apps' ? Api\Image::find('api', 'home') :
(($i=Api\Image::find($part, 'navbar')) ? $i : Api\Image::find('api', 'nonav'))); (($i=Api\Image::find($part, 'navbar')) ? $i : Api\Image::find('api', 'nonav')));
$parent[$path] = array( $parent[$path] = array(
'id' => $path, Tree::ID => $path,
'text' => $part == 'apps' ? lang('Applications') : lang($part), Tree::LABEL => $part == 'apps' ? lang('Applications') : lang($part),
//'im0' => 'folderOpen.gif', //'im0' => 'folderOpen.gif',
'im1' => $icon, Tree::IMAGE_FOLDER_OPEN => $icon,
'im2' => $icon, Tree::IMAGE_FOLDER_CLOSED => $icon,
'item' => array(), Tree::CHILDREN => array(),
'child' => 1, 'child' => 1,
); );
if ($path == '/admin') $parent[$path]['open'] = true; if ($path == '/admin') $parent[$path]['open'] = true;
} }
$parent =& $parent[$path]['item']; $parent =& $parent[$path][Tree::CHILDREN];
} }
$data['text'] = lang($data['text']); $data[Tree::LABEL] = lang($data[Tree::LABEL]);
if (!empty($data['tooltip'])) $data['tooltip'] = lang($data['tooltip']); if (!empty($data['tooltip'])) $data['tooltip'] = lang($data['tooltip']);
// make sure keys are unique, as we overwrite tree entries otherwise // make sure keys are unique, as we overwrite tree entries otherwise
if (isset($parent[$data['id']])) $data['id'] .= md5($data['link']); if (isset($parent[$data[Tree::ID]])) $data[Tree::ID] .= md5($data['link']);
$parent[$data['id']] = self::fix_userdata($data); $parent[$data[Tree::ID]] = self::fix_userdata($data);
} }
} }
} }
@ -502,14 +503,14 @@ class admin_ui
'sort' => 'ASC', 'sort' => 'ASC',
)) as $group) )) as $group)
{ {
$tree['item'][] = self::fix_userdata(array( $tree[Tree::CHILDREN][] = self::fix_userdata(array(
'text' => $group['account_lid'], Tree::LABEL => $group['account_lid'],
'tooltip' => $group['account_description'], Tree::TOOLTIP => $group['account_description'],
'id' => $root.'/'.$group['account_id'], Tree::ID => $root.'/'.$group['account_id'],
)); ));
} }
} }
self::strip_item_keys($tree['item']); self::strip_item_keys($tree[Tree::CHILDREN]);
//_debug_array($tree); exit; //_debug_array($tree); exit;
return $tree; return $tree;
} }
@ -522,9 +523,13 @@ class admin_ui
*/ */
private static function fix_userdata(array $data) private static function fix_userdata(array $data)
{ {
if(!$data[Tree::LABEL])
{
$data[Tree::LABEL] = $data['text'];
}
// store link as userdata, maybe we should store everything not directly understood by tree this way ... // store link as userdata, maybe we should store everything not directly understood by tree this way ...
foreach(array_diff_key($data, array_flip(array( foreach(array_diff_key($data, array_flip(array(
'id','text','tooltip','im0','im1','im2','item','child','select','open','call', Tree::ID,Tree::LABEL,Tree::TOOLTIP,'im0','im1','im2','item','child','select','open','call',
))) as $name => $content) ))) as $name => $content)
{ {
$data['userdata'][] = array( $data['userdata'][] = array(