ajaxgetdropmenu.html.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * The ajaxgetdropmenu view file of caselib module of ZenTaoPMS.
  4. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  5. * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  6. * @author Mengyi Liu <liumengyi@easycorp.ltd>
  7. * @package caselib
  8. * @link https://www.zentao.net
  9. */
  10. namespace zin;
  11. if(in_array("{$module}-{$method}", $config->index->oldPages))
  12. {
  13. include '../view/ajaxgetdropmenu.html.php';
  14. return;
  15. }
  16. $data = array('my' => array(), 'other' => array(), 'closed' => array());
  17. $allProductlink = $module == 'ticket' ? helper::createLink('ticket', 'browse', 'browseType=byProduct&param=all') : helper::createLink('feedback', 'admin', 'browseType=byProduct&param=all');
  18. if($this->config->vision == 'lite' and $module != 'ticket') $allProductlink = helper::createLink('feedback', 'browse', 'browseType=byProduct&param=all');
  19. /**
  20. * 获取产品所属分组。
  21. * Get product group.
  22. *
  23. * @param object $product
  24. * @return string
  25. */
  26. $getProductGroup = function($product): string
  27. {
  28. global $app;
  29. if($product->status == 'normal' and $product->PO == $app->user->account) return 'my';
  30. if($product->status == 'closed') return 'closed';
  31. return 'other';
  32. };
  33. /**
  34. * 定义产品所属分组。
  35. * Define the group of product.
  36. */
  37. $productGroup = array();
  38. /* 处理分组数据。Process grouped data. */
  39. foreach($products as $programID => $programProducts)
  40. {
  41. $programItem = array();
  42. $programItem['id'] = $programID;
  43. $programItem['type'] = 'program';
  44. $programItem['text'] = $programID ? zget($programs, $programID) : $lang->product->emptyProgram;
  45. $programItem['items'] = array();
  46. if(!$programID) $programItem['label'] = '';
  47. foreach($programProducts as $index => $product)
  48. {
  49. $group = $productGroup[$product->id] = $getProductGroup($product);
  50. $name = (in_array($this->config->systemMode, array('ALM', 'PLM')) and $product->line) ? zget($lines, $product->line, '') . ' / ' . $product->name : $product->name;
  51. $item = array();
  52. $item['id'] = $product->id;
  53. $item['text'] = $product->name;
  54. $item['active'] = $productID == $product->id;
  55. $item['keys'] = zget(common::convert2Pinyin(array($product->name)), $product->name, '');
  56. $item['data-app'] = $app->tab;
  57. if($config->systemMode == 'light' || $config->vision == 'or')
  58. {
  59. $data[$group][] = $item;
  60. }
  61. else
  62. {
  63. if(!isset($data[$group][$programID])) $data[$group][$programID] = $programItem;
  64. $data[$group][$programID]['items'][] = $item;
  65. }
  66. }
  67. }
  68. /* 将分组数据转换为索引数组。Format grouped data to indexed array. */
  69. foreach($data as $key => $value) $data[$key] = array_values($value);
  70. /**
  71. * 定义每个分组名称信息,包括可展开的已关闭分组。
  72. * Define every group name, include expanded group.
  73. */
  74. $tabs = array();
  75. $tabs[] = array('name' => 'my', 'text' => $lang->product->mine, 'active' => zget($productGroup, $productID, '') === 'my');
  76. $tabs[] = array('name' => 'other', 'text' => $lang->product->other, 'active' => zget($productGroup, $productID, '') === 'other');
  77. $tabs[] = array('name' => 'closed', 'text' => $lang->product->closedProducts);
  78. /**
  79. * 定义最终的 JSON 数据。
  80. * Define the final json data.
  81. */
  82. $json = array();
  83. $json['data'] = $data;
  84. $json['tabs'] = $tabs;
  85. $json['searchHint'] = $lang->searchAB;
  86. $json['link'] = array('product' => sprintf($link, '{id}'));
  87. $json['labelMap'] = array('program' => $lang->program->common);
  88. $json['expandName'] = 'closed';
  89. $json['itemType'] = 'product';
  90. /**
  91. * 渲染 JSON 字符串并发送到客户端。
  92. * Render json data to string and send to client.
  93. */
  94. renderJson($json);