Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

(no description)

File Size: 649 lines (23 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: api  - X-Ref

Class api is the public endpoint of the communication api. This class is the point of contact for api usage.

Communication api allows to add ad-hoc tasks to the queue to perform actions on the communication providers. This api will
not allow any immediate actions to be performed on the communication providers. It will only add the tasks to the queue. The
exception has been made for deletion of members in case of deleting the user. This is because the user will not be available.
The member management api part allows run actions immediately if required.

Communication api does allow to have form elements related to communication api in the required forms. This is done by using
the form_definition method. This method will add the form elements to the form.

__construct(private context $context,private string $component,private string $instancetype,private int $instanceid,private ?string $provider = null,)   X-Ref
Communication handler constructor to manage and handle all communication related actions.

This class is the entrypoint for all kinda usages.
It will be used by the other api to manage the communication providers.

param: context $context The context of the item for the instance
param: string $component The component of the item for the instance
param: string $instancetype The type of the item for the instance
param: int $instanceid The id of the instance
param: string|null $provider The provider type - if null will load for this context's active provider.

load_by_instance(context $context,string $component,string $instancetype,int $instanceid,?string $provider = null,)   X-Ref
Get the communication processor object.

param: context $context The context of the item for the instance
param: string $component The component of the item for the instance
param: string $instancetype The type of the item for the instance
param: int $instanceid The id of the instance
param: string|null $provider The provider type - if null will load for this context's active provider.
return: api

reload()   X-Ref
Reload in the internal instance data.


get_processor()   X-Ref
Return the underlying communication processor object.

return: processor

get_room_provider()   X-Ref
Return the room provider.

return: \core_communication\room_chat_provider

get_user_provider()   X-Ref
Return the user provider.

return: \core_communication\user_provider

get_room_user_provider()   X-Ref
Return the room user provider.

return: \core_communication\room_user_provider

get_form_provider()   X-Ref
Return the form provider.

return: \core_communication\form_provider

is_available()   X-Ref
Check if the communication api is enabled.


get_communication_room_url()   X-Ref
Get the communication room url.

return: string|null

get_communication_plugin_list_for_form()   X-Ref
Get the list of plugins for form selection.

return: array

get_enabled_providers_and_default(string $selecteddefaulprovider = null)   X-Ref
Get the enabled communication providers and default provider according to the selected provider.

param: string|null $selecteddefaulprovider
return: array

form_definition(\MoodleQuickForm $mform,string $selectdefaultcommunication = processor::PROVIDER_NONE)   X-Ref
Define the form elements for the communication api.
This method will be called from the form definition method of the instance.

param: \MoodleQuickForm $mform The form element
param: string $selectdefaultcommunication The default selected communication provider in the form field

form_definition_for_provider(\MoodleQuickForm $mform, string $provider = processor::PROVIDER_NONE)   X-Ref
Set the form definitions for the plugins.

param: \MoodleQuickForm $mform The moodle form
param: string $provider The provider name

get_avatar()   X-Ref
Get the avatar file.

return: null|\stored_file

get_avatar_filerecord(string $filename)   X-Ref
Get the avatar file record for the avatar for filesystem.

param: string $filename The filename of the avatar
return: stdClass

set_avatar(?\stored_file $avatar)   X-Ref
Get the avatar file.

If null is set, then delete the old area file and set the avatarfilename to null.
This will make sure the plugin api deletes the avatar from the room.

param: null|\stored_file $avatar The stored file for the avatar
return: bool

get_room_name()   X-Ref
A helper to fetch the room name

return: string

set_data(\stdClass $instance)   X-Ref
Set the form data if the data is already available.

param: \stdClass $instance The instance object

get_provider()   X-Ref
Get the communication provider.

return: string

create_and_configure_room(string $communicationroomname,?\stored_file $avatar = null,?\stdClass $instance = null,)   X-Ref
Create a communication ad-hoc task for create operation.
This method will add a task to the queue to create the room.

param: string $communicationroomname The communication room name
param: null|\stored_file $avatar The stored file for the avatar
param: \stdClass|null $instance The actual instance object

update_room(?int $active = null,?string $communicationroomname = null,?\stored_file $avatar = null,?\stdClass $instance = null,)   X-Ref
Create a communication ad-hoc task for update operation.
This method will add a task to the queue to update the room.

param: null|int $active The selected active state of the provider
param: null|string $communicationroomname The communication room name
param: null|\stored_file $avatar The stored file for the avatar
param: \stdClass|null $instance The actual instance object

delete_room()   X-Ref
Create a communication ad-hoc task for delete operation.
This method will add a task to the queue to delete the room.


add_members_to_room(array $userids, bool $queue = true)   X-Ref
Create a communication ad-hoc task for add members operation and add the user mapping.

This method will add a task to the queue to add the room users.

param: array $userids The user ids to add to the room
param: bool $queue Whether to queue the task or not

update_room_membership(array $userids, bool $queue = true)   X-Ref
Create a communication ad-hoc task for updating members operation and update the user mapping.

This method will add a task to the queue to update the room users.

param: array $userids The user ids to add to the room
param: bool $queue Whether to queue the task or not

remove_members_from_room(array $userids, bool $queue = true)   X-Ref
Create a communication ad-hoc task for remove members operation or action immediately.

This method will add a task to the queue to remove the room users.

param: array $userids The user ids to remove from the room
param: bool $queue Whether to queue the task or not

show_communication_room_status_notification()   X-Ref
Display the communication room status notification.