# Task Model

DB Table Name {wp_db_prefix}_fbs_tasks
Schema Check Schema
Source File fluent-boards/app/Models/Task.php
Name Space FluentBoards\App\Models
Class FluentBoards\App\Models\Task

# Attributes

Attribute Data Type Comment
id INT UNSIGNED Auto Increment Primary key of the task
parent_id INT UNSIGNED NULL Parent task ID if this is a subtask
board_id INT UNSIGNED NULL ID of the board the task is in
crm_contact_id BIGINT UNSIGNED NULL User ID, Contact ID, Deal ID, Subscriber ID, etc.
title TEXT NULL Title or name of the task; it can be longer than 255 characters.
slug VARCHAR(255) NULL Slug of the task
type VARCHAR(50) NULL Type of the task, e.g., task, deal, idea, to-do, etc.
status VARCHAR(50) NULL DEFAULT 'open' Status of the task: open, completed; for boards: won or lost for pipelines
stage_id INT UNSIGNED NULL ID of the stage the task is in
source VARCHAR(50) NULL DEFAULT 'web' Source of the task, e.g., web, funnel, contact-section, etc.
source_id VARCHAR(255) NULL Source ID related to the task
priority VARCHAR(50) NULL DEFAULT 'low' Priority of the task: low, medium, high
description LONGTEXT NULL Description of the task
lead_value DECIMAL(10,2) DEFAULT 0.00 Lead value associated with the task
created_by BIGINT UNSIGNED NULL ID of the user who created the task
position DECIMAL(10,2) NOT NULL DEFAULT '1' Position of the task within the board. 1 = first, 2 = second, etc.
comments_count INT UNSIGNED NULL DEFAULT 0 Number of comments associated with the task
issue_number INT UNSIGNED NULL Board-specific issue number to track the task
reminder_type VARCHAR(100) NULL DEFAULT 'none' Type of reminder set for the task
settings TEXT NULL Serialized settings for the task
remind_at TIMESTAMP NULL Timestamp when a reminder is set for the task
started_at TIMESTAMP NULL Timestamp when the task was started
due_at TIMESTAMP NULL Timestamp when the task is due
last_completed_at TIMESTAMP NULL Timestamp when the task was last completed
archived_at TIMESTAMP NULL Timestamp when the task was archived
created_at TIMESTAMP NULL Timestamp when the task was created
updated_at TIMESTAMP NULL Timestamp when the task was last updated
## Usage Please check Model Basic for Common methods.

# Accessing Attributes


$task = FluentBoards\App\Models\Task::find(1);

$task->id; // returns id
$task->title; // returns title
.......
1
2
3
4
5
6

# Scopes

This model has the following scopes that you can use

# Scopes

This model has the following scopes that you can use

# type($type)

Filter task by type

  • Parameters
    • $type - string - Type of the task

# Usage:

// Get all boards by user id
$task = FluentBoards\App\Models\Task::type('task')->get();
1
2

# upcoming()

To check is task upcoming

# Usage:

// Is task upcoming
$upcoming = $task->upcoming();
1
2

# isOverdue()

To check is task overdue

# Usage:

// Is task upcoming
$upcoming = $task->isOverdue();
1
2

# Relations

This model has the following relationships that you can use

# board

Access the associated stages of a model

  • return FluentBoards\App\Models\Board Model Collection

# Example:

// Accessing Board
$taskBoard = $task->board;

1
2
3

# stage

Access the associated stages of a task model

  • return FluentBoards\App\Models\Stage Model Collection

# Example:

// Accessing Stage
$taskStage = $task->stage;

1
2
3

# labels

Access all the associated labels of a task model

  • return FluentBoards\App\Models\Label Model Collections

# Example:

// Accessing task labels
$taskTasks = $task->labels;

// For Filtering by tags relationship

// Get Task which has label slug: green
$tasks = FluentBoards\App\Models\Task::whereHas('labels', funtion($query) {
    $query->where('slug', 'green');
})->get();

// Get Task which does not have label slug: green
$tasks = FluentBoards\App\Models\Board::whereDoesntHave('tasks', funtion($query) {
    $query->where('slug', 'green');
})->get();
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# subtasks

Access all the associated subtasks of a task model

  • return FluentBoards\App\Models\Task Model Collections

# Example:

// Accessing task subtasks
$subtasks = $task->subtasks;

// For Filtering by tags relationship

// Get Tasks which has subtask status: open
$tasks = FluentBoards\App\Models\Task::whereHas('subtasks', funtion($query) {
    $query->where('status', 'open');
})->get();

