Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]

File size admin setting.

Copyright: 2019 Shamim Rezaie <shamim@moodle.com>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 197 lines (7 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

filesize:: (7 methods):
  __construct()
  get_units()
  get_size_text()
  parse_bytes()
  get_setting()
  write_setting()
  output_html()


Class: filesize  - X-Ref

An admin setting to support entering and displaying of file sizes in Bytes, KB, MB or GB.

__construct(string $name, string $visiblename, string $description,int $defaultvalue = null, int $defaultunit = null)   X-Ref
Constructor

param: string    $name           unique ascii name, either 'mysetting' for settings that in config,
param: string    $visiblename    localised name
param: string    $description    localised long description
param: int|null  $defaultvalue   Value of the settings in bytes
param: int|null  $defaultunit    GB, MB, etc. (in bytes)

get_units()   X-Ref
Returns selectable units.

return: array

get_size_text(int $bytes)   X-Ref
Converts bytes to some more user friendly string.

param: int     $bytes  The number of bytes we want to convert from
return: string

parse_bytes(int $bytes)   X-Ref
Finds suitable units for given file size.

param: int     $bytes  The number of bytes
return: array           Parsed file size in the format of ['v' => value, 'u' => unit]

get_setting()   X-Ref
Get the selected file size as array.

return: array|null  An array containing 'v' => xx, 'u' => xx, or null if not set

write_setting($data)   X-Ref
Store the file size as bytes.

param: array   $data   Must be form 'h' => xx, 'm' => xx
return: string          The error string if any

output_html($data, $query = '')   X-Ref
Returns file size text+select fields.

param: array   $data   The current setting value. Must be form 'v' => xx, 'u' => xx.
param: string  $query  Admin search query to be highlighted.
return: string          File size text+select fields and wrapping div(s).