Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
file_info_context_course Class Reference

Represents a course context in the tree navigated by file_browser. More...

Inheritance diagram for file_info_context_course:
file_info

Public Member Functions

 __construct ($browser, $context, $course)
 Constructor.
 
 copy_to_pathname ($pathname)
 Copy content of this file to local storage, overriding current file if needed.
 
 copy_to_storage ($filerecord)
 Copy content of this file to local storage, overriding current file if needed.
 
 count_non_empty_children ($extensions=' *', $limit=1)
 Returns the number of children which are either files matching the specified extensions or folders containing at least one such file.
 
 create_directory ($newdirname, $userid=NULL)
 Create new directory, may throw exception - make sure params are valid.
 
 create_file_from_pathname ($newfilename, $pathname, $userid=NULL)
 Create new file from pathname - make sure params are valid.
 
 create_file_from_storedfile ($newfilename, $fid, $userid=NULL)
 Create new file from stored file - make sure params are valid.
 
 create_file_from_string ($newfilename, $content, $userid=NULL)
 Create new file from string - make sure params are valid.
 
 delete ()
 Delete file, make sure file is deletable first.
 
 get_author ()
 Returns the author name of the file.
 
 get_children ()
 Returns list of children.
 
 get_file_info ($component, $filearea, $itemid, $filepath, $filename)
 Return information about this specific context level.
 
 get_filesize ()
 Returns file size in bytes, null for directories.
 
 get_license ()
 Returns the license type of the file.
 
 get_mimetype ()
 Returns mimetype.
 
 get_non_empty_children ($extensions=' *')
 Returns list of children which are either files matching the specified extensions or folders that contain at least one such file.
 
 get_params ()
 Returns list of standard virtual file/directory identification.
 
 get_params_rawencoded ()
 Returns array of url encoded params.
 
 get_parent ()
 Returns parent file_info instance.
 
 get_readable_fullname ()
 Returns the localised human-readable name of the file together with virtual path.
 
 get_sortorder ()
 Returns the sort order of the file.
 
 get_source ()
 Returns the source of the file.
 
 get_status ()
 Returns file status flag.
 
 get_timecreated ()
 Returns time created unix timestamp if known.
 
 get_timemodified ()
 Returns time modified unix timestamp if known.
 
 get_url ($forcedownload=false, $https=false)
 Returns file download url.
 
 get_visible_name ()
 Returns localised visible name.
 
 is_directory ()
 Whether or not this is a directory.
 
 is_empty_area ()
 Is this info area and is it "empty"? Are there any files in subfolders?
 
 is_external_file ()
 Whether or not this is a external resource.
 
 is_readable ()
 Whether or not I can read content of this file or enter directory.
 
 is_writable ()
 Whether or not new files or directories can be added.
 

Protected Member Functions

 build_search_files_sql ($extensions, $prefix=null)
 Builds SQL sub query (WHERE clause) for selecting files with the specified extensions.
 
 get_area_backup_automated ($itemid, $filepath, $filename)
 Gets a stored file for the automated backup filearea directory.
 
 get_area_backup_course ($itemid, $filepath, $filename)
 Gets a stored file for the backup course filearea directory.
 
 get_area_backup_section ($itemid, $filepath, $filename)
 Gets a stored file for the backup section filearea directory.
 
 get_area_course_legacy ($itemid, $filepath, $filename)
 Gets a stored file for the course legacy filearea directory.
 
 get_area_course_overviewfiles ($itemid, $filepath, $filename)
 Gets a stored file for the course images filearea directory.
 
 get_area_course_section ($itemid, $filepath, $filename)
 Gets a stored file for the course section filearea directory.
 
 get_area_course_summary ($itemid, $filepath, $filename)
 Gets a stored file for the course summary filearea directory.
 
 get_child_module ($cm)
 Returns the child module if it is accessible by the current user.
 
 get_course_areas ($extensions=' *', $returnemptyfolders=false)
 Returns list of areas inside this course.
 
 get_module_areas_with_files ($extensions=' *')
 Returns list of areas inside the course modules that have files with the given extension.
 

