<?php
/*
|--------------------------------------------------------------------------
| opt.php 记录字段的表
|--------------------------------------------------------------------------
*/
# 定义几个常用的选项
$option = array
(
	1 => '显示',
	2 => '不显示',
);

$status = array
(
	1 => '未做任何操作',
	2 => '已建立索引',
);

$info = Dever\Loader\Project::read();

$path = $info['manage']['path'];

if(isset($info['manage']['setup']))
{
	$path = $info['manage']['setup'];
}

# 获取project
$project = function() use ($info)
{
	$data = array();
	foreach($info as $k => $v)
	{
		$k = $v['name'];
		$data[$k]['id'] = $v['name'];
		$data[$k]['name'] = $v['lang'];
	}

	return $data;
};

return array
(
	# 表名
	'name' => 'opt',
	# 显示给用户看的名称
	'lang' => '字段记录表',
	'desc' => Dever::markdown('**本表记录所有数据表文件里的request方法：**
	1. 启用本表的记录功能，不会影响所有业务逻辑的执行效率，但会消耗服务器资源。建议仅在测试环境下开启或短时间内开启。请在config/base项中添加opt来确定是否启用。 
	2. 在这里可以根据相应的记录，手动添加索引。'),
	# 表类型 值为\innodb\myisam\，默认为innodb，仅在mysql类型有效
	'type' => 'innodb',
	# 数据结构
	'struct' => array
	(
		'id' 		=> array
		(
			'type' 		=> 'int-11',
			'name' 		=> 'ID',
			'default' 	=> '',
			'desc' 		=> '',
			'match' 	=> 'is_numeric',
			'search'	=> 'order',
			//'list'		=> true,
		),
		
		'project'		=> array
		(
			'type' 		=> 'varchar-30',
			'name' 		=> '项目',
			'default' 	=> '',
			'desc' 		=> '请选择项目',
			'match' 	=> 'is_string',
			'update'	=> 'select',
			'search'	=> 'select',
			'option'	=> $project,
			'list'		=> true,
		),
		
		'table'		=> array
		(
			'type' 		=> 'varchar-30',
			'name' 		=> '数据表-请输入表的英文名',
			'default' 	=> '',
			'desc' 		=> '请选择数据表',
			'match' 	=> 'is_string',
			'update'	=> 'text',
			'search'	=> 'fulltext',
			'list'		=> 'Dever::load("manage/opt.get#table", {id})',
		),
		
		'method'		=> array
		(
			'type' 		=> 'varchar-32',
			'name' 		=> '所属方法名',
			'default' 	=> '',
			'desc' 		=> '请输入所属方法名',
			'match' 	=> 'option',
			//'update'	=> 'text',
			//'search'	=> 'fulltext',
			//'list'		=> true,
		),

		'col'			=> array
		(
			'type' 		=> 'varchar-500',
			'name' 		=> '使用的字段',
			'default' 	=> '',
			'desc' 		=> '请选择字段',
			'match' 	=> 'is_string',
			'update'	=> 'text',
			'search'	=> 'fulltext',
			'list'		=> 'Dever::load("manage/opt.get#text", {id})',
			'list_name'	=> '分析优化',
		),
		
		'col_index'			=> array
		(
			'type' 		=> 'varchar-500',
			'name' 		=> '建立索引的字段',
			'default' 	=> '',
			'desc' 		=> '请选择建立索引的字段',
			'match' 	=> 'is_string',
			'update'	=> 'text',
		),
		
		'version'			=> array
		(
			'type' 		=> 'int-11',
			'name' 		=> '版本号',
			'default' 	=> '0',
			'desc' 		=> '版本号',
			'match' 	=> 'is_numeric',
			'update'	=> 'text',
		),

		'num'		=> array
		(
			'type' 		=> 'int-11',
			'name' 		=> '执行次数',
			'default' 	=> '0',
			'match' 	=> 'is_numeric',
			'desc' 		=> '执行次数',
			'update'	=> 'text',
			'search'	=> 'order',
			'list'		=> true,
		),

		'time'		=> array
		(
			'type' 		=> 'varchar-30',
			'name' 		=> '执行时间',
			'default' 	=> '0',
			'match' 	=> 'is_string',
			'desc' 		=> '执行时间',
			'update'	=> 'text',
			'search'	=> 'order',
			'list'		=> true,
		),
		
		'status'		=> array
		(
			'type' 		=> 'tinyint-1',
			'name' 		=> '是否建立索引',
			'default' 	=> '1',
			'desc' 		=> '请选择是否建立索引',
			'match' 	=> 'is_numeric',
			'option' 	=> $status,
			'update'	=> 'radio',
			//'list'		=> true,
		),

		'state'		=> array
		(
			'type' 		=> 'tinyint-1',
			'name' 		=> '数据是否存在',
			'default' 	=> '1',
			'desc' 		=> '请选择数据是否存在',
			'match' 	=> 'is_numeric',
			'option' 	=> $option,
			'update'	=> 'radio',
			//'list'		=> true,
		),
		
		'cdate'		=> array
		(
			'type' 		=> 'int-11',
			'name' 		=> '录入时间',
			'match' 	=> array('is_numeric', time()),
			'desc' 		=> '',
			# 只有insert时才生效
			'insert'	=> true,
			//'list'		=> 'date("Y-m-d H:i:s", {cdate})',
		),
	),
	
	'manage' => array
	(
		'edit' => false,
		'insert' => false,
		'delete' => false,

		'button' => array
		(
			'生成数据结构文档' => Dever::url('doc/view?type=db', 'manage'),
			'Mysql规范和建议' => Dever::url('doc/view?type=mysql', 'manage'),
			//'全部清空' => 'manage/menu.delete',
		)
	),
	
	# request 请求接口定义
	'request' => array
	(
		'updateNum' => array
		(
			'type' => 'update',
			'where' => array
			(
				'id' => 'yes',
			),
			'set' => array
			(
				'col' => 'yes',
				'time' => 'yes',
				'num' => array('1', '+='),
			),
		),
	),
);
