Esempio n. 1
0
/**
 * Creates nodes that can be used to display the service configuration tree using the CTree class.
 *
 * @see CTree
 *
 * @param array $services
 * @param array $parentService
 * @param array $service
 * @param array $dependency
 * @param array $tree
 */
function createServiceConfigurationTree(array $services, &$tree, array $parentService = array(), array $service = array(), array $dependency = array())
{
    if (!$service) {
        $caption = new CLink(_('root'), '#');
        $caption->setMenuPopup(CMenuPopupHelper::getServiceConfiguration(null, _('root'), false));
        $serviceNode = array('id' => 0, 'parentid' => 0, 'caption' => $caption, 'trigger' => array(), 'algorithm' => SPACE, 'description' => SPACE);
        $service = $serviceNode;
        $service['serviceid'] = 0;
        $service['dependencies'] = array();
        $service['trigger'] = array();
        // add all top level services as children of "root"
        foreach ($services as $topService) {
            if (!$topService['parent']) {
                $service['dependencies'][] = array('servicedownid' => $topService['serviceid'], 'soft' => 0, 'linkid' => 0);
            }
        }
        $tree = array($serviceNode);
    } else {
        // caption
        $caption = new CLink($service['name'], '#');
        // service is deletable only if it has no hard dependency
        $deletable = true;
        foreach ($service['dependencies'] as $dep) {
            if ($dep['soft'] == 0) {
                $deletable = false;
                break;
            }
        }
        $caption->setMenuPopup(CMenuPopupHelper::getServiceConfiguration($service['serviceid'], $service['name'], $deletable));
        $serviceNode = array('id' => $service['serviceid'], 'caption' => $caption, 'description' => $service['trigger'] ? $service['trigger']['description'] : '-', 'parentid' => $parentService ? $parentService['serviceid'] : 0, 'algorithm' => serviceAlgorythm($service['algorithm']));
    }
    if (!$dependency || !$dependency['soft']) {
        $tree[$serviceNode['id']] = $serviceNode;
        foreach ($service['dependencies'] as $dependency) {
            $childService = $services[$dependency['servicedownid']];
            createServiceConfigurationTree($services, $tree, $service, $childService, $dependency);
        }
    } else {
        $serviceNode['caption'] = new CSpan($serviceNode['caption'], 'service-caption-soft');
        $tree[$serviceNode['id'] . '.' . $dependency['linkid']] = $serviceNode;
    }
}