* Add getRecords function for calc.
This commit is contained in:
@@ -206,4 +206,41 @@ class baseCalc
|
||||
{
|
||||
return $this->getStatement()->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换计算结果数组为度量记录数据数组。
|
||||
* Get records from result.
|
||||
*
|
||||
* @param array $keyNames
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getRecords($keyNames)
|
||||
{
|
||||
if(empty($keyNames)) return $this->result;
|
||||
|
||||
$records = array();
|
||||
$keyName = array_shift($keyNames);
|
||||
foreach($this->result as $key => $value) $records[] = array($keyName => $key, 'value' => $value);
|
||||
|
||||
while($keyName = array_shift($keyNames))
|
||||
{
|
||||
if($keyName == 'value') break;
|
||||
|
||||
$newRecords = array();
|
||||
foreach($records as $record)
|
||||
{
|
||||
foreach($record['value'] as $key => $value)
|
||||
{
|
||||
$record[$keyName] = $key;
|
||||
$record['value'] = $value;
|
||||
$newRecords[] = $record;
|
||||
}
|
||||
}
|
||||
|
||||
$records = $newRecords;
|
||||
}
|
||||
|
||||
return $records;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,17 +66,7 @@ class consume_of_monthly_closed_project extends baseCalc
|
||||
|
||||
public function getResult($options = array())
|
||||
{
|
||||
$records = array();
|
||||
foreach($this->result as $year => $months)
|
||||
{
|
||||
foreach($months as $month => $projects)
|
||||
{
|
||||
foreach($projects as $project => $value)
|
||||
{
|
||||
$records[] = array('project' => $project, 'year' => $year, 'month' => $month, 'value' => $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
$records = $this->getRecords(array('year', 'month', 'project', 'value'));
|
||||
return $this->filterByOptions($records, $options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,21 +44,7 @@ class count_of_daily_closed_bug_in_product extends baseCalc
|
||||
|
||||
public function getResult($options = array())
|
||||
{
|
||||
$records = array();
|
||||
foreach($this->result as $product => $years)
|
||||
{
|
||||
foreach($years as $year => $months)
|
||||
{
|
||||
foreach($months as $month => $days)
|
||||
{
|
||||
foreach($days as $day => $value)
|
||||
{
|
||||
$records[] = array('product' => $product, 'year' => $year, 'month' => $month, 'day' => $day, 'value' => $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$records = $this->getRecords(array('product', 'year', 'month', 'day'));
|
||||
return $this->filterByOptions($records, $options);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user