Example #1
0
 public function edit($f3)
 {
     $post = $f3->get("POST");
     $issue = new \Model\Issue();
     $issue->load($post["itemId"]);
     $issue->sprint_id = empty($post["reciever"]["receiverId"]) ? null : $post["reciever"]["receiverId"];
     $issue->save();
     $this->_printJson($issue);
 }
Example #2
0
 /**
  * Update an existing task
  */
 public function edit($f3, $params)
 {
     $post = $f3->get("POST");
     $issue = new \Model\Issue();
     $issue->load($post["taskId"]);
     if (!empty($post["receiver"])) {
         if ($post["receiver"]["story"]) {
             $issue->parent_id = $post["receiver"]["story"];
         }
         $issue->status = $post["receiver"]["status"];
         $status = new \Model\Issue\Status();
         $status->load($issue->status);
         if ($status->closed) {
             if (!$issue->closed_date) {
                 $issue->closed_date = $this->now();
             }
         } else {
             $issue->closed_date = null;
         }
     } else {
         $issue->name = $post["title"];
         $issue->description = $post["description"];
         $issue->owner_id = $post["assigned"];
         $issue->hours_remaining = $post["hours"];
         $issue->hours_spent += $post["hours_spent"];
         if (!empty($post["hours_spent"]) && !empty($post["burndown"])) {
             $issue->hours_remaining -= $post["hours_spent"];
         }
         if ($issue->hours_remaining < 0) {
             $issue->hours_remaining = 0;
         }
         if (!empty($post["dueDate"])) {
             $issue->due_date = date("Y-m-d", strtotime($post["dueDate"]));
         } else {
             $issue->due_date = null;
         }
         if (!empty($post["repeat_cycle"])) {
             $issue->repeat_cycle = $post["repeat_cycle"];
         }
         $issue->priority = $post["priority"];
         if (!empty($post["storyId"])) {
             $issue->parent_id = $post["storyId"];
         }
         $issue->title = $post["title"];
     }
     if (!empty($post["comment"])) {
         $comment = new \Model\Issue\Comment();
         $comment->user_id = $this->_userId;
         $comment->issue_id = $issue->id;
         if (!empty($post["hours_spent"])) {
             $comment->text = trim($post["comment"]) . sprintf(" (%s %s spent)", $post["hours_spent"], $post["hours_spent"] == 1 ? "hour" : "hours");
         } else {
             $comment->text = $post["comment"];
         }
         $comment->created_date = $this->now();
         $comment->save();
         $issue->update_comment = $comment->id;
     }
     $issue->save();
     $this->_printJson($issue->cast() + array("taskId" => $issue->id));
 }
Example #3
0
<?php

/**
 * Tests the Issue model's core functionality
 * @package  Test
 * @author   Alan Hardman <*****@*****.**>
 */
