# Tasks API Function
The Tasks API provides methods to interact with task-related data in FluentBoards. This API allows you to retrieve, create, update, manage tasks, and handle task attachments, ensuring operations are secured based on user permissions.
# Initialization
To initialize the Tasks API, use the following code:
$tasksApi = FluentBoardsApi('tasks');
FluentBoardsApi('tasks') returns an instance of the FluentBoards\App\Api\Classes\Tasks class.
# Methods
# getTasksByBoard()
The getTasksByBoard method retrieves all tasks associated with a specific board, excluding archived tasks.
Parameters
$board_id(int|string): The ID of the board.$with(array): An array of relationships to include (optional).
Return
- An array of
Taskmodels orfalseif the board ID is invalid or the user lacks permission.
Example
$tasks = $tasksApi->getTasksByBoard(1, ['labels', 'assignees']);
# getTask()
The getTask method retrieves a single task by its ID.
Parameters
$id(int|string): The ID of the task.
Return
- A
Taskmodel with the specified ID orfalseif the task is not found or the user lacks permission.
Example
$task = $tasksApi->getTask(1);
# getTasksCreatedBy()
The getTasksCreatedBy method retrieves all tasks created by a specific user.
Parameters
$userId(int|string): The ID of the user.$with(array): An array of relationships to include (optional).
Return
- An array of
Taskmodels orfalseif the user ID is invalid or the user lacks permission.
Example
$tasks = $tasksApi->getTasksCreatedBy(2, ['labels']);
# create()
The create method creates a new task with the provided data.
Parameters
$data(array): The task data, includingtitle,board_id, andstage_id(all required).
Return
- The created
Taskmodel orfalseif creation fails due to missing data or permission issues.
Example
$newTask = $tasksApi->create([
'title' => 'New Task',
'board_id' => 1,
'stage_id' => 2,
'description' => 'Task description'
]);
2
3
4
5
6
# createTask()
The createTask method defines the required and optional fields for creating a task.
Parameters
$data(array): Task data includingtitle,board_id,stage_id, and other optional fields.
Return
- A Task
modelorfalseif creation fails.
Example
$tasksApi->createTask([
'title' => 'Task Title',
'board_id' => 1,
'stage_id' => 2,
// Additional fields as necessary
]);
2
3
4
5
6
# addAssignees()
The addAssignees method adds one or more assignees to a task.
Parameters
$task_id(int): The ID of the task.$assignees(array): An array of WP user IDs to be added as assignees.
Return
trueif assignees were successfully added, otherwisefalse.
Example
$tasksApi->addAssignees(1, [3, 4]);
# removeAssignees()
The removeAssignees method removes one or more assignees from a task.
Parameters
$task_id(int): The ID of the task.$assignees(array): An array of WP user IDs to be removed as assignees.
Return
trueif assignees were successfully removed, otherwisefalse.
Example
$tasksApi->removeAssignees(1, [3]);
# attachLabels()
The attachLabels method attaches one or more labels to a task.
Parameters
$taskId(int): The ID of the task.$labelIds(array): An array of label IDs to be attached.
Return
trueif labels were successfully attached, otherwisefalse.
Example
$tasksApi->attachLabels(1, [5, 6]);
# removeLabels()
The removeLabels method removes one or more labels from a task.
Parameters
$taskId(int): The ID of the task.$labelIds(array): An array of label IDs to be removed.
Return
trueif labels were successfully removed, otherwisefalse.
Example
$tasksApi->removeLabels(1, [5]);
# changeStage()
The changeStage method updates the stage of a task.
Parameters
$task(int|Task): The ID of the task or aTaskmodel.$stageId(int): The ID of the new stage.
Return
- The updated
Taskmodel orfalseif the operation fails.
Example
$tasksApi->changeStage(1, 3);
# updateProperty()
The updateProperty method updates a specific property of a task.
Parameters
$taskId(int): The ID of the task.$property(string): The property to update (e.g., title, description, due_at).$value(mixed): The new value for the property.
Return
- The updated
Taskmodel orfalseif the property is not allowed or the user lacks permission.
Example
$updatedTask = $tasksApi->updateProperty(1, 'title', 'Updated Task Title');
# createTaskAttachment()
The createTaskAttachment method creates an attachment for a task.
Parameters
$boardId(int): The ID of the board.$taskId(int): The ID of the task.$data(array): The attachment data, including title and url (required).
Return
- The created
TaskAttachmentmodel orfalseif creation fails.
Example
$attachment = $tasksApi->createTaskAttachment(1, 1, [
'title' => 'Attachment Title',
'url' => 'https://example.com/attachment.jpg'
]);
2
3
4
# deleteTaskAttachment()
The deleteTaskAttachment method deletes an attachment from a task.
Parameters
$boardId(int): The ID of the board.$taskId(int): The ID of the task.$attachmentId(int): The ID of the attachment.
Return
trueif the attachment was successfully deleted, otherwisefalse.
Example
$tasksApi->deleteTaskAttachment(1, 1, 1);
# getInstance()
The getInstance method returns the raw Task model instance, allowing you to use all the methods of the query builder or ORM.
Return
- The
Taskmodel instance.
Example
$taskInstance = $tasksApi->getInstance();
$task = $taskInstance->where('title', 'like', '%Task%')->first();
2