<?php
/**
 * 上传表
 * demo: data/upload/upload_name/10000/10/10.thumb_test.jpg
 * 基本操作：根据upload上传、保存到pic表，所有保存到pic表的图片，均可参与后续处理操作　
 */
 
# 定义几个常用的选项
$option = array
(
	1 => '启用',
	2 => '关闭',
);
$cate = function()
{
	return Dever::db('upload/cate')->state();
};
$upload = function()
{
	return Dever::db('upload/upload')->state();
};

return array
(
	# 表名
	'name' => 'file',
	# 显示给用户看的名称
	'lang' => '资源列表',
	'order' => 9,
	'end' => array
	(
		//'insert' => 'upload/manage.add_tag',
		//'update' => 'upload/manage.add_tag',
	),

	/*
	# 同步更新另外一个或多个表的数据
	'sync' => array
	(
		'upload/file_tag' => array
		(
			# 更新另外一个表的字段 => 本表的字段
			'where' => array('file_id', 'id'),
			# 要更新的数据
			'update' => array('tag_id' => 'tag'),
			# 同步更新的类型，delete为先删再插入，update为先查询是否存在，存在直接更新，不存在则插入, only为仅更新
			'type' => 'delete',
		)
	),*/
	# 数据结构
	'struct' => array
	(
		'id' 		=> array
		(
			'type' 		=> 'int-11',
			'name' 		=> 'ID',
			'default' 	=> '',
			'desc' 		=> '',
			'match' 	=> 'is_numeric',
			'search'	=> 'order',
			//'list'		=> true,
		),
		
		'name'		=> array
		(
			'type' 		=> 'varchar-32',
			'name' 		=> '文件名',
			'default' 	=> '',
			'desc' 		=> '请输入文件名',
			'match' 	=> 'is_string',
			'search'	=> 'fulltext',
			//'list'		=> true,
		),

		'source_name'		=> array
		(
			'type' 		=> 'varchar-200',
			'name' 		=> '原文件名',
			'default' 	=> '',
			'desc' 		=> '请输入原文件名',
			'match' 	=> 'is_string',
			'search'	=> 'fulltext',
			'list'		=> true,
		),

		'upload'		=> array
		(
			'type' 		=> 'int-11',
			'name' 		=> '所属资源配置',
			'default' 	=> '1',
			'desc' 		=> '所属资源配置',
			'match' 	=> 'is_numeric',
			'option' 	=> $upload,
			//'update'	=> 'select',
			'search'	=> 'select',
			//'control'	=> 'type',
			//'list'		=> true,
		),

		'cate'		=> array
		(
			'type' 		=> 'int-11',
			'name' 		=> '所属分类',
			'default' 	=> '1',
			'desc' 		=> '分类',
			'match' 	=> 'is_numeric',
			'option' 	=> $cate,
			'update'	=> 'select',
			'search'	=> 'select',
			//'control'	=> 'type',
			'list'		=> true,
			'edit'		=> true,
		),

		/*
		'tag'		=> array
		(
			'type' 		=> 'text-255',
			'name' 		=> '标签',
			'default' 	=> '',
			'desc' 		=> '标签',
			'match' 	=> 'is_numeric',
			'update'	=> 'text',
			'search'	=> 'fulltext',
			'autocomplete' => array('upload/manage.search_tag?json=1', 'id', 'upload/manage.search_tag_by_ids'),
			//'control'	=> 'type',
			//'list'		=> true,
		),
		*/

		'key'		=> array
		(
			'type' 		=> 'varchar-32',
			'name' 		=> 'key',
			'default' 	=> '',
			'desc' 		=> 'key',
			'match' 	=> 'is_string',
			//'search'	=> 'fulltext',
			//'list'		=> true,
		),
		
		'ext'		=> array
		(
			'type' 		=> 'varchar-24',
			'name' 		=> '后缀名',
			'default' 	=> '',
			'desc' 		=> '请输入后缀名',
			'match' 	=> 'is_string',
			'list_name'	=> '文件信息',
			'list'		=> 'Dever::load("upload/manage.file", {id})',
		),
		
		'file'		=> array
		(
			'type' 		=> 'varchar-150',
			'name' 		=> '访问路径',
			'default' 	=> '',
			'desc' 		=> '请输入访问路径',
			'match' 	=> 'is_string',
			//'list'		=> true,
		),

		'yunfile'		=> array
		(
			'type' 		=> 'varchar-150',
			'name' 		=> '云端访问路径',
			'default' 	=> '',
			'desc' 		=> '云端访问路径',
			'match' 	=> 'is_string',
			//'list'		=> true,
		),
		
		'width'		=> array
		(
			'type' 		=> 'int-11',
			'name' 		=> '宽度',
			'default' 	=> '0',
			'desc' 		=> '请输入宽度',
			'match' 	=> 'option',
			//'list'		=> true,
		),
		
		'height'		=> array
		(
			'type' 		=> 'int-11',
			'name' 		=> '高度',
			'default' 	=> '0',
			'desc' 		=> '请输入高度',
			'match' 	=> 'option',
			//'list'		=> true,
		),
		
		'size'		=> array
		(
			'type' 		=> 'int-11',
			'name' 		=> '大小',
			'default' 	=> '0',
			'desc' 		=> '请输入大小',
			'match' 	=> 'option',
			//'list'		=> 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' 		=> '',
			'list'		=> 'date("Y-m-d H:i:s", {cdate})',
		),
	),

	# 更新表结构
	'alter' => array
	(
		2 => array
		(
			array('update', 'upload', 'upload', 'int-11 1 所属资源配置'),
			//array('add', 'config', 'config', 'int-11 1 配置'),
		),
		'version' => 2,
	),

	'manage' => array
	(
		'insert' => false,
		'delete' => false,
	),
	
	# request 请求接口定义
	'request' => array
	(
		# info 根据文件名获取数据
		'file' => array
		(
			'where' => array
			(
				'file' => 'is_string',
			),
			'type' => 'one',
		),
		
		'name' => array
		(
			'where' => array
			(
				'name' => 'yes',
				'upload' => 'yes',
			),
			'type' => 'one',
		),

		'getData' => array
		(
			'option' => array
			(
				'state' => 1,
				'upload' => 'yes',
				'cate' => 'yes',
				'source_name' => array('yes', 'like'),
				//'source_name' => array('yes', 'like', 'and('),
				//'name' => array('yes', 'like', 'or)'),
				
			),
			'order' => array('id' => 'desc'),
			'type' => 'all',
			'page' => array(12, 'list')
		),
	)
);
