zentaomax.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * 获取单元测试用例列表树。
  4. * Get testtask tree menu.
  5. *
  6. * @param int $taskID
  7. * @param int $startModule
  8. * @param array $userFunc
  9. * @access public
  10. * @return array
  11. */
  12. public function getTestTaskTreeMenu($taskID, $startModule = 0, $userFunc = array())
  13. {
  14. $this->app->loadLang('branch');
  15. $extra['taskID'] = $taskID;
  16. $startModulePath = '';
  17. if($startModule > 0)
  18. {
  19. $startModule = $this->getById($startModule);
  20. if($startModule) $startModulePath = $startModule->path . '%';
  21. }
  22. /* Get module according to product. */
  23. $products = $this->loadModel('testtask')->getTaskProducts($taskID);
  24. $products = $this->dao->select('id, name')->from(TABLE_PRODUCT)->where('id')->in(array_keys($products))->andWhere('deleted')->eq('0')->fetchPairs();
  25. $branchGroups = $this->loadModel('execution')->getBranchByProduct(array_keys($products));
  26. $paths = $this->dao->select('DISTINCT t3.path')->from(TABLE_TESTRUN)->alias('t1')
  27. ->leftJoin(TABLE_CASE)->alias('t2')->on('t1.`case` = t2.id')
  28. ->leftJoin(TABLE_MODULE)->alias('t3')->on('t2.module = t3.id')
  29. ->where('t1.task')->eq($taskID)
  30. ->andWhere('t3.deleted')->eq(0)
  31. ->andWhere('t2.deleted')->eq(0)
  32. ->fetchPairs();
  33. $caseModules = array();
  34. foreach($paths as $path)
  35. {
  36. $modules = explode(',', $path);
  37. foreach($modules as $module) $caseModules[$module] = $module;
  38. }
  39. $modules = array();
  40. $productNum = count($products);
  41. foreach($products as $id => $product)
  42. {
  43. $extra['productID'] = $id;
  44. $data = new stdclass();
  45. $data->id = 'product-' . $id;
  46. $data->parent = 0;
  47. $data->name = $product;
  48. $modules[] = $data;
  49. /* tree menu. */
  50. $tree = '';
  51. $branchGroups[$id][BRANCH_MAIN] = empty($branchGroups[$id]) ? '' : $this->lang->branch->main;
  52. foreach($branchGroups[$id] as $branch => $branchName)
  53. {
  54. $query = $this->dao->select('*')->from(TABLE_MODULE)
  55. ->where('root')->eq((int)$id)
  56. ->andWhere('(type')->eq('case')
  57. ->orWhere('type')->eq('story')
  58. ->markRight(1)
  59. ->beginIF(count($branchGroups[$id]) > 1)->andWhere('branch')->eq($branch)->fi()
  60. ->beginIF($startModulePath)->andWhere('path')->like($startModulePath)->fi()
  61. ->andWhere('deleted')->eq(0)
  62. ->orderBy('grade desc, branch, `order`, type')
  63. ->get();
  64. $stmt = $this->dbh->query($query);
  65. while($module = $stmt->fetch())
  66. {
  67. /* If not manage, ignore unused modules. */
  68. if(isset($caseModules[$module->id]))
  69. {
  70. $childData = $this->buildTree($module, 'case', $data->id, $userFunc, $extra);
  71. if($childData) $modules[] = $childData;
  72. }
  73. }
  74. }
  75. }
  76. return $modules;
  77. }