v1.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace zin;
  3. require_once dirname(__DIR__) . DS . 'datalist' . DS . 'v1.php';
  4. class bugRelatedInfo extends wg
  5. {
  6. /**
  7. * @var mixed[]
  8. */
  9. protected static $defineProps = array
  10. (
  11. 'bug' => '?object', // 当前Bug。
  12. );
  13. protected function getItems()
  14. {
  15. global $lang, $app;
  16. $bug = $this->prop('bug', data('bug'));
  17. if(!$bug) return array();
  18. $project = $this->prop('project', data('project'));
  19. $canViewProduct = common::hasPriv('product', 'view');
  20. $canBrowseExecution = common::hasPriv('execution', 'browse');
  21. $canViewStory = common::hasPriv('story', 'view');
  22. $canViewTask = common::hasPriv('task', 'view');
  23. $executionTitle = isset($project->model) && $project->model == 'kanban' ? $lang->bug->kanban : $lang->bug->execution;
  24. $projectLink = $bug->project && $canViewProduct ? helper::createLink('project', 'view', "projectID={$bug->project}") : '';
  25. $executionLink = $bug->execution && $canBrowseExecution ? helper::createLink('execution', 'browse', "executionID={$bug->execution}") : '';
  26. $storyLink = $bug->story && $canViewStory ? helper::createLink('story', 'view', "storyID={$bug->story}") : '';
  27. $taskLink = $bug->task && $canViewTask ? helper::createLink('task', 'view', "taskID={$bug->task}") : '';
  28. $items = array();
  29. $items[$lang->bug->project] = $projectLink ? array
  30. (
  31. 'control' => 'link',
  32. 'url' => $projectLink,
  33. 'text' => zget($bug, 'projectName', '')
  34. ) : zget($bug, 'projectName', '');
  35. if(empty($project) || !empty($project->multiple))
  36. {
  37. $items[$executionTitle] = $executionLink ? array
  38. (
  39. 'control' => 'link',
  40. 'url' => $executionLink,
  41. 'text' => zget($bug, 'executionName', '')
  42. ) : zget($bug, 'executionName', '');
  43. }
  44. $storyHtml = $bug->story ? div
  45. (
  46. label
  47. (
  48. setClass('gray-outline rounded-full size-sm mr-2'),
  49. $bug->story
  50. ),
  51. $storyLink ? a(
  52. zget($bug, 'storyTitle', ''),
  53. set::href($storyLink),
  54. setData('toggle', 'modal'),
  55. setData('size', 'lg')
  56. ) : span(zget($bug, 'storyTitle', '')),
  57. $bug->storyStatus == 'active' && $bug->latestStoryVersion > $bug->storyVersion && common::hasPriv('bug', 'confirmStoryChange') ? span
  58. (
  59. ' (',
  60. a(set::href(createLink('bug', 'confirmStoryChange', "bugID={$bug->id}")), $lang->confirm),
  61. ')'
  62. ) : null
  63. ) : null;
  64. $items[$lang->bug->story] = array
  65. (
  66. 'control' => 'html',
  67. 'content' => $storyHtml
  68. );
  69. $taskHtml = div
  70. (
  71. label(setClass('gray-outline rounded-full size-sm mr-2'), $bug->task),
  72. $taskLink ? a(
  73. zget($bug, 'taskName', ''),
  74. set::href($taskLink),
  75. setData('toggle', 'modal'),
  76. setData('size', 'lg')
  77. ) : span(zget($bug, 'taskName', ''))
  78. );
  79. $items[$lang->bug->task] = array
  80. (
  81. 'control' => 'html',
  82. 'content' => $bug->task ? $taskHtml : ''
  83. );
  84. return $items;
  85. }
  86. protected function build()
  87. {
  88. return new datalist(set::className('bug-related-info'), set::items($this->getItems()));
  89. }
  90. }