> ## Documentation Index
> Fetch the complete documentation index at: https://docs.opigno.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Training Prerequisites

> Controls training availability using a rule set based on the completion of prerequisite trainings

The Opigno Enterprise API allows administrators to control access to a specific training by defining Training Prerequisites conditions.
These conditions ensure that a learner can only access the training after successfully completing one or more designated prerequisite trainings.

By configuring prerequisites, administrators can specify the condition type that defines which trainings must be completed before a training is made accessible to the user.

## Data Structure

### TrainingPrerequisite

Represents a conditions preset to be met by user context for training application.

| Field                        | Type                                  | Description                                                                                                                                                |
| ---------------------------- | ------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `conditionType`              | `TrainingPrerequisitesConditionType!` | The condition type.                                                                                                                                        |
| `conditionFormulaExpression` | `String!`                             | The logical expression formula to be met for accessing the Learning Path. Represented by list of LP's ids separated by logical operators such as: AND, OR. |
| `learningPaths`              | `[LearningPath]`                      | List of referenced `LearningPath` objects to be considered for prerequisites conditions.                                                                   |
| `conditionPassed`            | `Boolean!`                            | Indicates whether the current user context is passed the prerequisites condition for the Learning Path.                                                    |

### TrainingPrerequisitesConditionType

The `TrainingPrerequisitesConditionType` enum defines the possible variant of training prerequisites condition types

| Condition type | Description                                                                                                    |
| :------------- | :------------------------------------------------------------------------------------------------------------- |
| `AND`          | All the listed Learning Paths in the prerequisites section should be successfully passed.                      |
| `OR`           | At least one Learning Paths from listed references in the prerequisites section should be successfully passed. |
| `CUSTOM`       | The list of required Learning Paths to be passed is defined by custom condition formula expression.            |

## Queries

The training prerequisites can be accessed by any `LearningPass` object with `trainingPrerequisites` field:

<CodeGroup>
  ```graphql GraphQL Query theme={null}
  query getLearningPath {
    getLearningPath(lpId: 60) {
      training {
        title
      }
      trainingPrerequisites {
        conditionType
        conditionFormulaExpression
        conditionPassed
        learningPaths {
          id
          training {
            title
          }
        }
      }
    }
  }
  ```

  ```json Response theme={null}
  {
    "data": {
      "getLearningPath": {
        "training": {
          "title": "Training with prerequisites "
        },
        "trainingPrerequisites": {
          "conditionType": "CUSTOM",
          "conditionFormulaExpression": "61 AND 62 AND (27 OR 2)",
          "conditionPassed": false,
          "learningPaths": [
            {
              "id": "2",
              "training": {
                "title": "Training 1"
              }
            },
            {
              "id": "27",
              "training": {
                "title": "Training 2"
              }
            },
            {
              "id": "61",
              "training": {
                "title": "Training 3"
              }
            },
            {
              "id": "62",
              "training": {
                "title": "Training 4"
              }
            }
          ]
        }
      }
    }
  }
  ```
</CodeGroup>

<Info>
  * You must have `AUTHENTICATED` scope to access prerequisites. Anonymous users cannot retrieve this data.
  * The API user context must be present and valid - otherwise, training prerequisites data won't be presented.
</Info>