require_once "base.php";
$test = new Test();
$issue = new Model\Issue();
$test->expect($issue->load(1) && $issue->id == 1, "Issue->load() by Integer");
$test->expect($issue->load(array('id = ?', 1)) && $issue->id == 1, "Issue->load() by String");
$test->expect(is_array($issue->getChildren()), "Issue->getChildren()");
$test->expect(is_array($issue->getAncestors()), "Issue->getAncestors()");
$test->expect($issue->save(false) && $issue->id, "Issue->save() without notifications");
// Output results
showResults($test);
Example #4
0
     if (!empty($issue->id)) {
         $comment = new \Model\Issue\Comment();
         $comment->user_id = $author;
         $comment->issue_id = $issue->id;
         $comment->text = html_entity_decode(strip_tags($message));
         $comment->created_date = date("Y-m-d H:i:s");
         $comment->save();
         $notification = \Helper\Notification::instance();
         $notification->issue_comment($issue->id, $comment->id);
     } else {
         $issue->name = $header->subject;
         $issue->description = html_entity_decode(strip_tags($message));
         $issue->author_id = $author;
         $issue->owner_id = $owner;
         $issue->type_id = 1;
         $issue->save();
         $log->write('Saved issue ' . $issue->id);
     }
 }
 if (!empty($issue->id)) {
     // add other recipients as watchers
     if (!empty($header->cc) || count($header->to) > 1) {
         if (!empty($header->cc)) {
             $watchers = array_merge($header->to, $header->cc);
         } else {
             $watchers = $header->to;
         }
         foreach ($watchers as $more_people) {
             $watcher_email = $more_people->mailbox . "@" . $more_people->host;
             $watcher = new \Model\User();
             $watcher->load(array('email=? AND (deleted_date IS NULL OR deleted_date != ?)', $watcher_email, '0000-00-00 00:00:00'));
Example #5
0
 /**
  * Save an updated issue
  *
  * @return \Model\Issue
  */
 protected function _saveUpdate()
 {
     $f3 = \Base::instance();
     $post = array_map("trim", $f3->get("POST"));
     $issue = new \Model\Issue();
     // Load issue and return if not set
     $issue->load($post["id"]);
     if (!$issue->id) {
         return $issue;
     }
     // Diff contents and save what's changed.
     $hashState = json_decode($post["hash_state"]);
     foreach ($post as $i => $val) {
         if ($issue->exists($i) && $i != "id" && $issue->{$i} != $val && md5($val) != $hashState->{$i}) {
             if (empty($val)) {
                 $issue->{$i} = null;
             } else {
                 $issue->{$i} = $val;
                 if ($i == "status") {
                     $status = new \Model\Issue\Status();
                     $status->load($val);
                     // Toggle closed_date if issue has been closed/restored
                     if ($status->closed) {
                         if (!$issue->closed_date) {
                             $issue->closed_date = $this->now();
                         }
                     } else {
                         $issue->closed_date = null;
                     }
                 }
                 // Save to the sprint of the due date unless one already set
                 if ($i == "due_date" && !empty($val)) {
                     if (empty($post['sprint_id'])) {
                         $sprint = new \Model\Sprint();
                         $sprint->load(array("DATE(?) BETWEEN start_date AND end_date", $val));
                         $issue->sprint_id = $sprint->id;
                     }
                 }
             }
         }
     }
     // Save comment if given
     if (!empty($post["comment"])) {
         $comment = new \Model\Issue\Comment();
         $comment->user_id = $this->_userId;
         $comment->issue_id = $issue->id;
         $comment->text = $post["comment"];
         $comment->created_date = $this->now();
         $comment->save();
         $f3->set("update_comment", $comment);
     }
     // Save issue, optionally send notifications
     $notify = !empty($post["notify"]);
     $issue->save($notify);
     return $issue;
 }
Example #6
0
                }
                // Create sprint project
                if (count($tasks_for_this_sprint)) {
                    echo "Creating project for sprint {$sprint->id}\n";
                    $sprint_project = new \Model\Issue();
                    $sprint_project->type_id = $issue_type_project;
                    $sprint_project->parent_id = $project->id;
                    $sprint_project->sprint_id = $sprint->id;
                    $sprint_project->author_id = $project->author_id;
                    $sprint_project->owner_id = $project->owner_id;
                    if ($sprint->name) {
                        $sprint_project->name = $project->name . " - " . $sprint->name . " - " . date("n/j", strtotime($sprint->start_date)) . "-" . date("n/j", strtotime($sprint->start_date));
                    } else {
                        $sprint_project->name = $project->name . " - " . date("n/j", strtotime($sprint->start_date)) . "-" . date("n/j", strtotime($sprint->start_date));
                    }
                    $sprint_project->description = "This is an automatically generated project for breaking large projects into sprints.";
                    $sprint_project->created_date = date("Y-m-d H:i:s");
                    $sprint_project->save();
                    // Move tasks into sprint project
                    foreach ($tasks_for_this_sprint as $task) {
                        echo "Moving task {$task->id} into sprint project {$sprint_project->id}\n";
                        $task->parent_id = $sprint_project->id;
                        $task->save();
                    }
                }
            }
        } else {
            echo "No tasks found.\n";
        }
    }
}
Example #7
0
 public function single_put($f3, $params)
 {
     $issue = new \Model\Issue();
     $issue->load($params["id"]);
     if (!$issue->id) {
         $f3->error(404);
         return;
     }
     $updated = array();
     foreach ($f3->get("REQUEST") as $key => $val) {
         if (is_scalar($val) && $issue->exists($key)) {
             $updated[] = $key;
             $issue->set($key, $val);
         }
     }
     if ($updated) {
         $issue->save();
     }
     $this->printJson(array("updated_fields" => $updated, "issue" => $this->_issueMultiArray($issue)));
 }
