ajaxgetdropmenu.html.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. /**
  3. * The ajaxgetdropmenu view file of execution module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.cnezsoft.com)
  6. * @author Sun Guangming<sunguangming@easycorp.ltd>
  7. * @package execution
  8. * @version $Id
  9. * @link https://www.zentao.net
  10. */
  11. namespace zin;
  12. $executionNames = array();
  13. foreach($projectExecutions as $projectID => $executions)
  14. {
  15. $executionNames = array_merge($executionNames, array_column($executions, 'name'));
  16. }
  17. $executionPinyinNames = common::convert2Pinyin($executionNames);
  18. if(!empty($execution->isTpl))
  19. {
  20. /* 处理分组数据。Process grouped data. */
  21. foreach($projectExecutions as $projectID => $executions)
  22. {
  23. $projectItem = array();
  24. $projectItem['id'] = $projectID;
  25. $projectItem['type'] = 'project';
  26. $projectItem['text'] = zget($projects, $projectID);
  27. $projectItem['items'] = array();
  28. foreach($executions as $index => $execution)
  29. {
  30. $item = array();
  31. $item['id'] = $execution->id;
  32. $item['text'] = $execution->name;
  33. $item['keys'] = zget($executionPinyinNames, $execution->name, '');
  34. $item['url'] = sprintf($link, $execution->id);
  35. if($execution->type == 'stage') $item['url'] = helper::createLink('execution', 'task', "executionID={$execution->id}");
  36. if(!isset($data[$projectID])) $data[$projectID] = $projectItem;
  37. $data[$projectID]['items'][] = $item;
  38. }
  39. }
  40. $data = array_values($data);
  41. /**
  42. * 定义最终的 JSON 数据。
  43. * Define the final json data.
  44. */
  45. $json = array();
  46. $json['data'] = $data;
  47. $json['searchHint'] = $lang->searchAB;
  48. $json['labelMap'] = array('project' => $lang->project->template);
  49. $json['itemType'] = 'execution';
  50. }
  51. else
  52. {
  53. /**
  54. * 获取项目所属分组。
  55. * Get execution group.
  56. *
  57. * @param object $execution
  58. * @return string
  59. */
  60. $getExecutionGroup = function($execution): string
  61. {
  62. global $app;
  63. if($execution->status != 'done' and $execution->status != 'closed' and ($execution->PM == $app->user->account or isset($execution->teams[$app->user->account]))) return 'my';
  64. if($execution->status != 'done' and $execution->status != 'closed' and $execution->PM != $app->user->account and !isset($execution->teams[$app->user->account])) return 'other';
  65. if($execution->status == 'done' or $execution->status == 'closed') return 'closed';
  66. };
  67. /**
  68. * 定义每个分组下的选项数据列表。
  69. * Define the grouped data list.
  70. */
  71. $data = array('my' => array(), 'other' => array(), 'closed' => array());
  72. /**
  73. * 定义执行所属分组。
  74. * Define the group of execution.
  75. */
  76. $executionGroup = array();
  77. /* 处理分组数据。Process grouped data. */
  78. foreach($projectExecutions as $projectID => $executions)
  79. {
  80. $projectItem = array();
  81. $projectItem['id'] = $projectID;
  82. $projectItem['type'] = 'project';
  83. $projectItem['text'] = zget($projects, $projectID);
  84. $projectItem['items'] = array();
  85. foreach($executions as $index => $execution)
  86. {
  87. $group = $executionGroup[$execution->id] = $getExecutionGroup($execution);
  88. $item = array();
  89. $item['id'] = $execution->id;
  90. $item['text'] = $execution->name;
  91. $item['keys'] = zget($executionPinyinNames, $execution->name, '');
  92. $item['url'] = sprintf($link, $execution->id);
  93. if($execution->type == 'stage') $item['url'] = helper::createLink('execution', 'task', "executionID={$execution->id}");
  94. if($execution->type == 'kanban') $item['url'] = helper::createLink('execution', 'kanban', "execution={$execution->id}");
  95. if(strpos($link, 'ajaxSwitchBelong') !== false) $item['url'] = sprintf($link, $execution->id);
  96. if(!isset($data[$group][$projectID])) $data[$group][$projectID] = $projectItem;
  97. $data[$group][$projectID]['items'][] = $item;
  98. }
  99. }
  100. /* 将分组数据转换为索引数组。Format grouped data to indexed array. */
  101. foreach ($data as $key => $value) $data[$key] = array_values($value);
  102. /**
  103. * 定义每个分组名称信息,包括可展开的已关闭分组。
  104. * Define every group name, include expanded group.
  105. */
  106. $tabs = array();
  107. $tabs[] = array('name' => 'my', 'text' => $lang->execution->involved, 'active' => (isset($executionGroup[$executionID]) && $executionGroup[$executionID] === 'my'));
  108. $tabs[] = array('name' => 'other', 'text' => $lang->execution->other, 'active' => (isset($executionGroup[$executionID]) && $executionGroup[$executionID] == 'other'));
  109. $tabs[] = array('name' => 'closed', 'text' => $lang->execution->closedExecution);
  110. /**
  111. * 定义最终的 JSON 数据。
  112. * Define the final json data.
  113. */
  114. $json = array();
  115. $json['data'] = $data;
  116. $json['tabs'] = $tabs;
  117. $json['searchHint'] = $lang->searchAB;
  118. $json['labelMap'] = array('project' => $lang->project->common);
  119. $json['expandName'] = 'closed';
  120. $json['itemType'] = 'execution';
  121. }
  122. /**
  123. * 渲染 JSON 字符串并发送到客户端。
  124. * Render json data to string and send to client.
  125. */
  126. renderJson($json);