loduis / teamwork.com-project-management

PHP API for Teamwork.com
https://developer.teamwork.com/
MIT License
70 stars 59 forks source link

Ability to add sub-tasks to tasks #27

Open ghost opened 8 years ago

ghost commented 8 years ago

Does your API framework allow the ability to add a subtask to a task? can you give an example if so?

jhnferraris commented 7 years ago

@dleinbach Any news on this?

ghost commented 7 years ago

Hey @jhnferraris, I did my own hack and wrote the following function in the src/Task.php... Not sure if its the absoulte best way to do it but it seems to work.

public function insertSubTask(array $data)
    {
        $parent_task_id = empty($data['parent_task_id']) ? 0 : (int) $data['parent_task_id'];
        if ($parent_task_id <= 0) {
            throw new Exception('Required field parent_task_id');
        }
        if (!empty($data['files'])) {
            $file = \TeamWorkPm\Factory::build('file');
            $data['pending_file_attachments'] = $file->upload($data['files']);
            unset($data['files']);
        }
        return $this->rest->post("tasks/$parent_task_id", $data);
    }

then it can be called by doing something like this

public function addsubtask($id,$name,$date){
        $task = TeamWorkPm::build('task');
        $task_id = $task->insertSubTask(array(
            'parent_task_id' => $id,
            'content'      => $name,
            'notify'       => false,
            'description'  => '',
            'due_date'     => date('Ymd', strtotime($date)),
            'start_date'   => date('Ymd'),
            'private'      => false,
            'priority'     => 'low',
            'estimated_minutes' => 1000,
            'responsible_party_id' => $this->TwId,
        ));
        return 'subtask added';
    }