/** * Single tag route (/tag/@tag) * @param \Base $f3 * @param array $params */ public function single($f3, $params) { $tag = new \Model\Issue\Tag(); $tag->load(array("tag = ?", $params["tag"])); if (!$tag->id) { $f3->error(404); return; } $issue = new \Model\Issue\Detail(); $issue_ids = implode(',', $tag->issues()); $f3->set("title", "#" . $params["tag"] . " - " . $f3->get("dict.issue_tags")); $f3->set("tag", $tag); $f3->set("issues.subset", $issue->find("id IN ({$issue_ids})")); $this->_render("tag/single.html"); }
public function index_old($f3) { $sprint_model = new \Model\Sprint(); $sprints = $sprint_model->find(array("end_date < ?", $this->now(false)), array("order" => "start_date ASC")); $issue = new \Model\Issue\Detail(); $sprint_details = array(); foreach ($sprints as $sprint) { $projects = $issue->find(array("deleted_date IS NULL AND sprint_id = ? AND type_id = ?", $sprint->id, $f3->get("issue_type.project"))); $sprint_details[] = $sprint->cast() + array("projects" => $projects); } $f3->set("sprints", $sprint_details); $f3->set("title", $f3->get("dict.backlog")); $f3->set("menuitem", "backlog"); $this->_render("backlog/old.html"); }
/** * Send an email to watchers detailing the updated fields * @param int $issue_id */ public function issue_create($issue_id) { $f3 = \Base::instance(); $log = new \Log("mail.log"); if ($f3->get("mail.from")) { $log = new \Log("mail.log"); // Get issue and update data $issue = new \Model\Issue\Detail(); $issue->load($issue_id); $f3->set("issue", $issue); // Get issue parent if set if ($issue->parent_id) { $parent = new \Model\Issue(); $parent->load($issue->parent_id); $f3->set("parent", $parent); } // Get recipient list, keeping current user $recipients = $this->_issue_watchers($issue_id); // Render message body $f3->set("issue", $issue); $text = $this->_render("notification/new.txt"); $body = $this->_render("notification/new.html"); $subject = "[#{$issue->id}] - {$issue->name} created by {$issue->author_name}"; // Send to recipients foreach ($recipients as $recipient) { $this->utf8mail($recipient, $subject, $body, $text); $log->write("Sent create notification to: " . $recipient); } } }
/** * View a taskboard */ public function index($f3, $params) { // Require a valid numeric sprint ID if (!intval($params["id"])) { $f3->error(404); return; } // Default to showing group tasks if (empty($params["filter"])) { $params["filter"] = "groups"; } // Load the requested sprint $sprint = new \Model\Sprint(); $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'), null, $f3->get("cache_expire.db")); $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")); // 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"); }
public function atom($f3) { // Authenticate user if ($f3->get("GET.key")) { $user = new \Model\User(); $user->load(array("api_key = ?", $f3->get("GET.key"))); if (!$user->id) { $f3->error(403); return; } } else { $f3->error(403); return; } // Get requested array substituting defaults $get = $f3->get("GET") + array("type" => "assigned", "user" => $user->username); unset($user); // Load target user $user = new \Model\User(); $user->load(array("username = ?", $get["user"])); if (!$user->id) { $f3->error(404); return; } // Load issues $issue = new \Model\Issue\Detail(); $options = array("order" => "created_date DESC"); if ($get["type"] == "assigned") { $issues = $issue->find(array("author_id = ? AND status_closed = 0 AND deleted_date IS NULL", $user->id), $options); } elseif ($get["type"] == "created") { $issues = $issue->find(array("owner = ? AND status_closed = 0 AND deleted_date IS NULL", $user->id), $options); } elseif ($get["type"] == "all") { $issues = $issue->find("status_closed = 0 AND deleted_date IS NULL", $options + array("limit" => 50)); } else { $f3->error(400, "Invalid feed type"); return; } // Render feed $f3->set("get", $get); $f3->set("feed_user", $user); $f3->set("issues", $issues); $this->_render("index/atom.xml", "application/atom+xml"); }
/** * 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"); }
/** * GET /issues/project/@id * Project Overview action * * @param \Base $f3 * @param array $params */ public function project_overview($f3, $params) { // Load issue $project = new \Model\Issue\Detail(); $project->load($params["id"]); if (!$project->id) { $f3->error(404); return; } if ($project->type_id != $f3->get("issue_type.project")) { $f3->error(400, "Issue is not a project."); return; } /** * Helper function to get a percentage of completed issues and some totals across the entire tree * @param \Model\Issue $issue * @var callable $completeCount This function, required for recursive calls * @return array */ $projectStats = function (\Model\Issue &$issue) use(&$projectStats) { $total = 0; $complete = 0; $hoursSpent = 0; $hoursTotal = 0; if ($issue->id) { $total++; if ($issue->closed_date) { $complete++; } if ($issue->hours_spent > 0) { $hoursSpent += $issue->hours_spent; } if ($issue->hours_total > 0) { $hoursTotal += $issue->hours_total; } foreach ($issue->getChildren() as $child) { $result = $projectStats($child); $total += $result["total"]; $complete += $result["complete"]; $hoursSpent += $result["hours_spent"]; $hoursTotal += $result["hours_total"]; } } return array("total" => $total, "complete" => $complete, "hours_spent" => $hoursSpent, "hours_total" => $hoursTotal); }; $f3->set("stats", $projectStats($project)); /** * Helper function for recursive tree rendering * @param \Model\Issue $issue * @var callable $renderTree This function, required for recursive calls */ $renderTree = function (\Model\Issue &$issue, $level = 0) use(&$renderTree) { if ($issue->id) { $f3 = \Base::instance(); $children = $issue->getChildren(); $hive = array("issue" => $issue, "children" => $children, "dict" => $f3->get("dict"), "BASE" => $f3->get("BASE"), "level" => $level, "issue_type" => $f3->get("issue_type")); echo \Helper\View::instance()->render("issues/project/tree-item.html", "text/html", $hive); if ($children) { foreach ($children as $item) { $renderTree($item, $level + 1); } } } }; $f3->set("renderTree", $renderTree); // Render view $f3->set("project", $project); $f3->set("title", $project->type_name . " #" . $project->id . ": " . $project->name . " - " . $f3->get("dict.project_overview")); $this->_render("issues/project.html"); }
public function single_tree($f3, $params) { $this->_requireLogin(); $user = new \Model\User(); $user->load(array("username = ? AND deleted_date IS NULL", $params["username"])); if ($user->id) { $f3->set("title", $user->name); $f3->set("this_user", $user); // Load assigned issues $issue = new \Model\Issue\Detail(); $assigned = $issue->find(array("closed_date IS NULL AND deleted_date IS NULL AND owner_id = ?", $user->id)); // Build issue list $issues = array(); $assigned_ids = array(); $missing_ids = array(); foreach ($assigned as $iss) { $issues[] = $iss->cast(); $assigned_ids[] = $iss->id; } foreach ($issues as $iss) { if ($iss["parent_id"] && !in_array($iss["parent_id"], $assigned_ids)) { $missing_ids[] = $iss["parent_id"]; } } while (!empty($missing_ids)) { $parents = $issue->find("id IN (" . implode(",", $missing_ids) . ")"); foreach ($parents as $iss) { if (($key = array_search($iss->id, $missing_ids)) !== false) { unset($missing_ids[$key]); } $issues[] = $iss->cast(); $assigned_ids[] = $iss->id; if ($iss->parent_id && !in_array($iss->parent_id, $assigned_ids)) { $missing_ids[] = $iss->parent_id; } } } // Convert list to tree $tree = $this->_buildTree($issues); /** * Helper function for recursive tree rendering * @param Issue $issue * @var callable $renderTree This function, required for recursive calls */ $renderTree = function (&$issue, $level = 0) use(&$renderTree) { if (!empty($issue['id'])) { $f3 = \Base::instance(); $hive = array("issue" => $issue, "dict" => $f3->get("dict"), "BASE" => $f3->get("BASE"), "level" => $level, "issue_type" => $f3->get("issue_type")); echo \Helper\View::instance()->render("issues/project/tree-item.html", "text/html", $hive); if (!empty($issue['children'])) { foreach ($issue['children'] as $item) { $renderTree($item, $level + 1); } } } }; $f3->set("renderTree", $renderTree); // Render view $f3->set("issues", $tree); $this->_render($f3->get("AJAX") ? "user/single/tree/ajax.html" : "user/single/tree.html"); } else { $f3->error(404); } }
public function tag_single($f3, $params) { $tag = new \Model\Issue\Tag(); $issueIds = $tag->issues($params['tag']); $return = array(); if ($issueIds) { $issue = new \Model\Issue\Detail(); $issues = $issue->find(array("id IN (" . implode(",", $issueIds) . ") AND deleted_date IS NULL")); foreach ($issues as $item) { $return[] = $this->_issueMultiArray($item); } } $this->_printJson($return); }
/** * GET /user/@username * * @param \Base $f3 * @param array $params * @throws \Exception */ public function single($f3, $params) { $this->_requireLogin(); $user = new \Model\User(); $user->load(array("username = ?", $params["username"])); if ($user->id && (!$user->deleted_date || $f3->get("user.rank") >= 3)) { $f3->set("title", $user->name); $f3->set("this_user", $user); // Extra arrays required for bulk update $status = new \Model\Issue\Status(); $f3->set("statuses", $status->find(null, null, $f3->get("cache_expire.db"))); $f3->set("users", $user->getAll()); $f3->set("groups", $user->getAllGroups()); $priority = new \Model\Issue\Priority(); $f3->set("priorities", $priority->find(null, array("order" => "value DESC"), $f3->get("cache_expire.db"))); $type = new \Model\Issue\Type(); $f3->set("types", $type->find(null, null, $f3->get("cache_expire.db"))); $issue = new \Model\Issue\Detail(); $f3->set("created_issues", $issue->paginate(0, 200, array("status_closed = '0' AND deleted_date IS NULL AND author_id = ?", $user->id), array("order" => "priority DESC, due_date DESC"))); $f3->set("assigned_issues", $issue->paginate(0, 200, array("status_closed = '0' AND deleted_date IS NULL AND owner_id = ?", $user->id), array("order" => "priority DESC, due_date DESC"))); $f3->set("overdue_issues", $issue->paginate(0, 200, array("status_closed = '0' AND deleted_date IS NULL AND owner_id = ? AND due_date IS NOT NULL AND due_date < ?", $user->id, date("Y-m-d", \Helper\View::instance()->utc2local())), array("order" => "due_date ASC"))); $this->_render("user/single.html"); } else { $f3->error(404); } }