Skip to content

Commit

Permalink
模型字段
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyao-work committed Jan 18, 2016
1 parent 75f5762 commit 64fa283
Show file tree
Hide file tree
Showing 155 changed files with 555 additions and 595 deletions.
12 changes: 0 additions & 12 deletions App/Admin/Common/fields/author/config.inc.php

This file was deleted.

1 change: 0 additions & 1 deletion App/Admin/Common/fields/catid/field_edit_form.inc.php

This file was deleted.

12 changes: 0 additions & 12 deletions App/Admin/Common/fields/keyword/config.inc.php

This file was deleted.

1 change: 0 additions & 1 deletion App/Admin/Common/fields/keyword/field_edit_form.inc.php

This file was deleted.

1 change: 0 additions & 1 deletion App/Admin/Common/fields/pages/field_edit_form.inc.php

This file was deleted.

1 change: 0 additions & 1 deletion App/Admin/Common/fields/readpoint/field_edit_form.inc.php

This file was deleted.

1 change: 0 additions & 1 deletion App/Admin/Common/fields/template/field_edit_form.inc.php

This file was deleted.

1 change: 0 additions & 1 deletion App/Admin/Common/fields/title/field_edit_form.inc.php

This file was deleted.

3 changes: 1 addition & 2 deletions App/Admin/Controller/ModelController.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ function __construct() {

public function index() {
$models = $this->db->where("siteid = %d", $this->siteid)->select();
// $types = $this->type_db->where("siteid = %d", $this->siteid)->select();
$this->assign("types",$this->modelTypes);
$this->assign("models",$models);
$this->display();
Expand All @@ -39,7 +38,7 @@ public function add() {

$this->db->startTrans();
if ($modelid = $this->db->add($data)) {
if (logic('Model')->execModelCreateSql($data['tablename'], $modelid)) {
if (logic('Model')->execModelCreateSql($data['tablename'], $modelid, $data['siteid'])) {
$this->db->commit();
$this->success('添加成功!');
} else {
Expand Down
93 changes: 58 additions & 35 deletions App/Admin/Controller/ModelFieldController.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,22 @@ class ModelFieldController extends CommonController {
protected $db, $model_db;
function __construct() {
parent::__construct();
$this->db = D('ModelField');
$this->model_db = D('Model');
$this->db = model('ModelField');
$this->model_db = model('Model');
}

public function index() {
$fields = $this->db->where(array('siteid' => $this->siteid, 'modelid' => $_GET['modelid']))->order("listorder asc , fieldid asc")->select();
$model = $this->model_db->find($_GET['modelid']);
$modelid = I('get.modelid');
if (empty($modelid)) {
$this->error('参数异常');
}
$fields = $this->db->where(array('siteid' => $this->siteid, 'modelid' => $modelid))->order("listorder asc , fieldid asc")->select();
$model = $this->model_db->find($modelid);
$this->assign('model', $model);
$this->assign('fields', $fields);

require MODEL_PATH.'fields.inc.php';

$this->assign('forbid_fields',$forbid_fields);
$this->assign('forbid_delete',$forbid_delete);
$this->display();
Expand All @@ -35,42 +41,48 @@ public function index() {
public function add() {
if (IS_POST) {
$this->checkToken();

$modelid = $_POST['info']['modelid'] = intval($_POST['info']['modelid']);
$model = $this->model_db->find($modelid);
$model_table = $model['tablename'];
$tablename = ($model['typeid'] == 2 || $_POST['issystem']) ? C('DB_PREFIX').$model_table : C('DB_PREFIX').$model_table.'_data';
$tablename = C('DB_PREFIX') . $model['tablename'];

$field = $_POST['info']['field'];
$minlength = $_POST['info']['minlength'] ? $_POST['info']['minlength'] : 0;
$maxlength = $_POST['info']['maxlength'] ? $_POST['info']['maxlength'] : 0;
$field_type = $_POST['info']['formtype'];

require MODEL_PATH.$field_type.DIRECTORY_SEPARATOR.'config.inc.php';
if(isset($_POST['setting']['fieldtype'])) {
$field_type = $_POST['setting']['fieldtype'];
}
require MODEL_PATH.'add.sql.php';

//附加属性值
$_POST['info']['setting'] = array2string($_POST['setting']);
$_POST['info']['siteid'] = $this->siteid;
$_POST['info']['unsetgroupids'] = isset($_POST['unsetgroupids']) ? implode(',',$_POST['unsetgroupids']) : '';
$_POST['info']['unsetroleids'] = isset($_POST['unsetroleids']) ? implode(',',$_POST['unsetroleids']) : '';

if ($this->db->add($_POST['info'])) {
$this->success('添加成功');
} else {
$this->success('添加失败');
}

} else {
import("ORG.Util.Form");
require MODEL_PATH.'fields.inc.php';
$modelid = $_GET['modelid'];
$f_datas = $this->db->where(array('modelid'=>$modelid))->order('listorder ASC')->field('field,name')->limit(100)->select();
$modelid = I('get.modelid');

$f_datas = $this->db->where(array('modelid'=>$modelid))
->order('listorder ASC')
->field('field, name')
->select();

$model = $this->model_db->find($modelid);
foreach($f_datas as $_k=>$_v) {
$exists_field[] = $_v['field'];
}

$all_field = array();
foreach($fields as $_k=>$_v) {
if(in_array($_k,$not_allow_fields) || in_array($_k,$exists_field) && in_array($_k,$unique_fields)) continue;
if(in_array($_k, $not_allow_fields) || (in_array($_k, $exists_field) && in_array($_k, $unique_fields))) continue;
$all_field[$_k] = $_v;
}

Expand All @@ -87,8 +99,7 @@ public function edit() {
$this->checkToken();
$modelid = $_POST['info']['modelid'] = intval($_POST['info']['modelid']);
$model = $this->model_db->find($modelid);
$model_table = $model['tablename'];
$tablename = ($model['typeid'] == 2 || $_POST['issystem']) ? C('DB_PREFIX').$model_table : C('DB_PREFIX').$model_table.'_data';
$tablename = C('DB_PREFIX') . $model['tablename'];
$field = $_POST['info']['field'];
$minlength = $_POST['info']['minlength'] ? $_POST['info']['minlength'] : 0;
$maxlength = $_POST['info']['maxlength'] ? $_POST['info']['maxlength'] : 0;
Expand All @@ -103,15 +114,15 @@ public function edit() {
$_POST['info']['setting'] = array2string($_POST['setting']);
$fieldid = intval($_POST['fieldid']);

$_POST['info']['unsetgroupids'] = isset($_POST['unsetgroupids']) ? implode(',',$_POST['unsetgroupids']) : '';
$_POST['info']['unsetroleids'] = isset($_POST['unsetroleids']) ? implode(',',$_POST['unsetroleids']) : '';
/*$_POST['info']['unsetgroupids'] = isset($_POST['unsetgroupids']) ? implode(',',$_POST['unsetgroupids']) : '';
$_POST['info']['unsetroleids'] = isset($_POST['unsetroleids']) ? implode(',',$_POST['unsetroleids']) : '';*/

if ($this->db->where(array('fieldid'=>$fieldid,'siteid'=>$this->siteid))->save($_POST['info']) !== false) {
$this->success('更新成功');
} else {
$this->error('操作失败');
}
} else {
import("ORG.Util.Form");
require MODEL_PATH.'fields.inc.php';
$modelid = intval($_GET['modelid']);
$fieldid = intval($_GET['fieldid']);
Expand All @@ -129,13 +140,15 @@ public function edit() {
$this->assign('model',$model);
$this->assign('model_field',$model_field);
$this->assign('form_data',$form_data);

// field.inc
$this->assign('fields', $fields);
$this->assign('not_allow_fields', $not_allow_fields);
$this->assign('unique_fields', $unique_fields);
$this->assign('forbid_fields', $forbid_fields);
$this->assign('forbid_delete', $forbid_delete);
$this->assign('att_css_js', $att_css_js);

// config.inc
$this->assign('field_type',$field_type);
$this->assign('field_basic_table',$field_basic_table);
Expand All @@ -162,18 +175,21 @@ public function delete() {
}

/**
* 禁用字段
*/
* 禁用字段
*/
public function disabled() {
$fieldid = intval($_GET['fieldid']);
$fieldid = I('get.fieldid');
$disabled = $_GET['disabled'] ? 0 : 1;
$this->db->where(array('fieldid'=>$fieldid,'siteid'=>$this->siteid))->save(array('disabled'=>$disabled));
$this->success(L('operation_success'));
if ($this->db->where(array('fieldid'=>$fieldid,'siteid'=>$this->siteid))->save(array('disabled'=>$disabled)) !== false) {
$this->success('操作成功!');
} else {
$this->error('操作失败!');
}
}

/**
* 排序
*/
* 排序
*/
public function listorder() {
if(isset($_POST['dosubmit'])) {
foreach($_POST['listorders'] as $id => $listorder) {
Expand All @@ -186,8 +202,8 @@ public function listorder() {
}

/**
* 检查字段是否存在
*/
* 检查字段是否存在
*/
public function public_checkfield() {
$field = strtolower($_GET['field']);
$oldfield = strtolower($_GET['oldfield']);
Expand All @@ -206,24 +222,31 @@ public function public_checkfield() {
}

/**
* 字段属性设置
*/
* 字段属性设置
*/
public function public_field_setting() {
$fieldtype = $_GET['fieldtype'];
require MODEL_PATH.$fieldtype.DIRECTORY_SEPARATOR.'config.inc.php';
ob_start();
include MODEL_PATH.$fieldtype.DIRECTORY_SEPARATOR.'field_add_form.inc.php';
$data_setting = ob_get_contents();
//$data_setting = iconv('gbk','utf-8',$data_setting);
ob_end_clean();
$settings = array('field_basic_table'=>$field_basic_table,'field_minlength'=>$field_minlength,'field_maxlength'=>$field_maxlength,'field_allow_search'=>$field_allow_search,'field_allow_fulltext'=>$field_allow_fulltext,'field_allow_isunique'=>$field_allow_isunique,'setting'=>$data_setting);
echo json_encode($settings);
return true;

$settings = array(
'field_basic_table'=>$field_basic_table,
'field_minlength'=>$field_minlength,
'field_maxlength'=>$field_maxlength,
'field_allow_search'=>$field_allow_search,
'field_allow_fulltext'=>$field_allow_fulltext,
'field_allow_isunique'=>$field_allow_isunique,
'setting'=>$data_setting);

$this->ajaxReturn($settings);
}

/**
* 预览模型
*/
* 预览模型
*/
public function public_priview() {
import('ORG.Util.Form');
$modelid = intval($_GET['modelid']);
Expand Down
2 changes: 1 addition & 1 deletion App/Admin/View/Attachment/album_for_ckeditor.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php defined('THINK_PATH') or exit('No permission resources.'); ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
Expand Down
2 changes: 1 addition & 1 deletion App/Admin/View/Attachment/album_list.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php defined('THINK_PATH') or exit('No permission resources.'); ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
Expand Down
2 changes: 1 addition & 1 deletion App/Admin/View/File/upload.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php defined('THINK_PATH') or exit('No permission resources.'); ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
Expand Down
2 changes: 1 addition & 1 deletion App/Admin/View/Layout/list.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php defined('THINK_PATH') or exit('No permission resources.'); ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
Expand Down
Loading

0 comments on commit 64fa283

Please sign in to comment.