Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Utility class for browsing of course files.

Copyright: 2008 Petr Skoda (http://skodak.org)
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 997 lines (36 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 4 classes

file_info_context_course:: (20 methods):
  __construct()
  get_file_info()
  get_course_areas()
  get_area_course_summary()
  get_area_course_overviewfiles()
  get_area_course_section()
  get_area_course_legacy()
  get_area_backup_course()
  get_area_backup_automated()
  get_area_backup_section()
  get_visible_name()
  is_writable()
  is_directory()
  get_children()
  get_child_module()
  get_filtered_children()
  get_module_areas_with_files()
  get_non_empty_children()
  count_non_empty_children()
  get_parent()

file_info_area_course_legacy:: (4 methods):
  __construct()
  get_url()
  get_children()
  get_non_empty_children()

file_info_area_course_section:: (9 methods):
  __construct()
  get_params()
  get_visible_name()
  is_writable()
  is_empty_area()
  is_directory()
  get_children()
  count_non_empty_children()
  get_parent()

file_info_area_backup_section:: (9 methods):
  __construct()
  get_params()
  get_visible_name()
  is_writable()
  is_empty_area()
  is_directory()
  get_children()
  count_non_empty_children()
  get_parent()


Class: file_info_context_course  - X-Ref

Represents a course context in the tree navigated by {@link file_browser}.

__construct($browser, $context, $course)   X-Ref
Constructor

param: file_browser $browser file browser instance
param: stdClass $context context object
param: stdClass $course course object

get_file_info($component, $filearea, $itemid, $filepath, $filename)   X-Ref
Return information about this specific context level

param: string $component component
param: string $filearea file area
param: int $itemid item ID
param: string $filepath file path
param: string $filename file name
return: file_info|null file_info instance or null if not found or access not allowed

get_course_areas($extensions = '*', $returnemptyfolders = false)   X-Ref
Returns list of areas inside this course

param: string $extensions Only return areas that have files with these extensions
param: bool $returnemptyfolders return all areas always, if true it will ignore the previous argument
return: array

get_area_course_summary($itemid, $filepath, $filename)   X-Ref
Gets a stored file for the course summary filearea directory

param: int $itemid item ID
param: string $filepath file path
param: string $filename file name
return: file_info|null file_info instance or null if not found or access not allowed

get_area_course_overviewfiles($itemid, $filepath, $filename)   X-Ref
Gets a stored file for the course images filearea directory

param: int $itemid item ID
param: string $filepath file path
param: string $filename file name
return: file_info|null file_info instance or null if not found or access not allowed

get_area_course_section($itemid, $filepath, $filename)   X-Ref
Gets a stored file for the course section filearea directory

param: int $itemid item ID
param: string $filepath file path
param: string $filename file name
return: file_info|null file_info instance or null if not found or access not allowed

get_area_course_legacy($itemid, $filepath, $filename)   X-Ref
Gets a stored file for the course legacy filearea directory

param: int $itemid item ID
param: string $filepath file path
param: string $filename file name
return: file_info|null file_info instance or null if not found or access not allowed

get_area_backup_course($itemid, $filepath, $filename)   X-Ref
Gets a stored file for the backup course filearea directory

param: int $itemid item ID
param: string $filepath file path
param: string $filename file name
return: file_info|null file_info instance or null if not found or access not allowed

get_area_backup_automated($itemid, $filepath, $filename)   X-Ref
Gets a stored file for the automated backup filearea directory

param: int $itemid item ID
param: string $filepath file path
param: string $filename file name
return: file_info|null

get_area_backup_section($itemid, $filepath, $filename)   X-Ref
Gets a stored file for the backup section filearea directory

param: int $itemid item ID
param: string $filepath file path
param: string $filename file name
return: file_info|null file_info instance or null if not found or access not allowed

get_visible_name()   X-Ref
Returns localised visible name.

return: string

is_writable()   X-Ref
Whether or not new files or directories can be added

return: bool

is_directory()   X-Ref
Whether or not this is a directory

return: bool

get_children()   X-Ref
Returns list of children.

return: array of file_info instances

get_child_module($cm)   X-Ref
Returns the child module if it is accessible by the current user

param: cm_info|int $cm
return: file_info_context_module|null

get_filtered_children($extensions = '*', $countonly = false, $returnemptyfolders = false)   X-Ref
Help function to return files matching extensions or their count

param: string|array $extensions, either '*' or array of lowercase extensions, i.e. array('.gif','.jpg')
param: bool|int $countonly if false returns the children, if an int returns just the
param: bool $returnemptyfolders if true returns items that don't have matching files inside
return: array|int array of file_info instances or the count

get_module_areas_with_files($extensions = '*')   X-Ref
Returns list of areas inside the course modules that have files with the given extension

param: string $extensions
return: array

get_non_empty_children($extensions = '*')   X-Ref
Returns list of children which are either files matching the specified extensions
or folders that contain at least one such file.

param: string|array $extensions, either '*' or array of lowercase extensions, i.e. array('.gif','.jpg')
return: array of file_info instances

count_non_empty_children($extensions = '*', $limit = 1)   X-Ref
Returns the number of children which are either files matching the specified extensions
or folders containing at least one such file.

param: string|array $extensions, for example '*' or array('.gif','.jpg')
param: int $limit stop counting after at least $limit non-empty children are found
return: int

get_parent()   X-Ref
Returns parent file_info instance

return: file_info or null for root

Class: file_info_area_course_legacy  - X-Ref

Subclass of file_info_stored for files in the course files area.

__construct($browser, $context, $storedfile)   X-Ref
Constructor

param: file_browser $browser file browser instance
param: stdClass $context context object
param: stored_file $storedfile stored_file instance

get_url($forcedownload=false, $https=false)   X-Ref
Returns file download url

param: bool $forcedownload whether or not force download
param: bool $https whether or not force https
return: string url

get_children()   X-Ref
Returns list of children.

return: array of file_info instances

get_non_empty_children($extensions = '*')   X-Ref
Returns list of children which are either files matching the specified extensions
or folders that contain at least one such file.

param: string|array $extensions, either '*' or array of lowercase extensions, i.e. array('.gif','.jpg')
return: array of file_info instances

Class: file_info_area_course_section  - X-Ref

Represents a course category context in the tree navigated by {@link file_browser}.

__construct($browser, $context, $course, file_info_context_course $courseinfo)   X-Ref
Constructor

param: file_browser $browser file browser instance
param: stdClass $context context object
param: stdClass $course course object
param: file_info_context_course $courseinfo file info instance

get_params()   X-Ref
Returns list of standard virtual file/directory identification.
The difference from stored_file parameters is that null values
are allowed in all fields

return: array with keys contextid, filearea, itemid, filepath and filename

get_visible_name()   X-Ref
Returns localised visible name.

return: string

is_writable()   X-Ref
Return whether or not new files or directories can be added

return: bool

is_empty_area()   X-Ref
Return whether or not this is a empty area

return: bool

is_directory()   X-Ref
Return whether or not this is a empty area

return: bool

get_children()   X-Ref
Returns list of children.

return: array of file_info instances

count_non_empty_children($extensions = '*', $limit = 1)   X-Ref
Returns the number of children which are either files matching the specified extensions
or folders containing at least one such file.

param: string|array $extensions, for example '*' or array('.gif','.jpg')
param: int $limit stop counting after at least $limit non-empty children are found
return: int

get_parent()   X-Ref
Returns parent file_info instance

return: file_info|null file_info or null for root

Class: file_info_area_backup_section  - X-Ref

Implementation of course section backup area

__construct($browser, $context, $course, file_info_context_course $courseinfo)   X-Ref
Constructor

param: file_browser $browser file browser instance
param: stdClass $context context object
param: stdClass $course course object
param: file_info_context_course $courseinfo file info instance

get_params()   X-Ref
Returns list of standard virtual file/directory identification.
The difference from stored_file parameters is that null values
are allowed in all fields

return: array with keys contextid, component, filearea, itemid, filepath and filename

get_visible_name()   X-Ref
Returns localised visible name.

return: string

is_writable()   X-Ref
Return whether or not new files and directories can be added

return: bool

is_empty_area()   X-Ref
Whether or not this is an empty area

return: bool

is_directory()   X-Ref
Return whether or not this is a directory

return: bool

get_children()   X-Ref
Returns list of children.

return: array of file_info instances

count_non_empty_children($extensions = '*', $limit = 1)   X-Ref
Returns the number of children which are either files matching the specified extensions
or folders containing at least one such file.

param: string|array $extensions, for example '*' or array('.gif','.jpg')
param: int $limit stop counting after at least $limit non-empty children are found
return: int

get_parent()   X-Ref
Returns parent file_info instance

return: file_info or null for root