# TaskTemplates

## Introduction

`TaskTemplates` are the component where all information about what the task is and how it should be reported is stored.

Usually it will have related [FormFields](https://docs.api.intratool.de/api-reference/forms/form-fields) which describe how [TaskProgressFields](https://docs.api.intratool.de/api-reference/tasks-2/task-progress-fields) should be filled by the executing user. `TaskTemplates` can have other `TaskTemplates` as children.

[TaskAssignments](https://docs.api.intratool.de/api-reference/tasks-2/task-assignments) will utilize the `TaskTemplate` information to create [Tasks](https://docs.api.intratool.de/api-reference/tasks-2/task-executions) assigned to users or user groups.

## Model Definition

**Alias**

`taskTemplate`

**Relations**

| Relation                                                                                | Key               | Type             | Relation Field(s)                                  |
| --------------------------------------------------------------------------------------- | ----------------- | ---------------- | -------------------------------------------------- |
| [TaskTemplate](https://docs.api.intratool.de/api-reference/tasks-2/task-templates)      | `parent`          | Belongs to       | `parent_id`                                        |
| [TaskTemplates](https://docs.api.intratool.de/api-reference/tasks-2/task-templates)     | `children`        | Has many         | `parent_id`                                        |
| [TaskAssignments](https://docs.api.intratool.de/api-reference/tasks-2/task-assignments) | `taskAssignments` | Has many         | `parent_id`                                        |
| [Tasks](https://docs.api.intratool.de/api-reference/tasks-2/task-executions)            | `tasks`           | Has many through | `tasks.task_assignment_id`                         |
| [FormFields](https://docs.api.intratool.de/api-reference/forms/form-fields)             | `formFields`      | Has many         | `form_fields.form_id form_fields.type`             |
| [User](https://docs.api.intratool.de/api-reference/users)                               | `user`            | Belongs to       | `user_id`                                          |
| [Layouts](https://docs.api.intratool.de/api-reference/layouts/layouts)                  | `layouts`         | Has many         | `layouts.layoutable_type`, `layouts.layoutable_id` |

**Traits**

* `Sortable`
* `Layoutable`

## List

To get a list of task template, create a GET request to:

`/api/administration/tasks-2/templates/`.

**Example Request**

{% tabs %}
{% tab title="PHP" %}

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('GET', '/api/administration/tasks-2/templates', [
    'headers' => ['Authorization' => "Bearer {accessToken}"]
]);
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
[
  {
    "id": 6,
    "title": "Template-1",
    "description": "<p>Describe your template</p>",
    "parent_id": null,
    "revision_id": null,
    "origin_id": null,
    "folder_id": null,
    "sort_number": 39,
    "user_id": 144,
    "created_at": "2019-09-20 11:47:09",
    "updated_at": "2019-09-21 09:57:09",
    "deleted_at": null,
    "grade_scale": null,
    "tour_enabled": true,
    "quick_assignable": false
  },
  {
    "id": 7,
    "title": "SubTemplate-1",
    "description": "<p>Describe your template</p>",
    "parent_id": 6,
    "revision_id": null,
    "origin_id": null,
    "folder_id": null,
    "sort_number": 1,
    "user_id": 2,
    "created_at": "2019-09-20 11:47:09",
    "updated_at": "2019-09-20 11:47:09",
    "deleted_at": null,
    "grade_scale": null,
    "tour_enabled": false,
    "quick_assignable": false
  }
]
```

## List Quick Assignable

To get a list of task templates which can be used for quick assignments, create a GET request to:

`/api/tasks-2/templates/quick-assignable`.

**Example Request**

{% tabs %}
{% tab title="PHP" %}

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('GET', '/api/administration/tasks-2/templates/quick-assignable', [
    'headers' => ['Authorization' => "Bearer {accessToken}"]
]);
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
[
  {
    "id": 6,
    "title": "Template-1",
    "description": "<p>Describe your template</p>",
    "parent_id": null,
    "revision_id": null,
    "origin_id": null,
    "folder_id": null,
    "sort_number": 39,
    "user_id": 144,
    "created_at": "2019-09-20 11:47:09",
    "updated_at": "2019-09-21 09:57:09",
    "deleted_at": null,
    "grade_scale": null,
    "tour_enabled": true,
    "quick_assignable": true
  },
  {
    "id": 7,
    "title": "SubTemplate-1",
    "description": "<p>Describe your template</p>",
    "parent_id": 6,
    "revision_id": null,
    "origin_id": null,
    "folder_id": null,
    "sort_number": 1,
    "user_id": 2,
    "created_at": "2019-09-20 11:47:09",
    "updated_at": "2019-09-20 11:47:09",
    "deleted_at": null,
    "grade_scale": null,
    "tour_enabled": false,
    "quick_assignable": true
  }
]
```

## Show

To show a task template, create a GET request to:

`/api/administration/tasks-2/templates/{id}`.

**Example Request**

{% tabs %}
{% tab title="PHP" %}

```php
$client = new GuzzleHttp\Client(['base_uri' => 'https://{tenant}.intratool.de']);
$response = $client->request('GET', '/api/administration/tasks-2/templates/{id}', [
    'headers' => ['Authorization' => "Bearer {accessToken}"]
]);
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "id": 6,
  "title": "Template-1",
  "description": "<p>Describe your Template</p>",
  "parent_id": null,
  "revision_id": null,
  "origin_id": null,
  "folder_id": null,
  "sort_number": 39,
  "user_id": 144,
  "created_at": "2019-09-20 11:47:09",
  "updated_at": "2019-09-21 09:57:09",
  "deleted_at": null,
  "grade_scale": null,
  "tour_enabled": true,
  "quick_assignable": false
}
```

## Create

To create a new task template, create a POST request to:

`/api/administration/tasks-2/templates/`.

**Request Keys**

| Key                |   Type  | Default | Description                                             |
| ------------------ | :-----: | :-----: | ------------------------------------------------------- |
| `title`\*          |  string |    -    | The title of the template                               |
| `description`      |  string |    -    | The description of the template                         |
| `parent_id`        | integer |    -    | The parent\_id                                          |
| `sort_number`      | integer |    -    | The sort number of this template.                       |
| `grade_scale`      | integer |    -    | The grade scale of this template                        |
| `tour_enabled`     | boolean |    -    | Enables a user tour for tasks of this template          |
| `quick_assignable` | boolean |    -    | Enables a the template to be used for quick assignments |

Keys with `*` are required.

#### Advanced Key-Specifications

* `sort_number` - The input will be set to the maximum number, if left empty.
* `sort_number` - If you pass a number in between existing sorted entries, other entries will be automatically updated.
* `parent_id` - Has to be an existing task template id.

## Delete

To delete a Post, create a DELETE request to:

`/api/administration/tasks-2/templates/{id}`.

## Update

To update a task template, create a PUT request to:

`/api/administration/tasks-2/templates/{id}`.

**Request Keys**

| Key                |   Type  | Default | Description                                             |
| ------------------ | :-----: | :-----: | ------------------------------------------------------- |
| `title`            |  string |    -    | The title of the template                               |
| `description`      |  string |    -    | The description of the template                         |
| `parent_id`        | integer |    -    | The parent\_id                                          |
| `sort_number`      | integer |    -    | The sort number of this template.                       |
| `grade_scale`      | integer |    -    | The grade scale of this template                        |
| `tour_enabled`     | boolean |    -    | Enables a user tour for tasks of this template          |
| `quick_assignable` | boolean |    -    | Enables a the template to be used for quick assignments |

Keys with `*` are required.

#### Advanced Key-Specifications

* `sort_number` - The input will be set to the maximum number, if left empty.
* `sort_number` - If you pass a number in between existing sorted entries, other entries will be automatically updated.
* `parent_id` - Has to be an existing task template id.
