xuanxuan.class.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <?php
  2. class xuanxuanMessage extends messageModel
  3. {
  4. /**
  5. * @param string $objectType
  6. * @param int $objectID
  7. * @param string $actionType
  8. * @param int $actionID
  9. * @param string $actor
  10. * @param string $extra
  11. */
  12. public function send($objectType, $objectID, $actionType, $actionID, $actor = '', $extra = '')
  13. {
  14. if(commonModel::isTutorialMode()) return;
  15. $messageSetting = $this->config->message->setting;
  16. if(is_string($messageSetting)) $messageSetting = json_decode($messageSetting, true);
  17. if($objectType == 'instance' && $actionType == 'monitor') return;
  18. if(isset($messageSetting['xuanxuan']))
  19. {
  20. $messageActions = $messageSetting['xuanxuan']['setting'];
  21. if(isset($messageActions[$objectType]) and in_array($actionType, $messageActions[$objectType]))
  22. {
  23. $this->loadModel('action');
  24. $field = 'obj.*';
  25. if($objectType == 'task') $field = 'obj.*,project.name as projectName,execu.name as execuName';
  26. if($objectType == 'story') $field = 'obj.*,product.name as productName';
  27. if($objectType == 'bug') $field = 'obj.*,project.name as projectName,product.name as productName,execu.name as execuName';
  28. if($objectType == 'feedback') $field = 'obj.*,product.name as productName';
  29. if($objectType == 'demand') $field = 'obj.*,pool.name as poolName';
  30. $object = $this->dao->select($field)->from($this->config->objectTables[$objectType])->alias('obj')
  31. ->beginIF($objectType == 'task')
  32. ->leftJoin($this->config->objectTables['project'])->alias('project')->on('project.id = obj.project')
  33. ->leftJoin($this->config->objectTables['execution'])->alias('execu')->on('execu.id = obj.execution')
  34. ->fi()
  35. ->beginIF($objectType == 'story')
  36. ->leftJoin($this->config->objectTables['product'])->alias('product')->on('product.id = obj.product')
  37. ->fi()
  38. ->beginIF($objectType == 'bug')
  39. ->leftJoin($this->config->objectTables['project'])->alias('project')->on('project.id = obj.project')
  40. ->leftJoin($this->config->objectTables['execution'])->alias('execu')->on('execu.id = obj.execution')
  41. ->leftJoin($this->config->objectTables['product'])->alias('product')->on('product.id = obj.product')
  42. ->fi()
  43. ->beginIF($objectType == 'feedback')
  44. ->leftJoin($this->config->objectTables['product'])->alias('product')->on('product.id = obj.product')
  45. ->fi()
  46. ->beginIF($objectType == 'demand')
  47. ->leftJoin($this->config->objectTables['demandpool'])->alias('pool')->on('pool.id = obj.pool')
  48. ->fi()
  49. ->where('obj.id')->eq($objectID)
  50. ->fetch();
  51. $field = $this->config->action->objectNameFields[$objectType];
  52. $title = $objectType == 'mr' ? '' : sprintf($this->lang->message->notifyTitle, $this->app->user->realname, $this->lang->action->label->$actionType, 1, $this->lang->action->objectTypes[$objectType]);
  53. if($objectType == 'story' && $actionType == 'reviewed' && !empty($extra))
  54. {
  55. $notifyExtra = explode(',', $extra);
  56. $notifyType = strtolower($notifyExtra[0]);
  57. if($notifyType == 'pass') $title = sprintf($this->lang->message->notifyPassTitle, $this->app->user->realname, 1);
  58. if($notifyType == 'clarify') $title = sprintf($this->lang->message->notifyClarifyTitle, $this->app->user->realname, 1);
  59. if($notifyType == 'reject') $title = sprintf($this->lang->message->notifyRejectTitle, $this->app->user->realname, 1);
  60. }
  61. if($objectType == 'feedback' && ($actionType == 'tobug' || $actionType == 'tostory' || $actionType == 'totask' || $actionType == 'todo'))
  62. {
  63. if($actionType == 'tobug') $title = sprintf($this->lang->message->feedbackToBugTitle, $this->app->user->realname, 1);
  64. if($actionType == 'tostory') $title = sprintf($this->lang->message->feedbackToStoryTitle, $this->app->user->realname, 1);
  65. if($actionType == 'totask') $title = sprintf($this->lang->message->feedbackToTaskTitle, $this->app->user->realname, 1);
  66. if($actionType == 'todo') $title = sprintf($this->lang->message->feedbackToDoTitle, $this->app->user->realname, 1);
  67. }
  68. $server = $this->loadModel('im')->getServer('zentao');
  69. $dataID = $objectType == 'kanbancard' ? $object->kanban : $objectID;
  70. $url = $server . helper::createLink($objectType == 'kanbancard' ? 'kanban' : $objectType, 'view', "id=$dataID", 'html');
  71. $target = '';
  72. if($objectType == 'feedback')
  73. {
  74. $feedback = $this->loadModel('feedback')->getByID($objectID);
  75. $senderUser = $this->feedback->getToAndCcList($feedback);
  76. if(is_array($senderUser) && !empty($senderUser))
  77. {
  78. foreach($senderUser as $user) $target .= ',' . $user;
  79. }
  80. }
  81. elseif($objectType == 'demandpool')
  82. {
  83. if(!empty($object->owner)) $target .= trim($object->owner, ',');
  84. if(!empty($object->reviewer)) $target .= ',' . trim($object->reviewer, ',');
  85. }
  86. elseif($objectType == 'demand')
  87. {
  88. $target .= $object->createdBy;
  89. if(!empty($object->assignedTo)) $target .= $object->assignedTo == 'closed' ? '' : $object->assignedTo;
  90. if(!empty($object->mailto)) $target .= ",{$object->mailto}";
  91. $reviewers = $this->loadModel('demand')->getReviewerPairs($object->id, $object->version);
  92. $reviewers = array_keys($reviewers);
  93. if($reviewers) $target .= ',' . implode(',', $reviewers);
  94. $target = trim($target, ',');
  95. }
  96. elseif($objectType == 'deploy')
  97. {
  98. $senderUser = $this->loadModel('deploy')->getToAndCcList($object, $actionType);
  99. if(is_array($senderUser) && !empty($senderUser))
  100. {
  101. foreach($senderUser as $user) $target .= ',' . $user;
  102. }
  103. }
  104. else
  105. {
  106. if(!empty($object->assignedTo)) $target .= $object->assignedTo == 'closed' ? $object->openedBy : $object->assignedTo;
  107. if(!empty($object->mailto)) $target .= ",{$object->mailto}";
  108. }
  109. if(($objectType == 'mr' or $objectType == 'kanbancard') and !empty($object->createdBy)) $target .= ",{$object->createdBy}";
  110. $target = trim($target, ',');
  111. $target = explode(',', $target);
  112. $target = $this->dao->select('id')->from(TABLE_USER)
  113. ->where('account')->in($target)
  114. ->beginIF($objectType != 'mr')->andWhere('account')->ne($this->app->user->account)->fi()
  115. ->fetchAll('id');
  116. $target = array_keys($target);
  117. $subContent = (object)array('action' => $actionType, 'object' => $objectID, 'objectName' => $object->$field, 'objectType' => $objectType, 'actor' => $this->app->user->id, 'actorName' => $this->app->user->realname);
  118. $subContent->name = $object->$field;
  119. $subContent->id = sprintf('%03d', $object->id);
  120. $subContent->count = 1;
  121. if($objectType == 'task')
  122. {
  123. $subContent->headTitle = $object->projectName;
  124. $subContent->headSubTitle = $object->execuName;
  125. $subContent->parentType = 'execution';
  126. $subContent->parent = $object->execution;
  127. $subContent->parentURL = "xxc:openInApp/zentao-integrated/" . urlencode($server . helper::createLink('execution', 'task', "id=$object->execution", 'html'));
  128. $subContent->cardURL = $url;
  129. }
  130. elseif($objectType == 'story')
  131. {
  132. $subContent->headTitle = $object->productName;
  133. $subContent->parentType = 'product';
  134. $subContent->parent = $object->product;
  135. $subContent->parentURL = "xxc:openInApp/zentao-integrated/" . urlencode($server . helper::createLink('product', 'browse', "id=$object->product", 'html'));
  136. $subContent->cardURL = $url;
  137. }
  138. elseif($objectType == 'bug')
  139. {
  140. $parentType = empty($object->execuName) ? 'product' : 'project';
  141. $parentNameKey = $parentType . 'Name';
  142. $subContent->headTitle = $object->$parentNameKey;
  143. $subContent->headSubTitle = $object->execuName;
  144. $subContent->parentType = $parentType;
  145. $subContent->parent = $object->$parentType;
  146. $subContent->parentURL = "xxc:openInApp/zentao-integrated/" . urlencode($server . helper::createLink($parentType, 'browse', "id=$subContent->parent", 'html'));
  147. $subContent->cardURL = $url;
  148. }
  149. elseif($objectType == 'feedback')
  150. {
  151. $subContent->headTitle = $object->productName;
  152. $subContent->parentType = 'product';
  153. $subContent->parent = $object->product;
  154. $subContent->parentURL = "xxc:openInApp/zentao-integrated/" . urlencode($server . helper::createLink('feedback', 'browse', "id=$object->product", 'html'));
  155. $subContent->cardURL = $url;
  156. }
  157. elseif($objectType == 'demandpool')
  158. {
  159. $subContent->headTitle = $object->name;
  160. $subContent->parentType = '';
  161. $subContent->parent = 0;
  162. $subContent->parentURL = "xxc:openInApp/zentao-integrated/" . urlencode($server . helper::createLink('demandpool', 'browse', '', 'html'));
  163. $subContent->cardURL = $url;
  164. }
  165. elseif($objectType == 'demand')
  166. {
  167. $subContent->headTitle = $object->poolName;
  168. $subContent->parentType = 'demandpool';
  169. $subContent->parent = $object->pool;
  170. $subContent->parentURL = "xxc:openInApp/zentao-integrated/" . urlencode($server . helper::createLink('demand', 'browse', "id=$object->pool", 'html'));
  171. $subContent->cardURL = $url;
  172. }
  173. elseif($objectType == 'deploy')
  174. {
  175. $subContent->headTitle = $object->name;
  176. $subContent->headSubTitle = $this->lang->devops->deploy;
  177. $subContent->parentType = $objectType;
  178. $subContent->parent = 0;
  179. $subContent->parentURL = "xxc:openInApp/zentao-integrated/" . urlencode($url);
  180. $subContent->cardURL = $url;
  181. }
  182. else
  183. {
  184. $subContent->parentType = $objectType;
  185. }
  186. $contentData = new stdclass();
  187. if($objectType == 'mr')
  188. {
  189. $contentData->contentType = 'text';
  190. $contentData->url = "xxc:openInApp/zentao-integrated/" . urlencode($url);
  191. $contentData->actions = array();
  192. if(is_array($this->lang->message->mr->$actionType))
  193. {
  194. $contentData->content = sprintf($this->lang->message->mr->{$actionType}['creator'], $object->title);
  195. }
  196. else
  197. {
  198. $contentData->content = sprintf($this->lang->message->mr->$actionType, $object->title);
  199. $contentData->actions[] = array(
  200. 'type' => 'normal',
  201. 'label' => $this->lang->message->mr->logTitle,
  202. 'url' => "xxc:openInApp/zentao-integrated/" . urlencode($server . helper::createLink('compile', 'logs', "compileID=$object->compileID", 'html'))
  203. );
  204. }
  205. }
  206. else
  207. {
  208. $contentData->title = $title;
  209. $contentData->subtitle = '';
  210. $contentData->contentType = "zentao-$objectType-$actionType";
  211. $contentData->parentType = $subContent->parentType;
  212. $contentData->content = json_encode($subContent);
  213. $contentData->actions = array();
  214. $contentData->url = "xxc:openInApp/zentao-integrated/" . urlencode($url);
  215. }
  216. $contentData->extra = is_array($extra) ? $extra : '';
  217. $content = json_encode($contentData);
  218. $avatarUrl = $server . $this->app->getWebRoot() . 'favicon.ico';
  219. $objectTypeList = array('bug', 'task', 'story', 'feedback', 'demand', 'demandpool', 'deploy');
  220. if($target && in_array($objectType, $objectTypeList)) $this->loadModel('im')->messageCreateNotify($target, $title, '', $content, 'object', $url, array(), array('id' => 'zentao', 'realname' => $this->lang->message->sender, 'name' => $this->lang->message->sender, 'avatar' => $avatarUrl));
  221. if($objectType == 'mr' and is_array($this->lang->message->mr->$actionType) and !empty($object->assignee))
  222. {
  223. $contentData->content = sprintf($this->lang->message->mr->{$actionType}['reviewer'], $object->title);
  224. $content = json_encode($contentData);
  225. $target = $this->dao->select('id')->from(TABLE_USER)->where('account')->eq($object->assignee)->fetch('id');
  226. if($target) $this->loadModel('im')->messageCreateNotify(array($target), $title, '', $content, 'object', $url, array(), array('id' => 'zentao', 'realname' => $this->lang->message->sender, 'name' => $this->lang->message->sender, 'avatar' => $avatarUrl));
  227. }
  228. }
  229. }
  230. return;
  231. }
  232. }