From b53abbc4e872897869e19e17be35aa30b199224c Mon Sep 17 00:00:00 2001 From: songchenxuan Date: Wed, 27 Mar 2024 14:33:24 +0800 Subject: [PATCH] * Add bi getScopeOption. --- module/bi/model.php | 32 ++++++++++++++++++++ module/chart/model.php | 67 +++++++++++++++------------------------- module/pivot/model.php | 69 ++++++++++++++---------------------------- 3 files changed, 78 insertions(+), 90 deletions(-) diff --git a/module/bi/model.php b/module/bi/model.php index 8237537510..013be84821 100644 --- a/module/bi/model.php +++ b/module/bi/model.php @@ -2,6 +2,38 @@ class biModel extends model { + /** + * Get object options. + * + * @param string $type user|product|project|execution|dept + * @access public + * @return array + */ + public function getScopeOptions($type) + { + $options = array(); + switch($type) + { + case 'user': + $options = $this->loadModel('user')->getPairs('noletter'); + break; + case 'product': + $options = $this->loadModel('product')->getPairs(); + break; + case 'project': + $options = $this->loadModel('project')->getPairsByProgram(); + break; + case 'execution': + $options = $this->loadModel('execution')->getPairs(); + break; + case 'dept': + $options = $this->loadModel('dept')->getOptionMenu(0); + break; + } + + return $options; + } + /** * Get object options. * diff --git a/module/chart/model.php b/module/chart/model.php index 4323f01d9d..796d58be79 100644 --- a/module/chart/model.php +++ b/module/chart/model.php @@ -22,6 +22,7 @@ class chartModel extends model { parent::__construct($appName); $this->loadBIDAO(); + $this->loadModel('bi'); } /** @@ -254,7 +255,7 @@ class chartModel extends model } $indicator = array(); - $optionList = $this->getFieldOptions($fields[$group]['type'], $fields[$group]['object'], $fields[$group]['field']); + $optionList = $this->getSysOptions($fields[$group]['type'], $fields[$group]['object'], $fields[$group]['field']); foreach($xLabels as $xLabel) { $labelName = isset($optionList[$xLabel]) ? $optionList[$xLabel] : $xLabel; @@ -293,7 +294,7 @@ class chartModel extends model if(empty($date)) arsort($stat); $seriesData = array(); - $optionList = $this->getFieldOptions($fields[$group]['type'], $fields[$group]['object'], $fields[$group]['field']); + $optionList = $this->getSysOptions($fields[$group]['type'], $fields[$group]['object'], $fields[$group]['field']); foreach($stat as $name => $value) { if(empty($value)) continue; @@ -345,7 +346,7 @@ class chartModel extends model } } - $optionList = $this->getFieldOptions($fields[$group]['type'], $fields[$group]['object'], $fields[$group]['field']); + $optionList = $this->getSysOptions($fields[$group]['type'], $fields[$group]['object'], $fields[$group]['field']); foreach($xLabels as $index => $xLabel) $xLabels[$index] = isset($optionList[$xLabel]) ? $optionList[$xLabel] : $xLabel; $series = array(); @@ -388,7 +389,7 @@ class chartModel extends model $yDatas[] = $data; } - $optionList = $this->getFieldOptions($fields[$group]['type'], $fields[$group]['object'], $fields[$group]['field']); + $optionList = $this->getSysOptions($fields[$group]['type'], $fields[$group]['object'], $fields[$group]['field']); foreach($xLabels as $index => $xLabel) $xLabels[$index] = isset($optionList[$xLabel]) ? $optionList[$xLabel] : $xLabel; $series = array(); @@ -521,61 +522,41 @@ class chartModel extends model * @param string $object * @param string $field * @param string $sql + * @param string $saveAs * @access public * @return array */ - public function getFieldOptions(string $type, string $object = '', string $field = '', string $sql = ''): array + public function getSysOptions(string $type, string $object = '', string $field = '', string $sql = '', string $saveAs = ''): array { + if(in_array($type, array('user', 'product', 'project', 'execution', 'dept'))) return $this->bi->getScopeOptions($type); + if(!$field) return array(); + $options = array(); switch($type) { - case 'user': - $options = $this->loadModel('user')->getPairs(); - break; - case 'product': - $options = $this->loadModel('product')->getPairs(); - break; - case 'project': - $options = $this->loadModel('project')->getPairsByProgram(); - break; - case 'execution': - $options = $this->loadModel('execution')->getPairs(); - break; - case 'dept': - $options = $this->loadModel('dept')->getOptionMenu(0); - break; case 'option': - if($field) - { - $path = $this->app->getModuleRoot() . 'dataview' . DS . 'table' . DS . "$object.php"; - if(is_file($path)) - { - include $path; - $options = $schema->fields[$field]['options']; - } - } + $options = $this->bi->getDataviewOptions($object, $field); break; case 'object': - if($field) - { - $table = zget($this->config->objectTables, $object, ''); - if($table) $options = $this->dao->select("id, {$field}")->from($table)->fetchPairs(); - } + $options = $this->bi->getObjectOptions($object, $field); break; - default: - if($field and $sql) + case 'string': + case 'number': + if($sql) { - $cols = $this->dbh->query($sql)->fetchAll(); - foreach($cols as $col) - { - $data = $col->$field; - $options[$data] = $data; - } + $keyField = $field; + $valueField = $saveAs ? $saveAs : $field; + $options = $this->bi->getOptionsFromSql($sql, $keyField, $valueField); } break; } - return $options; + if($sql and $saveAs and in_array($type, array('user', 'product', 'project', 'execution', 'dept', 'option', 'object'))) + { + $options = $this->bi->getOptionsFromSql($sql, $field, $saveAs); + } + + return array_filter($options); } /** diff --git a/module/pivot/model.php b/module/pivot/model.php index 2d09fb79fe..a757ceae0c 100644 --- a/module/pivot/model.php +++ b/module/pivot/model.php @@ -22,6 +22,7 @@ class pivotModel extends model { parent::__construct(); $this->loadBIDAO(); + $this->loadModel('bi'); } /* @@ -2123,74 +2124,48 @@ class pivotModel extends model */ public function getSysOptions($type, $object = '', $field = '', $source = '', $saveAs = '') { - $this->loadModel('bi'); - $options = array('' => ''); + if(in_array($type, array('user', 'product', 'project', 'execution', 'dept'))) return $this->bi->getScopeOptions($type); + if(!$field) return array(); + + $options = array(); switch($type) { - case 'user': - $options = $this->loadModel('user')->getPairs('noletter'); - break; - case 'product': - $options = $this->loadModel('product')->getPairs(); - break; - case 'project': - $options = $this->loadModel('project')->getPairsByProgram(); - break; - case 'execution': - $options = $this->loadModel('execution')->getPairs(); - break; - case 'dept': - $options = $this->loadModel('dept')->getOptionMenu(0); - break; - case 'project.status': - $this->app->loadLang('project'); - $options = $this->lang->project->statusList; - break; case 'option': - if($field) - { - $options = $this->bi->getDataviewOptions($object, $field); - } + $options = $this->bi->getDataviewOptions($object, $field); break; case 'object': - if($field) + if(is_array($source)) { - if(is_array($source)) - { - $options = array(); - foreach($source as $row) $options[$row->id] = $row->$field; - } - else - { - $options = $this->bi->getObjectOptions($object, $field); - } + $options = array(); + foreach($source as $row) $options[$row->id] = $row->$field; + } + else + { + $options = $this->bi->getObjectOptions($object, $field); } break; case 'string': case 'number': - if($field) + if($source) { $options = array(); if(is_array($source)) { foreach($source as $row) $options["{$row->$field}"] = $row->$field; } + else + { + $keyField = $field; + $valueField = $saveAs ? $saveAs : $field; + $options = $this->bi->getOptionsFromSql($source, $keyField, $valueField); + } } break; } - if(is_string($source) and $source) + if(is_string($source) and $source and $saveAs and in_array($type, array('user', 'product', 'project', 'execution', 'dept', 'option', 'object'))) { - if(in_array($type, array('string', 'number'))) - { - $keyField = $field; - $valueField = $saveAs ? $saveAs : $field; - $options = $this->bi->getOptionsFromSql($source, $keyField, $valueField); - } - elseif($saveAs) - { - $options = $this->bi->getOptionsFromSql($source, $field, $saveAs); - } + $options = $this->bi->getOptionsFromSql($source, $field, $saveAs); } return array_filter($options);