Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
core_contentbank\contentbank Class Reference

Content bank class. More...

Public Member Functions

 create_content_from_file (\context $context, int $userid, stored_file $file)
 Create content from a file information.
 
 delete_contents (context $context)
 Delete content bank content by context.
 
 get_content_from_id (int $id)
 Return a content class form a content id.
 
 get_contenttypes_with_capability_feature (string $feature, context $context=null, bool $enabled=true)
 Get the list of content types that have the requested feature.
 
 get_contexts_with_capabilities_by_user ($capability='moodle/contentbank:access', $userid=null)
 Return all the context where a user has all the given capabilities.
 
 get_enabled_content_types ()
 Obtains the list of core_contentbank_content objects currently active.
 
 get_extension (string $filename)
 Returns the file extension for a file.
 
 get_extension_supporter (string $extension, context $context=null)
 Get the first content bank plugin supports a file extension.
 
 get_supported_extensions_as_string (context $context=null)
 Obtains a string with all supported extensions by active plugins.
 
 is_context_allowed (context $context)
 Whether the context is allowed.
 
 load_all_supported_extensions ()
 Obtains an array of supported extensions by active plugins.
 
 load_context_supported_extensions (context $context=null)
 Obtains an array of supported extensions in the given context.
 
 move_contents (context $from, context $to)
 Move content bank content from a context to another.
 
 search_contents (?string $search=null, ?int $contextid=0, ?array $contenttypenames=null)
 Find the contents with $search% in the contextid defined.
 

Detailed Description

Content bank class.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Member Function Documentation

◆ create_content_from_file()

core_contentbank\contentbank::create_content_from_file ( \context $context,
int $userid,
stored_file $file )

Create content from a file information.

Exceptions
file_exceptionIf file operations fail
dml_exceptionif the content creation fails
Parameters
context$contextContext where to upload the file and content.
int$useridId of the user uploading the file.
stored_file$fileThe file to get information from
Return values
content

◆ delete_contents()

core_contentbank\contentbank::delete_contents ( context $context)

Delete content bank content by context.

Parameters
context$contextThe context to delete content from.
Return values
bool

◆ get_content_from_id()

core_contentbank\contentbank::get_content_from_id ( int $id)

Return a content class form a content id.

Exceptions
coding_exceptionif the ID is not valid or some class does no exists
Parameters
int$idthe content id
Return values
contentthe content class instance

◆ get_contenttypes_with_capability_feature()

core_contentbank\contentbank::get_contenttypes_with_capability_feature ( string $feature,
context $context = null,
bool $enabled = true )

Get the list of content types that have the requested feature.

Parameters
string$featureFeature code e.g CAN_UPLOAD.
null | context$contextOptional context to check the permission to use the feature.
bool$enabledWhether check only the enabled content types or all of them.
Return values
string[]List of content types where the user has permission to access the feature.

◆ get_contexts_with_capabilities_by_user()

core_contentbank\contentbank::get_contexts_with_capabilities_by_user ( $capability = 'moodle/contentbank:access',
$userid = null )

Return all the context where a user has all the given capabilities.

Parameters
string$capabilityThe capability the user needs to have.
int | null$useridOptional userid. $USER by default.
Return values
arrayArray of the courses and course categories where the user has the given capability.

◆ get_enabled_content_types()

core_contentbank\contentbank::get_enabled_content_types ( )

Obtains the list of core_contentbank_content objects currently active.

The list does not include players which are disabled.

Return values
string[]Array of contentbank contenttypes.

◆ get_extension()

core_contentbank\contentbank::get_extension ( string $filename)

Returns the file extension for a file.

Parameters
string$filenameThe name of the file
Return values
stringThe extension of the file

◆ get_extension_supporter()

core_contentbank\contentbank::get_extension_supporter ( string $extension,
context $context = null )

Get the first content bank plugin supports a file extension.

Parameters
string$extensionContent file extension
context$context$context Optional context to check (default null)
Return values
stringcontenttype name supports the file extension or null if the extension is not supported by any allowed plugin.

◆ get_supported_extensions_as_string()

core_contentbank\contentbank::get_supported_extensions_as_string ( context $context = null)

Obtains a string with all supported extensions by active plugins.

Mainly to use as filepicker options parameter.

Parameters
context$contextOptional context to check (default null)
Return values
stringA string with all the extensions supported.

◆ is_context_allowed()

core_contentbank\contentbank::is_context_allowed ( context $context)

Whether the context is allowed.

Parameters
context$contextContext to check.
Return values
bool

◆ load_all_supported_extensions()

core_contentbank\contentbank::load_all_supported_extensions ( )

Obtains an array of supported extensions by active plugins.

Return values
arrayThe array with all the extensions supported and the supporting plugin names.

◆ load_context_supported_extensions()

core_contentbank\contentbank::load_context_supported_extensions ( context $context = null)

Obtains an array of supported extensions in the given context.

Parameters
context$contextOptional context to check (default null)
Return values
arrayThe array with all the extensions supported and the supporting plugin names.

◆ move_contents()

core_contentbank\contentbank::move_contents ( context $from,
context $to )

Move content bank content from a context to another.

Parameters
context$fromThe context to get content from.
context$toThe context to move content to.
Return values
bool

◆ search_contents()

core_contentbank\contentbank::search_contents ( ?string $search = null,
?int $contextid = 0,
?array $contenttypenames = null )

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().

Parameters
string | null$searchOptional string to search (for now it will search only into the name).
int$contextidOptional contextid to search.
array$contenttypenamesOptional array with the list of content-type names to search.
Return values
arrayThe contents for the enabled contentbank-type plugins having $search as name and placed in $contextid.

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