后台代码格式化,内核更新

This commit is contained in:
2016-08-29 16:51:13 +08:00
parent 1710eb742c
commit dff622f0ac
21 changed files with 842 additions and 838 deletions

View File

@@ -10,30 +10,30 @@
namespace app\admin\controller;
use app\common\controller\Admin;
class Content extends Admin{
class Content extends Admin {
public function _initialize(){
public function _initialize() {
parent::_initialize();
$this->getContentMenu();
$this->model_id = $model_id = $this->request->param('model_id');
$row = db('Model')->select();
$row = db('Model')->select();
foreach ($row as $key => $value) {
$list[$value['id']] = $value;
$list[$value['id']] = $value;
}
if (empty($list[$model_id])) {
return $this->error("无此模型!");
}else {
} else {
$this->modelInfo = $list[$model_id];
if ($this->modelInfo['extend'] > 1) {
$this->model = model($this->modelInfo['name']);
}else{
} else {
$this->model = model('Document')->extend($this->modelInfo['name']);
}
}
$this->assign('model_id',$model_id);
$this->assign('model_list',$list);
$this->assign('model_id', $model_id);
$this->assign('model_list', $list);
}
/**
@@ -41,32 +41,32 @@ class Content extends Admin{
* @return [html] [页面内容]
* @author molong <ycgpp@126.com>
*/
public function index(){
public function index() {
if ($this->modelInfo['list_grid'] == '') {
return $this->error("列表定义不正确!", url('admin/model/edit',array('id'=>$this->modelInfo['id'])));
return $this->error("列表定义不正确!", url('admin/model/edit', array('id' => $this->modelInfo['id'])));
}
$grid_list = get_grid_list($this->modelInfo['list_grid']);
$order = "id desc";
$map = $this->buildMap();
$field = array_filter($grid_list['fields']);
$order = "id desc";
$map = $this->buildMap();
$field = array_filter($grid_list['fields']);
if ($this->modelInfo['extend'] == 1) {
array_push($field, 'is_top');
}else{
} else {
unset($map['model_id']);
}
$list = $this->model->where($map)->order($order)->paginate(15, false, array(
'query' => $this->param
));
'query' => $this->param,
));
$data = array(
'grid' => $grid_list,
'list' => $list,
'page' => $list->render()
'grid' => $grid_list,
'list' => $list,
'page' => $list->render(),
);
if($this->modelInfo['template_list']){
if ($this->modelInfo['template_list']) {
$template = 'content/' . $this->modelInfo['template_list'];
}else{
} else {
$template = 'content/index';
}
$this->assign($data);
@@ -78,29 +78,29 @@ class Content extends Admin{
* 内容添加
* @author molong <ycgpp@126.com>
*/
public function add(){
public function add() {
if (IS_POST) {
$result = $this->model->change();
if ($result) {
return $this->success("添加成功!", url('admin/content/index',array('model_id'=>$this->modelInfo['id'])));
}else{
return $this->error($this->model->getError(), url('admin/content/add',array('model_id'=>$this->modelInfo['id'])));
return $this->success("添加成功!", url('admin/content/index', array('model_id' => $this->modelInfo['id'])));
} else {
return $this->error($this->model->getError(), url('admin/content/add', array('model_id' => $this->modelInfo['id'])));
}
}else{
} else {
$info = array(
'model_id' => $this->modelInfo['id']
'model_id' => $this->modelInfo['id'],
);
$data = array(
'info' => $info,
'fieldGroup' => $this->getField($this->modelInfo)
'info' => $info,
'fieldGroup' => $this->getField($this->modelInfo),
);
if($this->modelInfo['template_add']){
if ($this->modelInfo['template_add']) {
$template = 'content/' . $this->modelInfo['template_add'];
}else{
} else {
$template = 'public/edit';
}
$this->assign($data);
$this->setMeta("添加".$this->modelInfo['title']);
$this->setMeta("添加" . $this->modelInfo['title']);
return $this->fetch($template);
}
}
@@ -109,15 +109,15 @@ class Content extends Admin{
* 内容修改
* @author molong <ycgpp@126.com>
*/
public function edit($id){
public function edit($id) {
if (IS_POST) {
$result = $this->model->change();
if ($result !== false) {
return $this->success("更新成功!",url('admin/content/index',array('model_id'=>$this->modelInfo['id'])));
}else{
return $this->error($this->model->getError(), url('admin/content/edit',array('model_id'=>$this->modelInfo['id'],'id'=>$id)));
return $this->success("更新成功!", url('admin/content/index', array('model_id' => $this->modelInfo['id'])));
} else {
return $this->error($this->model->getError(), url('admin/content/edit', array('model_id' => $this->modelInfo['id'], 'id' => $id)));
}
}else{
} else {
if (!$id) {
return $this->error("非法操作!");
}
@@ -126,17 +126,17 @@ class Content extends Admin{
return $this->error($this->model->getError());
}
$info['model_id'] = $this->modelInfo['id'];
$data = array(
'info' => $info,
'fieldGroup' => $this->getField($this->modelInfo)
$data = array(
'info' => $info,
'fieldGroup' => $this->getField($this->modelInfo),
);
if($this->modelInfo['template_edit']){
if ($this->modelInfo['template_edit']) {
$template = 'content/' . $this->modelInfo['template_edit'];
}else{
} else {
$template = 'public/edit';
}
$this->assign($data);
$this->setMeta("编辑".$this->modelInfo['title']);
$this->setMeta("编辑" . $this->modelInfo['title']);
return $this->fetch($template);
}
}
@@ -145,18 +145,18 @@ class Content extends Admin{
* 内容删除
* @author molong <ycgpp@126.com>
*/
public function del(){
public function del() {
$id = $this->getArrayParam('id');
if (empty($id)) {
return $this->error("非法操作!");
}
$map['id'] = array('IN',$id);
$result = $this->model->del($map);
$map['id'] = array('IN', $id);
$result = $this->model->del($map);
if ($result) {
return $this->success("删除成功!");
}else{
} else {
return $this->error("删除失败!");
}
}
@@ -165,14 +165,14 @@ class Content extends Admin{
* 设置状态
* @author molong <ycgpp@126.com>
*/
public function status($id, $status){
public function status($id, $status) {
$model = $this->model;
$map['id'] = $id;
$result = $model::where($map)->setField('status',$status);
$result = $model::where($map)->setField('status', $status);
if (false !== $result) {
return $this->success("操作成功!");
}else{
} else {
return $this->error("操作失败!!");
}
}
@@ -181,14 +181,14 @@ class Content extends Admin{
* 设置置顶
* @author molong <ycgpp@126.com>
*/
public function settop($id, $is_top){
public function settop($id, $is_top) {
$model = $this->model;
$map['id'] = $id;
$result = $model::where($map)->setField('is_top',$is_top);
$result = $model::where($map)->setField('is_top', $is_top);
if (false !== $result) {
return $this->success("操作成功!");
}else{
} else {
return $this->error("操作失败!!");
}
}
@@ -198,26 +198,26 @@ class Content extends Admin{
* @return array 字段数组
* @author molong <ycgpp@126.com>
*/
protected function getField(){
protected function getField() {
$field_group = parse_config_attr($this->modelInfo['field_group']);
$field_sort = json_decode($this->modelInfo['field_sort'],true);
$field_sort = json_decode($this->modelInfo['field_sort'], true);
if ($this->modelInfo['extend'] > 1) {
$map['model_id'] = $this->modelInfo['id'];
}else{
$model_id[] = $this->modelInfo['id'];
$model_id[] = 1;
$map['model_id'] = array('IN',$model_id);
} else {
$model_id[] = $this->modelInfo['id'];
$model_id[] = 1;
$map['model_id'] = array('IN', $model_id);
}
if ($this->request->action() == 'add') {
$map['is_show'] = array('in',array('1','2'));
}elseif($this->request->action() == 'edit'){
$map['is_show'] = array('in',array('1','3'));
$map['is_show'] = array('in', array('1', '2'));
} elseif ($this->request->action() == 'edit') {
$map['is_show'] = array('in', array('1', '3'));
}
//获得数组的第一条数组
$first_key = array_keys($field_group);
$fields = model('Attribute')->getFieldlist($map);
$fields = model('Attribute')->getFieldlist($map);
if (!empty($field_sort)) {
foreach ($field_sort as $key => $value) {
foreach ($value as $index) {
@@ -229,8 +229,8 @@ class Content extends Admin{
}
}
//未进行排序的放入第一组中
$fields[] = array('name'=>'model_id','type'=>'hidden'); //加入模型ID值
$fields[] = array('name'=>'id','type'=>'hidden'); //加入模型ID值
$fields[] = array('name' => 'model_id', 'type' => 'hidden'); //加入模型ID值
$fields[] = array('name' => 'id', 'type' => 'hidden'); //加入模型ID值
foreach ($fields as $key => $value) {
$groupfield[$first_key[0]][] = $value;
}
@@ -247,18 +247,18 @@ class Content extends Admin{
* 创建搜索
* @return [array] [查询条件]
*/
protected function buildMap(){
$map = array();
protected function buildMap() {
$map = array();
$data = $this->request->get();
foreach ($data as $key => $value) {
if ($value) {
if ($key == 'keyword') {
$map['title'] = array("LIKE", "%$value%");
}elseif($key == 'category'){
} elseif ($key == 'category') {
$map['category_id'] = $value;
}elseif($key == 'create_time'){
$map['create_time'] = array('BETWEEN',array(strtotime($value[0]),strtotime($value[1])));
}else{
} elseif ($key == 'create_time') {
$map['create_time'] = array('BETWEEN', array(strtotime($value[0]), strtotime($value[1])));
} else {
$map[$key] = $value;
}
}
@@ -267,7 +267,7 @@ class Content extends Admin{
unset($map['page']);
}
if ($this->modelInfo['extend'] == 1) {
$category = isset($data['category']) ? $data['category'] : '';
$category = isset($data['category']) ? $data['category'] : '';
$cate_list = parse_field_bind('category', $category, 0);
$this->assign('cate_list', $cate_list);
}
@@ -285,20 +285,20 @@ class Content extends Admin{
*
* @author 朱亚杰 <xcoolcc@gmail.com>
*/
protected function checkDynamic(){
protected function checkDynamic() {
$model_id = $this->request->param('model_id');
if(IS_ROOT){
return true;//管理员允许访问任何页面
if (IS_ROOT) {
return true; //管理员允许访问任何页面
}
$models = model('AuthGroup')->getAuthModels(session('user_auth.uid'));
if (!$model_id) {
return false;
}elseif (in_array($model_id, $models)) {
} elseif (in_array($model_id, $models)) {
//返回null继续判断操作权限
return null;
}else{
return false;//无权限
}
} else {
return false; //无权限
}
return false;
}
}