ipd.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /**
  3. * Update the story order of roadmap.
  4. *
  5. * @param int $storyID
  6. * @param string $oldRoadmapIDList
  7. * @param string $roadmapList
  8. * @access public
  9. * @return bool
  10. */
  11. public function updateStoryOrderOfRoadmap($storyID, $roadmapList = '', $oldRoadmapIDList = '')
  12. {
  13. $roadmapList = $roadmapList ? explode(',', $roadmapList) : array();
  14. $oldRoadmapIDList = $oldRoadmapIDList ? explode(',', $oldRoadmapIDList) : array();
  15. /* Get the ids to be inserted and deleted by comparing roadmap ids. */
  16. $roadmapsTobeInsert = array_diff($roadmapList, $oldRoadmapIDList);
  17. $roadmapsTobeDelete = array_diff($oldRoadmapIDList, $roadmapList);
  18. /* Delete old story sort of roadmap. */
  19. if(!empty($roadmapsTobeDelete)) $this->dao->delete()->from(TABLE_ROADMAPSTORY)->where('story')->eq($storyID)->andWhere('roadmap')->in($roadmapsTobeDelete)->exec();
  20. if(!empty($roadmapsTobeInsert))
  21. {
  22. /* Get last story order of roadmap list. */
  23. $maxOrders = $this->dao->select('roadmap, max(`order`) as `order`')->from(TABLE_ROADMAPSTORY)->where('roadmap')->in($roadmapsTobeInsert)->groupBy('roadmap')->fetchPairs();
  24. foreach($roadmapsTobeInsert as $roadmapID)
  25. {
  26. /* Set story order in new roadmap. */
  27. $data = new stdClass();
  28. $data->roadmap = $roadmapID;
  29. $data->story = $storyID;
  30. $data->order = zget($maxOrders, $roadmapID, 0) + 1;
  31. $this->dao->replace(TABLE_ROADMAPSTORY)->data($data)->exec();
  32. }
  33. }
  34. return !dao::isError();
  35. }
  36. /**
  37. * Update the story order according to the roadmap.
  38. *
  39. * @param int $roadmapID
  40. * @param array $sortIDList
  41. * @param string $orderBy
  42. * @param int $pageID
  43. * @param int $recPerPage
  44. * @access public
  45. * @return bool
  46. */
  47. public function sortStoriesOfRoadmap($roadmapID, $sortIDList, $orderBy = 'id_desc', $pageID = 1, $recPerPage = 100)
  48. {
  49. /* Append id for secend sort. */
  50. $orderBy = common::appendOrder($orderBy);
  51. /* Get all stories by roadmap. */
  52. $stories = $this->loadModel('roadmap')->getRoadmapStories($roadmapID, 'all', $orderBy);
  53. $storyIDList = array_keys($stories);
  54. /* Calculate how many numbers there are before the sort list and after the sort list. */
  55. $frontStoryCount = $recPerPage * ($pageID - 1);
  56. $behindStoryCount = $recPerPage * $pageID;
  57. $frontStoryIDList = array_slice($storyIDList, 0, $frontStoryCount);
  58. $behindStoryIDList = array_slice($storyIDList, $behindStoryCount, count($storyIDList) - $behindStoryCount);
  59. /* Merge to get a new sort list. */
  60. $newSortIDList = array_merge($frontStoryIDList, $sortIDList, $behindStoryIDList);
  61. if(strpos($orderBy, 'order_desc') !== false) $newSortIDList = array_reverse($newSortIDList);
  62. /* Loop update the story order of roadmap. */
  63. $order = 1;
  64. foreach($newSortIDList as $storyID)
  65. {
  66. $this->dao->update(TABLE_ROADMAPSTORY)->set('`order`')->eq($order)->where('story')->eq($storyID)->andWhere('roadmap')->eq($roadmapID)->exec();
  67. $order++;
  68. }
  69. return !dao::isError();
  70. }
  71. /**
  72. * Batch change the roadmap of story.
  73. *
  74. * @param array $storyIdList
  75. * @param int $roadmapID
  76. * @access public
  77. * @return array
  78. */
  79. public function batchChangeRoadmap($storyIdList, $roadmapID)
  80. {
  81. return $this->loadExtension('ipd')->batchChangeRoadmap($storyIdList, $roadmapID);
  82. }
  83. /**
  84. * Batch create stories.
  85. *
  86. * @param array $stories
  87. * @access public
  88. * @return array
  89. */
  90. public function batchCreate($stories)
  91. {
  92. return $this->loadExtension('ipd')->batchCreate($stories);
  93. }
  94. /**
  95. * Batch update stories.
  96. *
  97. * @param array $stories
  98. * @access public
  99. * @return array
  100. */
  101. public function batchUpdate($stories)
  102. {
  103. return $this->loadExtension('ipd')->batchUpdate($stories);
  104. }
  105. /**
  106. * Append affected stories.
  107. *
  108. * @param object $story
  109. * @access public
  110. * @return bool
  111. */
  112. public function getAffectedScope($story)
  113. {
  114. return $this->loadExtension('ipd')->getAffectedScope($story);
  115. }
  116. /**
  117. * @param mixed[] $stories
  118. * @param string $storyType
  119. * @param mixed[] $demands
  120. */
  121. public function getTracksByStories($stories, $storyType, $demands = array())
  122. {
  123. return $this->loadExtension('ipd')->getTracksByStories($stories, $storyType, $demands);
  124. }