/**
 * Clears the menu database and then creates a test tree
 *
 * The test tree is equivalent to the ioMenuItem tree created in
 * create_test_tree() from ioMenuPlugin
 */
function create_doctrine_test_tree(lime_test $t)
{
    $t->info('### Creating test tree.');
    // create the root
    $rt = create_root('Root li', true, array('attributes' => 'class="root"'));
    $pt1 = new ioDoctrineMenuItem();
    $pt1->name = 'Parent 1';
    $pt1->save();
    $pt1->getNode()->insertAsLastChildOf($rt);
    $rt->refresh();
    $pt2 = new ioDoctrineMenuItem();
    $pt2->name = 'Parent 2';
    $pt2->save();
    $pt2->getNode()->insertAsLastChildOf($rt);
    $rt->refresh();
    $ch1 = new ioDoctrineMenuItem();
    $ch1->name = 'Child 1';
    $ch1->save();
    $ch1->getNode()->insertAsLastChildOf($pt1);
    $pt1->refresh();
    $ch2 = new ioDoctrineMenuItem();
    $ch2->name = 'Child 2';
    $ch2->save();
    $ch2->getNode()->insertAsLastChildOf($pt1);
    $pt1->refresh();
    $ch3 = new ioDoctrineMenuItem();
    $ch3->name = 'Child 3';
    $ch3->save();
    $ch3->getNode()->insertAsLastChildOf($pt1);
    $pt1->refresh();
    // refresh because adding children to pt1 moved pt2's lft,rgt values
    $pt2->refresh();
    $ch4 = new ioDoctrineMenuItem();
    $ch4->name = 'Child 4';
    $ch4->save();
    $ch4->getNode()->insertAsLastChildOf($pt2);
    $pt2->refresh();
    $gc1 = new ioDoctrineMenuItem();
    $gc1->name = 'Grandchild 1';
    $gc1->save();
    $gc1->getNode()->insertAsLastChildOf($ch4);
    $ch4->refresh();
    $rt->refresh();
    $pt1->refresh();
    $pt2->refresh();
    $ch1->refresh();
    $ch2->refresh();
    $ch3->refresh();
    $ch4->refresh();
    $gc1->refresh();
    return array('rt' => $rt, 'pt1' => $pt1, 'pt2' => $pt2, 'ch1' => $ch1, 'ch2' => $ch2, 'ch3' => $ch3, 'ch4' => $ch4, 'gc1' => $gc1);
}
$t->info('    2.1.7 - Give rt c1 and c2 credentials then merge in a menu with no credentials.');
$rt = create_root('rt');
$c1 = Doctrine_Core::getTable('sfGuardGroup')->findOneByName('c1');
$rt->link('Permissions', array($c1['id'], $c2['id']));
$rt->save();
$menu->setCredentials(array());
$rt->persistFromMenuArray($menu->toArray(false));
$rt->refresh(true);
$t->is(count($rt->Permissions), 0, '->Permissions matches 0 items - c1 and c2 were removed.');
$t->info('  2.2 - Test persisting with children');
$arr = create_test_tree($t);
$menu = $arr['menu'];
$menu['Parent 1']->setAttributes(array('class' => 'parent1'));
$menu['Parent 1']['Child 2']->setCredentials(array('c2', 'c3'));
print_test_tree($t);
$rt = create_root('rt');
persist_menu($t, $rt, $menu);
$t->info('  Check the integrity of the tree.');
complex_root_menu_check($rt, $t, 2);
test_total_nodes($t, array(0 => 1, 1 => 2, 2 => 4, 3 => 1));
root_sanity_check($t, $rt);
$t->info('  2.3 - Persist the tree again with no changes, should still be intact');
print_test_tree($t);
persist_menu($t, $rt, $menu);
$t->info('  Check the integrity of the tree.');
complex_root_menu_check($rt, $t, 3);
test_total_nodes($t, array(0 => 1, 1 => 2, 2 => 4, 3 => 1));
root_sanity_check($t, $rt);
$t->info('  2.4 - Make some normal property changes to the menu, re-persist');
$menu->setRoute('http://www.sympalphp.org');
$menu['Parent 1']->requiresAuth(true);
示例#3
0
<?php