Protected Attributes

file_browser $browser
 File browser instance.
 
file_info_context_module[] $childrenmodules = []
 cached child modules.
 
context $context
 File context.
 
stdClass $course
 course object
 

Detailed Description

Represents a course context in the tree navigated by file_browser.

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

Constructor & Destructor Documentation

◆ __construct()

file_info_context_course::__construct ( $browser,
$context,
$course )

Constructor.

Parameters
file_browser$browserfile browser instance
stdClass$contextcontext object
stdClass$coursecourse object

Member Function Documentation

◆ build_search_files_sql()

file_info::build_search_files_sql ( $extensions,
$prefix = null )
protectedinherited

Builds SQL sub query (WHERE clause) for selecting files with the specified extensions.

If $extensions == '*' (any file), the result is array('', array()) otherwise the result is something like array('AND filename ...', array(...))

Parameters
string | array$extensions- either '*' or array of lowercase extensions, i.e. array('.gif','.jpg')
string$prefixprefix for DB table files in the query (empty by default)
Return values
arrayof two elements: $sql - sql where clause and $params - array of parameters

◆ copy_to_pathname()

file_info::copy_to_pathname ( $pathname)
inherited

Copy content of this file to local storage, overriding current file if needed.

Todo
MDL-31068 implement move() rename() unzip() zip()
Parameters
string$pathnamereal local full file name
Return values
booleansuccess

Reimplemented in file_info_stored.

◆ copy_to_storage()

file_info::copy_to_storage ( $filerecord)
inherited

Copy content of this file to local storage, overriding current file if needed.

Parameters
array | stdClass$filerecordcontains contextid, component, filearea, itemid, filepath, filename and optionally other attributes of the new file
Return values
boolsuccess

Reimplemented in file_info_stored.

◆ count_non_empty_children()

file_info_context_course::count_non_empty_children ( $extensions = '*',
$limit = 1 )

Returns the number of children which are either files matching the specified extensions or folders containing at least one such file.

Parameters
string | array$extensions,forexample '*' or array('.gif','.jpg')
int$limitstop counting after at least $limit non-empty children are found
Return values
int

Reimplemented from file_info.

◆ create_directory()

file_info::create_directory ( $newdirname,
$userid = NULL )
inherited

Create new directory, may throw exception - make sure params are valid.

Parameters
string$newdirnamename of new directory
int$useridid of author, default $USER->id
Return values
file_infonew directory

Reimplemented in file_info_stored.

◆ create_file_from_pathname()

file_info::create_file_from_pathname ( $newfilename,
$pathname,
$userid = NULL )
inherited

Create new file from pathname - make sure params are valid.

Parameters
string$newfilenamename of new file
string$pathnamelocation of file
int$useridid of author, default $USER->id
Return values
file_infonew file

Reimplemented in file_info_stored.

◆ create_file_from_storedfile()

file_info::create_file_from_storedfile ( $newfilename,
$fid,
$userid = NULL )
inherited

Create new file from stored file - make sure params are valid.

Parameters
string$newfilenamename of new file
int | stored_file$fidid or stored_file of file
int$useridid of author, default $USER->id
Return values
file_infonew file

Reimplemented in file_info_stored.

◆ create_file_from_string()

file_info::create_file_from_string ( $newfilename,
$content,
$userid = NULL )
inherited

Create new file from string - make sure params are valid.

Parameters
string$newfilenamename of new file
string$contentof file
int$useridid of author, default $USER->id
Return values
file_infonew file

Reimplemented in file_info_stored.

◆ delete()

file_info::delete ( )
inherited

Delete file, make sure file is deletable first.

Return values
boolsuccess

Reimplemented in file_info_stored.

◆ get_area_backup_automated()

file_info_context_course::get_area_backup_automated ( $itemid,
$filepath,
$filename )
protected

Gets a stored file for the automated backup filearea directory.

