relation.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. /**
  3. * 处理关联关系数据。
  4. * Process relation data.
  5. *
  6. * @access public
  7. * @return bool|array
  8. */
  9. public function processRelationData()
  10. {
  11. $formData = array();
  12. foreach($_POST['relation'] as $key => $relationName)
  13. {
  14. $relativeRelationName = zget($_POST['relativeRelation'], $key, '');
  15. if($this->app->getMethodName() == 'createrelation' && empty($relationName) && empty($relativeRelationName)) continue;
  16. if(empty($relationName)) dao::$errors["relation[$key]"] = sprintf($this->lang->error->notempty, $this->lang->custom->relation);
  17. if(empty($relativeRelationName)) dao::$errors["relativeRelation[$key]"] = sprintf($this->lang->error->notempty, $this->lang->custom->relativeRelation);
  18. if(dao::isError()) return false;
  19. $relation = new stdClass();
  20. $relation->relation = $relationName;
  21. $relation->relativeRelation = $relativeRelationName;
  22. $formData[$key] = $relation;
  23. }
  24. return $formData;
  25. }
  26. /**
  27. * 构建搜索表单。
  28. * Build search form.
  29. *
  30. * @param int $objectID
  31. * @param string $objectType
  32. * @param string $relatedObjectType
  33. * @access protected
  34. * @return void
  35. */
  36. protected function buildSearchForm($objectID, $objectType, $relatedObjectType)
  37. {
  38. $actionURL = $this->createLink('custom', 'relateObject', "objectID=$objectID&objectType=$objectType&relatedObjectType=$relatedObjectType&browseType=bySearch");
  39. if(in_array($relatedObjectType, array('epic', 'requirement', 'story'))) $this->loadModel('product')->buildSearchForm(0, array(), 0, $actionURL, $relatedObjectType);
  40. if($relatedObjectType == 'task') $this->loadModel('execution')->buildTaskSearchForm(0, array(), 0, $actionURL);
  41. if($relatedObjectType == 'bug') $this->loadModel('bug')->buildSearchForm(0, array(), 0, $actionURL);
  42. if($relatedObjectType == 'testcase') $this->loadModel('testcase')->buildSearchForm(0, array(), 0, $actionURL);
  43. if($relatedObjectType == 'issue') $this->loadModel('issue')->buildSearchForm($actionURL, 0);
  44. if($relatedObjectType == 'risk') $this->loadModel('risk')->buildSearchForm(0, $actionURL);
  45. if($relatedObjectType == 'feedback') $this->loadModel('feedback')->buildSearchForm($actionURL);
  46. if($relatedObjectType == 'ticket') $this->loadModel('ticket')->buildSearchForm(0, $actionURL, 'all');
  47. if($relatedObjectType == 'design')
  48. {
  49. $this->loadModel('design');
  50. $this->config->design->search['actionURL'] = $actionURL;
  51. $this->config->design->search['queryID'] = 0;
  52. $this->loadModel('search')->setSearchParams($this->config->design->search);
  53. }
  54. if($relatedObjectType == 'doc')
  55. {
  56. $this->loadModel('doc');
  57. $products = $this->loadModel('product')->getPairs();
  58. $projects = $this->loadModel('project')->getPairs();
  59. $executions = $this->loadModel('execution')->getPairs();
  60. $this->config->doc->search['module'] = 'doc';
  61. $this->config->doc->search['actionURL'] = $actionURL;
  62. $this->config->doc->search['queryID'] = 0;
  63. $this->config->doc->search['params']['product']['values'] = $products;
  64. $this->config->doc->search['params']['execution']['values'] = $executions;
  65. $this->config->doc->search['params']['lib']['values'] = $this->doc->getLibPairs('all', 'withObject', 0, '', $products, $projects, $executions);
  66. $this->loadModel('search')->setSearchParams($this->config->doc->search);
  67. }
  68. if($relatedObjectType == 'repocommit')
  69. {
  70. $this->loadModel('repo');
  71. $this->config->repo->repocommitSearch = array();
  72. $this->config->repo->repocommitSearch['module'] = 'repocommit';
  73. $this->config->repo->repocommitSearch['actionURL'] = $actionURL;
  74. $this->config->repo->repocommitSearch['queryID'] = 0;
  75. $this->config->repo->repocommitSearch['fields'] = array();
  76. $this->config->repo->repocommitSearch['params'] = array();
  77. $this->config->repo->repocommitSearch['fields']['revision'] = $this->lang->repo->revisionA;
  78. $this->config->repo->repocommitSearch['fields']['time'] = $this->lang->repo->time;
  79. $this->config->repo->repocommitSearch['fields']['committer'] = $this->lang->repo->committer;
  80. $this->config->repo->repocommitSearch['params']['revision'] = array('operator' => 'include', 'control' => 'input', 'values' => '');
  81. $this->config->repo->repocommitSearch['params']['time'] = array('operator' => '=', 'control' => 'date', 'values' => '');
  82. $this->config->repo->repocommitSearch['params']['committer'] = array('operator' => 'include', 'control' => 'input', 'values' => '');
  83. $this->loadModel('search')->setSearchParams($this->config->repo->repocommitSearch);
  84. }
  85. if($relatedObjectType == 'demand')
  86. {
  87. $this->loadModel('demand');
  88. $this->config->demand->search['module'] = 'demand';
  89. $this->config->demand->search['actionURL'] = $actionURL;
  90. $this->config->demand->search['queryID'] = 0;
  91. $this->config->demand->search['params']['product']['values'] = arrayUnion(array('' => ''), $this->loadModel('product')->getPairs());
  92. $this->config->demand->search['params']['pool']['values'] = arrayUnion(array('' => ''), $this->dao->select('id,name')->from(TABLE_DEMANDPOOL)->where('deleted')->eq(0)->fetchPairs());
  93. $this->loadModel('search')->setSearchParams($this->config->demand->search);
  94. }
  95. if(strpos($relatedObjectType, 'workflow_') !== false)
  96. {
  97. $this->app->loadLang('workflowfield');
  98. $statusList = $this->dao->select('options')->from(TABLE_WORKFLOWFIELD)->where('module')->eq(str_replace('workflow_', '', $relatedObjectType))->andWhere('field')->eq('status')->fetch('options');
  99. $workflowSearch = array();
  100. $workflowSearch['module'] = $relatedObjectType;
  101. $workflowSearch['actionURL'] = $actionURL;
  102. $workflowSearch['queryID'] = 0;
  103. $workflowSearch['fields']['id'] = 'ID';
  104. $workflowSearch['fields']['createdBy'] = $this->lang->workflowfield->default->fields['createdBy'];
  105. $workflowSearch['fields']['assignedTo'] = $this->lang->workflowfield->default->fields['assignedTo'];
  106. $workflowSearch['fields']['status'] = $this->lang->workflowfield->default->fields['status'];
  107. $workflowSearch['params']['id'] = array('operator' => '=', 'control' => 'input', 'values' => '');
  108. $workflowSearch['params']['createdBy'] = array('operator' => '=', 'control' => 'select', 'values' => 'users');
  109. $workflowSearch['params']['assignedTo'] = array('operator' => '=', 'control' => 'select', 'values' => 'users');
  110. $workflowSearch['params']['status'] = array('operator' => '=', 'control' => 'select', 'values' => json_decode($statusList));
  111. $this->loadModel('search')->setSearchParams($workflowSearch);
  112. }
  113. }
  114. /**
  115. * 获取图谱数据。
  116. * Get graph data.
  117. *
  118. * @param array $relatedObjects
  119. * @param int $objectID
  120. * @param string $objectType
  121. * @access protected
  122. * @return array
  123. */
  124. protected function getGraphData($relatedObjects, $objectID, $objectType)
  125. {
  126. $module = in_array($objectType, array('epic', 'requirement', 'story')) ? 'story' : ($objectType == 'repocommit' ? 'repo' : $objectType);
  127. $this->loadModel($module);
  128. $mainObjectInfo = $this->custom->getObjectInfoByType(array($objectType => $objectID));
  129. $mainObjectInfo = $mainObjectInfo[$objectType][$objectID];
  130. $relateObjectFields = $this->config->custom->relateObjectFields;
  131. $relateObjectList = $this->config->custom->relateObjectList;
  132. $relateObjectList['commit'] = $this->config->custom->relateObjectList['repocommit'];
  133. if(!isset($relateObjectList[$objectType])) $relateObjectList[$objectType] = $this->lang->$objectType->common;
  134. $graphData = array();
  135. $graphData['id'] = 'main';
  136. $graphData['objectType'] = $objectType;
  137. $graphData['objectTypeName'] = $relateObjectList[$objectType];
  138. $graphData['objectID'] = $objectID;
  139. $graphData['objectTitle'] = zget($mainObjectInfo, 'title', '');
  140. $graphData['nodeType'] = 'card';
  141. $graphData['children'] = array();
  142. if(strpos($objectType, 'workflow_') === false && $objectType != 'doc')
  143. {
  144. $graphData['objectStatus'] = zget($mainObjectInfo, 'status', '');
  145. $graphData['statusName'] = zget($mainObjectInfo, 'status', '') && isset($relateObjectFields[$objectType]) && in_array('status', $relateObjectFields[$objectType == 'commit' ? 'repocommit' : $objectType]) ? zget($this->lang->$module->statusList, $mainObjectInfo->status, '') : '';
  146. $graphData['objectAssign'] = zget($mainObjectInfo, 'assignedTo', '');
  147. }
  148. foreach($relatedObjects as $relationKey => $objectList)
  149. {
  150. $explodeName = explode('_', $relationKey, 2);
  151. $mainChildren = array();
  152. $mainChildren['id'] = $relationKey;
  153. $mainChildren['text'] = $explodeName[1];
  154. $mainChildren['nodeType'] = 'relation';
  155. $mainChildren['children'] = array();
  156. foreach($objectList as $objectType => $objectInfo)
  157. {
  158. $module = in_array($objectType, array('epic', 'requirement', 'story')) ? 'story' : ($objectType == 'repocommit' ? 'repo' : $objectType);
  159. $this->loadModel($module);
  160. if(!isset($relateObjectList[$objectType])) $relateObjectList[$objectType] = $this->lang->$objectType->common;
  161. foreach($objectInfo as $objectID => $object)
  162. {
  163. $relationChildren = array();
  164. $relationChildren['id'] = "$relationKey-$objectType-$objectID";
  165. $relationChildren['objectType'] = $objectType;
  166. $relationChildren['objectTypeName'] = $relateObjectList[$objectType];
  167. $relationChildren['objectID'] = $objectID;
  168. $relationChildren['objectTitle'] = zget($object, 'title', '');
  169. $relationChildren['objectURL'] = zget($object, 'url', '');
  170. $relationChildren['nodeType'] = 'card';
  171. if(strpos($objectType, 'workflow_') === false && !in_array($objectType, array('release', 'build', 'mr', 'doc')))
  172. {
  173. $relationChildren['objectStatus'] = zget($object, 'status', '');
  174. $relationChildren['statusName'] = isset($relateObjectFields[$objectType]) && in_array('status', $relateObjectFields[$objectType]) ? zget($this->lang->$module->statusList, $object['status'], '') : '';
  175. $relationChildren['objectAssign'] = zget($object, 'assignedTo', '');
  176. }
  177. $mainChildren['children'][] = $relationChildren;
  178. }
  179. }
  180. $graphData['children'][] = $mainChildren;
  181. }
  182. return $graphData;
  183. }