| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- <?php
- /**
- * The zen file of report module of ZenTaoPMS.
- *
- * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
- * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
- * @author Mengyi Liu <liumengyi@easycorp.ltd>
- * @package report
- * @link https://www.zentao.net
- */
- class reportZen extends report
- {
- /**
- * 获取每日提醒邮件的内容。
- * Get the content of daily reminder mail.
- *
- * @access public
- * @return array
- */
- protected function getReminder()
- {
- $this->app->loadConfig('message');
- $messageSetting = $this->config->message->setting;
- if(is_string($messageSetting)) $messageSetting = json_decode($messageSetting, true);
- /* Get reminder data. */
- $bugs = $tasks = $todos = $testTasks = $cards = array();
- if($this->config->report->dailyreminder->bug) $bugs = $this->report->getUserBugs();
- if($this->config->report->dailyreminder->task) $tasks = $this->report->getUserTasks();
- if($this->config->report->dailyreminder->todo) $todos = $this->report->getUserTodos();
- if($this->config->report->dailyreminder->testTask) $testTasks = $this->report->getUserTestTasks();
- $cardMailSetting = isset($messageSetting['mail']['setting']['kanbancard']) ? $messageSetting['mail']['setting']['kanbancard'] : array();
- $cardMessageSetting = isset($messageSetting['message']['setting']['kanbancard']) ? $messageSetting['message']['setting']['kanbancard'] : array();
- if(in_array('nearing', $cardMailSetting)) $cards = $this->report->getUserKanbanCards();
- if(in_array('nearing', $cardMessageSetting)) $this->loadModel('kanban')->saveCardNotice($cards);
- /* Get user who need reminders, and set reminder data to them. */
- $reminder = array();
- $users = array_unique(array_merge(array_keys($bugs), array_keys($tasks), array_keys($todos), array_keys($testTasks), array_keys($cards)));
- if(!empty($users)) foreach($users as $user) $reminder[$user] = new stdclass();
- if(!empty($bugs)) foreach($bugs as $user => $bug) $reminder[$user]->bugs = $bug;
- if(!empty($tasks)) foreach($tasks as $user => $task) $reminder[$user]->tasks = $task;
- if(!empty($todos)) foreach($todos as $user => $todo) $reminder[$user]->todos = $todo;
- if(!empty($testTasks)) foreach($testTasks as $user => $testTask) $reminder[$user]->testTasks = $testTask;
- if(!empty($cards)) foreach($cards as $user => $card) $reminder[$user]->cards = $card;
- return $reminder;
- }
- /**
- * 指派年度报告。
- * Assign annual data.
- *
- * @param string $year
- * @param string $dept
- * @param string $account
- * @access public
- * @return void
- */
- protected function assignAnnualReport($year, $dept, $account)
- {
- /* 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);
- $deptEmpty = (int)$dept && empty($accounts);
- /* Get contribution releated data. */
- $contributionGroups = array();
- $maxCount = 0;
- foreach($years as $yearValue)
- {
- $contributionList = $deptEmpty ? array() : $this->report->getUserYearContributions($accounts, $yearValue);
- $max = 0;
- $radarData = array('product' => 0, 'execution' => 0, 'devel' => 0, 'qa' => 0, 'other' => 0);
- if(!empty($contributionList))
- {
- foreach($contributionList as $objectType => $objectContributions)
- {
- $sum = array_sum($objectContributions);
- if($sum > $max) $max = $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;
- }
- }
- else
- {
- $contributionGroups[$yearValue] = $radarData;
- }
- /* If year value is selected, set maxCount. */
- if($yearValue == $year) $maxCount = $max;
- }
- $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->contributionCount = $this->report->getUserYearContributionCount($accounts, $year);
- }
- /**
- * 指派年度报告的基础数据。
- * Assign annual base data.
- *
- * @param string $account
- * @param string $dept
- * @param string $year
- * @access protected
- * @return array
- */
- protected function assignAnnualBaseData($account, $dept, $year)
- {
- /* 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);
- if(!(int)$dept && empty($account)) $accounts = array(); // 如果dept=0,且没有选具体的人,置空让数据查所有人,否则离职的人的数据查不到
- $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] = (string)$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
- {
- unset($depts[0]);
- $depts = array('0' => $this->lang->report->annualData->allDept) + $depts;
- }
- $who = '';
- if(isset($depts[$dept]))
- {
- $who = $depts[$dept];
- if(strpos($who, '/') !== false) $who = substr($who, strrpos($who, '/') + 1);
- }
- if($account) $who = zget($users, $account, '');
- $this->view->title = sprintf($this->lang->report->annualData->title, $who, $year);
- $this->view->depts = $depts;
- $this->view->users = $users;
- return array($years, count($users) - 1, $accounts, $dept, (string)$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($year, $dept, $account, $accounts, $userCount)
- {
- $data = array();
- if(!$account)
- {
- $data['users'] = $dept ? count($accounts) : $userCount;
- }
- else
- {
- $data['logins'] = $this->report->getUserYearLogins($accounts, $year);
- }
- $deptEmpty = (int)$dept && empty($accounts);
- $data['actions'] = $deptEmpty ? 0 : $this->report->getUserYearActions($accounts, $year);
- $data['todos'] = $deptEmpty ? (object)array('count' => 0, 'undone' => 0, 'done' => 0) : $this->report->getUserYearTodos($accounts, $year);
- $data['contributions'] = $deptEmpty ? array() : $this->report->getUserYearContributions($accounts, $year);
- $data['executionStat'] = $deptEmpty ? array() : $this->report->getUserYearExecutions($accounts, $year);
- $data['productStat'] = $deptEmpty ? array() : $this->report->getUserYearProducts($accounts, $year);
- $data['storyStat'] = $deptEmpty ? array('statusStat' => array(), 'actionStat' => array()) : $this->report->getYearObjectStat($accounts, $year, 'story');
- $data['taskStat'] = $deptEmpty ? array('statusStat' => array(), 'actionStat' => array()) : $this->report->getYearObjectStat($accounts, $year, 'task');
- $data['bugStat'] = $deptEmpty ? array('statusStat' => array(), 'actionStat' => array()) : $this->report->getYearObjectStat($accounts, $year, 'bug');
- $data['caseStat'] = $deptEmpty ? array('resultStat' => array(), 'actionStat' => array()) : $this->report->getYearCaseStat($accounts, $year);
- $yearEfforts = $this->report->getUserYearEfforts($accounts, $year);
- $data['consumed'] = $deptEmpty ? 0 : $yearEfforts->consumed;
- if(empty($dept) && empty($account)) $data['statusStat'] = $this->report->getAllTimeStatusStat();
- $this->view->data = $data;
- }
- }
|