Example #8
0
 /**
  * Log and save an issue update
  * @param  boolean $notify
  * @return Issue\Update
  */
 protected function _saveUpdate($notify = true)
 {
     $f3 = \Base::instance();
     // Ensure issue is not tied to itself as a parent
     if ($this->get("id") == $this->get("parent_id")) {
         $this->set("parent_id", $this->_getPrev("parent_id"));
     }
     // Log update
     $update = new \Model\Issue\Update();
     $update->issue_id = $this->id;
     $update->user_id = $f3->get("user.id");
     $update->created_date = date("Y-m-d H:i:s");
     if ($f3->exists('update_comment')) {
         $update->comment_id = $f3->get('update_comment')->id;
         if ($notify) {
             $update->notify = 1;
         }
     } else {
         $update->notify = 0;
     }
     $update->save();
     // Set hours_total to the hours_remaining value if it's 0 or null
     if ($this->get("hours_remaining") && !$this->get("hours_total")) {
         $this->set("hours_total", $this->get("hours_remaining"));
     }
     // Set hours remaining to 0 if the issue has been closed
     if ($this->get("closed_date") && $this->get("hours_remaining")) {
         $this->set("hours_remaining", 0);
     }
     // Create a new issue if repeating
     if ($this->get("closed_date") && $this->get("repeat_cycle") && $this->get("repeat_cycle") != "none") {
         $repeat_issue = new \Model\Issue();
         $repeat_issue->name = $this->get("name");
         $repeat_issue->type_id = $this->get("type_id");
         $repeat_issue->parent_id = $this->get("parent_id");
         $repeat_issue->author_id = $this->get("author_id");
         $repeat_issue->owner_id = $this->get("owner_id");
         $repeat_issue->description = $this->get("description");
         $repeat_issue->priority = $this->get("priority");
         $repeat_issue->repeat_cycle = $this->get("repeat_cycle");
         $repeat_issue->hours_total = $this->get("hours_total");
         $repeat_issue->hours_remaining = $this->get("hours_total");
         // Reset hours remaining to start hours
         $repeat_issue->created_date = date("Y-m-d H:i:s");
         // Find a due date in the future
         switch ($repeat_issue->repeat_cycle) {
             case 'daily':
                 $repeat_issue->start_date = $this->get("start_date") ? date("Y-m-d", strtotime("tomorrow")) : NULL;
                 $repeat_issue->due_date = date("Y-m-d", strtotime("tomorrow"));
                 break;
             case 'weekly':
                 $repeat_issue->start_date = $this->get("start_date") ? date("Y-m-d", strtotime($this->get("start_date") . " +1 week")) : NULL;
                 $repeat_issue->due_date = date("Y-m-d", strtotime($this->get("due_date") . " +1 week"));
                 break;
             case 'monthly':
                 $repeat_issue->start_date = $this->get("start_date") ? date("Y-m-d", strtotime($this->get("start_date") . " +1 month")) : NULL;
                 $repeat_issue->due_date = date("Y-m-d", strtotime($this->get("due_date") . " +1 month"));
                 break;
             case 'sprint':
                 $sprint = new \Model\Sprint();
                 $sprint->load(array("start_date > NOW()"), array('order' => 'start_date'));
                 $repeat_issue->start_date = $this->get("start_date") ? $sprint->start_date : NULL;
                 $repeat_issue->due_date = $sprint->end_date;
                 break;
             default:
                 $repeat_issue->repeat_cycle = 'none';
         }
         // If the issue was in a sprint before, put it in a sprint again.
         if ($this->get("sprint_id")) {
             $sprint = new \Model\Sprint();
             $sprint->load(array("end_date >= ? AND start_date <= ?", $repeat_issue->due_date, $repeat_issue->due_date), array('order' => 'start_date'));
             $repeat_issue->sprint_id = $sprint->id;
         }
         $repeat_issue->save();
         $notification = \Helper\Notification::instance();
         $notification->issue_create($repeat_issue->id);
         $this->set("repeat_cycle", null);
     }
     // Log updated fields
     $updated = 0;
     $important_changes = 0;
     $important_fields = array('status', 'name', 'description', 'owner_id', 'priority', 'due_date');
     foreach ($this->fields as $key => $field) {
         if ($field["changed"] && $field["value"] != $this->_getPrev($key)) {
             $update_field = new \Model\Issue\Update\Field();
             $update_field->issue_update_id = $update->id;
             $update_field->field = $key;
             $update_field->old_value = $this->_getPrev($key);
             $update_field->new_value = $field["value"];
             $update_field->save();
             $updated++;
             if ($key == 'sprint_id') {
                 $this->resetTaskSprints();
             }
             if (in_array($key, $important_fields)) {
                 $important_changes++;
             }
         }
     }
     // Delete update if no fields were changed
     if (!$updated) {
         $update->delete();
     }
     // Set notify flag if important changes occurred
     if ($notify && $important_changes) {
         $update->notify = 1;
         $update->save();
     }
     // Send back the update
     return $update->id ? $update : false;
 }
