* Refactor report::annualData.
This commit is contained in:
@@ -2038,4 +2038,16 @@ class actionModel extends model
|
||||
$this->dao->delete()->from(TABLE_ACTIONRECENT)->where('date')->lt($lastMonth)->exec();
|
||||
return !dao::isError();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取最早的动态记录。
|
||||
* Get the first action.
|
||||
*
|
||||
* @access public
|
||||
* @return object|bool
|
||||
*/
|
||||
public function getFirstAction(): object|bool
|
||||
{
|
||||
return $this->dao->select('*')->from(TABLE_ACTION)->orderBy('id')->limit(1)->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -755,4 +755,20 @@ class actionTest
|
||||
|
||||
return count($objects);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试获取第一条动态。
|
||||
* Test get first action.
|
||||
*
|
||||
* @access public
|
||||
* @return array|object
|
||||
*/
|
||||
public function getFirstActionTest(): array|object
|
||||
{
|
||||
$object = $this->objectModel->getFirstAction();
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $object;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/action.class.php';
|
||||
|
||||
zdTable('action')->gen('10');
|
||||
zdTable('user')->gen(10);
|
||||
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 actionModel->getFirstAction();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
|
||||
$action = new actionTest();
|
||||
|
||||
r($action->getFirstActionTest()) && p('id,objectID,objectType') && e('1,1,product'); // 测试获取对象类型 story 对象ID 1 的动态信息
|
||||
+5
-119
@@ -97,6 +97,7 @@ class report extends control
|
||||
}
|
||||
|
||||
/**
|
||||
* 展示年度数据。
|
||||
* Show annual data.
|
||||
*
|
||||
* @param string $year
|
||||
@@ -105,132 +106,17 @@ class report extends control
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function annualData($year = '', $dept = '', $account = '')
|
||||
public function annualData(string $year = '', string $dept = '', string $account = '')
|
||||
{
|
||||
$this->app->loadLang('story');
|
||||
$this->app->loadLang('task');
|
||||
$this->app->loadLang('bug');
|
||||
$this->app->loadLang('testcase');
|
||||
$this->loadModel('dept');
|
||||
$this->loadModel('user');
|
||||
|
||||
$super = common::hasPriv('screen', 'allAnnualData');
|
||||
|
||||
$firstAction = $this->dao->select('*')->from(TABLE_ACTION)->orderBy('id')->limit(1)->fetch();
|
||||
$currentYear = date('Y');
|
||||
$firstYear = empty($firstAction) ? $currentYear : substr($firstAction->date, 0, 4);
|
||||
|
||||
/* Get years for use zentao. */
|
||||
$years = array();
|
||||
for($thisYear = $firstYear; $thisYear <= $currentYear; $thisYear ++) $years[$thisYear] = $thisYear;
|
||||
|
||||
/* Init year when year is empty. */
|
||||
if(empty($year))
|
||||
{
|
||||
$year = date('Y');
|
||||
$month = date('n');
|
||||
if($month <= $this->config->report->annualData['minMonth'])
|
||||
{
|
||||
$year -= 1;
|
||||
if(!isset($years[$year])) $year += 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get users and depts. */
|
||||
if($account)
|
||||
{
|
||||
$user = $this->user->getByID($account);
|
||||
$dept = $user->dept;
|
||||
}
|
||||
|
||||
$userPairs = $this->dept->getDeptUserPairs($dept);
|
||||
$accounts = !empty($user) ? array($user->account) : array_keys($userPairs);
|
||||
$users = array('' => $this->lang->report->annualData->allUser) + $userPairs;
|
||||
|
||||
$noDepartment = array('0' => '/' . $this->lang->dept->noDepartment);
|
||||
$depts = $this->dept->getOptionMenu();
|
||||
if(!$super)
|
||||
{
|
||||
$depts = ($dept and isset($depts[$dept])) ? array($dept => $depts[$dept]) : $noDepartment;
|
||||
}
|
||||
else
|
||||
{
|
||||
$depts = array('' => $this->lang->report->annualData->allDept) + $depts;
|
||||
|
||||
unset($depts[0]);
|
||||
$depts += $noDepartment;
|
||||
}
|
||||
|
||||
/* Get annual data. */
|
||||
$data = array();
|
||||
if(!$account)
|
||||
{
|
||||
$data['users'] = $dept ? count($accounts) : (count($users) - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
$data['logins'] = $this->report->getUserYearLogins($accounts, $year);
|
||||
}
|
||||
|
||||
$data['actions'] = $this->report->getUserYearActions($accounts, $year);
|
||||
$data['todos'] = $this->report->getUserYearTodos($accounts, $year);
|
||||
$data['contributions'] = $this->report->getUserYearContributions($accounts, $year);
|
||||
$data['executionStat'] = $this->report->getUserYearExecutions($accounts, $year);
|
||||
$data['productStat'] = $this->report->getUserYearProducts($accounts, $year);
|
||||
$data['storyStat'] = $this->report->getYearObjectStat($accounts, $year, 'story');
|
||||
$data['taskStat'] = $this->report->getYearObjectStat($accounts, $year, 'task');
|
||||
$data['bugStat'] = $this->report->getYearObjectStat($accounts, $year, 'bug');
|
||||
$data['caseStat'] = $this->report->getYearCaseStat($accounts, $year);
|
||||
|
||||
$yearEfforts = $this->report->getUserYearEfforts($accounts, $year);
|
||||
$data['consumed'] = $yearEfforts->consumed;
|
||||
|
||||
if(empty($dept) and empty($account)) $data['statusStat'] = $this->report->getAllTimeStatusStat();
|
||||
|
||||
$contributionGroups = array();
|
||||
$maxCount = 0;
|
||||
$contributions = 0;
|
||||
foreach($years as $yearValue)
|
||||
{
|
||||
$contributionList = $this->report->getUserYearContributions($accounts, $yearValue);
|
||||
$contributionCount = 0;
|
||||
$max = 0;
|
||||
$radarData = array('product' => 0, 'execution' => 0, 'devel' => 0, 'qa' => 0, 'other' => 0);
|
||||
foreach($contributionList as $objectType => $objectContributions)
|
||||
{
|
||||
$sum = array_sum($objectContributions);
|
||||
if($sum > $max) $max = $sum;
|
||||
$contributionCount += $sum;
|
||||
|
||||
foreach($objectContributions as $actionName => $count)
|
||||
{
|
||||
$radarTypes = isset($this->config->report->annualData['radar'][$objectType][$actionName]) ? $this->config->report->annualData['radar'][$objectType][$actionName] : array('other');
|
||||
foreach($radarTypes as $radarType) $radarData[$radarType] += $count;
|
||||
}
|
||||
$contributionGroups[$yearValue] = $radarData;
|
||||
}
|
||||
|
||||
if($yearValue == $year)
|
||||
{
|
||||
$maxCount = $max;
|
||||
$contributions = $contributionCount;
|
||||
}
|
||||
}
|
||||
|
||||
$this->view->title = sprintf($this->lang->report->annualData->title, ($account ? zget($users, $account, '') : (($dept !== '') ? substr($depts[$dept], strrpos($depts[$dept], '/') + 1) : '')), $year);
|
||||
$this->view->data = $data;
|
||||
$this->view->year = $year;
|
||||
$this->view->users = $users;
|
||||
$this->view->depts = $depts;
|
||||
$this->view->years = $years;
|
||||
$this->view->dept = $dept;
|
||||
$this->view->account = $account;
|
||||
$this->view->months = $this->report->getYearMonths($year);
|
||||
$this->view->contributionGroups = $contributionGroups;
|
||||
$this->view->radarData = $contributionGroups[$year];
|
||||
$this->view->maxCount = $maxCount;
|
||||
$this->view->contributions = $contributions;
|
||||
/* Assign annual data. */
|
||||
$this->reportZen->assignAnnualReport($year, $dept, $account);
|
||||
|
||||
$this->view->account = $account;
|
||||
$this->display();
|
||||
}
|
||||
}
|
||||
|
||||
+158
-1
@@ -11,7 +11,7 @@ declare(strict_types=1);
|
||||
*/
|
||||
class reportZen extends report
|
||||
{
|
||||
/**
|
||||
/**
|
||||
* 获取每日提醒邮件的内容。
|
||||
* Get the content of daily reminder mail.
|
||||
*
|
||||
@@ -37,5 +37,162 @@ class reportZen extends report
|
||||
if(!empty($testTasks)) foreach($testTasks as $user => $testTask) $reminder[$user]->testTasks = $testTask;
|
||||
return $reminder;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指派年度报告。
|
||||
* Assign annual data.
|
||||
*
|
||||
* @param string $year
|
||||
* @param string $dept
|
||||
* @param string $account
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
protected function assignAnnualReport(string $year, string $dept, string $account): void
|
||||
{
|
||||
/* Assign dept, year, years, depts, accounts and users. */
|
||||
list($years, $userCount, $accounts, $dept, $year) = $this->assignAnnualBaseData($account, $dept, $year);
|
||||
|
||||
/* Assign annual data. */
|
||||
$this->assignAnnualData($year, (int)$dept, $account, $accounts, $userCount);
|
||||
|
||||
/* Get contribution releated data. */
|
||||
$contributionGroups = array();
|
||||
$maxCount = $contributions = 0;
|
||||
foreach($years as $yearValue)
|
||||
{
|
||||
$contributionList = $this->report->getUserYearContributions($accounts, $yearValue);
|
||||
$contributionCount = $max = 0;
|
||||
$radarData = array('product' => 0, 'execution' => 0, 'devel' => 0, 'qa' => 0, 'other' => 0);
|
||||
foreach($contributionList as $objectType => $objectContributions)
|
||||
{
|
||||
$sum = array_sum($objectContributions);
|
||||
if($sum > $max) $max = $sum;
|
||||
$contributionCount += $sum;
|
||||
|
||||
foreach($objectContributions as $actionName => $count)
|
||||
{
|
||||
$radarTypes = isset($this->config->report->annualData['radar'][$objectType][$actionName]) ? $this->config->report->annualData['radar'][$objectType][$actionName] : array('other');
|
||||
foreach($radarTypes as $radarType) $radarData[$radarType] += $count;
|
||||
}
|
||||
$contributionGroups[$yearValue] = $radarData;
|
||||
}
|
||||
/* If year value is selected, set maxCount and contributions. */
|
||||
if($yearValue == $year)
|
||||
{
|
||||
$maxCount = $max;
|
||||
$contributions = $contributionCount;
|
||||
}
|
||||
}
|
||||
|
||||
$this->view->dept = $dept;
|
||||
$this->view->year = $year;
|
||||
$this->view->years = $years;
|
||||
$this->view->months = $this->report->getYearMonths($year);
|
||||
$this->view->contributionGroups = $contributionGroups;
|
||||
$this->view->radarData = $contributionGroups[$year];
|
||||
$this->view->maxCount = $maxCount;
|
||||
$this->view->contributions = $contributions;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指派年度报告的基础数据。
|
||||
* Assign annual base data.
|
||||
*
|
||||
* @param string $account
|
||||
* @param string $dept
|
||||
* @param string $year
|
||||
* @access protected
|
||||
* @return array
|
||||
*/
|
||||
protected function assignAnnualBaseData(string $account, string $dept, string $year): array
|
||||
{
|
||||
/* Get users. */
|
||||
if($account)
|
||||
{
|
||||
$user = $this->loadModel('user')->getByID($account);
|
||||
$dept = $user->dept;
|
||||
}
|
||||
$userPairs = $this->loadModel('dept')->getDeptUserPairs((int)$dept);
|
||||
$accounts = !empty($user) ? array($user->account) : array_keys($userPairs);
|
||||
$users = array('' => $this->lang->report->annualData->allUser) + $userPairs;
|
||||
|
||||
$firstAction = $this->loadModel('action')->getFirstAction();
|
||||
$currentYear = date('Y');
|
||||
$firstYear = empty($firstAction) ? $currentYear : substr($firstAction->date, 0, 4);
|
||||
|
||||
/* Get years for use zentao. */
|
||||
$years = array();
|
||||
for($thisYear = $firstYear; $thisYear <= $currentYear; $thisYear ++) $years[$thisYear] = $thisYear;
|
||||
|
||||
/* Init year when year is empty. */
|
||||
if(empty($year))
|
||||
{
|
||||
$year = date('Y');
|
||||
$month = date('n');
|
||||
if($month <= $this->config->report->annualData['minMonth'] && isset($years[$year -1])) $year -= 1;
|
||||
}
|
||||
|
||||
/* Get depts. */
|
||||
$depts = $this->loadModel('dept')->getOptionMenu();
|
||||
$noDepartment = array('0' => '/' . $this->lang->dept->noDepartment);
|
||||
if(!common::hasPriv('screen', 'allAnnualData'))
|
||||
{
|
||||
$depts = $dept && isset($depts[$dept]) ? array($dept => $depts[$dept]) : $noDepartment;
|
||||
}
|
||||
else
|
||||
{
|
||||
$depts = array('' => $this->lang->report->annualData->allDept) + $depts;
|
||||
unset($depts[0]);
|
||||
$depts += $noDepartment;
|
||||
}
|
||||
|
||||
$this->view->title = sprintf($this->lang->report->annualData->title, ($account ? zget($users, $account, '') : ($dept !== '' ? substr($depts[$dept], strrpos($depts[$dept], '/') + 1) : '')), $year);
|
||||
$this->view->depts = $depts;
|
||||
$this->view->users = $users;
|
||||
return array($years, count($users) - 1, $accounts, $dept, $year);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指派年度数据。
|
||||
* Assign annual data.
|
||||
*
|
||||
* @param string $year
|
||||
* @param string|int $dept
|
||||
* @param string $account
|
||||
* @param array $accounts
|
||||
* @param int $userCount
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function assignAnnualData(string $year, string|int $dept, string $account, array $accounts, int $userCount): void
|
||||
{
|
||||
$data = array();
|
||||
if(!$account)
|
||||
{
|
||||
$data['users'] = $dept ? count($accounts) : $userCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
$data['logins'] = $this->report->getUserYearLogins($accounts, $year);
|
||||
}
|
||||
|
||||
$data['actions'] = $this->report->getUserYearActions($accounts, $year);
|
||||
$data['todos'] = $this->report->getUserYearTodos($accounts, $year);
|
||||
$data['contributions'] = $this->report->getUserYearContributions($accounts, $year);
|
||||
$data['executionStat'] = $this->report->getUserYearExecutions($accounts, $year);
|
||||
$data['productStat'] = $this->report->getUserYearProducts($accounts, $year);
|
||||
$data['storyStat'] = $this->report->getYearObjectStat($accounts, $year, 'story');
|
||||
$data['taskStat'] = $this->report->getYearObjectStat($accounts, $year, 'task');
|
||||
$data['bugStat'] = $this->report->getYearObjectStat($accounts, $year, 'bug');
|
||||
$data['caseStat'] = $this->report->getYearCaseStat($accounts, $year);
|
||||
|
||||
$yearEfforts = $this->report->getUserYearEfforts($accounts, $year);
|
||||
$data['consumed'] = $yearEfforts->consumed;
|
||||
|
||||
if(empty($dept) && empty($account)) $data['statusStat'] = $this->report->getAllTimeStatusStat();
|
||||
|
||||
$this->view->data = $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user