/** * 任务列表 */ public function index() { $param = array(); $condition = "1=1"; if (is_numeric($_GET['su'])) { $param['task_status'] = (int) $_GET['su']; $condition .= " AND t.task_status = :task_status"; } if (!empty($_GET['p'])) { $param['task_project'] = (int) $_GET['p']; $condition .= " AND t.task_project = :task_project"; } if (!empty($_GET['u'])) { $param['task_user_id'] = (int) $_GET['u']; $condition .= " AND t.task_user_id = :task_user_id"; } if (!empty($_GET['k'])) { $keyword = $this->g('k'); $param['task_title'] = "%{$keyword}%"; $param['task_id'] = $keyword; $condition .= " AND t.task_title like :task_title OR t.task_id = :task_id"; } $page = new \Expand\Page(); $total = $this->db('task AS t', 'process')->field('count(t.task_id) AS total')->join("`process`.{$this->prefix}user AS u ON u.user_id = t.task_user_id")->where($condition)->find($param)['total']; $count = $page->total($total); $page->handle(); $list = $this->db('task AS t', 'process')->join("`process`.{$this->prefix}user AS u ON u.user_id = t.task_user_id")->where($condition)->order('t.task_status ASC, t.task_priority ASC, t.task_id DESC')->limit("{$page->firstRow}, {$page->listRows}")->select($param); $show = $page->show(); $this->assign('page', $show); $this->assign('list', $list); $this->layout(); }
/** * 内容列表 */ public function _list() { $catid = $this->isG('id', '请选择分类'); $catid = $this->categorys[$catid]['category_child']; $orderBy = "{$this->model}_id DESC"; $field = \Model\Field::fieldList($this->modelInfo['model_id'], array('field_status' => '1', 'field_list' => '1')); $condition = "{$this->model}_catid in ({$catid}) AND {$this->model}_status = 1"; foreach ($field as $key => $value) { if (!empty($_GET)) { foreach ($_GET as $gk => $gv) { if ($gk == $value['field_name']) { $condition .= " AND {$this->model}_{$value['field_name']} = :{$value['field_name']} "; $data[$value['field_name']] = "{$gv}"; } } } //判断是否存在排序字段 if ($value['field_name'] == 'listsort') { $orderBy = "{$this->model}_listsort ASC, {$orderBy}"; } } $page = new \Expand\Page(); $total = count($this->db($this->model)->where($condition)->select($data)); $count = $page->total($total); $page->handle(); $list = $this->db($this->model)->where($condition)->order($orderBy)->limit("{$page->firstRow}, {$page->listRows}")->select($data); $show = $page->show(); $this->assign('title', $this->categorys[$catid]['category_name']); $this->assign('keyword', $this->categorys[$catid]['category_keyword']); $this->assign('description', $this->categorys[$catid]['category_description']); $this->assign('page', $show); $this->assign('list', $list); if (empty($this->categorys[$catid]['theme'])) { $theme = MODULE . "_list"; $themeFunc = 'layout'; } else { $theme = $this->categorys[$catid]['theme']; $themeFunc = 'display'; } $this->layout(is_file(THEME . '/' . GROUP . "/{$this->theme}/" . MODULE . "/{$theme}.php") ? $theme : 'Content_list'); }
/** * 快速构造内容分页 * @param array $sql 结构内容如下: * count => 一个完整的SQL count查询。用户获取本当前内容的总数量 如:SELECT count(*) TABLE WHERE id = :id * normal => 结合上面的SQL。这部分是分类的。如: SELECT * TABLE WHERE id = :id * param => 预处理参数。如果SQL语句中有占位符,此处也应该调用。如: array('id' => $id) * 上面说的可能不太好理解。有如下SQL: * $sql = SELECT %s FROM user WHERE user_id = :user_id ORDER BY user_id DESC * $param = array('user_id' => $uid); * * 最终可以这样调用本方法: * \Model\Content::listContent(array('count' => sprintf($sql, 'count(*)'), 'normal' => sprintf($sql, '*'), 'param' => $param)) * * @return array 结果返回:处理好的 列表二维数组和 一个分类超链接 */ public static function quickListContent(array $sql = array('count' => '', 'normal' => '', 'param' => array())) { $sql = array_merge(['param' => array(), 'page' => '10'], $sql); $page = new \Expand\Page(); $page->listRows = $sql['page']; $total = current(self::db()->fetch($sql['count'], $sql['param'])); $page->total($total); $page->handle(); $list = self::db()->getAll("{$sql['normal']} LIMIT {$page->firstRow}, {$page->listRows}", $sql['param']); return array('list' => $list, 'page' => $page->show()); }