<?php

$func = function()
{
    $array = array
    (
        -1 => array('id' => '-1', 'name' => '自定义',),
    );
    $info = Dever::db('page/func')->state();
    if($info)
    {
        $array += $info;
    }
    return $array;
};

$col = function()
{
    $array = array
    (
        
    );
    $info = Dever::db('page/col')->state();
    if($info)
    {
        $array += $info;
    }
    return $array;
};

$page = function()
{
    $array = array
    (
        
    );
    $info = Dever::db('page/page')->state();
    if($info)
    {
        $array += $info;
    }
    return $array;
};

$content = array
(
    1 => '显示',
    2 => '不显示',
);

return array
(
    # 表名
    'name' => 'module',
    # 显示给用户看的名称
    'lang' => '模块列表',
    'order' => 2,
    'func' => $func,

    'sync' => array
    (
        'page/page_module' => array
        (
            # 更新时的条件,另外一个表的字段 => 本表的字段
            'where' => array('module_id', 'id'),
            # 要更新的数据
            'update' => array('page_id' => 'page_id'),
            # 同步更新的类型,delete为先删再插入,update为先查询是否存在,存在直接更新,不存在则插入, only为仅更新
            'type' => 'delete',
        ),
    ),

    # 数据结构
    'struct' => array
    (
        'id'        => array
        (
            'type'      => 'int-11',
            'name'      => '模块ID',
            'default'   => '',
            'desc'      => '',
            'match'     => 'is_numeric',
            //'search'  => 'order',
            'order'     => 'desc',
            //'list'        => true,
        ),
        
        'name'      => array
        (
            'type'      => 'varchar-60',
            'name'      => '模块标题',
            'default'   => '',
            'desc'      => '请输入模块标题',
            'match'     => 'is_string',
            'update'    => 'text',
            'search'    => 'fulltext',
            'list'      => true,
            'edit'      => true,
        ),

        'key'       => array
        (
            'type'      => 'varchar-60',
            'name'      => '模块标识',
            'default'   => '',
            'desc'      => '模块标识',
            'match'     => 'is_string',
            'update'    => 'text',
            'search'    => 'fulltext',
            'list'      => true,
        ),

        'pic'       => array
        (
            'type'      => 'varchar-150',
            'name'      => '模块图片',
            'default'   => '',
            'desc'      => '模块图片',
            'match'     => 'option',
            'update'    => 'image',
            'key'       => 1,
            'tab'       => 2,
        ),

        'desc'      => array
        (
            'type'      => 'varchar-2000',
            'name'      => '模块描述',
            'default'   => '',
            'desc'      => '模块描述',
            'match'     => 'is_string',
            'update'    => 'editor',
            'key'       => 1,
            'tab'       => 2,
        ),

        'content'        => array
        (
            'type'      => 'tinyint-1',
            'name'      => '是否显示内容',
            'default'   => '1',
            'desc'      => '是否显示内容',
            'match'     => 'is_numeric',
            'update'    => 'radio',
            'option'    => $content,
            'control'   => 'content',
            'tab'       => 1,
        ),

        'num'       => array
        (
            'type'      => 'int-11',
            'name'      => '内容显示条数-为空或小于0则取默认值10,只对前台有效,当有分页时,则为每页显示的条数',
            'default'   => '10',
            'desc'      => '内容显示条数',
            'match'     => 'is_numeric',
            'update'    => 'text',
            //'list'      => true,
            //'edit'      => true,
            'tab'       => 1,
            'show'      => 'content=1',
        ),

        'page_id'       => array
        (
            'type'      => 'varchar-100',
            'name'      => '所属页面',
            'default'   => '',
            'desc'      => '所属页面',
            'match'     => 'is_string',
            'option'    => $page,
            'update'    => 'checkbox',
            'search'    => 'select',
            'list'      => true,
            'list_order' => -1,
        ),

        'func'       => array
        (
            'type'      => 'varchar-300',
            'name'      => '内容功能类型',
            'default'   => '-1',
            'desc'      => '功能类型',
            'match'     => 'is_string',
            'option'    => $func,
            'update'    => 'checkbox',
            'tab'       => 1,
            'show'      => 'content=1',
        ),

        'col'       => array
        (
            'type'      => 'varchar-300',
            'name'      => '内容启用的字段',
            'default'   => '1,2,3',
            'desc'      => '请选择启用的字段',
            'match'     => 'is_string',
            'option'    => $col,
            'update'    => 'checkbox',
            'tab'       => 1,
            'show'      => 'content=1',
        ),

        'col_pic'       => array
        (
            'type'      => 'varchar-500',
            'name'      => '内容图片尺寸提醒-请直接输入提醒的文字即可,如100*100,如果有多个图片字段,请用换行隔开',
            'default'   => '',
            'desc'      => '图片尺寸提醒',
            'match'     => 'option',
            'update'    => 'textarea',
            'tab'       => 1,
            'show'      => 'content=1',
        ),
        
        'reorder'       => array
        (
            'type'      => 'int-11',
            'name'      => '排序-数值越小越靠前',
            'default'   => '1',
            'desc'      => '请输入排序',
            'match'     => 'option',
            'update'    => 'text',
            'search'    => 'order',
            'list'      => true,
            'order'     => 'asc',
            'edit'      => true,
        ),

        'state'     => array
        (
            'type'      => 'tinyint-1',
            'name'      => '状态',
            'default'   => '1',
            'desc'      => '请选择状态',
            'match'     => 'is_numeric',
        ),
        
        'cdate'     => array
        (
            'type'      => 'int-11',
            'name'      => '录入时间',
            'match'     => array('is_numeric', time()),
            'desc'      => '',
            # 只有insert时才生效
            'insert'    => true,
            //'list'      => 'date("Y-m-d H:i:s", {cdate})',
        ),
    ),

    # 权限精细控制 加入到该项目的详细权限中,注意与top的不同
    /*
    'auth' => array
    (
        # 数据来源
        'data' => 'all',
        # 所属项目
        'project' => 'module',
        # 项目名称
        'project_name' => '模块管理',
    ),
    */

    'manage' => array
    (
        'lang' => 'name,desc',
        'tab' => array('基本配置', '内容配置', '展示配置'),
        'delete' => false,
        //'edit' => false,
        //'insert' => $curPage ? true : false,

        # 自定义快捷新增和编辑
        'link' => 'parent=module',
        'button' => array
        (
            '新增' => array('fast'),
            '字段配置' => array('list', 'col&parent=page'),
            '功能配置' => array('list', 'func&parent=page'),
        ),
        'list_button' => array
        (
            //'fast' => array('新增内容', '"data&search_option_module_id={id}&parent=module"', '{content} == 1'),

            'list' => array('内容列表', '"data&search_option_module_id={id}&parent=module"', '{content} == 1'),
        ),
    ),

    # request 请求接口定义
    'request' => array
    (
        # 获取列表页
        'getAll' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'type' => 'yes',
                'page_id' => 'yes',
                'state' => 1,
            ),
            'type' => 'all',
            'order' => array('reorder' => 'asc'),
            'col' => '*',
        ),
    ),
);