public static function findAllComments() { $db = new Model(); $comments = $db->findAll("comments"); $obj = array(); foreach ($comments as $c) { $obj[] = self::instantiate($c); } return $obj; }
public static function getAllUsers() { $db = new Model(); $users = $db->findAll("users"); $obj = array(); foreach ($users as $u) { if ($u->id != $_SESSION['uid']) { $obj[] = self::instantiate($u); } } return $obj; }
public static function getAllPics() { $db = new Model(); $pics = $db->findAll("pics"); return $pics; }
/** * Returns an array with keys "prev" and "next" that holds the id's of neighbouring data, * which is useful when creating paged lists. * * @param string $conditions SQL conditions for matching rows * @param string $field Field name (parameter for findAll) * @param unknown_type $value * @return array Array with keys "prev" and "next" that holds the id's * @access public */ function findNeighbours($conditions = null, $field, $value) { $db =& ConnectionManager::getDataSource($this->useDbConfig); if (!is_null($conditions)) { $conditions = $conditions . ' AND '; } @(list($prev) = Model::findAll($conditions . $field . ' < ' . $db->value($value), $field, $field . ' DESC', 1, null, 0)); @(list($next) = Model::findAll($conditions . $field . ' > ' . $db->value($value), $field, $field . ' ASC', 1, null, 0)); if (!isset($prev)) { $prev = null; } if (!isset($next)) { $next = null; } return array('prev' => $prev, 'next' => $next); }
function help_list() { $help_category = new Model('help_category'); $rows = $help_category->findAll(); $categorys = array(0 => '默认分类'); foreach ($rows as $row) { $categorys[$row['id']] = $row['name']; } $this->categorys = $categorys; $this->redirect('help_list'); }
public function order_list() { $condition = Req::args("condition"); $condition_str = Common::str2where($condition); if ($condition_str) { $this->assign("where", $condition_str); } else { $status = Req::args("status"); if ($status) { $this->assign("where", "od.status=" . $status); } else { $this->assign("where", "1=1"); } } $this->assign("condition", $condition); $this->assign("status", array('0' => '<span class="red">等待审核</span>', '1' => '<span class="red">等待审核</span>', '2' => '<span class="red">等待审核</span>', '3' => '已审核', '4' => '已完成', '5' => '已取消', '6' => '<span class="red"><s>已作废</s></span>')); $this->assign("pay_status", array('0' => '<span class="red">未付款</span>', '1' => '已付款', '2' => '申请退款', '3' => '已退款')); $this->assign("delivery_status", array('0' => '<span class="red">未发货</span>', '1' => '已发货', '2' => '已签收', '3' => '申请换货', '4' => '已换货')); $model = new Model("payment"); $items = $model->findAll(); $payment = array(); foreach ($items as $item) { $payment[$item['id']] = $item['pay_name']; } $this->assign("payment", $payment); $this->redirect(); }
public function message_edit() { $model = new Model('grade'); $rows = $model->findAll(); $grade = ''; foreach ($rows as $row) { $grade .= $row['id'] . ":'" . $row['name'] . "',"; } $grade = trim($grade, ','); $this->assign('grade', $grade); $this->redirect(); }
public function roles_edit() { $id = Req::args("id"); $model = new Model("resources"); $rows = $model->findAll(); $resources = array(); foreach ($rows as $row) { $resources[$row['group']][] = $row; } $this->assign('resources', $resources); $role_rights = ''; if ($id) { $role = $model->table('roles')->where("id={$id}")->find(); if ($role) { $role_rights = $role['rights']; } $data = $role; } else { $data = Req::args(); } $this->assign("rights", $role_rights); $this->redirect("roles_edit", false, $data); }
public function prom_order_list() { $parse_type = array('0' => '满额打折', '1' => '满额优惠金额', '2' => '满额送倍数积分', '3' => '满额送优惠券', '4' => '满额免运费'); $this->assign("parse_type", $parse_type); $model = new Model('grade'); $rows = $model->findAll(); $grades = array(0 => '默认会员'); foreach ($rows as $row) { $grades[$row['id']] = $row['name']; } $this->assign("grades", $grades); $this->redirect(); }
/** +---------------------------------------------------------- * 根据表单生成查询条件 * 进行列表过滤 +---------------------------------------------------------- * @access protected +---------------------------------------------------------- * @param Model $model 数据对象 * @param HashMap $map 过滤条件 * @param string $sortBy 排序 * @param boolean $asc 是否正序 +---------------------------------------------------------- * @return void +---------------------------------------------------------- * @throws ThinkExecption +---------------------------------------------------------- */ protected function _list($model, $map, $sortBy = '', $asc = true) { //排序字段 默认为主键名 if (isset($_REQUEST['order'])) { $order = $_REQUEST['order']; } else { $order = !empty($sortBy) ? $sortBy : $model->getPk(); } //排序方式默认按照倒序排列 //接受 sost参数 0 表示倒序 非0都 表示正序 if (isset($_REQUEST['sort'])) { $sort = $_REQUEST['sort'] ? 'asc' : 'desc'; } else { $sort = $asc ? 'asc' : 'desc'; } //取得满足条件的记录数 $count = $model->count($map); import("ORG.Util.Page"); //创建分页对象 if (!empty($_REQUEST['listRows'])) { $listRows = $_REQUEST['listRows']; } else { $listRows = ''; } $p = new Page($count, $listRows); //分页查询数据 $voList = $model->findAll($map, '*', $order . ' ' . $sort, $p->firstRow . ',' . $p->listRows); //分页跳转的时候保证查询条件 foreach ($map as $key => $val) { $p->parameter .= "{$key}={$val}&"; } //分页显示 $page = $p->show(); //列表排序显示 $sortImg = $sort; //排序图标 $sortAlt = $sort == 'desc' ? '升序排列' : '倒序排列'; //排序提示 $sort = $sort == 'desc' ? 1 : 0; //排序方式 //模板赋值显示 $this->assign('list', $voList); $this->assign('sort', $sort); $this->assign('order', $order); $this->assign('sortImg', $sortImg); $this->assign('sortType', $sortAlt); $this->assign("page", $page); return; }
/** * Special findAll variation for tables joined to themselves. * The table needs the fields id and parent_id to work. * * @param array $conditions Conditions for the findAll() call * @param array $fields Fields for the findAll() call * @param string $sort SQL ORDER BY statement * @return array Threaded results * @access public * @todo Perhaps create a Component with this logic */ function findAllThreaded($conditions = null, $fields = null, $sort = null) { return $this->__doThread(Model::findAll($conditions, $fields, $sort), null); }