diff --git a/module/screen/control.php b/module/screen/control.php index 28915086fb..c6169b7024 100644 --- a/module/screen/control.php +++ b/module/screen/control.php @@ -171,20 +171,23 @@ class screen extends control $mergeFilters[] = $filter; } - if($table == TABLE_PIVOT) + if($type != 'metric') { - list($sql, $filterFormat) = $this->loadModel($type)->getFilterFormat($chart->sql, $mergeFilters); - $chart->sql = $sql; - } - else - { - $filterFormat = $this->loadModel($type)->getFilterFormat($mergeFilters); + if($table == TABLE_PIVOT) + { + list($sql, $filterFormat) = $this->loadModel($type)->getFilterFormat($chart->sql, $mergeFilters); + $chart->sql = $sql; + } + else + { + $filterFormat = $this->loadModel($type)->getFilterFormat($mergeFilters); + } } } if($type == 'metric') { - $chartData = $this->screen->genMetricComponent($chart); + $chartData = $this->screen->genMetricComponent($chart, null, $filterParams); } else { diff --git a/module/screen/model.php b/module/screen/model.php index e49383d789..dafa4e803b 100644 --- a/module/screen/model.php +++ b/module/screen/model.php @@ -322,17 +322,19 @@ class screenModel extends model * Generate metric component. * * @param object $metric + * @param object $component + * @param object $filterParams * @access public * @return object */ - public function genMetricComponent($metric, $component = null) + public function genMetricComponent($metric, $component = null, $filterParams = null) { list($component, $typeChanged) = $this->initMetricComponent($metric, $component); $component->chartConfig->title = $metric->name; $component->chartConfig->sourceID = $metric->id; $component->chartConfig->chartOption = $this->getMetricChartOption($metric); - $component->chartConfig->tableOption = $this->getMetricTableOption($metric); + $component->chartConfig->tableOption = $this->getMetricTableOption($metric, $filterParams); $component->chartConfig->card = $this->getMetricCardOption($metric); $component->chartConfig->filters = $this->buildMetricFilters($metric); @@ -1657,10 +1659,11 @@ class screenModel extends model * Get option of metric table. * * @param object $metric + * @param object $filterParams * @access public * @return object */ - public function getMetricTableOption($metric) + public function getMetricTableOption($metric, $filterParams = null) { $this->loadModel('metric'); @@ -1674,7 +1677,7 @@ class screenModel extends model $tableOption = new stdclass(); $tableOption->headers = $isObjectMetric ? $this->getMetricHeaders($groupHeader, $dateType) : array($groupHeader); - $tableOption->data = $groupData; + $tableOption->data = $this->filterMetricData($groupData, $filterParams); if($metric->scope != 'system') $tableOption->objectPairs = $this->loadModel('metric')->getPairsByScope($metric->scope); $tableOption->scope = $metric->scope; @@ -1686,6 +1689,31 @@ class screenModel extends model return $tableOption; } + /** + * Filter metric data. + * + * @param array $data + * @param array $filter + * @access public + * @return array + */ + public function filterMetricData($data, $filters = null) + { + if(empty($filters)) return $data; + + $objectPairs = $this->loadModel('metric')->getPairsByScope($filters[0]['field']); + + $filteredData = array(); + foreach($data as $row) + { + foreach($filters as $filter) + { + if($row['scope'] == $objectPairs[$filter['default']]) $filteredData[] = $row; + } + } + return $filteredData; + } + /** * 获取度量项卡片参数。 * Get card option of metric.