/** * Create a new todolist. * * @param int $project_id * @param array $data * * - tasklist_name (string, required) * - tasklist_detail (string) * - tasklist_privacy (string) * - tasklist_milestone (integer) * * - Method: POST * - URL: http://example.com/cpm-json/projects/project_id/lists * * @since 1.2 * @return array $response */ public function create_list($project_id, $data) { $project_id = (int) $project_id; $list_id = (int) $list_id; if (!$project_id) { return new WP_Error('json_post_invalid_id', __('Invalid project ID.'), array('status' => 404)); } $manage_capability = cpm_manage_capability(); if (!$manage_capability && !cpm_is_single_project_manager($project_id)) { if (!cpm_project_user_role_pre_chache($project_id)) { return new WP_Error('permission', __('Sorry! you are not assigned in this project', 'cpm'), array('status' => 404)); } if (!cpm_user_can_access($project_id, 'create_todolist')) { return new WP_Error('permission', __('Sorry! you do not have permission to create todo list', 'cpm'), array('status' => 404)); } } if (empty($data['tasklist_name'])) { return new WP_Error('task_list_name', __('Task List Name Required', 'cpm')); } $data['tasklist_milestone'] = isset($data['tasklist_milestone']) ? $data['tasklist_milestone'] : '-1'; $data['tasklist_privacy'] = isset($data['tasklist_privacy']) ? $data['tasklist_privacy'] : 'no'; $list_id = cpm()->task->add_list($project_id, $data); $get_list = cpm()->task->get_task_list($list_id); $response = new WP_JSON_Response(); $response->set_data($get_list); return $response; }
/** * Check comment create permission * * @param int $project_id * @param int $post_id * * @since 1.2 * @return boolen | array */ function check_create_comment_permission($project_id, $post_id) { $post_id = intval($post_id); $project_id = intval($project_id); if (!$post_id) { return array('key' => 'json_post_invalid_id', 'message' => __('Invalid post ID.')); } if (!$project_id) { return array('key' => 'json_post_invalid_id', 'message' => __('Invalid project ID.')); } $post = get_post($post_id); $post_type = $post->post_type; switch ($post_type) { case 'message': $manage_capability = cpm_manage_capability(); if ($manage_capability || cpm_is_single_project_manager($project_id)) { return true; } else { if (!cpm_project_user_role_pre_chache($project_id)) { return array('key' => 'permission', 'message' => __('Sorry! you are not assigned in this project', 'cpm')); } else { if (!cpm_user_can_access($project_id, 'create_message')) { return array('key' => 'permission', 'message' => __('Sorry! you do not have permission to view this comments', 'cpm')); } } } break; case 'task': $manage_capability = cpm_manage_capability(); if ($manage_capability || cpm_is_single_project_manager($project_id)) { $condition = true; } else { if (!cpm_project_user_role_pre_chache($project_id)) { return array('key' => 'permission', 'message' => __('Sorry! you are not assinged in this project', 'cpm'), array('status' => 404)); } else { if (!cpm_user_can_access($project_id, 'tdolist_view_private')) { return array('key' => 'permission', 'message' => __('Sorry! you do no have permission to view this comment', 'cpm'), array('status' => 404)); } else { if (!cpm_user_can_access($project_id, 'create_todo')) { return array('key' => 'permission', 'message' => __('Sorry! you do no have permission to view this comment', 'cpm'), array('status' => 404)); } } } } break; case 'task_list': $manage_capability = cpm_manage_capability(); if ($manage_capability || cpm_is_single_project_manager($project_id)) { return true; } else { if (!cpm_project_user_role_pre_chache($project_id)) { return array('key' => 'permission', 'message' => __('Sorry! you are not assinged in this project', 'cpm'), array('status' => 404)); } else { if (!cpm_user_can_access($project_id, 'create_todolist')) { return array('key' => 'permission', 'message' => __('Sorry! you do no have permission to view this comment', 'cpm'), array('status' => 404)); } } } break; } return true; }
/** * Create a new milestone. * * @param int $project_id * @param array $data * * - milestone_name (string, required) * - milestone_due (date format) * - milestone_detail (string) * - milestone_privacy (string) * * - Method: POST * - URL: http://example.com/cpm-json/projects/project_id/milestones * * @since 1.2 * @return array $response */ public function create_milestone($project_id, $data) { $project_id = intval($project_id); if (!$project_id) { return new WP_Error('json_post_invalid_id', __('Invalid project ID.'), array('status' => 404)); } if (isset($data['milestone_name']) && empty($data['milestone_name'])) { return new WP_Error('milestone_name', __('Milestone Name Required', 'cpm')); } $manage_capability = cpm_manage_capability(); if (!$manage_capability && !cpm_is_single_project_manager($project_id)) { if (!cpm_project_user_role_pre_chache($project_id)) { return new WP_Error('permission', __('Sorry! you are not assigned in this project', 'cpm'), array('status' => 404)); } if (!cpm_user_can_access($project_id, 'create_milestone')) { return new WP_Error('permission', __('Sorry! you do not have permission to create milestone', 'cpm'), array('status' => 404)); } } $milestone_id = cpm()->milestone->create($project_id, $data); $get_milestone = cpm()->milestone->get($milestone_id); $response = new WP_JSON_Response(); $response->set_data($get_milestone); return $response; }
/** * Create a new task. * * @param int $project_id * @param int $list_id * @param array $data * * - task_text (string, required) * - task_privacy (string) * - task_assign (array) * - task_due (date format) * - task_start (date format) * * - Method: POST * - URL: http://example.com/cpm-json/projects/project_id/lists/list_id/tasks * * @since 1.2 * @return array $response */ public function create_task($project_id, $list_id, $data) { $project_id = (int) $project_id; $list_id = (int) $list_id; if (!$project_id) { return new WP_Error('json_post_invalid_id', __('Invalid project ID.'), array('status' => 404)); } if (!$list_id) { return new WP_Error('json_post_invalid_id', __('Invalid todo list ID.'), array('status' => 404)); } if (empty($data['task_text'])) { return new WP_Error('task_text', __('Task Name Required', 'cpm')); } $posts_list = cpm()->task->get_task_list($list_id); $manage_capability = cpm_manage_capability(); if (!$manage_capability && !cpm_is_single_project_manager($project_id)) { if (!cpm_project_user_role_pre_chache($project_id)) { return new WP_Error('permission', __('Sorry! you are not assigned in this project', 'cpm'), array('status' => 404)); } if (!cpm_user_can_access($project_id, 'create_todolist')) { return new WP_Error('permission', __('Sorry! you do not have permission to create todo list', 'cpm'), array('status' => 404)); } if (!cpm_user_can_access($project_id, 'create_todo')) { return new WP_Error('permission', __('Sorry! you do not have permission to create todo', 'cpm'), array('status' => 404)); } } add_filter('cpm_new_task_notification', array($this, 'change_notification_status')); $task_id = cpm()->task->add_task($list_id, $data); $get_task = cpm()->task->get_task($task_id); $response = new WP_JSON_Response(); $response->set_data($get_task); return $response; }