Moodle PHP Documentation 5.1
Moodle 5.1dev (Build: 20250711) (9addea9f0ac)
core_ai\manager Class Reference

Public Member Functions

 __construct (protected moodle_database readonly moodle_database $db,)
 Create a new AI manager.
 
 change_provider_order (int $providerid, int $direction)
 Change the order of the provider instance relative to other provider instances.
 
 create_provider_instance (string $classname, string $name, bool $enabled=false, ?array $config=null, ?array $actionconfig=null,)
 Create a new provider instance.
 
 delete_provider_instance (provider $provider)
 Delete the provider instance.
 
 disable_provider_instance (provider $provider)
 Disable a provider.
 
 enable_provider_instance (provider $provider)
 Enable a provider instance.
 
 get_provider_instances (?array $filter=null)
 Get a list of all provider instances.
 
 get_provider_record (array $filter=[], int $strictness=IGNORE_MISSING)
 Get single provider record according to the filter.
 
 get_provider_records (?array $filter=null)
 Get the provider records according to the filter.
 
 get_providers_for_actions (array $actions, bool $enabledonly=false)
 Given a list of actions get the provider instances that support them.
 
 get_sorted_providers ()
 Get the configured ai providers from the manager.
 
 is_action_available (string $actionclass)
 Check if an action is available.
 
 is_action_enabled (string $plugin, string $actionclass, int $instanceid=0)
 Check if an action is enabled for a given plugin.
 
 process_action (base $action)
 Process an action.
 
 set_action_state (string $plugin, string $actionbasename, int $enabled, int $instanceid=0)
 Set the action state for a given plugin.
 
 set_provider_config (array $data, string $plugin)
 Sets config variable for given provider instance.
 
 update_provider_instance (provider $provider, ?array $config=null, ?array $actionconfig=null)
 Update provider instance.
 
 update_provider_order (int $providerid, string|int $action)
 Update the provider instance order configuration.
 

Static Public Member Functions

static get_supported_actions (string $pluginname)
 Get the list of actions that this provider or placement supports, given the name of the plugin.
 
static get_user_policy_status (int $userid)
 Get the user policy.
 
static sort_providers_by_order (array $unsorted)
 Sorts provider instances by configured order.
 
static user_policy_accepted (int $userid, int $contextid)
 Set the policy acceptance for a given user.
 

Protected Member Functions

 call_action_provider (provider $provider, base $action)
 Call the action provider.
 

Constructor & Destructor Documentation

◆ __construct()

core_ai\manager::__construct ( protected moodle_database readonly moodle_database $db)

Create a new AI manager.

Parameters
moodle_database$db
Parameters
$dbThe database instance

Member Function Documentation

◆ call_action_provider()

core_ai\manager::call_action_provider ( provider $provider,
base $action )
protected

Call the action provider.

The named provider will process the action and return the result.

Parameters
provider$providerThe provider to call.
base$actionThe action to process.
Return values
responses::response_baseThe result of the action.

◆ change_provider_order()

core_ai\manager::change_provider_order ( int $providerid,
int $direction )

Change the order of the provider instance relative to other provider instances.

When possible, the change will be stored into the config_log table, to let admins check when/who has modified it.

Parameters
int$provideridThe provider ID.
int$directionThe direction to move the provider instance. Negative numbers mean up, Positive mean down.
Return values
boolWhether the provider has been updated or not.

◆ create_provider_instance()

core_ai\manager::create_provider_instance ( string $classname,
string $name,
bool $enabled = false,
?array $config = null,
?array $actionconfig = null )

Create a new provider instance.

Parameters
string$classnameClassname of the provider.
string$nameThe name of the provider config.
bool$enabledThe enabled state of the provider.
array | null$configThe config json.
array | null$actionconfigThe action config json.
Return values
provider

◆ delete_provider_instance()

core_ai\manager::delete_provider_instance ( provider $provider)

Delete the provider instance.

Parameters
provider$providerThe provider instance.
Return values
bool

◆ disable_provider_instance()

core_ai\manager::disable_provider_instance ( provider $provider)

Disable a provider.

Parameters
provider$provider
Return values
provider

◆ enable_provider_instance()

core_ai\manager::enable_provider_instance ( provider $provider)

Enable a provider instance.

Parameters
provider$provider
Return values
provider

◆ get_provider_instances()

core_ai\manager::get_provider_instances ( ?array $filter = null)

Get a list of all provider instances.

