Manage.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace Log\Lib;
  3. use Dever;
  4. class Manage extends Core
  5. {
  6. # 增加维度
  7. public function addCol($col)
  8. {
  9. if ($col && isset($col[0])) {
  10. foreach ($col as $k => $v) {
  11. $this->addColOne($v);
  12. }
  13. } else {
  14. $this->addColOne($col);
  15. }
  16. $this->create();
  17. }
  18. private function addColOne($col)
  19. {
  20. $info = Dever::db('log/col')->one(array('key' => $col['key']));
  21. if (!$info) {
  22. Dever::db('log/col')->insert(array('key' => $col['key'], 'name' => $col['name']));
  23. }
  24. return true;
  25. }
  26. # 从数据库生成维度和项目的配置文件
  27. public function create()
  28. {
  29. $config = array();
  30. $project = Dever::db('log/project')->state();
  31. if ($project) {
  32. foreach ($project as $k => $v) {
  33. $config['project'][$v['key']] = $v;
  34. }
  35. }
  36. $source = Dever::db('log/source')->state();
  37. if ($project) {
  38. foreach ($project as $k => $v) {
  39. $config['source'][$v['key']] = $v;
  40. }
  41. }
  42. $col = Dever::db('log/col')->state();
  43. if ($col) {
  44. foreach ($col as $k => $v) {
  45. $config['col'][$v['key']] = $v;
  46. }
  47. }
  48. $data = '<?php return ' . var_export($config, true) . ';';
  49. file_put_contents($this->file(), $data);
  50. return true;
  51. }
  52. }