IcePHP框架中的快速后台中的通用CRUD功能框架(九) SCrudOperationIndex 及 SCrudOperationSearch 类
2014-01-17 11:10
417 查看
<?php
/**
* 首页操作类
*
* @author bluehire
*
*/
class SCrudOperationIndex extends SCrudOperation {
public function __construct($father){
parent::__construct($father, SCrudOperation::METHOD_INDEX);
}
/**
* 首页处理
*
* @see SCrudOperationTable::process()
*/
public function process(SRequest $req) {
// @todo:细节检查权限
$this->output ();
}
/**
* 显示首页
*/
private function output() {
//输出首页头
$this->crud->display('index_header',array('title'=>$this->crud->title));
//输出用户信息,退出登录等
$this->crud->display('index_userinfo');
//输出操作菜单
$this->crud->display('index_menu');
//输出脚本
$this->crud->display('javascript');
//输出功能区头
$this->crud->display('work_header');
//输出搜索区
$this->crud->display('search_header');
foreach ( $this->crud->fields as $field ) {
$field->showSearch();
}
$this->crud->display('search_footer');
//输出表级操作
$this->crud->operation->outputTable();
// 输出分页及排序
$this->crud->display ( 'page_sort', array (
'pagesize' => $this->crud->pageSize, //默认每页行数
'all' => $this->crud->listSortable(), //全部字段配置信息
'curField' => $this->crud->pageSort, //默认字段
'dir' => strtolower ( $this->crud->pageDir ) //排序方向
) );
//输出空白表格容器
$this->crud->display ( 'grid_container');
//输出多选操作
$this->crud->operation->outputMulti();
//输出分页
$this->crud->display('page_page');
//输出功能区尾
$this->crud->display('work_footer');
//输出首页尾
$this->crud->display('index_footer');
}
public function show($row=null){
//@todo:显示操作
echo $this->title;
}
}
<?php
/**
* 默认搜索操作
* @author bluehire
*
*/
class SCrudOperationSearch extends SCrudOperation{
public function __construct(SCrud $father) {
parent::__construct($father, self::METHOD_SEARCH);
}
/**
* 点击查询按钮后的操作
* @see SCrudOperation::process()
*
*/
public function process(SRequest $req){
//如果请求中指定了页面尺寸,设置页面尺寸
if ($req->exist ( '_pagesize' )) {
$size = intval ( $req->_pagesize );
$size = max ( min ( $size, 1000 ), 1 );
$this->crud->pageSize = $size;
} else {
$size = $this->crud->pageSize;
}
//如果请求中指定了排序依据
if ($req->exist ( '_orderby' )) {
$orderby = trim ( $req->_orderby );
$orderField = $this->crud->field ( $orderby );
if ($orderField and $orderField->isSortable ()) {
if (! $req->exist ( '_dir' )) {
$dir = 'desc';
} else {
$dir = trim ( $req->_dir );
if ($dir !== 'asc' and $dir !== 'desc') {
$dir = 'desc';
}
}
$this->crud->pageSort = $orderby;
$this->crud->pageDir = $dir;
}
}
$orderby = $this->crud->pageSort;
$dir = $this->crud->pageDir;
//查看所有搜索条件
$filter = $this->crud->gridFilter;
if (! $filter) {
$where = array ();
} elseif (is_array ( $filter )) {
$where = $filter;
} else {
$where = array (
$filter
);
}
//处理所有 可搜索字段,构造查询条件
foreach ( $this->crud->listSearchable () as $field ) {
$w = $field->where ( $req );
if (! $w) {
continue;
}
if (is_array ( $w )) {
$where = array_merge ( $where, $w );
} else {
$where [] = $w;
}
}
if (! $req->exist ( '_page' )) {
$page = 1;
} else {
$page = max(1,intval ( $req->_page ));
}
$this->output ( $where, $page, $size, $orderby, $dir );
}
//查询数据并输出
private function output($where,$page,$size,$orderby,$dir){
//所有满足条件的数据数量
$count=$this->crud->model->count($where);
//页数
$pageAll=ceil($count/$size);
//当前页
$page=max(min($page,$pageAll),1);
//主键字段必须查询
$fields=array_keys($this->crud->listGridable());
//查询数据
$data=$this->crud->model->fields($fields)->where($where)->orderby(array($orderby,$dir))->limit(array(($page-1)*$size,$size))->select();
//生成表格内容的显示
$grid=$this->outputGrid($data);
//Ajax形式返回前端
echo json_encode(array(
'count'=>$count,
'pageAll'=>$pageAll,
'page'=>$page,
'size'=>$size,
'grid'=>$grid
));
}
/**
* 根据数据输出表格内容
* @param SResult $data
* @return string
*/
private function outputGrid(SResult $data) {
$rowNo = $this->crud->rowNo;
$multi = $this->crud->operation->hasMulti ();
$operations = $this->crud->operation->rowOperations;
$fields = $this->crud->fields;
// 显示表头
$this->crud->display ( 'grid_header', array (
'rowNo' => $rowNo,
'multi' => $multi,
'operations' => $operations,
'fields' => $fields
) );
// 显示表格数据行
$this->crud->display ( 'grid_body', array (
'rowNo' => $rowNo,
'multi' => $multi,
'operations' => $operations,
'fields' => $fields,
'data' => $data
) );
// 显示表格尾
$this->crud->display('grid_footer');
return ob_get_clean ();
}
public function show($row=null){
//此处不被调用
}
}
/**
* 首页操作类
*
* @author bluehire
*
*/
class SCrudOperationIndex extends SCrudOperation {
public function __construct($father){
parent::__construct($father, SCrudOperation::METHOD_INDEX);
}
/**
* 首页处理
*
* @see SCrudOperationTable::process()
*/
public function process(SRequest $req) {
// @todo:细节检查权限
$this->output ();
}
/**
* 显示首页
*/
private function output() {
//输出首页头
$this->crud->display('index_header',array('title'=>$this->crud->title));
//输出用户信息,退出登录等
$this->crud->display('index_userinfo');
//输出操作菜单
$this->crud->display('index_menu');
//输出脚本
$this->crud->display('javascript');
//输出功能区头
$this->crud->display('work_header');
//输出搜索区
$this->crud->display('search_header');
foreach ( $this->crud->fields as $field ) {
$field->showSearch();
}
$this->crud->display('search_footer');
//输出表级操作
$this->crud->operation->outputTable();
// 输出分页及排序
$this->crud->display ( 'page_sort', array (
'pagesize' => $this->crud->pageSize, //默认每页行数
'all' => $this->crud->listSortable(), //全部字段配置信息
'curField' => $this->crud->pageSort, //默认字段
'dir' => strtolower ( $this->crud->pageDir ) //排序方向
) );
//输出空白表格容器
$this->crud->display ( 'grid_container');
//输出多选操作
$this->crud->operation->outputMulti();
//输出分页
$this->crud->display('page_page');
//输出功能区尾
$this->crud->display('work_footer');
//输出首页尾
$this->crud->display('index_footer');
}
public function show($row=null){
//@todo:显示操作
echo $this->title;
}
}
<?php
/**
* 默认搜索操作
* @author bluehire
*
*/
class SCrudOperationSearch extends SCrudOperation{
public function __construct(SCrud $father) {
parent::__construct($father, self::METHOD_SEARCH);
}
/**
* 点击查询按钮后的操作
* @see SCrudOperation::process()
*
*/
public function process(SRequest $req){
//如果请求中指定了页面尺寸,设置页面尺寸
if ($req->exist ( '_pagesize' )) {
$size = intval ( $req->_pagesize );
$size = max ( min ( $size, 1000 ), 1 );
$this->crud->pageSize = $size;
} else {
$size = $this->crud->pageSize;
}
//如果请求中指定了排序依据
if ($req->exist ( '_orderby' )) {
$orderby = trim ( $req->_orderby );
$orderField = $this->crud->field ( $orderby );
if ($orderField and $orderField->isSortable ()) {
if (! $req->exist ( '_dir' )) {
$dir = 'desc';
} else {
$dir = trim ( $req->_dir );
if ($dir !== 'asc' and $dir !== 'desc') {
$dir = 'desc';
}
}
$this->crud->pageSort = $orderby;
$this->crud->pageDir = $dir;
}
}
$orderby = $this->crud->pageSort;
$dir = $this->crud->pageDir;
//查看所有搜索条件
$filter = $this->crud->gridFilter;
if (! $filter) {
$where = array ();
} elseif (is_array ( $filter )) {
$where = $filter;
} else {
$where = array (
$filter
);
}
//处理所有 可搜索字段,构造查询条件
foreach ( $this->crud->listSearchable () as $field ) {
$w = $field->where ( $req );
if (! $w) {
continue;
}
if (is_array ( $w )) {
$where = array_merge ( $where, $w );
} else {
$where [] = $w;
}
}
if (! $req->exist ( '_page' )) {
$page = 1;
} else {
$page = max(1,intval ( $req->_page ));
}
$this->output ( $where, $page, $size, $orderby, $dir );
}
//查询数据并输出
private function output($where,$page,$size,$orderby,$dir){
//所有满足条件的数据数量
$count=$this->crud->model->count($where);
//页数
$pageAll=ceil($count/$size);
//当前页
$page=max(min($page,$pageAll),1);
//主键字段必须查询
$fields=array_keys($this->crud->listGridable());
//查询数据
$data=$this->crud->model->fields($fields)->where($where)->orderby(array($orderby,$dir))->limit(array(($page-1)*$size,$size))->select();
//生成表格内容的显示
$grid=$this->outputGrid($data);
//Ajax形式返回前端
echo json_encode(array(
'count'=>$count,
'pageAll'=>$pageAll,
'page'=>$page,
'size'=>$size,
'grid'=>$grid
));
}
/**
* 根据数据输出表格内容
* @param SResult $data
* @return string
*/
private function outputGrid(SResult $data) {
$rowNo = $this->crud->rowNo;
$multi = $this->crud->operation->hasMulti ();
$operations = $this->crud->operation->rowOperations;
$fields = $this->crud->fields;
// 显示表头
$this->crud->display ( 'grid_header', array (
'rowNo' => $rowNo,
'multi' => $multi,
'operations' => $operations,
'fields' => $fields
) );
// 显示表格数据行
$this->crud->display ( 'grid_body', array (
'rowNo' => $rowNo,
'multi' => $multi,
'operations' => $operations,
'fields' => $fields,
'data' => $data
) );
// 显示表格尾
$this->crud->display('grid_footer');
return ob_get_clean ();
}
public function show($row=null){
//此处不被调用
}
}
相关文章推荐
- IcePHP框架中的快速后台中的通用CRUD功能框架(七) SCrudOperationSet 操作集类
- IcePHP框架中的快速后台中的通用CRUD功能框架(五) SCrud 主控类
- IcePHP框架中的快速后台中的通用CRUD功能框架(二)
- IcePHP框架中的快速后台中的通用CRUD功能框架(三) 具体业务示例
- IcePHP框架中的快速后台中的通用CRUD功能框架(四) 表配置文件
- IcePHP框架中的快速后台中的通用CRUD功能框架(六) SCrudField 字段类
- IcePHP框架中的快速后台中的通用CRUD功能框架(八) SCrudOperation 指定操作类
- IcePHP框架中的快速后台中的通用CRUD功能框架
- IcePHP框架中的快速后台中的通用CRUD功能框架(十) 运行效果图
- IcePHP框架中的快速后台中的通用CRUD功能框架(十一) 运行效果图改进
- ASP.NET快速开发框架不得不做的几个功能、高大上档次后台管理UI界面
- IcePHP框架 新增了 管理后台四层权限功能
- IcePHP框架 新增 管理后台 自动 日志功能
- ASP.NET MVC 学习4、Controller中添加SearchIndex页面,实现简单的查询功能
- C#.NET 大型通用信息化系统集成快速开发平台 4.1 版本 - 即时消息提醒功能改进
- 以简求快 Java快速开发框架LML功能菜单管理
- 基于JFinal2.x的后台业务框架通用模块
- Spring学习之SpringMVC框架快速搭建实现用户登录功能
- 基于java极速WEB+ORM 框架:jfinal2.0开发的通用后台管理系统及源码
- 公司的Java框架应具备的通用功能