83 lines
2.5 KiB
PHP
83 lines
2.5 KiB
PHP
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
|
// +----------------------------------------------------------------------
|
|
namespace app\model;
|
|
|
|
use think\facade\Config;
|
|
|
|
/**
|
|
* 设置模型
|
|
*/
|
|
class Attribute extends \think\Model {
|
|
|
|
protected $type = array(
|
|
'id' => 'integer',
|
|
);
|
|
|
|
protected static function onAfterInsert($model){
|
|
// if ($data['model_id']) {
|
|
// $name = db('Model')->where('id', $data['model_id'])->value('name');
|
|
// $db = new \com\Datatable();
|
|
// $attr = $data->toArray();
|
|
// $model_attr = array(
|
|
// 'model_id' => $data['model_id'],
|
|
// 'attr_id' => $data->id,
|
|
// 'group_id' => 0,
|
|
// 'is_add_table' => 1,
|
|
// 'is_show' => $data['is_show'],
|
|
// 'is_must' => $data['is_must'],
|
|
// 'sort' => 0,
|
|
// );
|
|
// $attr['after'] = db('Attribute')->where('name', '<>', $data['name'])->where('model_id', $data['model_id'])->order('id desc')->value('name');
|
|
// return $db->columField(strtolower($name), $attr)->query();
|
|
// }
|
|
}
|
|
|
|
protected static function onAfterUpdate($model){
|
|
// $attr = $data->toArray();
|
|
// $attr['action'] = 'CHANGE';
|
|
// $attr['oldname'] = db('Attribute')->where('id', $attr['id'])->value('name');
|
|
// if ($attr['id']) {
|
|
// $name = db('Model')->where('id', $attr['model_id'])->value('name');
|
|
// $db = new \com\Datatable();
|
|
// return $db->columField(strtolower($name), $attr)->query();
|
|
// } else {
|
|
// return false;
|
|
// }
|
|
}
|
|
|
|
protected static function onAfterDelete($model){
|
|
$tablename = strtolower($tablename);
|
|
//删除模型表中字段
|
|
$db = new \com\Datatable();
|
|
if (!$db->CheckField($tablename, $info['name'])) {
|
|
return true;
|
|
}
|
|
$result = $db->delField($tablename, $info['name'])->query();
|
|
}
|
|
|
|
protected function getTypeTextAttr($value, $data) {
|
|
$config_type_list = Config::get('config.config_type_list');
|
|
$type = [];
|
|
foreach ($config_type_list as $key => $value) {
|
|
$type[$value['key']] = $value['label'];
|
|
}
|
|
return isset($type[$data['type']]) ? $type[$data['type']] : '';
|
|
}
|
|
|
|
protected function getOptionAttr($value, $data){
|
|
if ($data == '') {
|
|
return [];
|
|
}
|
|
if (in_array($data['type'], ['checkbox', 'radio', 'select', 'bool'])) {
|
|
# code...
|
|
}elseif($data['type'] == 'bind'){
|
|
|
|
}
|
|
}
|
|
} |