* Filter metric's data for screen designer.
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
||||
+32
-4
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user