control.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <?php
  2. /**
  3. * The control file of pivot module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.cnezsoft.com)
  6. * @license ZPL(http://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author Chunsheng Wang <chunsheng@cnezsoft.com>
  8. * @package pivot
  9. * @version $Id: control.php 4622 2013-03-28 01:09:02Z chencongzhi520@gmail.com $
  10. * @link https://www.zentao.net
  11. */
  12. class pivot extends control
  13. {
  14. /**
  15. * @param string $moduleName
  16. * @param string $methodName
  17. * @param string $appName
  18. */
  19. public function __construct($moduleName = '', $methodName = '', $appName = '')
  20. {
  21. parent::__construct($moduleName, $methodName, $appName);
  22. $this->dao->exec("SET @@sql_mode=''");
  23. }
  24. /**
  25. * 透视表首页,跳转到访问透视表页面。
  26. * The index of pivot, goto preview.
  27. *
  28. * @access public
  29. * @return void
  30. */
  31. public function index()
  32. {
  33. $this->locate(inlink('preview'));
  34. }
  35. /**
  36. * 访问透视表。
  37. * Preview a pivot.
  38. *
  39. * @param int $dimensionID
  40. * @param int $groupID
  41. * @param string $method
  42. * @param string $params
  43. * @access public
  44. * @return void
  45. */
  46. public function preview($dimensionID = 0, $groupID = 0, $method = '', $params = '')
  47. {
  48. $dimensionID = $this->loadModel('dimension')->getDimension($dimensionID);
  49. if(!$groupID) $groupID = $this->pivot->getFirstGroup($dimensionID);
  50. $params = helper::safe64Decode($params);
  51. if(!$method) list($method, $params) = $this->getDefaultMethodAndParams($dimensionID, $groupID);
  52. if($method && $method != 'show' && !common::hasPriv('pivot', $method)) $this->loadModel('common')->deny('pivot', $method);
  53. parse_str($params, $result);
  54. if(method_exists($this->pivotZen, $method)) call_user_func_array(array($this->pivotZen, $method), $result);
  55. $this->session->set('backDimension', $dimensionID);
  56. $this->session->set('backGroup', $groupID);
  57. if(!$this->view->title) $this->view->title = $this->lang->pivot->preview;
  58. $this->view->groups = $this->loadModel('tree')->getGroupPairs($dimensionID, 0, 1, 'pivot');
  59. $this->view->menus = $this->getSidebarMenus($dimensionID, $groupID, $method, $params);
  60. $this->view->recTotal = count($this->getMenuItems($this->view->menus));
  61. $this->view->dimensionID = $dimensionID;
  62. $this->view->groupID = $groupID;
  63. $this->view->method = $method;
  64. $this->view->params = $params;
  65. $this->display();
  66. }
  67. /**
  68. * 透视表版本列表。
  69. * Show versions of a pivot.
  70. *
  71. * @param int $groupID
  72. * @param int $pivotID
  73. * @param string $version
  74. * @access public
  75. * @return void
  76. */
  77. public function versions($groupID, $pivotID, $version = 'newest')
  78. {
  79. $pivot = $this->pivot->getByID($pivotID);
  80. if($version == 'newest') $version = $this->pivot->getMaxVersion($pivotID);
  81. if($version == 'current') $version = $pivot->version;
  82. $versionSpecs = $this->pivot->getPivotVersions($pivotID);
  83. if(empty($versionSpecs)) $this->sendError($this->lang->pivot->tipNoVersions);
  84. if(strtolower($this->server->request_method) == 'post' && !isset($_POST['preview']))
  85. {
  86. $result = $this->pivot->switchNewVersion($pivotID, $version);
  87. if($result) $this->sendSuccess(array('closeModal' => true, 'message' => $this->lang->saveSuccess, 'load' => true));
  88. }
  89. $this->pivotZen->show($groupID, $pivotID, '', $version);
  90. $marks = array();
  91. if($pivot->builtin == 1)
  92. {
  93. $this->loadModel('mark')->setMark(array($pivotID), 'pivot', $version, 'version');
  94. $marks = $this->loadModel('mark')->getNeededMarks(array($pivotID), 'pivot', 'all', 'version');
  95. }
  96. $this->view->versionSpecs = $versionSpecs;
  97. $this->view->markedVersions = array_column($marks, 'version');
  98. $this->view->builtin = $pivot->builtin;
  99. $this->view->version = $version;
  100. $this->view->groupID = $groupID;
  101. $this->view->pivotID = $pivotID;
  102. $this->display();
  103. }
  104. /**
  105. * Drill data modal.
  106. * 下钻数据的弹窗。
  107. *
  108. * @param int $pivotID
  109. * @param string $colName
  110. * @param string $status
  111. * @param string $drillFields
  112. * @param string $filterValues
  113. * @param string $value
  114. * @access public
  115. * @return void
  116. * @param string $version
  117. * @param string $conditions
  118. */
  119. public function drillModal($pivotID, $version, $colName, $status, $conditions, $filterValues, $value)
  120. {
  121. $drill = $this->pivotZen->getDrill($pivotID, $version, $colName, $status);
  122. $conditions = json_decode(base64_decode($conditions), true);
  123. $filterValues = json_decode(base64_decode($filterValues), true);
  124. $mergeConditions = array();
  125. foreach($drill->condition as $index => $condition)
  126. {
  127. $condition['value'] = $conditions[$index];
  128. $mergeConditions[] = $condition;
  129. }
  130. $pivot = $this->pivot->getByID($pivotID);
  131. $pivotState = $this->pivotZen->initPivotState($pivot, $status == 'design');
  132. $cols = $this->pivot->getDrillCols($drill->object);
  133. $datas = $value == 0 ? array() : $this->pivot->getDrillDatas($pivotState, $drill, $mergeConditions, $filterValues);
  134. if(strpos(',story,task,bug,', ",{$drill->object},") !== false) $datas = $this->pivot->processKanbanDatas($drill->object, $datas);
  135. $this->view->title = $this->lang->pivot->stepDrill->drillView;
  136. $this->view->cols = $cols;
  137. $this->view->datas = $datas;
  138. $this->view->users = $this->loadModel('user')->getPairs('noletter');
  139. $this->display();
  140. }
  141. /**
  142. * AJAX: 获取系统数据下拉选项。
  143. * AJAX: get sys options.
  144. *
  145. * @param string $search
  146. * @param int $limit
  147. * @access public
  148. * @return void
  149. */
  150. public function ajaxGetSysOptions($search = '', $limit = 100)
  151. {
  152. /* Decode search from base64: */
  153. $search = base64_decode($search);
  154. $type = zget($_POST, 'type', '');
  155. $object = zget($_POST, 'object', '');
  156. $field = zget($_POST, 'field', '');
  157. $saveAs = zget($_POST, 'saveAs', '');
  158. $sql = zget($_POST, 'sql', '');
  159. $options = $this->pivot->getSysOptions($type, $object, $field, $sql, $saveAs);
  160. /* 根据关键字过滤选项。*/
  161. /* Filter options by keywords. */
  162. $limitOptions = $options;
  163. if(!empty($search))
  164. {
  165. foreach($limitOptions as $key => $text)
  166. {
  167. if(strpos($text, $search) === false) unset($limitOptions[$key]);
  168. }
  169. }
  170. /* 根据限制数量过滤选项。*/
  171. /* Filter options by limit. */
  172. $limitOptions = array_slice($limitOptions, 0, $limit, true);
  173. /* 添加默认值到选项列表。*/
  174. /* Add default value to options. */
  175. $values = zget($_POST, 'values', '');
  176. if(!empty($values))
  177. {
  178. $values = explode(',', $values);
  179. foreach($values as $value)
  180. {
  181. if(!isset($limitOptions[$value]) && isset($options[$value])) $limitOptions[$value] = $options[$value];
  182. }
  183. }
  184. /* 转换为value text格式。*/
  185. /* Convert to value text format. */
  186. $valueTextList = array();
  187. foreach($limitOptions as $value => $text)
  188. {
  189. $valueTextList[] = array('value' => $value, 'text' => $text);
  190. }
  191. echo json_encode($valueTextList);
  192. }
  193. }