/**
 * Define constants
 *
 **/
//Define project status (dev, test, live)
define('STATUS', 'dev');
//shorten DIRECTORY_SEPERATOR
define('DS', DIRECTORY_SEPARATOR);
//Define pathing
//create app root
define('ROOT', create_root() . DS);
define('APP', ROOT . 'app' . DS);
define('CONTROLLERS', ROOT . 'app' . DS . 'controllers' . DS);
define('VIEWS', ROOT . 'app' . DS . 'views' . DS);
define('WWW_ROOT', ROOT . 'public' . DS);
define('SITE_URL', $_SERVER["SERVER_NAME"] . DS);
define('TMP', APP . 'tmp' . DS);
define('LIBS', APP . 'libs' . DS);
define('CONFIG', APP . 'config' . DS);
//include config data
require_once CONFIG . 'config.php';
function __autoload($name)
{
    if (is_file(APP . 'classes' . DS . $name . '.php')) {
        require_once APP . 'classes' . DS . $name . '.php';
    }
}
/****
 * Setup routing and continue
示例#4
0
文件: index.php 项目: hunanhd/cbm
function mockups_to_soui_xml($jsonfile, $bMainWnd = true)
{
    if (!is_file($jsonfile)) {
        return '';
    }
    //从文件中读取json字符串
    $json = file_get_contents($jsonfile);
    // var_dump(decode_json($json, true));
    //解析成json数组对象
    $mockup = decode_json($json, true)['mockup'];
    //创建一个XML文档并设置XML版本和编码
    $doc = new DomDocument();
    //$doc->preserveWhiteSpace = false;
    //$doc->formatOutput = true;
    //xml输出的时候要加上编码,否则输出的中文变成一堆奇怪的符号
    $doc->encoding = 'UTF-8';
    //界面的宽度和高度
    $wnd_width = intval($mockup['mockupW']);
    $wnd_height = intval($mockup['mockupH']);
    //图形的宽度和高度(包含多出的空白部分)
    $fig_width = intval($mockup['measuredW']);
    $fig_height = intval($mockup['measuredH']);
    //left和top的偏移量
    $dx = $fig_width - $wnd_width;
    $dy = $fig_height - $wnd_height;
    $root_attribs = null;
    if ($bMainWnd) {
        $root_attribs = array('width' => $wnd_width, 'height' => $wnd_height);
    }
    //创建根节点
    $root = create_root($doc, $root_attribs);
    //所有子控件
    $controls = $mockup['controls']['control'];
    foreach ($controls as $control) {
        //定义属性数组
        $attribs = array();
        //控件的坐标位置
        $left = intval($control['x']) - $dx;
        $top = intval($control['y']) - $dy;
        $attribs['pos'] = $left . "," . $top;
        //控件的宽度和高度属性
        $attribs['width'] = intval($control['measuredW']);
        $attribs['height'] = intval($control['measuredH']);
        if (isset($control['w'])) {
            $attribs['width'] = intval($control['w']);
        }
        if (isset($control['h'])) {
            $attribs['height'] = intval($control['h']);
        }
        //微调(margin-x和margin-y设为1后导致label显示不全,稍微增大宽度和高度用于抵消被margin吃掉的空间)
        $attribs['width'] = $attribs['width'] + 2;
        // $attribs['height'] = $attribs['height'] + 2;
        //控件类型(mockups类型映射到soui控件类型)
        $type = mockups_type_to_soui_type($control['typeID']);
        if ($type == 'unknown') {
            if ($control['typeID'] == 'StickyNote') {
                //从Comment中提取skin(字符串用换行分隔)
                $skin_text = $control['properties']['text'];
                $skins = explode("\\n", $skin_text);
                foreach ($skins as $skin_name) {
                    addToSkin($doc, $skin_name, "img");
                    // addToSkin($doc, $skin_name, "ico");
                }
            } else {
                echo '<h1>暂不支持' . $control['typeID'] . '控件!!!</h1><br>';
            }
            //销毁内存
            unset($attribs);
            //跳过该次循环
            continue;
        } else {
            echo '<h1>' . $control['typeID'] . '-->' . $type . '</h1><br>';
        }
        if (isset($control['properties']['state'])) {
            if ($control['properties']['state'] == 'disabled') {
                // $attribs['enable'] = 0;
            }
        }
        //控件的字体属性
        $font_attrib = '';
        if (isset($control['properties']['underline'])) {
            $font_attrib = $font_attrib . ',underline:' . intval($control['properties']['underline'] == 'true');
        }
        if (isset($control['properties']['italic'])) {
            $font_attrib = $font_attrib . ',italic:' . intval($control['properties']['italic'] == 'true');
        }
        if (isset($control['properties']['bold'])) {
            $font_attrib = $font_attrib . ',bold:' . intval($control['properties']['bold'] == 'true');
        }
        if ($font_attrib != '') {
            $attribs['font'] = $font_attrib;
        }
        //所有控件增加边框,便于观察
        //后期可以用样式class进行替代或删除该属性
        // $attribs['ncSkin'] = '_skin.sys.border';
        if ($type == 'edit' || $type == 'richedit') {
            if (isset($control['properties']['state'])) {
                if ($control['properties']['state'] == 'disabled') {
                    unset($attribs['enable']);
                    // $attribs['readOnly'] = 1;
                }
            }
        }
        if ($type == 'check' || $type == 'radio') {
            $attribs['width'] = $attribs['width'] + 30;
            if (isset($control['properties']['state'])) {
                if ($control['properties']['state'] == 'selected') {
                    $attribs['checked'] = 1;
                }
            }
        }
        //listbox要特殊处理
        if ($type == 'listbox') {
            $attribs['itemHeight'] = '21';
            //高亮显示鼠标所在位置的item
            $attribs['hotTrack'] = 1;
            //$attribs['selectedIndex'] = '1';
            if (isset($control['properties']['rowHeight'])) {
                $attribs['itemHeight'] = $control['properties']['rowHeight'];
            }
        }
        //link要特殊处理
        if ($type == 'link') {
            $attribs['href'] = 'http://about:blank';
            // 默认打开空白页面
            if (isset($control['properties']['href'])) {
                $attribs['href'] = $control['properties']['href']['URL'];
                $attribs['class'] = 'cls_btn_weblink';
                //$attribs['cursor'] = "hand";
            }
        }
        //slider要特殊处理
        if ($type == 'sliderbar') {
            $attribs['value'] = '0';
            $attribs['min'] = '0';
            $attribs['max'] = '100';
            if (isset($control['properties']['value'])) {
                $attribs['value'] = $control['properties']['value'];
            }
            if ($control['typeID'] == 'VSlider') {
                $attribs['vertical'] = 1;
                //调整slider的宽度或高度,否则会出现一个多余的拖动按钮(原因未知!!)
                $attribs['width'] = $attribs['width'] + 8;
            } else {
                if ($control['typeID'] == 'HSlider') {
                    //调整slider的宽度或高度,否则会出现一个多余的拖动按钮(原因未知!!)
                    $attribs['height'] = $attribs['height'] + 8;
                }
            }
        }
        //进度条progress特殊处理
        if ($type == 'progress') {
            $attribs['scrollBarValue'] = '0';
            $attribs['min'] = '0';
            $attribs['max'] = '100';
            if (isset($control['properties']['scrollBarValue'])) {
                $attribs['value'] = $control['properties']['scrollBarValue'];
            }
            $attribs['showPercent'] = 1;
        }
        //设置水平或垂直线的线型
        if ($type == 'hr') {
            $attribs['lineStyle'] = 'solid';
            if (isset($control['properties']['stroke'])) {
                $lineStyle = $control['properties']['stroke'];
                if ($lineStyle == 'dashed') {
                    $lineStyle = 'dash';
                } else {
                    if ($lineStyle == 'dotted') {
                        $lineStyle = 'dot';
                    }
                }
                $attribs['lineStyle'] = $lineStyle;
            }
            //水平线或垂直线
            if ($control['typeID'] == 'HRule') {
                $attribs['mode'] = 'horizontal';
                $attribs['height'] = 1;
                //  强制修改水平线的宽度为1,如若按照原本的height显示效果比较难看!
            } else {
                if ($control['typeID'] == 'VRule') {
                    $attribs['mode'] = 'vertical';
                    $attribs['width'] = 1;
                    //  强制修改垂直线的宽度为1,如若按照原本的width显示效果比较难看!
                }
            }
        }
        //列表控件
        if ($type == 'listctrl') {
            $attribs['hotTrack'] = 1;
            $attribs['itemHeight'] = '20';
            $attribs['headerHeight'] = '30';
            if (isset($control['properties']['rowHeight'])) {
                $attribs['itemHeight'] = $control['properties']['rowHeight'];
                $attribs['headerHeight'] = $control['properties']['rowHeight'];
            }
            $attribs['align'] = 'left';
            if (isset($control['properties']['align'])) {
                $attribs['align'] = $control['properties']['align'];
            }
        }
        //treectrl控件
        if ($type == 'treectrl') {
            $attribs['itemHeight'] = "30";
            $attribs['checkBox'] = "1";
        }
        //combobox控件
        if ($type == 'combobox') {
            //下拉列表(edit不可编辑)
            $attribs['dropDown'] = 1;
            $attribs['curSel'] = 0;
        }
        //tab控件
        if ($type == 'tabctrl') {
            // $attribs['clipClient'] = 1;
            $attribs['tabAlign'] = 'top';
            //$attribs['tabWidth'] = "70";
            //$attribs['tabHeight'] = "38";
            //$attribs['tabInterSize'] = "0";
            //$attribs['tabPos'] = "10";
            //$attribs['dotted'] = "0";
            //$attribs['animateSteps'] = "10";
            if ($control['typeID'] == 'VerticalTabBar') {
                $attribs['tabAlign'] = 'left';
            } else {
                if ($control['typeID'] == 'TabBar') {
                    $attribs['tabAlign'] = 'top';
                }
            }
        }
        //group控件
        if ($type == 'group') {
            $attribs['align'] = 'left';
            // $attribs['clipClient'] = 1;
        }
        //window控件
        if ($type == 'window') {
            // $attribs['align'] = 'left';
            // $attribs['clipClient'] = 1;
        }
        //控件的其它属性
        //mockups提供了一种自定义属性功能(一个customID对应一个customData)
        //这2个字段可以是任意类型的数据
        //本程序规定customData以json格式传入自定义数据,从而补充mockups没有的一些属性和数据
        //比如name, min, max等等
        $zOrder = mockups_type_to_soui_type($control['zOrder']);
        // 图形的绘图顺序编号(也决定了图形的层位/遮挡关系)
        $name = mockups_type_to_soui_type($control['typeID']);
        $attribs['name'] = $name . $control['ID'];
        if (isset($control['properties']['customData'])) {
            $json_datas = trim($control['properties']['customData']);
            //json数据中的引号等符号被用url方式进行编码转义了,比如空格变成了%22,需要进行解码
            $json_datas = urldecode($json_datas);
            //将%u替换成\u
            $json_datas = str_replace('%u', '\\u', $json_datas);
            if (!empty($json_datas)) {
                //合并附加的json属性数据
                $more_attribs = decode_json($json_datas, true);
                if (!is_null($more_attribs)) {
                    foreach ($more_attribs as $key => $value) {
                        if (is_array($value)) {
                            $value = json_encode($value);
                        } else {
                            $value = escapeUnicodeString($value);
                        }
                        $more_attribs[$key] = $value;
                    }
                    //合并2个属性关联数组
                    $attribs = array_merge($attribs, $more_attribs);
                    //销毁内存
                    unset($more_attribs);
                }
            }
        }
        //控件上的文本内容
        $text = '';
        if (isset($control['properties']['text'])) {
            $text = $control['properties']['text'];
        }
        //创建子控件节点
        $control = create_node($doc, $type, $text, $attribs);
        $root->appendChild($control);
        //某些控件需要增加子节点,比如listbox
        postProcess($doc, $control, $type);
        //增加局部皮肤
        postProcessSkin($doc, $control, $type, "img");
        //销毁内存
        unset($attribs);
    }
    //调整节点顺序(主要是caption节点)
    adjust_node_seq($doc);
    return $doc->saveXML();
    //$doc->save($xmlfile);
}