Moodle APIs  3.8
Moodle 3.8.6 (Build: 20201109)
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
file_info_stored Class Reference

Represents an actual file or folder - a row in the file table in the tree navigated by file_browser. More...

Inheritance diagram for file_info_stored:
file_info file_info_area_course_legacy folder_content_file_info page_content_file_info resource_content_file_info scorm_package_file_info

Public Member Functions

 __construct (file_browser $browser, $context, $storedfile, $urlbase, $topvisiblename, $itemidused, $readaccess, $writeaccess, $areaonly)
 Constructor. More...
 
 copy_to_pathname ($pathname)
 Copy content of this file to local storage, overriding current file if needed. More...
 
 copy_to_storage ($filerecord)
 Copy content of this file to local storage, overriding current file if needed. More...
 
 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. More...
 
 create_directory ($newdirname, $userid=NULL)
 Create new directory, may throw exception - make sure params are valid. More...
 
 create_file_from_pathname ($newfilename, $pathname, $userid=NULL)
 Create new file from pathname - make sure params are valid. More...
 
 create_file_from_storedfile ($newfilename, $fid, $userid=NULL)
 Create new file from stored file - make sure params are valid. More...
 
 create_file_from_string ($newfilename, $content, $userid=NULL)
 Create new file from string - make sure params are valid. More...
 
 delete ()
 Delete file, make sure file is deletable first. More...
 
 get_author ()
 Returns the author name of the file. More...
 
 get_children ()
 Returns list of children. More...
 
 get_filesize ()
 Returns file size in bytes, null for directories. More...
 
 get_imageinfo ()
 Returns width, height and mimetype of the stored image, or false. More...
 
 get_license ()
 Returns the license type of the file. More...
 
 get_mimetype ()
 Returns mimetype. More...
 
 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. More...
 
 get_params ()
 Returns list of standard virtual file/directory identification. More...
 
 get_params_rawencoded ()
 Returns array of url encoded params. More...
 
 get_parent ()
 Returns parent file_info instance. More...
 
 get_readable_fullname ()
 Returns the localised human-readable name of the file together with virtual path. More...
 
 get_sortorder ()
 Returns the sort order of the file. More...
 
 get_source ()
 Returns the source of the file. More...
 
 get_status ()
 Returns file status flag. More...
 
 get_timecreated ()
 Returns time created unix timestamp if known. More...
 
 get_timemodified ()
 Returns time modified unix timestamp if known. More...
 
 get_url ($forcedownload=false, $https=false)
 Returns file download url. More...
 
 get_visible_name ()
 Returns localised visible name. More...
 
 is_directory ()
 Whether or not this is a directory. More...
 
 is_empty_area ()
 Whether or not this is an empty area. More...
 
 is_external_file ()
 Whether or not this is a external resource. More...
 
 is_readable ()
 Whether or not I can read content of this file or enter directory. More...
 
 is_writable ()
 Whether or not new files or directories can be added. More...
 

Protected Member Functions

 build_search_files_sql ($extensions, $prefix=null)
 Builds SQL sub query (WHERE clause) for selecting files with the specified extensions. More...
 

Protected Attributes

string $areaonly
 do not show links to parent context/area
 
file_browser $browser
 File browser instance.
 
stdClass $context
 File context.
 
int bool $itemidused
 it's false if itemid is 0 and not included in URL
 
stored_file virtual_root_file $lf
 stored_file or virtual_root_file instance
 
bool $readaccess
 allow file reading
 
string $topvisiblename
 the human readable name of this area
 
string $urlbase
 the serving script
 
bool $writeaccess
 allow file write, delee
 

Detailed Description

Represents an actual file or folder - a row in the file table 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_stored::__construct ( file_browser  $browser,
  $context,
  $storedfile,
  $urlbase,
  $topvisiblename,
  $itemidused,
  $readaccess,
  $writeaccess,
  $areaonly 
)

Constructor.

Parameters
file_browser$browserfile browser instance
stdClass$contextcontext object
stored_file | virtual_root_file$storedfilestored_file instance
string$urlbasethe serving script - usually the $CFG->wwwroot/.'pluginfile.php'
string$topvisiblenamethe human readable name of this area
int | bool$itemidusedfalse if itemid always 0 and not included in URL
bool$readaccessallow file reading
bool$writeaccessallow file write, delete
string$areaonlydo not show links to parent context/area

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_stored::copy_to_pathname (   $pathname)

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

Parameters
string$pathnamereal local full file name
Return values
boolsuccess

Reimplemented from file_info.

◆ copy_to_storage()

file_info_stored::copy_to_storage (   $filerecord)

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 from file_info.

◆ count_non_empty_children()