Parameters
int$itemiditem ID
string$filepathfile path
string$filenamefile name
Return values
file_info|null

◆ get_area_backup_course()

file_info_context_course::get_area_backup_course ( $itemid,
$filepath,
$filename )
protected

Gets a stored file for the backup course filearea directory.

Parameters
int$itemiditem ID
string$filepathfile path
string$filenamefile name
Return values
file_info|nullfile_info instance or null if not found or access not allowed

◆ get_area_backup_section()

file_info_context_course::get_area_backup_section ( $itemid,
$filepath,
$filename )
protected

Gets a stored file for the backup section filearea directory.

Parameters
int$itemiditem ID
string$filepathfile path
string$filenamefile name
Return values
file_info|nullfile_info instance or null if not found or access not allowed

◆ get_area_course_legacy()

file_info_context_course::get_area_course_legacy ( $itemid,
$filepath,
$filename )
protected

Gets a stored file for the course legacy filearea directory.

Parameters
int$itemiditem ID
string$filepathfile path
string$filenamefile name
Return values
file_info|nullfile_info instance or null if not found or access not allowed

◆ get_area_course_overviewfiles()

file_info_context_course::get_area_course_overviewfiles ( $itemid,
$filepath,
$filename )
protected

Gets a stored file for the course images filearea directory.

Parameters
int$itemiditem ID
string$filepathfile path
string$filenamefile name
Return values
file_info|nullfile_info instance or null if not found or access not allowed

◆ get_area_course_section()

file_info_context_course::get_area_course_section ( $itemid,
$filepath,
$filename )
protected

Gets a stored file for the course section filearea directory.

Parameters
int$itemiditem ID
string$filepathfile path
string$filenamefile name
Return values
file_info|nullfile_info instance or null if not found or access not allowed

◆ get_area_course_summary()

file_info_context_course::get_area_course_summary ( $itemid,
$filepath,
$filename )
protected

Gets a stored file for the course summary filearea directory.

Parameters
int$itemiditem ID
string$filepathfile path
string$filenamefile name
Return values
file_info|nullfile_info instance or null if not found or access not allowed

◆ get_author()

file_info::get_author ( )
inherited

Returns the author name of the file.

Return values
stringauthor name or null

Reimplemented in file_info_stored.

◆ get_child_module()

file_info_context_course::get_child_module ( $cm)
protected

Returns the child module if it is accessible by the current user.

Parameters
cm_info | int$cm
Return values
file_info_context_module|null

◆ get_children()

file_info_context_course::get_children ( )

Returns list of children.

Return values
arrayof file_info instances

Reimplemented from file_info.

◆ get_course_areas()

file_info_context_course::get_course_areas ( $extensions = '*',
$returnemptyfolders = false )
protected

Returns list of areas inside this course.

Parameters
string$extensionsOnly return areas that have files with these extensions
bool$returnemptyfoldersreturn all areas always, if true it will ignore the previous argument
Return values
array

◆ get_file_info()

file_info_context_course::get_file_info ( $component,
$filearea,
$itemid,
$filepath,
$filename )

Return information about this specific context level.

Parameters
string$componentcomponent
string$fileareafile area
int$itemiditem ID
string$filepathfile path
string$filenamefile name
Return values
file_info|nullfile_info instance or null if not found or access not allowed

◆ get_filesize()

file_info::get_filesize ( )
inherited

Returns file size in bytes, null for directories.

Return values
intbytes or null if not known

Reimplemented in file_info_stored.

◆ get_license()

file_info::get_license ( )
inherited

Returns the license type of the file.

Return values
stringlicense short name or null

Reimplemented in file_info_stored.

◆ get_mimetype()

file_info::get_mimetype ( )
inherited

Returns mimetype.

Return values
stringmimetype or null if not known

Reimplemented in file_info_stored.

◆ get_module_areas_with_files()

file_info_context_course::get_module_areas_with_files ( $extensions = '*')
protected