// Get Tasks which does not have subtask status: open
$tasks = FluentBoards\App\Models\Board::whereDoesntHave('tasks', funtion($query) {
    $query->where('status', 'open');
})->get();
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# parentTask

Access all the associated parentTask of a task model

  • return FluentBoards\App\Models\Task Model Collections

# Example:

// Accessing task subtasks
$parentTask = $task->parentTask;

1
2
3

# assignees

Access all the associated assignees of a task model

  • return FluentBoards\App\Models\User Model Collections

# Example:

// Accessing task assignees
$assignees = $task->assignees;

// For Filtering by assignees relationship

// Get Tasks which have assignee with id 1
$tasks = FluentBoards\App\Models\Task::whereHas('assignees', function($query) {
    $query->where('ID', 1);
})->get();

// Get Tasks which do not have assignee with id 1
$tasks = FluentBoards\App\Models\Task::whereDoesntHave('assignees', function($query) {
    $query->where('ID', 1);
})->get();
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# watchers

Access all the associated watchers of a task model

  • return FluentBoards\App\Models\User Model Collections

# Example:

// Accessing task watchers
$watchers = $task->watchers;

// For filtering by watchers relationship

// Get Tasks which have a watcher with user id 1
$tasks = FluentBoards\App\Models\Task::whereHas('watchers', function($query) {
    $query->where('foreign_id', 1)
          ->where('object_type', Constant::OBJECT_TYPE_USER_TASK_WATCH);
})->get();

// Get Tasks which do not have a watcher with user id 1
$tasks = FluentBoards\App\Models\Task::whereDoesntHave('watchers', function($query) {
    $query->where('foreign_id', 1)
          ->where('object_type', Constant::OBJECT_TYPE_USER_TASK_WATCH);
})->get();

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

# attachments

Access all the associated attachments of a task model

  • return FluentBoards\App\Models\TaskAttachment Model Collections

# Example:

// Accessing task attachments
$attachments = $task->attachments;

// For filtering by attachments relationship

// Get Tasks which have attachments
$tasks = FluentBoards\App\Models\Task::whereHas('attachments', function($query) {
    $query->where('object_type', Constant::OBJECT_TYPE_TASK);
})->get();

// Get Tasks which do not have attachments
$tasks = FluentBoards\App\Models\Task::whereDoesntHave('attachments', function($query) {
    $query->where('object_type', Constant::OBJECT_TYPE_TASK);
})->get();

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

# comments

Access all the associated comments of a task model

  • return FluentBoards\App\Models\Comment Model Collections

# Example:

// Accessing task comments
$comments = $task->comments;

// For filtering by comments relationship

// Get Tasks which have comments
$tasks = FluentBoards\App\Models\Task::whereHas('comments', function($query) {
    $query->where('type', 'comment')
          ->where('parent_id', null);
})->get();

// Get Tasks which do not have comments
$tasks = FluentBoards\App\Models\Task::whereDoesntHave('comments', function($query) {
    $query->where('type', 'comment')
          ->where('parent_id', null);
})->get();

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

# public_comments

Access all the associated public_comments of a task model

  • return FluentBoards\App\Models\Comment Model Collections

# Example:

// Accessing public comments for a task
$publicComments = $task->public_comments;

// For filtering by public comments relationship

// Get Tasks which have public comments
$tasks = FluentBoards\App\Models\Task::whereHas('public_comments')->get();

// Get Tasks which do not have public comments
$tasks = FluentBoards\App\Models\Task::whereDoesntHave('public_comments')->get();

1
2
3
4
5
6
7
8
9
10
11

# activities

Access all the associated activities of a task model

  • return FluentBoards\App\Models\Activity Model Collections

# Example:

// Accessing task activities
$activities = $task->activities;

// For filtering by activities relationship

// Get Tasks which have activities
$tasks = FluentBoards\App\Models\Task::whereHas('activities', function($query) {
    $query->where('object_type', Constant::ACTIVITY_TASK);
})->get();

// Get Tasks which do not have activities
$tasks = FluentBoards\App\Models\Task::whereDoesntHave('activities', function($query) {
    $query->where('object_type', Constant::ACTIVITY_TASK);
})->get();

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

# customFields

Access all the associated customFields of a task model

  • return FluentBoards\App\Models\CustomField Model Collections

# Example:

// Accessing task custom fields
$customFields = $task->customFields;

// For filtering by custom fields relationship

// Get Tasks which have a custom field with a specific ID
$tasks = FluentBoards\App\Models\Task::whereHas('customFields', function($query) {
    $query->where('foreign_id', 1)
          ->where('object_type', ProConstant::TASK_CUSTOM_FIELD);
})->get();