file_info_stored::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_stored::create_directory (   $newdirname,
  $userid = NULL 
)

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_info|nullnew directory's file_info instance or null if failed

Reimplemented from file_info.

◆ create_file_from_pathname()

file_info_stored::create_file_from_pathname (   $newfilename,
  $pathname,
  $userid = NULL 
)

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_info|nullnew file's file_info instance or null if failed

Reimplemented from file_info.

◆ create_file_from_storedfile()

file_info_stored::create_file_from_storedfile (   $newfilename,
  $fid,
  $userid = NULL 
)

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

Parameters
string$newfilenamename of new file
int | stored_file$fidfile id or stored_file of file
int$useridid of author, default $USER->id
Return values
file_info|nullnew file's file_info instance or null if failed

Reimplemented from file_info.

◆ create_file_from_string()

file_info_stored::create_file_from_string (   $newfilename,
  $content,
  $userid = NULL 
)

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_info|nullnew file's file_info instance or null if failed

Reimplemented from file_info.

◆ delete()

file_info_stored::delete ( )

Delete file, make sure file is deletable first.

Return values
boolsuccess

Reimplemented from file_info.

◆ get_author()

file_info_stored::get_author ( )

Returns the author name of the file.

Return values
stringauthor name or null

Reimplemented from file_info.

◆ get_children()

file_info_stored::get_children ( )

Returns list of children.

Return values
arrayof file_info instances

Reimplemented from file_info.

Reimplemented in file_info_area_course_legacy.

◆ get_filesize()

file_info_stored::get_filesize ( )

Returns file size in bytes, null for directories.

Return values
intbytes or null if not known

Reimplemented from file_info.

◆ get_imageinfo()

file_info_stored::get_imageinfo ( )

Returns width, height and mimetype of the stored image, or false.

See also
stored_file::get_imageinfo()
Return values
array|false

◆ get_license()

file_info_stored::get_license ( )

Returns the license type of the file.

Return values
stringlicense short name or null

Reimplemented from file_info.

◆ get_mimetype()

file_info_stored::get_mimetype ( )

Returns mimetype.

Return values
stringmimetype or null if not known

Reimplemented from file_info.

◆ get_non_empty_children()

file_info_stored::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.

Reimplemented in file_info_area_course_legacy.

◆ get_params()

file_info_stored::get_params ( )

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 from file_info.

◆ get_params_rawencoded()

file_info::get_params_rawencoded ( )
inherited

Returns array of url encoded params.

Return values
arraywith numeric keys

◆ get_parent()

file_info_stored::get_parent ( )

Returns parent file_info instance.

Return values
file_info|nullfile_info instance or null for root

Reimplemented from file_info.

Reimplemented in scorm_package_file_info, resource_content_file_info, page_content_file_info, and folder_content_file_info.

◆ get_readable_fullname()

file_info_stored::get_readable_fullname ( )

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

Return values
string

Reimplemented from file_info.

◆ get_sortorder()

file_info_stored::get_sortorder ( )

Returns the sort order of the file.

Return values
int

Reimplemented from file_info.

◆ get_source()

file_info_stored::get_source ( )

Returns the source of the file.

Return values
stringa source url or null

Reimplemented from file_info.

◆ get_status()

file_info_stored::get_status ( )

Returns file status flag.

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

Reimplemented from file_info.

◆ get_timecreated()

file_info_stored::get_timecreated ( )

Returns time created unix timestamp if known.

Return values
inttimestamp or null

Reimplemented from file_info.

◆ get_timemodified()

file_info_stored::get_timemodified ( )

Returns time modified unix timestamp if known.

Return values
inttimestamp or null

Reimplemented from file_info.

◆ get_url()

file_info_stored::get_url (   $forcedownload = false,
  $https = false 
)

Returns file download url.

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

Reimplemented from file_info.

Reimplemented in file_info_area_course_legacy.

◆ get_visible_name()

file_info_stored::get_visible_name ( )

Returns localised visible name.

Return values
string

Reimplemented from file_info.

Reimplemented in scorm_package_file_info, resource_content_file_info, page_content_file_info, and folder_content_file_info.

◆ is_directory()

file_info_stored::is_directory ( )

Whether or not this is a directory.

Return values
bool

Reimplemented from file_info.

◆ is_empty_area()

file_info_stored::is_empty_area ( )

Whether or not this is an empty area.

Return values
bool

Reimplemented from file_info.

◆ is_external_file()

file_info_stored::is_external_file ( )

Whether or not this is a external resource.

Return values
bool

Reimplemented from file_info.

◆ is_readable()

file_info_stored::is_readable ( )

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

Return values
bool

Reimplemented from file_info.

◆ is_writable()

file_info_stored::is_writable ( )

Whether or not new files or directories can be added.

Return values
bool

Reimplemented from file_info.


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