/** * 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"); }
/** * 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); } } }
public function single_get($f3, $params) { $issue = new \Model\Issue\Detail(); $issue->load($params["id"]); if ($issue->id) { $this->_printJson(array("issue" => $this->_issueMultiArray($issue))); } else { $f3->error(404); } }