Example #9
0
 /**
  * Repeat an issue by generating a minimal copy and setting new due date
  * @param  boolean $notify
  * @return Issue
  */
 public function repeat($notify = true)
 {
     $repeat_issue = new \Model\Issue();
     $repeat_issue->name = $this->name;
     $repeat_issue->type_id = $this->type_id;
     $repeat_issue->parent_id = $this->parent_id;
     $repeat_issue->author_id = $this->author_id;
     $repeat_issue->owner_id = $this->owner_id;
     $repeat_issue->description = $this->description;
     $repeat_issue->priority = $this->priority;
     $repeat_issue->repeat_cycle = $this->repeat_cycle;
     $repeat_issue->hours_total = $this->hours_total;
     $repeat_issue->hours_remaining = $this->hours_total;
     $repeat_issue->created_date = date("Y-m-d H:i:s");
     // Find a due date in the future
     switch ($repeat_issue->repeat_cycle) {
         case 'daily':
             $repeat_issue->start_date = $this->start_date ? date("Y-m-d", strtotime("tomorrow")) : NULL;
             $repeat_issue->due_date = date("Y-m-d", strtotime("tomorrow"));
             break;
         case 'weekly':
             $repeat_issue->start_date = $this->start_date ? date("Y-m-d", strtotime($this->start_date . " +1 week")) : NULL;
             $repeat_issue->due_date = date("Y-m-d", strtotime($this->due_date . " +1 week"));
             break;
         case 'monthly':
             $repeat_issue->start_date = $this->start_date ? date("Y-m-d", strtotime($this->start_date . " +1 month")) : NULL;
             $repeat_issue->due_date = date("Y-m-d", strtotime($this->due_date . " +1 month"));
             break;
         case 'sprint':
             $sprint = new \Model\Sprint();
             $sprint->load(array("start_date > NOW()"), array('order' => 'start_date'));
             $repeat_issue->start_date = $this->start_date ? $sprint->start_date : NULL;
             $repeat_issue->due_date = $sprint->end_date;
             break;
         default:
             $repeat_issue->repeat_cycle = 'none';
     }
     // If the issue was in a sprint before, put it in a sprint again.
     if ($this->sprint_id) {
         $sprint = new \Model\Sprint();
         $sprint->load(array("end_date >= ? AND start_date <= ?", $repeat_issue->due_date, $repeat_issue->due_date), array('order' => 'start_date'));
         $repeat_issue->sprint_id = $sprint->id;
     }
     $repeat_issue->save();
     if ($notify) {
         $notification = \Helper\Notification::instance();
         $notification->issue_create($repeat_issue->id);
     }
     return $repeat_issue;
 }