Exemplo n.º 1
0
 /**
  * View a taskboard
  *
  * @param \Base $f3
  * @param array $params
  */
 public function index($f3, $params)
 {
     $sprint = new \Model\Sprint();
     // Load current sprint if no sprint ID is given
     if (!intval($params["id"])) {
         $localDate = date('Y-m-d', \Helper\View::instance()->utc2local());
         $sprint->load(array("? BETWEEN start_date AND end_date", $localDate));
         if (!$sprint->id) {
             $f3->error(404);
             return;
         }
     }
     // Default to showing group tasks
     if (empty($params["filter"])) {
         $params["filter"] = "groups";
     }
     // Load the requested sprint
     if (!$sprint->id) {
         $sprint->load($params["id"]);
         if (!$sprint->id) {
             $f3->error(404);
             return;
         }
     }
     $f3->set("sprint", $sprint);
     $f3->set("title", $sprint->name . " " . date('n/j', strtotime($sprint->start_date)) . "-" . date('n/j', strtotime($sprint->end_date)));
     $f3->set("menuitem", "backlog");
     // Get list of all users in the user's groups
     $filter_users = $this->_filterUsers($params);
     // Load issue statuses
     $status = new \Model\Issue\Status();
     $statuses = $status->find(array('taskboard > 0'), array('order' => 'taskboard_sort ASC'));
     $mapped_statuses = array();
     $visible_status_ids = array();
     $column_count = 0;
     foreach ($statuses as $s) {
         $visible_status_ids[] = $s->id;
         $mapped_statuses[$s->id] = $s;
         $column_count += $s->taskboard;
     }
     $visible_status_ids = implode(",", $visible_status_ids);
     $f3->set("statuses", $mapped_statuses);
     $f3->set("column_count", $column_count);
     // Load issue priorities
     $priority = new \Model\Issue\Priority();
     $f3->set("priorities", $priority->find(null, array("order" => "value DESC"), $f3->get("cache_expire.db")));
     // Load project list
     $issue = new \Model\Issue\Detail();
     // Find all visible tasks
     $tasks = $issue->find(array("sprint_id = ? AND type_id != ? AND deleted_date IS NULL AND status IN ({$visible_status_ids})" . (empty($filter_users) ? "" : " AND owner_id IN (" . implode(",", $filter_users) . ")"), $sprint->id, $f3->get("issue_type.project")), array("order" => "priority DESC"));
     $task_ids = array();
     $parent_ids = array(0);
     foreach ($tasks as $task) {
         $task_ids[] = $task->id;
         if ($task->parent_id) {
             $parent_ids[] = $task->parent_id;
         }
     }
     $task_ids_str = implode(",", $task_ids);
     $parent_ids_str = implode(",", $parent_ids);
     $f3->set("tasks", $task_ids_str);
     // Find all visible projects or parent tasks
     $projects = $issue->find(array("id IN ({$parent_ids_str}) OR (sprint_id = ? AND type_id = ? AND deleted_date IS NULL" . (empty($filter_users) ? ")" : " AND owner_id IN (" . implode(",", $filter_users) . "))"), $sprint->id, $f3->get("issue_type.project")), array("order" => "owner_id ASC, priority DESC"));
     // Sort projects if a filter is given
     if (!empty($params["filter"]) && is_numeric($params["filter"])) {
         $sortModel = new \Model\Issue\Backlog();
         $sortModel->load(array("user_id = ? AND sprint_id = ?", $params["filter"], $sprint->id));
         $sortArray = array();
         if ($sortModel->id) {
             $sortArray = json_decode($sortModel->issues);
             usort($projects, function (\Model\Issue $a, \Model\Issue $b) use($sortArray) {
                 $ka = array_search($a->id, $sortArray);
                 $kb = array_search($b->id, $sortArray);
                 if ($ka === false && $kb !== false) {
                     return -1;
                 }
                 if ($ka !== false && $kb === false) {
                     return 1;
                 }
                 if ($ka === $kb) {
                     return 0;
                 }
                 if ($ka > $kb) {
                     return 1;
                 }
                 if ($ka < $kb) {
                     return -1;
                 }
             });
         }
     }
     // Build multidimensional array of all tasks and projects
     $taskboard = array();
     foreach ($projects as $project) {
         // Build array of statuses to put tasks under
         $columns = array();
         foreach ($statuses as $status) {
             $columns[$status["id"]] = array();
         }
         // Add current project's tasks
         foreach ($tasks as $task) {
             if ($task->parent_id == $project->id || $project->id == 0 && (!$task->parent_id || !in_array($task->parent_id, $parent_ids))) {
                 $columns[$task->status][] = $task;
             }
         }
         // Add hierarchical structure to taskboard array
         $taskboard[] = array("project" => $project, "columns" => $columns);
     }
     $f3->set("taskboard", array_values($taskboard));
     $f3->set("filter", $params["filter"]);
     // Get user list for select
     $users = new \Model\User();
     $f3->set("users", $users->getAll());
     $f3->set("groups", $users->getAllGroups());
     $this->_render("taskboard/index.html");
 }
Exemplo n.º 2
0
 /**
  * POST /sort
  * @param \Base $f3
  * @throws \Exception
  */
 public function sort($f3)
 {
     $this->_requireAdmin();
     $backlog = new \Model\Issue\Backlog();
     $backlog->load(array("user_id = ?", $f3->get("POST.user")));
     $backlog->user_id = $f3->get("POST.user");
     $backlog->issues = $f3->get("POST.items");
     $backlog->save();
 }
Exemplo n.º 3
0
 /**
  * POST /sort
  * @param \Base $f3
  * @throws \Exception
  */
 public function sort($f3)
 {
     $this->_requireLogin(\Model\User::RANK_MANAGER);
     $backlog = new \Model\Issue\Backlog();
     if ($f3->get("POST.sprint_id")) {
         $backlog->load(array("user_id = ? AND sprint_id = ?", $f3->get("POST.user"), $f3->get("POST.sprint_id")));
         $backlog->sprint_id = $f3->get("POST.sprint_id");
     } else {
         $backlog->load(array("user_id = ? AND sprint_id IS NULL", $f3->get("POST.user")));
     }
     $backlog->user_id = $f3->get("POST.user");
     $backlog->issues = $f3->get("POST.items");
     $backlog->save();
 }