PageRenderTime 53ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/test/class/report.class.php

https://github.com/easysoft/zentaopms
PHP | 542 lines | 255 code | 94 blank | 193 comment | 32 complexity | 0435085104aab2a277e7d590e39a267f MD5 | raw file
  1. <?php
  2. class reportTest
  3. {
  4. public function __construct()
  5. {
  6. global $tester;
  7. $this->objectModel = $tester->loadModel('report');
  8. $tester->dao->delete()->from(TABLE_ACTION)->where('id')->gt(100)->exec();
  9. }
  10. /**
  11. * Test compute percent of every item.
  12. *
  13. * @param array $datas
  14. * @access public
  15. * @return string
  16. */
  17. public function computePercentTest($datas)
  18. {
  19. $objects = $this->objectModel->computePercent($datas);
  20. if(dao::isError()) return dao::getError();
  21. $percents = '';
  22. foreach($objects as $moduleID => $object) $percents .= "$moduleID:$object->percent;";
  23. return $percents;
  24. }
  25. /**
  26. * Test create json data of single charts.
  27. *
  28. * @param int $executionID
  29. * @access public
  30. * @return string
  31. */
  32. public function createSingleJSONTest($executionID)
  33. {
  34. global $tester;
  35. $this->execution = $tester->loadModel('execution');
  36. $execution = $this->execution->getByID($executionID);
  37. $sets = $this->execution->getBurnDataFlot($executionID, 'left');
  38. $dateList = $this->execution->getDateList($execution->begin, $execution->end, 'noweekend', 0, 'Y-m-d');
  39. $objects = $this->objectModel->createSingleJSON($sets, $dateList[0]);
  40. if(dao::isError()) return dao::getError();
  41. return $objects;
  42. }
  43. /**
  44. * Test convert date format.
  45. *
  46. * @param array $dateList
  47. * @param string $format
  48. * @access public
  49. * @return string
  50. */
  51. public function convertFormatTest($dateList, $format = 'Y-m-d')
  52. {
  53. $objects = $this->objectModel->convertFormat($dateList, $format = 'Y-m-d');
  54. if(dao::isError()) return dao::getError();
  55. return implode(',', $objects);
  56. }
  57. /**
  58. * Test get executions.
  59. *
  60. * @param int $begin
  61. * @param int $end
  62. * @access public
  63. * @return void
  64. */
  65. public function getExecutionsTest($begin = 0, $end = 0)
  66. {
  67. global $tester;
  68. $tester->dao->update(TABLE_EXECUTION)->set('`status`')->eq('closed')->where('`id`')->in('101,102,103,107,111,121,151,183')->exec();
  69. $begin = $begin != 0 ? date('Y-m-d', strtotime(date('Y-m-d') . $begin)) : 0;
  70. $end = $end != 0 ? date('Y-m-d', strtotime(date('Y-m-d') . $end)) : 0;
  71. $objects = $this->objectModel->getExecutions($begin, $end);
  72. $tester->dao->update(TABLE_EXECUTION)->set('`status`')->eq('wait')->where('`id`')->in('101,103,107,111,121,151,183')->exec();
  73. $tester->dao->update(TABLE_EXECUTION)->set('`status`')->eq('doing')->where('`id`')->in('102')->exec();
  74. if(dao::isError()) return dao::getError();
  75. $executions = '';
  76. foreach($objects as $executionID => $execution) $executions .= "$executionID:$execution->estimate,$execution->consumed,$execution->projectName;";
  77. return $executions;
  78. }
  79. /**
  80. * Test get products.
  81. *
  82. * @param string $conditions
  83. * @param string $storyType
  84. * @access public
  85. * @return string
  86. */
  87. public function getProductsTest($conditions, $storyType = 'story')
  88. {
  89. $objects = $this->objectModel->getProducts($conditions, $storyType);
  90. if(dao::isError()) return dao::getError();
  91. $planCount = 0;
  92. foreach($objects as $object)
  93. {
  94. if(isset($object->plans)) $planCount += count($object->plans);
  95. }
  96. return 'product:' . count($objects) . ';plan:' . $planCount;
  97. }
  98. /**
  99. * Test get bugs.
  100. *
  101. * @param string $begin
  102. * @param string $end
  103. * @param int $product
  104. * @param int $execution
  105. * @access public
  106. * @return array
  107. */
  108. public function getBugsTest($begin, $end, $product, $execution)
  109. {
  110. $begin = date('Y-m-d', strtotime(date('Y-m-d') . $begin));
  111. $end = date('Y-m-d', strtotime(date('Y-m-d') . $end));
  112. $objects = $this->objectModel->getBugs($begin, $end, $product, $execution);
  113. if(dao::isError()) return dao::getError();
  114. $count = array();
  115. foreach($objects as $user => $types)
  116. {
  117. $count[$user] = '';
  118. foreach($types as $type => $typeCount) $count[$user] .= "$type:$typeCount;";
  119. }
  120. return $count;
  121. }
  122. /**
  123. * Test get workload.
  124. *
  125. * @param int $dept
  126. * @param string $assign
  127. * @access public
  128. * @return string
  129. */
  130. public function getWorkloadTest($dept = 0, $assign = 'assign')
  131. {
  132. $objects = $this->objectModel->getWorkload($dept, $assign);
  133. if(dao::isError()) return dao::getError();
  134. $workload = '';
  135. foreach($objects as $user => $work)
  136. {
  137. if(strlen($workload) > 40) break;
  138. $workload .= "$user:";
  139. foreach($work['total'] as $key => $value) $workload .= "$key:$value,";
  140. $workload = trim($workload, ',');
  141. $workload .= ';';
  142. }
  143. return $workload;
  144. }
  145. /**
  146. * Test get bug assign.
  147. *
  148. * @access public
  149. * @return void
  150. */
  151. public function getBugAssignTest()
  152. {
  153. $objects = $this->objectModel->getBugAssign();
  154. if(dao::isError()) return dao::getError();
  155. $count = array();
  156. foreach($objects as $user => $object) $count[$user] = $object['total']['count'];
  157. return $count;
  158. }
  159. /**
  160. * Test get user bugs.
  161. *
  162. * @access public
  163. * @return string
  164. */
  165. public function getUserBugsTest()
  166. {
  167. $objects = $this->objectModel->getUserBugs();
  168. if(dao::isError()) return dao::getError();
  169. $counts = '';
  170. foreach($objects as $user => $bugs) $counts .= "$user:" . count($bugs) . ';';
  171. return $counts;
  172. }
  173. /**
  174. * Test get user tasks.
  175. *
  176. * @access public
  177. * @return string
  178. */
  179. public function getUserTasksTest()
  180. {
  181. $objects = $this->objectModel->getUserTasks();
  182. if(dao::isError()) return dao::getError();
  183. $counts = '';
  184. foreach($objects as $user => $tasks) $counts .= "$user:" . count($tasks) . ';';
  185. return $counts;
  186. }
  187. /**
  188. * Test get user todos.
  189. *
  190. * @access public
  191. * @return string
  192. */
  193. public function getUserTodosTest($userType)
  194. {
  195. $objects = $this->objectModel->getUserTodos();
  196. if(dao::isError()) return dao::getError();
  197. $counts = '';
  198. foreach($objects as $user => $todos)
  199. {
  200. if(strpos($user, $userType) !== false and str_replace($userType, '', $user) < 11) $counts .= "$user:" . count($todos) . ';';
  201. }
  202. return $counts;
  203. }
  204. /**
  205. * Test get user test tasks.
  206. *
  207. * @access public
  208. * @return string
  209. */
  210. public function getUserTestTasksTest()
  211. {
  212. $objects = $this->objectModel->getUserTestTasks();
  213. if(dao::isError()) return dao::getError();
  214. $counts = '';
  215. foreach($objects as $user => $testtasks) $counts .= "$user:" . count($testtasks) . ';';
  216. return $counts;
  217. }
  218. /**
  219. * Test get user login count in this year.
  220. *
  221. * @param string $accounts
  222. * @access public
  223. * @return int
  224. */
  225. public function getUserYearLoginsTest($accounts)
  226. {
  227. $year = date('Y');
  228. $objects = $this->objectModel->getUserYearLogins($accounts, $year);
  229. if(dao::isError()) return dao::getError();
  230. return $objects;
  231. }
  232. /**
  233. * Test get user action count in this year.
  234. *
  235. * @param array $accounts
  236. * @access public
  237. * @return void
  238. */
  239. public function getUserYearActionsTest($accounts)
  240. {
  241. $year = date('Y');
  242. $objects = $this->objectModel->getUserYearActions($accounts, $year);
  243. if(dao::isError()) return dao::getError();
  244. return $objects;
  245. }
  246. /**
  247. * Test get user contributions in this year.
  248. *
  249. * @param array $accounts
  250. * @access public
  251. * @return string
  252. */
  253. public function getUserYearContributionsTest($accounts)
  254. {
  255. $year = date('Y');
  256. $objects = $this->objectModel->getUserYearContributions($accounts, $year);
  257. if(dao::isError()) return dao::getError();
  258. $contributions = '';
  259. foreach($objects as $type => $contributionTypes)
  260. {
  261. $contributions .= "$type:";
  262. foreach($contributionTypes as $contributionType => $count) $contributions .= "$contributionType:$count,";
  263. $contributions = trim($contributions, ',') . ';';
  264. }
  265. return $contributions;
  266. }
  267. /**
  268. * Test get user todo stat in this year.
  269. *
  270. * @param array $accounts
  271. * @access public
  272. * @return string
  273. */
  274. public function getUserYearTodosTest($accounts)
  275. {
  276. $year = date('Y');
  277. $objects = $this->objectModel->getUserYearTodos($accounts, $year);
  278. if(dao::isError()) return dao::getError();
  279. $count = '';
  280. foreach($objects as $type => $value) $count .= "$type:$value;";
  281. return $count;
  282. }
  283. /**
  284. * Test get user effort stat in this error.
  285. *
  286. * @param string $accounts
  287. * @access public
  288. * @return object
  289. */
  290. public function getUserYearEffortsTest($accounts)
  291. {
  292. $year = date('Y');
  293. $object = $this->objectModel->getUserYearEfforts($accounts, $year);
  294. if(dao::isError()) return dao::getError();
  295. return $object;
  296. }
  297. /**
  298. * Test get count of created story,plan and closed story by accounts every product in this year.
  299. *
  300. * @param mixed $accounts
  301. * @access public
  302. * @return void
  303. */
  304. public function getUserYearProductsTest($accounts)
  305. {
  306. $year = date('Y');
  307. $objects = $this->objectModel->getUserYearProducts($accounts, $year);
  308. if(dao::isError()) return dao::getError();
  309. return implode(',', array_keys($objects));
  310. }
  311. /**
  312. * Test get count of finished task, story and resolved bug by accounts every executions in this years.
  313. *
  314. * @param string $accounts
  315. * @access public
  316. * @return string
  317. */
  318. public function getUserYearExecutionsTest($accounts)
  319. {
  320. $year = date('Y');
  321. $objects = $this->objectModel->getUserYearExecutions($accounts, $year);
  322. if(dao::isError()) return dao::getError();
  323. return implode(',', array_keys($objects));
  324. }
  325. /**
  326. * Test get status stat that is all time, include story, task and bug.
  327. *
  328. * @access public
  329. * @return array
  330. */
  331. public function getAllTimeStatusStatTest()
  332. {
  333. $objects = $this->objectModel->getAllTimeStatusStat();
  334. if(dao::isError()) return dao::getError();
  335. $types = array();
  336. foreach($objects as $type => $status)
  337. {
  338. $types[$type] = '';
  339. foreach($status as $statusType => $statusCount) $types[$type] .= "$statusType:$statusCount;";
  340. }
  341. return $types;
  342. }
  343. /**
  344. * Test get year object stat, include status and action stat.
  345. *
  346. * @param string $accounts
  347. * @param string $objectType
  348. * @access public
  349. * @return string
  350. */
  351. public function getYearObjectStatTest($accounts, $objectType)
  352. {
  353. $year = date('Y');
  354. $objects = $this->objectModel->getYearObjectStat($accounts, $year, $objectType);
  355. if(dao::isError()) return dao::getError();
  356. $stats = '';
  357. foreach($objects['statusStat'] as $stat => $count) $stats .= "$stat:$count;";
  358. return $stats;
  359. }
  360. /**
  361. * Test get year case stat, include result and action stat.
  362. *
  363. * @param string $accounts
  364. * @access public
  365. * @return string
  366. */
  367. public function getYearCaseStatTest($accounts)
  368. {
  369. $year = date('Y');
  370. $objects = $this->objectModel->getYearCaseStat($accounts, $year);
  371. if(dao::isError()) return dao::getError();
  372. $result = '';
  373. foreach($objects['resultStat'] as $type => $value) $result .= "$type:$value;";
  374. return $result;
  375. }
  376. /**
  377. * Test get year months.
  378. *
  379. * @param string $year
  380. * @access public
  381. * @return string
  382. */
  383. public function getYearMonthsTest($year)
  384. {
  385. $objects = $this->objectModel->getYearMonths($year);
  386. if(dao::isError()) return dao::getError();
  387. return implode(',', $objects);
  388. }
  389. /**
  390. * Test get status overview.
  391. *
  392. * @param string $objectType
  393. * @param array $statusStat
  394. * @access public
  395. * @return string
  396. */
  397. public function getStatusOverviewTest($objectType, $statusStat)
  398. {
  399. $object = $this->objectModel->getStatusOverview($objectType, $statusStat);
  400. if(dao::isError()) return dao::getError();
  401. return $object;
  402. }
  403. /**
  404. * Test get project status overview.
  405. *
  406. * @param array $accounts
  407. * @access public
  408. * @return string
  409. */
  410. public function getProjectStatusOverviewTest($accounts = array())
  411. {
  412. $objects = $this->objectModel->getProjectStatusOverview($accounts);
  413. if(dao::isError()) return dao::getError();
  414. $counts = '';
  415. foreach($objects as $type => $count) $counts .= "$type:$count;";
  416. return $counts;
  417. }
  418. /**
  419. * Test get output data for API.
  420. *
  421. * @param string $accounts
  422. * @param string $year
  423. * @access public
  424. * @return string
  425. */
  426. public function getOutput4APITest($accounts)
  427. {
  428. $year = date('Y');
  429. $objects = $this->objectModel->getOutput4API($accounts, $year);
  430. if(dao::isError()) return dao::getError();
  431. $output = '';
  432. foreach($objects as $objectType => $object) $output .= "$objectType:" . $object['total'] . ";";
  433. return $output;
  434. }
  435. /**
  436. * Test get project and execution name.
  437. *
  438. * @param bool $count
  439. * @access public
  440. * @return int|array
  441. */
  442. public function getProjectExecutionsTest($count = false)
  443. {
  444. $objects = $this->objectModel->getProjectExecutions();
  445. if(dao::isError()) return dao::getError();
  446. return $count ? count($objects) : $objects;
  447. }
  448. }