Returns list of areas inside the course modules that have files with the given extension.

Parameters
string$extensions
Return values
array

◆ get_non_empty_children()

file_info_context_course::get_non_empty_children ( $extensions = '*')

Returns list of children which are either files matching the specified extensions or folders that contain at least one such file.

Parameters
string | array$extensions,either'*' or array of lowercase extensions, i.e. array('.gif','.jpg')
Return values
arrayof file_info instances

Reimplemented from file_info.

◆ get_params()

file_info::get_params ( )
inherited

Returns list of standard virtual file/directory identification.

The difference from stored_file parameters is that null values are allowed in all fields

Return values
arraywith keys contextid, component, filearea, itemid, filepath and filename

Reimplemented in book_file_info, data_file_info_container, file_info_area_backup_section, file_info_area_course_section, file_info_stored, forum_file_info_container, glossary_file_info_container, imscp_file_info, mod_lesson_file_info, workshop_file_info_overallfeedback_container, and workshop_file_info_submissions_container.

◆ get_params_rawencoded()

file_info::get_params_rawencoded ( )
inherited

Returns array of url encoded params.

Return values
arraywith numeric keys

◆ get_parent()

file_info_context_course::get_parent ( )

Returns parent file_info instance.

Return values
file_infoor null for root

Reimplemented from file_info.

◆ get_readable_fullname()

file_info::get_readable_fullname ( )
inherited

Returns the localised human-readable name of the file together with virtual path.

See also
file_info_stored\get_readable_fullname()
Return values
string

Reimplemented in file_info_stored.

◆ get_sortorder()

file_info::get_sortorder ( )
inherited

Returns the sort order of the file.

Return values
int

Reimplemented in file_info_stored.

◆ get_source()

file_info::get_source ( )
inherited

Returns the source of the file.

Return values
stringa source url or null

Reimplemented in file_info_stored.

◆ get_status()

file_info::get_status ( )
inherited

Returns file status flag.

Return values
int0 means file OK, anything else is a problem and file can not be used

Reimplemented in file_info_stored.

◆ get_timecreated()

file_info::get_timecreated ( )
inherited

Returns time created unix timestamp if known.

Return values
inttimestamp or null

Reimplemented in file_info_stored.

◆ get_timemodified()

file_info::get_timemodified ( )
inherited

Returns time modified unix timestamp if known.

Return values
inttimestamp or null

Reimplemented in file_info_stored.

◆ get_url()

file_info::get_url ( $forcedownload = false,
$https = false )
inherited

Returns file download url.

Parameters
bool$forcedownloadwhether or not force download
bool$httpswhether or not force https
Return values
stringurl

Reimplemented in file_info_area_course_legacy, and file_info_stored.

◆ get_visible_name()

file_info_context_course::get_visible_name ( )

Returns localised visible name.

Return values
string

Reimplemented from file_info.

◆ is_directory()

file_info_context_course::is_directory ( )

Whether or not this is a directory.

Return values
bool

Reimplemented from file_info.

◆ is_empty_area()

file_info::is_empty_area ( )
inherited

Is this info area and is it "empty"? Are there any files in subfolders?

This is used mostly in repositories to reduce the number of empty folders. This method may be very slow, use with care.

Return values
bool

Reimplemented in file_info_area_backup_section, file_info_area_course_section, file_info_context_module, and file_info_stored.

◆ is_external_file()

file_info::is_external_file ( )
inherited

Whether or not this is a external resource.

Return values
bool

Reimplemented in file_info_stored.

◆ is_readable()

file_info::is_readable ( )
inherited

Whether or not I can read content of this file or enter directory.

Return values
bool

Reimplemented in file_info_stored.

◆ is_writable()

file_info_context_course::is_writable ( )

Whether or not new files or directories can be added.

Return values
bool

Reimplemented from file_info.

Member Data Documentation

◆ $childrenmodules

file_info_context_module [] file_info_context_course::$childrenmodules = []
protected

cached child modules.

See get_child_module()


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