backlog.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace Controller;
  3. class Backlog extends \Controller {
  4. protected $_userId;
  5. public function __construct() {
  6. $this->_userId = $this->_requireLogin();
  7. }
  8. public function index($f3, $params) {
  9. if(empty($params["filter"])) {
  10. $params["filter"] = "groups";
  11. }
  12. if(empty($params["groupid"])) {
  13. $params["groupid"] = "";
  14. }
  15. // Get list of all users in the user's groups
  16. if($params["filter"] == "groups") {
  17. $group_model = new \Model\User\Group();
  18. if(!empty($params["groupid"]) && is_numeric($params["groupid"])) {
  19. //Get users list from a specific Group
  20. $users_result = $group_model->find(array("group_id = ?", $params["groupid"]));
  21. } else {
  22. //Get users list from all groups that you are in
  23. $groups_result = $group_model->find(array("user_id = ?", $this->_userId));
  24. $filter_users = array($this->_userId);
  25. foreach($groups_result as $g) {
  26. $filter_users[] = $g["group_id"];
  27. }
  28. $groups = implode(",", $filter_users);
  29. $users_result = $group_model->find("group_id IN ({$groups})");
  30. }
  31. foreach($users_result as $u) {
  32. $filter_users[] = $u["user_id"];
  33. }
  34. } elseif($params["filter"] == "me") {
  35. //Just get your own id
  36. $filter_users = array($this->_userId);
  37. }
  38. $filter_string = empty($filter_users) ? "" : "AND owner_id IN (" . implode(",", $filter_users) . ")";
  39. $f3->set("filter", $params["filter"]);
  40. $sprint_model = new \Model\Sprint();
  41. $sprints = $sprint_model->find(array("end_date >= ?", $this->now(false)), array("order" => "start_date ASC"));
  42. $issue = new \Model\Issue\Detail();
  43. $sprint_details = array();
  44. foreach($sprints as $sprint) {
  45. $projects = $issue->find(array("deleted_date IS NULL AND sprint_id = ? AND type_id = ? $filter_string", $sprint->id, $f3->get("issue_type.project")),
  46. array('order' => 'priority DESC, due_date')
  47. );
  48. $sprint_details[] = $sprint->cast() + array("projects" => $projects);
  49. }
  50. $large_projects = $f3->get("db.instance")->exec("SELECT parent_id FROM issue WHERE parent_id IS NOT NULL AND type_id = ?", $f3->get("issue_type.project"));
  51. $large_project_ids = array();
  52. foreach($large_projects as $p) {
  53. $large_project_ids[] = $p["parent_id"];
  54. }
  55. if(!empty($large_project_ids)) {
  56. $large_project_ids = implode(",", $large_project_ids);
  57. $unset_projects = $issue->find(array("deleted_date IS NULL AND sprint_id IS NULL AND type_id = ? AND status_closed = '0' AND id NOT IN ({$large_project_ids}) $filter_string", $f3->get("issue_type.project")),
  58. array('order' => 'priority DESC, due_date')
  59. );
  60. } else {
  61. $unset_projects = array();
  62. }
  63. $groups = new \Model\User();
  64. $f3->set("groups", $groups->getAllGroups());
  65. $f3->set("groupid", $params["groupid"]);
  66. $f3->set("sprints", $sprint_details);
  67. $f3->set("backlog", $unset_projects);
  68. $f3->set("title", "Backlog");
  69. $f3->set("menuitem", "backlog");
  70. $this->_render("backlog/index.html");
  71. }
  72. public function edit($f3) {
  73. $post = $f3->get("POST");
  74. $issue = new \Model\Issue();
  75. $issue->load($post["itemId"]);
  76. $issue->sprint_id = empty($post["reciever"]["receiverId"]) ? null : $post["reciever"]["receiverId"];
  77. $issue->save();
  78. $this->_printJson($issue);
  79. }
  80. public function index_old($f3) {
  81. $sprint_model = new \Model\Sprint();
  82. $sprints = $sprint_model->find(array("end_date < ?", $this->now(false)), array("order" => "start_date DESC"));
  83. $issue = new \Model\Issue\Detail();
  84. $sprint_details = array();
  85. foreach($sprints as $sprint) {
  86. $projects = $issue->find(array("deleted_date IS NULL AND sprint_id = ? AND type_id = ?", $sprint->id, $f3->get("issue_type.project")));
  87. $sprint_details[] = $sprint->cast() + array("projects" => $projects);
  88. }
  89. $f3->set("sprints", $sprint_details);
  90. $f3->set("title", "Backlog");
  91. $f3->set("menuitem", "backlog");
  92. $this->_render("backlog/old.html");
  93. }
  94. }