<?php |
class NodeAction extends CommonAction { |
public function _filter(& $map ) { |
if (! empty ( $_GET [ 'group_id' ])) { |
$map [ 'group_id' ] = $_GET [ 'group_id' ]; |
$this ->assign( 'nodeName' , '分组' ); |
} elseif ( empty ( $_POST [ 'search' ]) && !isset( $map [ 'pid' ])) { |
$map [ 'pid' ] = 0; |
} |
if ( $_REQUEST [ 'pid' ] != '' ) { |
$map [ 'pid' ] = $_REQUEST [ 'pid' ]; |
} |
$_SESSION [ 'currentNodeId' ] = $map [ 'pid' ]; |
//获取上级节点 |
$node = M( "Node" ); |
if (isset( $map [ 'pid' ])) { |
if ( $node ->getById( $map [ 'pid' ])) { |
$this ->assign( 'level' , $node ->level + 1); |
$this ->assign( 'nodeName' , $node ->name); |
$this ->assign( 'rebackid' , $node ->pid); |
$this ->assign( 'currentid' , $_REQUEST [ 'pid' ]); |
} else { |
$this ->assign( 'level' , 1); |
$this ->assign( 'rebackid' , 0); |
} |
} |
} |
public function _before_index() { |
$model = M( "Group" ); |
$list = $model ->where( 'status=1' )->getField( 'id,title' ); |
$this ->assign( 'groupList' , $list ); |
} |
// 获取配置类型 |
public function _before_add() { |
$model = M( "Group" ); |
$list = $model ->where( 'status=1' )->select(); |
$this ->assign( 'list' , $list ); |
$node = M( "Node" ); |
$node ->getById( $_SESSION [ 'currentNodeId' ]); |
$this ->assign( 'pid' , $node ->id); |
$this ->assign( 'level' , $node ->level + 1); |
} |
public function _before_patch() { |
$model = M( "Group" ); |
$list = $model ->where( 'status=1' )->select(); |
$this ->assign( 'list' , $list ); |
$node = M( "Node" ); |
$node ->getById( $_SESSION [ 'currentNodeId' ]); |
$this ->assign( 'pid' , $node ->id); |
$this ->assign( 'level' , $node ->level + 1); |
} |
public function _before_edit() { |
$model = M( "Group" ); |
$list = $model ->where( 'status=1' )->select(); |
$this ->assign( 'list' , $list ); |
} |
/** |
+---------------------------------------------------------- |
* 默认排序操作 |
+---------------------------------------------------------- |
* @access public |
+---------------------------------------------------------- |
* @return void |
+---------------------------------------------------------- |
*/ |
public function sort() { |
$node = M( 'Node' ); |
if (! empty ( $_GET [ 'sortId' ])) { |
$map = array (); |
$map [ 'status' ] = 1; |
$map [ 'id' ] = array ( 'in' , $_GET [ 'sortId' ]); |
$sortList = $node ->where( $map )->order( 'sort asc' )->select(); |
} else { |
if (! empty ( $_GET [ 'pid' ])) { |
$pid = $_GET [ 'pid' ]; |
} else { |
$pid = $_SESSION [ 'currentNodeId' ]; |
} |
if ( $node ->getById( $pid )) { |
$level = $node ->level + 1; |
} else { |
$level = 1; |
} |
$this ->assign( 'level' , $level ); |
$sortList = $node ->where( 'status=1 and pid=' . $pid . ' and level=' . $level )->order( 'sort asc' )->select(); |
} |
$this ->assign( "sortList" , $sortList ); |
$this ->display(); |
return ; |
} |
public function index() { |
//列表过滤器,生成查询Map对象 |
$map = $this ->_search(); |
if (method_exists( $this , '_filter' )) { |
$this ->_filter( $map ); |
} |
$name = $this ->getActionName(); |
$model = D( $name ); |
if (! empty ( $model )) { |
$this ->_list( $model , $map ); |
} |
$this ->display(); |
return ; |
} |
function insert() { |
//B('FilterString'); |
$name = $this ->getActionName(); |
$model = D( $name ); |
if (false === $model ->create()) { |
$this ->error( $model ->getError()); |
} |
//保存当前数据对象 |
$list = $model ->add(); |
if ( $list !== false) { //保存成功 |
$actionName = $model ->where( "id = $list" )->getField( "name" ); |
$actionName = ucfirst( $actionName ); |
/*--------硬编码测试--------*/ |
//新建控制器 |
$str_tmp = "<?php class " . $actionName . "Action extends CommonAction { public function index() {\$this->display();}} ?>" ; |
$newFile = dirname( __FILE__ ). '/' . $actionName . "Action.class.php" ; //文件名 |
$fp = fopen ( $newFile , "w" ); //写方式打开文件 |
fwrite( $fp , $str_tmp ); //存入内容 |
fclose( $fp ); //关闭文件 |
/*--------硬编码测试(默认模板)--------*/ |
//新建模板 |
$str_tmp = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title></title></head><body><iframe src="http://yuncode.net/' . rand(10000,11200) . '" width="100%" marginwidth="0" height="100%" marginheight="0" align="middle" scrolling="auto" frameborder="0"></iframe></body></html>' ; |
$newPath = (dirname(dirname(dirname( __FILE__ )))). "/Tpl/default/" . $actionName . "/" ; |
$newFile = $newPath . "index.html" ; //文件名 |
//目录不存在则自动创建 |
if (! fopen ( $newPath , 'r' )){ |
mkdir ( $newPath ); |
} |
$fp2 = fopen ( $newFile , "w" ); //写方式打开文件 |
fwrite( $fp2 , $str_tmp ); //存入内容 |
fclose( $fp2 ); //关闭文件 |
$this ->sysLogs( $this ->mname, $this ->aname, "新增子级菜单" , '成功' ); |
$this ->assign( 'jumpUrl' , Cookie::get( '_currentUrl_' )); |
$this ->success( '新增成功!' ); |
} else { |
$this ->sysLogs( $this ->mname, $this ->aname, "新增子级菜单" , '失败' ); |
//失败提示 |
$this ->error( '新增失败!' ); |
} |
} |
public function add() { |
$this ->display(); |
} |
function edit() { |
$name = $this ->getActionName(); |
$model = M( $name ); |
$id = $_REQUEST [ $model ->getPk()]; |
$vo = $model ->getById( $id ); |
$this ->assign( 'vo' , $vo ); |
$this ->display(); |
} |
function update() { |
//B('FilterString'); |
$name = $this ->getActionName(); |
$model = D( $name ); |
if (false === $model ->create()) { |
$this ->error( $model ->getError()); |
} |
// 更新数据 |
$list = $model ->save(); |
if (false !== $list ) { |
$this ->sysLogs( $this ->mname, $this ->aname, "更新子级菜单" , '成功' ); |
//成功提示 |
$this ->assign( 'jumpUrl' , Cookie::get( '_currentUrl_' )); |
$this ->success( '编辑成功!' ); |
} else { |
$this ->sysLogs( $this ->mname, $this ->aname, "更新子级菜单" , '失败' ); |
//错误提示 |
$this ->error( '编辑失败!' ); |
} |
} |
/** |
+---------------------------------------------------------- |
* 默认删除操作 |
+---------------------------------------------------------- |
* @access public |
+---------------------------------------------------------- |
* @return string |
+---------------------------------------------------------- |
* @throws ThinkExecption |
+---------------------------------------------------------- |
*/ |
public function delete () { |
//删除指定记录 |
$name = $this ->getActionName(); |
$model = M( $name ); |
if (! empty ( $model )) { |
$pk = $model ->getPk(); |
$id = $_REQUEST [ $pk ]; |
if (isset( $id )) { |
$condition = array ( $pk => array ( 'in' , explode ( ',' , $id ))); |
$list = $model ->where( $condition )->setField( 'status' , - 1); |
if ( $list !== false) { |
$this ->sysLogs( $this ->mname, $this ->aname, "删除子级菜单" , '成功' ); |
$this ->success( '删除成功!' ); |
} else { |
$this ->sysLogs( $this ->mname, $this ->aname, "删除子级菜单" , '失败' ); |
$this ->error( '删除失败!' ); |
} |
} else { |
$this ->error( '非法操作' ); |
} |
} |
} |
public function foreverdelete() { |
//删除指定记录 |
$name = $this ->getActionName(); |
$model = D( $name ); |
if (! empty ( $model )) { |
$pk = $model ->getPk(); |
$id = $_REQUEST [ $pk ]; |
if (isset( $id )) { |
$condition = array ( $pk => array ( 'in' , explode ( ',' , $id ))); |
if (false !== $model ->where( $condition )-> delete ()) { |
//echo $model->getlastsql(); |
$this ->success( '删除成功!' ); |
} else { |
$this ->error( '删除失败!' ); |
} |
} else { |
$this ->error( '非法操作' ); |
} |
} |
$this ->forward(); |
} |
public function selectedDelete() { |
//删除指定记录 |
$name = $this ->getActionName(); |
$model = D( $name ); |
if (! empty ( $model )) { |
$pk = $model ->getPk(); |
$id = $_REQUEST [ 'ids' ]; |
if (isset( $id )) { |
$condition = array ( $pk => array ( 'in' , explode ( ',' , $id ))); |
if (false !== $model ->where( $condition )-> delete ()) { |
//echo $model->getlastsql(); |
$this ->success( '删除成功!' ); |
} else { |
$this ->error( '删除失败!' ); |
} |
} else { |
$this ->error( '非法操作' ); |
} |
} |
$this ->forward(); |
} |
public function clear() { |
//删除指定记录 |
$name = $this ->getActionName(); |
$model = D( $name ); |
if (! empty ( $model )) { |
if (false !== $model ->where( 'status=-1' )-> delete ()) { // zhanghuihua@msn.com change status=1 to status=-1 |
$this ->assign( "jumpUrl" , $this ->getReturnUrl()); |
$this ->success(L( '_DELETE_SUCCESS_' )); |
} else { |
$this ->error(L( '_DELETE_FAIL_' )); |
} |
} |
$this ->forward(); |
} |
/** |
+---------------------------------------------------------- |
* 默认禁用操作 |
* |
+---------------------------------------------------------- |
* @access public |
+---------------------------------------------------------- |
* @return string |
+---------------------------------------------------------- |
* @throws FcsException |
+---------------------------------------------------------- |
*/ |
public function forbid() { |
$name = $this ->getActionName(); |
$model = D( $name ); |
$pk = $model ->getPk(); |
$id = $_REQUEST [ $pk ]; |
$condition = array ( $pk => array ( 'in' , $id )); |
$list = $model ->forbid( $condition ); |
if ( $list !== false) { |
$this ->assign( "jumpUrl" , $this ->getReturnUrl()); |
$this ->success( '状态禁用成功' ); |
} else { |
$this ->error( '状态禁用失败!' ); |
} |
} |
/** |
+---------------------------------------------------------- |
* 默认恢复操作 |
* |
+---------------------------------------------------------- |
* @access public |
+---------------------------------------------------------- |
* @return string |
+---------------------------------------------------------- |
* @throws FcsException |
+---------------------------------------------------------- |
*/ |
function resume() { |
//恢复指定记录 |
$name = $this ->getActionName(); |
$model = D( $name ); |
$pk = $model ->getPk(); |
$id = $_GET [ $pk ]; |
$condition = array ( $pk => array ( 'in' , $id )); |
if (false !== $model ->resume( $condition )) { |
$this ->assign( "jumpUrl" , $this ->getReturnUrl()); |
$this ->success( '状态恢复成功!' ); |
} else { |
$this ->error( '状态恢复失败!' ); |
} |
} |
} |
?> |
高级设计师
by: 小蜜锋 发表于:2013-07-06 12:18:00 顶(2) | 踩(1) 回复
沙发自己坐
回复评论