public function dashboard($f3, $params) { $issue = new \Model\Issue\Detail(); // Add user's group IDs to owner filter $owner_ids = array($this->_userId); $groups = new \Model\User\Group(); foreach ($groups->find(array("user_id = ?", $this->_userId)) as $r) { $owner_ids[] = $r->group_id; } $owner_ids = implode(",", $owner_ids); $order = "priority DESC, has_due_date ASC, due_date ASC"; $projects = $issue->find(array("owner_id IN ({$owner_ids}) AND type_id=:type AND deleted_date IS NULL AND closed_date IS NULL AND status_closed = 0", ":type" => $f3->get("issue_type.project")), array("order" => $order)); $subprojects = array(); foreach ($projects as $i => $project) { if ($project->parent_id) { $subprojects[] = $project; unset($projects[$i]); } } $f3->set("projects", $projects); $f3->set("subprojects", $subprojects); $f3->set("bugs", $issue->find(array("owner_id IN ({$owner_ids}) AND type_id=:type AND deleted_date IS NULL AND closed_date IS NULL AND status_closed = 0", ":type" => $f3->get("issue_type.bug")), array("order" => $order))); $f3->set("repeat_issues", $issue->find(array("owner_id IN ({$owner_ids}) AND deleted_date IS NULL AND closed_date IS NULL AND status_closed = 0 AND repeat_cycle NOT IN ('none', '')", ":type" => $f3->get("issue_type.bug")), array("order" => $order))); $watchlist = new \Model\Issue\Watcher(); $f3->set("watchlist", $watchlist->findby_watcher($this->_userId, $order)); $tasks = new \Model\Issue\Detail(); $f3->set("tasks", $tasks->find(array("owner_id IN ({$owner_ids}) AND type_id=:type AND deleted_date IS NULL AND closed_date IS NULL AND status_closed = 0", ":type" => $f3->get("issue_type.task")), array("order" => $order))); // Get current sprint if there is one $sprint = new \Model\Sprint(); $sprint->load("NOW() BETWEEN start_date AND end_date"); $f3->set("sprint", $sprint); $f3->set("menuitem", "index"); $this->_render("user/dashboard.html"); }
public function getOwnerIds() { if ($this->_ownerIds) { return $this->_ownerIds; } $f3 = \Base::instance(); $this->_ownerIds = array($f3->get("user.id")); $groups = new \Model\User\Group(); foreach ($groups->find(array("user_id = ?", $f3->get("user.id"))) as $r) { $this->_ownerIds[] = $r->group_id; } return $this->_ownerIds; }
/** * Get a list of users from a filter * @param string $params URL Parameters * @return array */ protected function _filterUsers($params) { if ($params["filter"] == "groups") { $group_model = new \Model\User\Group(); $groups_result = $group_model->find(array("user_id = ?", $this->_userId)); $filter_users = array($this->_userId); foreach ($groups_result as $g) { $filter_users[] = $g["group_id"]; } $groups = implode(",", $filter_users); $users_result = $group_model->find("group_id IN ({$groups})"); foreach ($users_result as $u) { $filter_users[] = $u["user_id"]; } } elseif ($params["filter"] == "me") { $filter_users = array($this->_userId); } elseif (is_numeric($params["filter"])) { $user = new \Model\User(); $user->load($params["filter"]); if ($user->role == 'group') { $group_model = new \Model\User\Group(); $users_result = $group_model->find(array("group_id = ?", $user->id)); $filter_users = array(intval($params["filter"])); foreach ($users_result as $u) { $filter_users[] = $u["user_id"]; } } else { $filter_users = array($params["filter"]); } } elseif ($params["filter"] == "all") { return array(); } else { return array($this->_userId); } return $filter_users; }
/** * GET /backlog * GET /backlog/@filter * GET /backlog/@filter/@groupid * * @param \Base $f3 * @param array $params */ public function index($f3, $params) { if (empty($params["filter"])) { $params["filter"] = "groups"; } if (empty($params["groupid"])) { $params["groupid"] = ""; } // Get list of all users in the user's groups if ($params["filter"] == "groups") { $group_model = new \Model\User\Group(); if (!empty($params["groupid"]) && is_numeric($params["groupid"])) { //Get users list from a specific Group $users_result = $group_model->find(array("group_id = ?", $params["groupid"])); } else { //Get users list from all groups that you are in $groups_result = $group_model->find(array("user_id = ?", $this->_userId)); $filter_users = array($this->_userId); foreach ($groups_result as $g) { $filter_users[] = $g["group_id"]; } $groups = implode(",", $filter_users); $users_result = $group_model->find("group_id IN ({$groups})"); } foreach ($users_result as $u) { $filter_users[] = $u["user_id"]; } } elseif ($params["filter"] == "me") { //Just get your own id $filter_users = array($this->_userId); } $filter_string = empty($filter_users) ? "" : "AND owner_id IN (" . implode(",", $filter_users) . ")"; $f3->set("filter", $params["filter"]); $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 = ? {$filter_string}", $sprint->id, $f3->get("issue_type.project")), array('order' => 'priority DESC, due_date')); $sprint_details[] = $sprint->cast() + array("projects" => $projects); } $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")); $large_project_ids = array(); foreach ($large_projects as $p) { $large_project_ids[] = $p["parent_id"]; } // Load backlog if (!empty($large_project_ids)) { $large_project_ids = implode(",", $large_project_ids); $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")), array('order' => 'priority DESC, due_date')); } else { $unset_projects = $issue->find(array("deleted_date IS NULL AND sprint_id IS NULL AND type_id = ? AND status_closed = '0' {$filter_string}", $f3->get("issue_type.project")), array('order' => 'priority DESC, due_date')); } // Filter projects into sorted and unsorted arrays if filtering by group if (!empty($params["groupid"])) { // Add sorted projects $backlog = array(); $sortModel = new \Model\Issue\Backlog(); $sortModel->load(array("user_id = ?", $params["groupid"])); $sortArray = array(); if ($sortModel->id) { $sortArray = json_decode($sortModel->issues); foreach ($sortArray as $id) { foreach ($unset_projects as $p) { if ($p->id == $id) { $backlog[] = $p; } } } } // Add remaining projects $unsorted = array(); foreach ($unset_projects as $p) { if (!in_array($p->id, $sortArray)) { $unsorted[] = $p; } } } else { $backlog = $unset_projects; } $groups = new \Model\User(); $f3->set("groups", $groups->getAllGroups()); $f3->set("groupid", $params["groupid"]); $f3->set("sprints", $sprint_details); $f3->set("backlog", $backlog); $f3->set("unsorted", $unsorted); $f3->set("title", $f3->get("dict.backlog")); $f3->set("menuitem", "backlog"); $this->_render("backlog/index.html"); }
/** * Build a WHERE clause for issue listings based on the current filters and sort options * * @return array */ protected function _buildFilter() { $f3 = \Base::instance(); $db = $f3->get("db.instance"); $issues = new \Model\Issue\Detail(); // Filter issue listing by URL parameters $filter = array(); $args = $f3->get("GET"); foreach ($args as $key => $val) { if (!empty($val) && !is_array($val) && $issues->exists($key)) { $filter[$key] = $val; } } unset($val); // Build SQL string to use for filtering $filter_str = ""; foreach ($filter as $i => $val) { if ($i == "name") { $filter_str .= "`{$i}` LIKE " . $db->quote("%{$val}%") . " AND "; } elseif ($i == "status" && $val == "open") { $filter_str .= "status_closed = 0 AND "; } elseif ($i == "status" && $val == "closed") { $filter_str .= "status_closed = 1 AND "; } elseif ($i == "repeat_cycle" && $val == "repeat") { $filter_str .= "repeat_cycle IS NOT NULL AND "; } elseif ($i == "repeat_cycle" && $val == "none") { $filter_str .= "repeat_cycle IS NULL AND "; } elseif (($i == "author_id" || $i == "owner_id") && !empty($val) && is_numeric($val)) { // Find all users in a group if necessary $user = new \Model\User(); $user->load($val); if ($user->role == 'group') { $group_users = new \Model\User\Group(); $list = $group_users->find(array('group_id = ?', $val)); $garray = array($val); // Include the group in the search foreach ($list as $obj) { $garray[] = $obj->user_id; } $filter_str .= "{$i} in (" . implode(",", $garray) . ") AND "; } else { // Just select by user $filter_str .= "{$i} = " . $db->quote($val) . " AND "; } } else { $filter_str .= "`{$i}` = " . $db->quote($val) . " AND "; } } unset($val); $filter_str .= " deleted_date IS NULL "; // Build SQL ORDER BY string $orderby = !empty($args['orderby']) ? $args['orderby'] : "priority"; $filter["orderby"] = $orderby; $ascdesc = !empty($args['ascdesc']) && strtolower($args['ascdesc']) == 'asc' ? "ASC" : "DESC"; $filter["ascdesc"] = $ascdesc; switch ($orderby) { case "id": $filter_str .= " ORDER BY id {$ascdesc} "; break; case "title": $filter_str .= " ORDER BY name {$ascdesc}"; break; case "type": $filter_str .= " ORDER BY type_id {$ascdesc}, priority DESC, due_date DESC "; break; case "status": $filter_str .= " ORDER BY status {$ascdesc}, priority DESC, due_date DESC "; break; case "parent_id": $filter_str .= " ORDER BY parent_id {$ascdesc}, priority DESC, due_date DESC "; break; case "author": $filter_str .= " ORDER BY author_name {$ascdesc}, priority DESC, due_date DESC "; break; case "assignee": $filter_str .= " ORDER BY owner_name {$ascdesc}, priority DESC, due_date DESC "; break; case "created": $filter_str .= " ORDER BY created_date {$ascdesc}, priority DESC, due_date DESC "; break; case "due": $filter_str .= " ORDER BY due_date {$ascdesc}, priority DESC"; break; case "sprint": $filter_str .= " ORDER BY sprint_start_date {$ascdesc}, priority DESC, due_date DESC "; break; case "closed": $filter_str .= " ORDER BY closed_date {$ascdesc}, priority DESC, due_date DESC "; break; case "priority": default: $filter_str .= " ORDER BY priority {$ascdesc}, due_date DESC "; break; } return array($filter, $filter_str); }
/** * Send an email alert with issues due on the given date * @param string $date * @return bool */ public function sendDueAlert($date = '') { if (!$this->id) { return false; } if (!$date) { $date = date("Y-m-d", \Helper\View::instance()->utc2local()); } // Get group owner IDs $ownerIds = array($this->id); $groups = new \Model\User\Group(); foreach ($groups->find(array("user_id = ?", $this->id)) as $r) { $ownerIds[] = $r->group_id; } $ownerStr = implode(",", $ownerIds); // Find issues assigned to user or user's group $issue = new Issue(); $issues = $issue->find(array("due_date = ? AND owner_id IN({$ownerStr}) AND closed_date IS NULL AND deleted_date IS NULL", $date), array("order" => "priority DESC")); if ($issues) { $notif = new \Helper\Notification(); return $notif->user_due_issues($this, $issues); } else { return false; } }