0,]; /** * 获取数据库中的配置列表 * @return array 配置数组 */ public function getGroupLists($where = null, $order = null, $field = null, $limit = null) { if (is_array($where)) { $where = array_merge(['stat' => ['eq', '0']], $where); } if ($where) { $this->where($where); } if ($field) { $this->field($field); } if ($order) { $this->order($order); } if ($limit) { $this->limit($limit); } $data = $this->select(); return $data; } /** * 获取数据库中的配置列表 * @return array 配置数组 */ public function getPageLists($where = null, $order = null, $field = null, $limit = null) { if (is_array($where)) { $where = array_merge(['stat' => 0], $where); } if ($where) { $this->where($where); } if ($order) { $this->order($order); } if ($field) { $this->field($field); } if (empty($limit)) { $limit = Config::get('list_rows'); } $object = $this->paginate($limit); return $object; } /** * 获取数据库中的配置列表 * @return array 配置数组 */ public function configLists($where = null) { $this->where(['stat' => 0])->field('type,name,value,extra'); if ($where) { $this->where($where); } $this->order(['sort' => 'asc', 'id' => 'asc']); $data = $this->select(); $config = []; if ($data && is_array($data)) { foreach ($data as $value) { $config[$value->data['name']] = self::parse($value->data['type'], $value->data['value'], $value->data['extra']); } } return $config; } /** * 根据配置类型解析配置 * @param integer $type 配置类型 * @param string $value 配置值 * @param string $extra 配置项 */ private function parse($type, $value, $extra = '') { switch ($type) { // case 'number': // $value = intval($value); // break; case 'json': $value = json_decode($value, true); break; case 'array': //解析数组 $array = preg_split('/[,;\r\n]+/', trim($value, ",;\r\n")); if (strpos($value, ':')) { $value = array(); foreach ($array as $val) { list($k, $v) = explode(':', $val); $value[$k] = $v; } } else { $value = $array; } break; // case 'enum': //解析数组 // $array = preg_split('/[,;\r\n]+/', trim($extra, ",;\r\n")); // if (strpos($value, ':')) { // $valarr = array(); // foreach ($array as $val) { // list($k, $v) = explode(':', $val); // $valarr[$k] = $v; // } // } else { // $valarr = $array; // } // $value = isset($valarr[$value]) ? $valarr[$value] : $value; // break; case 'dump': dump($value); // die; break; default: //dump($value); // die; break; } return $value; } /** * 配置标识转为小写 * @param 类型 参数 参数说明 */ protected function setNameAttr($value) { return strtolower($value); } /** * 配置名称过滤 * @param 类型 参数 参数说明 */ protected function setTitleAttr($value) { return htmlspecialchars($value); } }