storygrade.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * The story grade entry point of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2025 禅道软件(青岛)有限公司(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 Ruogu Liu <liuruogu@chandao.com>
  8. * @package entries
  9. * @version 1
  10. * @link https://www.zentao.net
  11. */
  12. class storygradeEntry extends entry
  13. {
  14. /**
  15. * GET method.
  16. * 获取所有层级
  17. * Get all story grades.
  18. *
  19. * @access public
  20. * @return string
  21. */
  22. public function get()
  23. {
  24. $type = $this->param('type', '');
  25. $status = $this->param('status', 'enable');
  26. $storyModel = $this->loadModel('story');
  27. /* 如果指定了类型,获取该类型的层级列表 */
  28. if($type)
  29. {
  30. $gradeList = $storyModel->getGradeList($type);
  31. }
  32. else
  33. {
  34. /* 获取所有类型的层级,按类型分组 */
  35. $gradeList = array();
  36. $types = array('story', 'requirement', 'epic');
  37. foreach($types as $storyType)
  38. {
  39. $grades = $storyModel->getGradeList($storyType);
  40. if(!empty($grades))
  41. {
  42. foreach($grades as $grade)
  43. {
  44. $gradeList[] = $grade;
  45. }
  46. }
  47. }
  48. }
  49. /* 根据status参数过滤 */
  50. if($status != 'all' && !empty($gradeList))
  51. {
  52. $filteredList = array();
  53. foreach($gradeList as $grade)
  54. {
  55. if(isset($grade->status) && $grade->status == $status)
  56. {
  57. $filteredList[] = $grade;
  58. }
  59. }
  60. $gradeList = $filteredList;
  61. }
  62. /* 格式化返回数据 */
  63. $result = array();
  64. foreach($gradeList as $grade)
  65. {
  66. /* 如果指定了类型,返回数组格式 */
  67. if($type)
  68. {
  69. $result[] = $grade;
  70. }
  71. else
  72. {
  73. /* 如果未指定类型,按类型分组返回 */
  74. $gradeType = isset($grade->type) ? $grade->type : '';
  75. if(!isset($result[$gradeType]))
  76. {
  77. $result[$gradeType] = array();
  78. }
  79. $result[$gradeType][] = $grade;
  80. }
  81. }
  82. return $this->send(200, $result);
  83. }
  84. }