This method retrieves provider records from the database, attempts to instantiate each provider class, and returns an array of provider instances. It filters out any records where the provider class does not exist.

Parameters
null | array$filterThe database filter to apply when fetching provider records.
Return values
arrayAn array of instantiated provider objects.

◆ get_provider_record()

core_ai\manager::get_provider_record ( array $filter = [],
int $strictness = IGNORE_MISSING )

Get single provider record according to the filter.

Parameters
array$filterThe filterable elements to get the record from
int$strictness
Return values
stdClass|false

◆ get_provider_records()

core_ai\manager::get_provider_records ( ?array $filter = null)

Get the provider records according to the filter.

Parameters
array | null$filterThe filterable elements to get the records from.
Return values
array

◆ get_providers_for_actions()

core_ai\manager::get_providers_for_actions ( array $actions,
bool $enabledonly = false )

Given a list of actions get the provider instances that support them.

Will return an array of arrays, indexed by action name.

Parameters
array$actionsAn array of fully qualified action class names.
bool$enabledonlyIf true, only return enabled providers.
Return values
arrayAn array of provider instances indexed by action name.

◆ get_sorted_providers()

core_ai\manager::get_sorted_providers ( )

Get the configured ai providers from the manager.

Return values
array

◆ get_supported_actions()

static core_ai\manager::get_supported_actions ( string $pluginname)
static

Get the list of actions that this provider or placement supports, given the name of the plugin.

Parameters
string$pluginnameThe name of the plugin to get the actions for.
Return values
arrayAn array of action class names.

◆ get_user_policy_status()

static core_ai\manager::get_user_policy_status ( int $userid)
static

Get the user policy.

Parameters
int$useridThe user id.
Return values
boolTrue if the policy was accepted, false otherwise.

◆ is_action_available()

core_ai\manager::is_action_available ( string $actionclass)

Check if an action is available.

Action is available if it is enabled for at least one enabled provider.

Parameters
string$actionclassThe fully qualified action class name to be checked.
Return values
bool

◆ is_action_enabled()

core_ai\manager::is_action_enabled ( string $plugin,
string $actionclass,
int $instanceid = 0 )

Check if an action is enabled for a given plugin.

Parameters
string$pluginThe name of the plugin.
string$actionclassThe fully qualified action class name to be checked.
int$instanceidThe instance id of the plugin.
Return values
boolReturns the configuration value of the action for the given plugin.

◆ process_action()

core_ai\manager::process_action ( base $action)

Process an action.

This is the entry point for processing an action.

Parameters
base$actionThe action to process. Action must be configured.
Return values
responses::response_baseThe result of the action.

◆ set_action_state()

core_ai\manager::set_action_state ( string $plugin,
string $actionbasename,
int $enabled,
int $instanceid = 0 )

Set the action state for a given plugin.

Parameters
string$pluginThe name of the plugin.
string$actionbasenameThe action to be set.
int$enabledThe state to be set (e.g., enabled or disabled).
int$instanceidThe instance id of the instance.
Return values
boolReturns true if the configuration was successfully set, false otherwise.

◆ set_provider_config()

core_ai\manager::set_provider_config ( array $data,
string $plugin )

Sets config variable for given provider instance.

Parameters
array$dataThe data to set.
string$pluginThe plugin name.
Return values
booltrue or exception.
Exceptions
dml_exception

◆ sort_providers_by_order()

static core_ai\manager::sort_providers_by_order ( array $unsorted)
static

Sorts provider instances by configured order.

Parameters
array$unsortedof provider instance objects
Return values
arrayof provider instance objects

◆ update_provider_instance()

core_ai\manager::update_provider_instance ( provider $provider,
?array $config = null,
?array $actionconfig = null )

Update provider instance.

Parameters
provider$providerThe provider instance.
array | null$configthe configuration of the provider instance to be updated.
array | null$actionconfigthe action configuration of the provider instance to be updated.
Return values
provider

◆ update_provider_order()

core_ai\manager::update_provider_order ( int $providerid,
string|int $action )

Update the provider instance order configuration.

Parameters
int$provideridThe provider ID.
string | int$action
Exceptions
dml_exception

◆ user_policy_accepted()

static core_ai\manager::user_policy_accepted ( int $userid,
int $contextid )
static

Set the policy acceptance for a given user.

Parameters
int$useridThe user id.
int$contextidThe context id the policy was accepted in.
Return values
boolTrue if the policy was set, false otherwise.

The documentation for this class was generated from the following file: