Exemple #1
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));
 }
Exemple #2
0
 public function post($f3)
 {
     if ($_REQUEST) {
         // By default, use standard HTTP POST fields
         $post = $_REQUEST;
     } else {
         // For Redmine compatibility, also accept a JSON object
         try {
             $post = json_decode(file_get_contents('php://input'), true);
         } catch (Exception $e) {
             throw new Exception("Unable to parse input");
         }
         if (!empty($post["issue"])) {
             $post = $post["issue"];
         }
         // Convert Redmine names to Phproject names
         if (!empty($post["subject"])) {
             $post["name"] = $post["subject"];
         }
         if (!empty($post["parent_issue_id"])) {
             $post["parent_id"] = $post["parent_issue_id"];
         }
         if (!empty($post["tracker_id"])) {
             $post["type_id"] = $post["tracker_id"];
         }
         if (!empty($post["assigned_to_id"])) {
             $post["owner_id"] = $post["assigned_to_id"];
         }
         if (!empty($post["fixed_version_id"])) {
             $post["sprint_id"] = $post["fixed_version_id"];
         }
     }
     // Ensure a status ID is added
     if (!empty($post["status_id"])) {
         $post["status"] = $post["status_id"];
     }
     if (empty($post["status"])) {
         $post["status"] = 1;
     }
     // Verify the required "name" field is passed
     if (empty($post["name"])) {
         $f3->error("The 'name' value is required.");
         return;
     }
     // Verify given values are valid (types, statueses, priorities)
     if (!empty($post["type_id"])) {
         $type = new \Model\Issue\Type();
         $type->load($post["type_id"]);
         if (!$type->id) {
             $f3->error("The 'type_id' field is not valid.");
             return;
         }
     }
     if (!empty($post["parent_id"])) {
         $parent = new \Model\Issue();
         $parent->load($post["parent_id"]);
         if (!$parent->id) {
             $f3->error("The 'type_id' field is not valid.");
             return;
         }
     }
     if (!empty($post["status"])) {
         $status = new \Model\Issue\Status();
         $status->load($post["status"]);
         if (!$status->id) {
             $f3->error("The 'status' field is not valid.");
             return;
         }
     }
     if (!empty($post["priority_id"])) {
         $priority = new \Model\Issue\Priority();
         $priority->load(array("value" => $post["priority_id"]));
         if (!$priority->id) {
             $f3->error("The 'priority_id' field is not valid.");
             return;
         }
     }
     // Create a new issue based on the data
     $issue = new \Model\Issue();
     $issue->author_id = !empty($post["author_id"]) ? $post["author_id"] : $this->_userId;
     $issue->name = trim($post["name"]);
     $issue->type_id = empty($post["type_id"]) ? 1 : $post["type_id"];
     $issue->priority_id = empty($post["priority_id"]) ? $f3->get("issue_priority.default") : $post["priority_id"];
     // Set due date if valid
     if (!empty($post["due_date"]) && preg_match("/^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}( [0-9:]{8})?\$/", $post["due_date"])) {
         $issue->due_date = $post["due_date"];
     } elseif (!empty($post["due_date"]) && ($due_date = strtotime($post["due_date"]))) {
         $issue->due_date = date("Y-m-d", $due_date);
     }
     if (!empty($post["description"])) {
         $issue->description = $post["description"];
     }
     if (!empty($post["parent_id"])) {
         $issue->parent_id = $post["parent_id"];
     }
     if (!empty($post["owner_id"])) {
         $issue->owner_id = $post["owner_id"];
     }
     $issue->save();
     $this->_printJson(array("issue" => $issue->cast()));
 }