Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400] [Versions 400 and 403]

Content bank class

Copyright: 2020 Amaia Anabitarte <amaia@moodle.com>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 387 lines (15 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: contentbank  - X-Ref

Content bank class

get_enabled_content_types()   X-Ref
Obtains the list of core_contentbank_content objects currently active.

The list does not include players which are disabled.

return: string[] Array of contentbank contenttypes.

load_all_supported_extensions()   X-Ref
Obtains an array of supported extensions by active plugins.

return: array The array with all the extensions supported and the supporting plugin names.

load_context_supported_extensions(context $context = null)   X-Ref
Obtains an array of supported extensions in the given context.

return: array The array with all the extensions supported and the supporting plugin names.
param: context $context Optional context to check (default null)

get_supported_extensions_as_string(context $context = null)   X-Ref
Obtains a string with all supported extensions by active plugins.
Mainly to use as filepicker options parameter.

return: string A string with all the extensions supported.
param: context $context   Optional context to check (default null)

get_extension(string $filename)   X-Ref
Returns the file extension for a file.

return: string The extension of the file
param: string $filename The name of the file

get_extension_supporter(string $extension, context $context = null)   X-Ref
Get the first content bank plugin supports a file extension.

return: string contenttype name supports the file extension or null if the extension is not supported by any allowed plugin.
param: string $extension Content file extension
param: context $context $context     Optional context to check (default null)

search_contents(?string $search = null, ?int $contextid = 0, ?array $contenttypenames = null)   X-Ref
Find the contents with %$search% in the contextid defined.
If contextid and search are empty, all contents are returned.
In all the cases, only the contents for the enabled contentbank-type plugins are returned.
No content-type permissions are validated here. It is the caller responsability to check that the user can access to them.
The only validation done here is, for each content, a call to the method $content->is_view_allowed().

return: array The contents for the enabled contentbank-type plugins having $search as name and placed in $contextid.
param: string|null $search Optional string to search (for now it will search only into the name).
param: int $contextid Optional contextid to search.
param: array $contenttypenames Optional array with the list of content-type names to search.

get_contexts_with_capabilities_by_user($capability = 'moodle/contentbank:access', $userid = null)   X-Ref
Return all the context where a user has all the given capabilities.

return: array Array of the courses and course categories where the user has the given capability.
param: string $capability The capability the user needs to have.
param: int|null $userid Optional userid. $USER by default.

create_content_from_file(\context $context, int $userid, stored_file $file)   X-Ref
Create content from a file information.

return: content
param: \context $context Context where to upload the file and content.
param: int $userid Id of the user uploading the file.
param: stored_file $file The file to get information from

delete_contents(context $context)   X-Ref
Delete content bank content by context.

return: bool
param: context $context The context to delete content from.

move_contents(context $from, context $to)   X-Ref
Move content bank content from a context to another.

return: bool
param: context $from The context to get content from.
param: context $to The context to move content to.

get_contenttypes_with_capability_feature(string $feature, \context $context = null, bool $enabled = true)   X-Ref
Get the list of content types that have the requested feature.

return: string[] List of content types where the user has permission to access the feature.
param: string $feature Feature code e.g CAN_UPLOAD.
param: null|\context $context Optional context to check the permission to use the feature.
param: bool $enabled Whether check only the enabled content types or all of them.

get_content_from_id(int $id)   X-Ref
Return a content class form a content id.

return: content the content class instance
param: int $id the content id

is_context_allowed(context $context)   X-Ref
Whether the context is allowed.

return: bool
param: context $context Context to check.