12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- namespace Log\Lib;
- use Dever;
- class Manage extends Core
- {
- # 增加维度
- public function addCol($col)
- {
- if ($col && isset($col[0])) {
- foreach ($col as $k => $v) {
- $this->addColOne($v);
- }
- } else {
- $this->addColOne($col);
- }
- $this->create();
- }
- private function addColOne($col)
- {
- $info = Dever::db('log/col')->one(array('key' => $col['key']));
- if (!$info) {
- Dever::db('log/col')->insert(array('key' => $col['key'], 'name' => $col['name']));
- }
- return true;
- }
- # 从数据库生成维度和项目的配置文件
- public function create()
- {
- $config = array();
- $project = Dever::db('log/project')->state();
- if ($project) {
- foreach ($project as $k => $v) {
- $config['project'][$v['key']] = $v;
- }
- }
- $source = Dever::db('log/source')->state();
- if ($project) {
- foreach ($project as $k => $v) {
- $config['source'][$v['key']] = $v;
- }
- }
- $col = Dever::db('log/col')->state();
- if ($col) {
- foreach ($col as $k => $v) {
- $config['col'][$v['key']] = $v;
- }
- }
- $data = '<?php return ' . var_export($config, true) . ';';
- file_put_contents($this->file(), $data);
- return true;
- }
- }
|