// Get Tasks which do not have a custom field with a specific ID
$tasks = FluentBoards\App\Models\Task::whereDoesntHave('customFields', function($query) {
    $query->where('foreign_id', 1)
          ->where('object_type', ProConstant::TASK_CUSTOM_FIELD);
})->get();

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

# notifications

Access all the associated notifications of a task model

  • return FluentBoards\App\Models\Notification Model Collections

# Example:

// Accessing task notifications
$notifications = $task->notifications;

// For filtering by notifications relationship

// Get Tasks which have notifications
$tasks = FluentBoards\App\Models\Task::whereHas('notifications')->get();

// Get Tasks which do not have notifications
$tasks = FluentBoards\App\Models\Task::whereDoesntHave('notifications')->get();

1
2
3
4
5
6
7
8
9
10
11

# taskMeta

Access all the associated taskMeta of a task model

  • return FluentBoards\App\Models\TaskMeta Model Collections

# Example:

// Accessing task metadata
$taskMeta = $task->taskMeta;

// For filtering by task metadata relationship

// Get Tasks which have metadata
$tasks = FluentBoards\App\Models\Task::whereHas('taskMeta')->get();

// Get Tasks which do not have metadata
$tasks = FluentBoards\App\Models\Task::whereDoesntHave('taskMeta')->get();

1
2
3
4
5
6
7
8
9
10
11

# Methods

Along with Global Model methods, this model has few helper methods.

# createTask($data)

Create a new task.

  • Parameters
    • $data array: An associative array containing the task data. The array may include keys for 'assignees' and 'labels', among others.
  • Returns Task: The created task instance.

# Usage

$data = [
    'title' => 'New Task Title', // required
    'description' => 'Description of the task', // optional
    'board_id' => 1, // required
    'stage_id' => 1, // required
];

$createdTask = $this->createTask($data);

1
2
3
4
5
6
7
8
9

# addOrRemoveAssignee($idToAddOrRemove)

Add or remove an assignee from the task based on their current assignment status.

  • Parameters
    • $idToAddOrRemove int: The ID of the user to add or remove as an assignee.
  • Returns string: The operation performed, either 'added' or 'removed'.

# Usage

$idToModify = 123; // User ID to add or remove

$operation = $task->addOrRemoveAssignee($idToModify);

echo "The user was " . $operation . " as an assignee.";

1
2
3
4
5
6

# moveToNewPosition($newIndex)

Move the task to a new position in the list, adjusting the positions of other tasks as necessary.

  • Parameters
    • $newIndex int: The new position index where the task should be moved. This index is 1-based.
  • Returns self: The updated task instance with the new position.

# Usage

$newIndex = 3; // The desired new position of the task

$updatedTask = $task->moveToNewPosition($newIndex);

echo "The task has been moved to position " . $updatedTask->position;
1
2
3
4
5

# adjustSubtaskCount($subTaskParentId)

Adjust the subtask count for a given parent task by updating its settings.

  • Parameters
    • $subTaskParentId int: The ID of the parent task whose subtask count needs to be updated.
  • Returns void: This method does not return a value.

# Usage

$parentTaskId = 123; // The ID of the parent task

Task::adjustSubtaskCount($parentTaskId);
1
2
3

# updateMeta($key, $value)

Update an existing meta entry or create a new one for the task.

  • Parameters
    • $key string: The key of the meta entry.
    • $value mixed: The value to associate with the key.
  • Returns TaskMeta: The updated or newly created TaskMeta instance.

# Usage

$key = 'is_template';
$value = 'yes';

$meta = $task->updateMeta($key, $value);

echo "Meta updated with key: " . $meta->key . " and value: " . $meta->value;

1
2
3
4
5
6
7

# getMeta($key, $default = null)

Retrieve the value of a meta entry for the task. If the meta entry does not exist, return a default value.

  • Parameters
    • $key string: The key of the meta entry to retrieve.
    • $default mixed: The default value to return if the meta entry does not exist. Defaults to null.
  • Returns mixed: The value of the meta entry if it exists, otherwise the default value.

# Usage

$key = 'is_template';
$default = 'yes';

$value = $task->getMeta($key, $default);

echo "The meta value is: " . $value;

1
2
3
4
5
6
7

# close()

Mark the task as closed by updating its status and setting the completion time.

  • Parameters
    • None.
  • Returns self: The updated task instance.

# Usage

$task = $task->close();

echo "The task has been closed and its status is now: " . $task->status;

1
2
3
4

# reopen()

Reopen the task by changing its status to open and clearing the completion time.

  • Parameters
    • None.
  • Returns self: The updated task instance.

# Usage

$task = $task->reopen();

echo "The task has been reopened and its status is now: " . $task->status;

1
2
3
4