Resource-fs base class.

package commandr

 Methods

Whether the filesystem hook can handle a particular file type.

can_accept_filetype(string $filetype) : array

Parameters

$filetype

string

The file type (no file extension)

Returns

arrayList of our resource types that can

Get the resource ID for a filename (of file or folder). Note that filenames are unique across all folders in a filesystem.

convert_filename_to_id(\ID_TEXT $filename, \ID_TEXT $resource_type) : \?array

Parameters

$filename

\ID_TEXT

The filename, or filepath

$resource_type

\ID_TEXT

The resource type

Returns

\?arrayA pair: The resource type, the resource ID (null: could not find)

Get the filename for a resource ID (of file or folder). Note that filenames are unique across all folders in a filesystem.

convert_id_to_filename(\ID_TEXT $resource_type, \ID_TEXT $resource_id) : \?ID_TEXT

Parameters

$resource_type

\ID_TEXT

The resource type

$resource_id

\ID_TEXT

The resource ID

Returns

\?ID_TEXTThe filename (null: not found)

Convert a label to a filename, possibly with auto-creating if needed. This is useful for the Composr-side resource-agnostic API.

convert_label_to_filename(\LONG_TEXT $label, string $subpath, \ID_TEXT $resource_type, boolean $must_already_exist = false, \?ID_TEXT $use_guid_for_new = null) : \?ID_TEXT

Parameters

$label

\LONG_TEXT

Resource label

$subpath

string

The path (blank: root / not applicable). It may end in "/*" if you want to look for a match under a certain directory

$resource_type

\ID_TEXT

Resource type

$must_already_exist

boolean

Whether the content must already exist

$use_guid_for_new

\?ID_TEXT

GUID to auto-create with (null: either not auto-creating, or not specifying the GUID if we are)

Returns

\?ID_TEXTThe filename (null: not found)

Convert a label to an ID, possibly with auto-creating if needed. This is useful for the Composr-side resource-agnostic API.

convert_label_to_id(\SHORT_TEXT $_label, string $subpath, \ID_TEXT $resource_type, boolean $must_already_exist = false, \?ID_TEXT $use_guid_for_new = null) : \?ID_TEXT

Parameters

$_label

\SHORT_TEXT

Resource label

$subpath

string

The path (blank: root / not applicable). It may end in "/*" if you want to look for a match under a certain directory

$resource_type

\ID_TEXT

Resource type

$must_already_exist

boolean

Whether the content must already exist

$use_guid_for_new

\?ID_TEXT

GUID to auto-create with (null: either not auto-creating, or not specifying the GUID if we are)

Returns

\?ID_TEXTThe ID (null: not found)

Get the resource ID for a filename (of file). Note that filenames are unique across all folders in a filesystem.

file_convert_filename_to_id(\ID_TEXT $filename, \?ID_TEXT $resource_type = null) : \?array

Parameters

$filename

\ID_TEXT

The filename, or filepath

$resource_type

\?ID_TEXT

The resource type (null: assumption of only one folder resource type for this hook; only passed as non-NULL from overridden functions within hooks that are calling this as a helper function)

Returns

\?arrayA pair: The resource type, the resource ID (null: could not find)

Get the filename for a resource ID. Note that filenames are unique across all folders in a filesystem.

file_convert_id_to_filename(\ID_TEXT $resource_type, \ID_TEXT $resource_id) : \?ID_TEXT

Parameters

$resource_type

\ID_TEXT

The resource type

$resource_id

\ID_TEXT

The resource ID

Returns

\?ID_TEXTThe filename (null: could not find)

Load function for resource-fs (for files). Finds the data for some resource from a resource-fs file.

file_load__flat(\ID_TEXT $filename, string $path) : \~string

Parameters

$filename

\ID_TEXT

Filename

$path

string

The path (blank: root / not applicable)

Returns

\~stringResource data (false: error)

Load function for resource-fs (for files). Finds the data for some resource from a resource-fs XML file.

file_load_xml(\ID_TEXT $filename, string $path) : \~string

Parameters

$filename

\ID_TEXT

Filename

$path

string

The path (blank: root / not applicable)

Returns

\~stringResource data (false: error)

Save function for resource-fs (for files).

file_save(\ID_TEXT $filename, string $path, array $properties, \?ID_TEXT $search_label_as = null, \?ID_TEXT $search_path = null) : \~ID_TEXT

Parameters

$filename

\ID_TEXT

Filename

$path

string

The path to save at (blank: root / not applicable)

$properties

array

Properties

$search_label_as

\?ID_TEXT

Whether to look for existing records using $filename as a label and this resource type (null: $filename is a strict file name)

$search_path

\?ID_TEXT

Search path (null: the same as the path saving at)

Returns

\~ID_TEXTThe resource ID (false: error, could not create via these properties / here)

Save function for resource-fs (for files). Parses the data for some resource to a resource-fs file.

file_save__flat(\ID_TEXT $filename, string $path, string $data) : \~ID_TEXT

Parameters

$filename

\ID_TEXT

Filename

$path

string

The path (blank: root / not applicable)

$data

string

Resource data

Returns

\~ID_TEXTThe resource ID (false: error, could not create via these properties / here)

Save function for resource-fs (for files). Parses the data for some resource to a resource-fs XML file.

file_save_xml(\ID_TEXT $filename, string $path, string $data) : \~ID_TEXT

Parameters

$filename

\ID_TEXT

Filename

$path

string

The path (blank: root / not applicable)

$data

string

Resource data

Returns

\~ID_TEXTThe resource ID (false: error, could not create via these properties / here)

Get the resource ID for a filename (of folder). Note that filenames are unique across all folders in a filesystem.

folder_convert_filename_to_id(\ID_TEXT $filename, \?ID_TEXT $resource_type = null) : array

Parameters

$filename

\ID_TEXT

The filename, or filepath

$resource_type

\?ID_TEXT

The resource type (null: assumption of only one folder resource type for this hook; only passed as non-NULL from overridden functions within hooks that are calling this as a helper function)

Returns

arrayA pair: The resource type, the resource ID

Get the filename for a resource ID. Note that filenames are unique across all folders in a filesystem.

folder_convert_id_to_filename(\ID_TEXT $resource_type, \ID_TEXT $resource_id) : \?ID_TEXT

Parameters

$resource_type

\ID_TEXT

The resource type

$resource_id

\ID_TEXT

The resource ID

Returns

\?ID_TEXTThe filename (null: could not find)

Load function for resource-fs (for folders). Finds the data for some resource from a resource-fs folder.

folder_load__flat(\ID_TEXT $filename, string $path) : \~string

Parameters

$filename

\ID_TEXT

Filename

$path

string

The path (blank: root / not applicable)

Returns

\~stringResource data (false: error)

Load function for resource-fs (for folders). Finds the data for some resource from a resource-fs XML folder.

folder_load_xml(\ID_TEXT $filename, string $path) : \~string

Parameters

$filename

\ID_TEXT

Filename

$path

string

The path (blank: root / not applicable)

Returns

\~stringResource data (false: error)

Save function for resource-fs (for folders).

folder_save(\ID_TEXT $filename, string $path, array $properties, \?ID_TEXT $search_label_as = null, \?ID_TEXT $search_path = null) : \~ID_TEXT

Parameters

$filename

\ID_TEXT

Filename

$path

string

The path (blank: root / not applicable)

$properties

array

Properties

$search_label_as

\?ID_TEXT

Whether to look for existing records using $filename as a label and this resource type (null: $filename is a strict file name)

$search_path

\?ID_TEXT

Search path (null: the same as the path saving at)

Returns

\~ID_TEXTThe resource ID (false: error, could not create via these properties / here)

Save function for resource-fs (for folders). Parses the data for some resource to a resource-fs folder.

folder_save__flat(\ID_TEXT $filename, string $path, string $data) : \~ID_TEXT

Parameters

$filename

\ID_TEXT

Filename

$path

string

The path (blank: root / not applicable)

$data

string

Resource data

Returns

\~ID_TEXTThe resource ID (false: error, could not create via these properties / here)

Save function for resource-fs (for folders). Parses the data for some resource to a resource-fs XML folder.

folder_save_xml(\ID_TEXT $filename, string $path, string $data) : \~ID_TEXT

Parameters

$filename

\ID_TEXT

Filename

$path

string

The path (blank: root / not applicable)

$data

string

Resource data

Returns

\~ID_TEXTThe resource ID (false: error, could not create via these properties / here)

Get resource view access on the resource.

get_resource_access(\ID_TEXT $filename) : array

Parameters

$filename

\ID_TEXT

Resource filename (assumed to be of a folder type)

Returns

arrayA mapping from group ID to view access

Get resource view access on the resource.

get_resource_access__members(\ID_TEXT $filename) : array

Parameters

$filename

\ID_TEXT

Resource filename (assumed to be of a folder type)

Returns

arrayA mapping from member ID to view access

Get the resource privileges for the resource.

get_resource_privileges(\ID_TEXT $filename) : array

Parameters

$filename

\ID_TEXT

Resource filename (assumed to be of a folder type)

Returns

arrayA map between group ID, and a map of privilege to setting

Get the resource privileges for all members that have custom privileges on the resource.

get_resource_privileges__members(\ID_TEXT $filename) : array

Parameters

$filename

\ID_TEXT

Resource filename (assumed to be of a folder type)

Returns

arrayA map between member ID, and a map of privilege to setting

Find whether a resource type is of a file-type.

is_file_type(\ID_TEXT $resource_type) : boolean

Parameters

$resource_type

\ID_TEXT

The resource type

Returns

booleanWhether it is

Find whether a resource type is of a folder-type.

is_folder_type(\ID_TEXT $resource_type) : boolean

Parameters

$resource_type

\ID_TEXT

The resource type

Returns

booleanWhether it is

Standard commandr_fs listing function for Commandr-fs hooks.

listing(array $meta_dir, string $meta_root_node, object $commandr_fs) : \~array

Parameters

$meta_dir

array

The current meta-directory path

$meta_root_node

string

The root node of the current meta-directory

$commandr_fs

object

A reference to the Commandr filesystem object

Returns

\~arrayThe final directory listing (false: failure)

Standard commandr_fs directory creation function for Commandr-fs hooks.

make_directory(array $meta_dir, string $meta_root_node, string $new_dir_name, object $commandr_fs) : boolean

Parameters

$meta_dir

array

The current meta-directory path

$meta_root_node

string

The root node of the current meta-directory

$new_dir_name

string

The new directory name

$commandr_fs

object

A reference to the Commandr filesystem object

Returns

booleanSuccess?

Standard commandr_fs file reading function for Commandr-fs hooks.

read_file(array $meta_dir, string $meta_root_node, string $file_name, object $commandr_fs) : \~string

Parameters

$meta_dir

array

The current meta-directory path

$meta_root_node

string

The root node of the current meta-directory

$file_name

string

The file name

$commandr_fs

object

A reference to the Commandr filesystem object

Returns

\~stringThe file contents (false: failure)

Standard commandr_fs directory removal function for Commandr-fs hooks.

remove_directory(array $meta_dir, string $meta_root_node, string $dir_name, object $commandr_fs) : boolean

Parameters

$meta_dir

array

The current meta-directory path

$meta_root_node

string

The root node of the current meta-directory

$dir_name

string

The directory name

$commandr_fs

object

A reference to the Commandr filesystem object

Returns

booleanSuccess?

Standard commandr_fs file removal function for Commandr-fs hooks.

remove_file(array $meta_dir, string $meta_root_node, string $file_name, object $commandr_fs) : boolean

Parameters

$meta_dir

array

The current meta-directory path

$meta_root_node

string

The root node of the current meta-directory

$file_name

string

The file name

$commandr_fs

object

A reference to the Commandr filesystem object

Returns

booleanSuccess?

Reset resource privileges on the resource for all usergroups.

reset_resource_access(\ID_TEXT $filename) 

Parameters

$filename

\ID_TEXT

Resource filename (assumed to be of a folder type)

Reset resource privileges on the resource for all usergroups.

reset_resource_privileges(\ID_TEXT $filename) 

Parameters

$filename

\ID_TEXT

Resource filename (assumed to be of a folder type)

Adds some resource with the given label and properties. Wraps file_add/folder_add.

resource_add(\ID_TEXT $resource_type, \LONG_TEXT $label, string $path, \?array $properties = null) : \~ID_TEXT

Parameters

$resource_type

\ID_TEXT

Resource type

$label

\LONG_TEXT

Filename OR Resource label

$path

string

The path (blank: root / not applicable)

$properties

\?array

Properties (may be empty, properties given are open to interpretation by the hook but generally correspond to database fields) (null: none)

Returns

\~ID_TEXTThe resource ID (false: error, could not create via these properties / here)

Deletes the resource. Wraps file_delete/folder_delete.

resource_delete(\ID_TEXT $resource_type, \ID_TEXT $filename, string $path) : boolean

Parameters

$resource_type

\ID_TEXT

Resource type

$filename

\ID_TEXT

The filename

$path

string

The path (blank: root / not applicable)

Returns

booleanSuccess status

Edits the resource to the given properties. Wraps file_edit/folder_edit.

resource_edit(\ID_TEXT $resource_type, \ID_TEXT $filename, string $path, array $properties, boolean $explicit_move = false) : \~ID_TEXT

Parameters

$resource_type

\ID_TEXT

Resource type

$filename

\ID_TEXT

The filename

$path

string

The path (blank: root / not applicable)

$properties

array

Properties (may be empty, properties given are open to interpretation by the hook but generally correspond to database fields)

$explicit_move

boolean

Whether we are definitely moving (as opposed to possible having it in multiple positions)

Returns

\~ID_TEXTThe resource ID (false: error, could not create via these properties / here)

Finds the properties for some resource. Wraps file_load/folder_load.

resource_load(\ID_TEXT $resource_type, \SHORT_TEXT $filename, string $path) : \~array

Parameters

$resource_type

\ID_TEXT

Resource type

$filename

\SHORT_TEXT

Filename

$path

string

The path (blank: root / not applicable)

Returns

\~arrayDetails of the resource (false: error)

Save function for resource-fs. Parses the data for some resource to a resource-fs XML file. Wraps file_save/folder_save.

resource_save(\ID_TEXT $resource_type, \ID_TEXT $label, string $path, \?array $properties = null, \?ID_TEXT $search_label_as = null, \?ID_TEXT $search_path = null) : \~ID_TEXT

Parameters

$resource_type

\ID_TEXT

The resource type

$label

\ID_TEXT

Filename OR Resource label

$path

string

The path (blank: root / not applicable)

$properties

\?array

Properties (null: none)

$search_label_as

\?ID_TEXT

Whether to look for existing records using $filename as a label and this resource type (null: $filename is a strict file name)

$search_path

\?ID_TEXT

Search path (null: the same as the path saving at)

Returns

\~ID_TEXTThe resource ID (false: error, could not create via these properties / here)

Set resource view access on the resource.

set_resource_access(\ID_TEXT $filename, array $groups) 

Parameters

$filename

\ID_TEXT

Resource filename (assumed to be of a folder type)

$groups

array

A mapping from group ID to view access

Set resource view access on the resource.

set_resource_access__members(\ID_TEXT $filename, array $members) 

Parameters

$filename

\ID_TEXT

Resource filename (assumed to be of a folder type)

$members

array

A mapping from member ID to view access

Set resource privileges on the resource.

set_resource_privileges(\ID_TEXT $filename, array $group_settings) 

Parameters

$filename

\ID_TEXT

Resource filename (assumed to be of a folder type)

$group_settings

array

A map between group ID, and a map of privilege to setting

Set a resource privilege so that a member has a custom privilege on the resource.

set_resource_privileges__members(\ID_TEXT $filename, array $member_settings) 

Parameters

$filename

\ID_TEXT

Resource filename (assumed to be of a folder type)

$member_settings

array

A map between member ID, and a map of privilege to setting

Set resource privileges from a preset on the resource.

set_resource_privileges_from_preset(\ID_TEXT $filename, array $group_presets) 

Parameters

$filename

\ID_TEXT

Resource filename (assumed to be of a folder type)

$group_presets

array

A mapping from group ID to preset value. Preset values are 0 (read only) to 3 (moderation)

Set resource privileges from a preset so that a member has custom privileges on the resource.

set_resource_privileges_from_preset__members(\ID_TEXT $filename, array $member_presets) 

Parameters

$filename

\ID_TEXT

Resource filename (assumed to be of a folder type)

$member_presets

array

A mapping from member ID to preset value. Preset values are 0 (read only) to 3 (moderation)

Standard commandr_fs file writing function for Commandr-fs hooks.

write_file(array $meta_dir, string $meta_root_node, string $file_name, string $contents, object $commandr_fs) : boolean

Parameters

$meta_dir

array

The current meta-directory path

$meta_root_node

string

The root node of the current meta-directory

$file_name

string

The file name

$contents

string

The new file contents

$commandr_fs

object

A reference to the Commandr filesystem object

Returns

booleanSuccess?

Work out what a privilege preset means for a kind of resource.

_compute_privilege_preset_scheme(\ID_TEXT $filename) : \?array

Parameters

$filename

\ID_TEXT

Resource filename (assumed to be of a folder type)

Returns

\?arrayA mapping from privilege to minimum preset level required for privilege activation (null: unworkable)

Turn a label into a name.

_create_name_from_label(\LONG_TEXT $label) : \ID_TEXT

Parameters

$label

\LONG_TEXT

The label

Returns

\ID_TEXTThe name

Find details of custom properties.

_custom_fields_enumerate_properties(\ID_TEXT $type) : array

Parameters

$type

\ID_TEXT

The resource type

Returns

arrayDetails of properties

Load custom properties.

_custom_fields_load(\ID_TEXT $type, \ID_TEXT $id) : array

Parameters

$type

\ID_TEXT

The resource type

$id

\ID_TEXT

The content ID

Returns

arrayLoaded properties

Save custom properties.

_custom_fields_save(\ID_TEXT $type, \ID_TEXT $id, array $properties) 

Parameters

$type

\ID_TEXT

The resource type

$id

\ID_TEXT

The content ID

$properties

array

Properties to save

Find an integer default property, defaulting to NULL.

_default_property_int(array $properties, \ID_TEXT $property) : \?integer

Parameters

$properties

array

The properties

$property

\ID_TEXT

The property

Returns

\?integerThe value (null: NULL value)

Find a default property, defaulting to the average of what is there already, or the given default if really necessary.

_default_property_int_modeavg(array $properties, \ID_TEXT $property, \ID_TEXT $table, integer $default, \?ID_TEXT $db_property = null) : integer

Parameters

$properties

array

The properties

$property

\ID_TEXT

The property

$table

\ID_TEXT

The table to average within

$default

integer

The last-resort default

$db_property

\?ID_TEXT

The database property (null: same as $property)

Returns

integerThe value

Find a default property, defaulting to blank.

_default_property_int_null(array $properties, \ID_TEXT $property) : \?integer

Parameters

$properties

array

The properties

$property

\ID_TEXT

The property

Returns

\?integerThe value (null: NULL value)

Find a default property, defaulting to blank.

_default_property_str(array $properties, \ID_TEXT $property) : \?string

Parameters

$properties

array

The properties

$property

\ID_TEXT

The property

Returns

\?stringThe value (null: NULL value)

Find a default property, defaulting to NULL.

_default_property_str_null(array $properties, \ID_TEXT $property) : \?string

Parameters

$properties

array

The properties

$property

\ID_TEXT

The property

Returns

\?stringThe value (null: NULL value)

Reinterpret the input of a file, into a way we can understand it to add/edit. Hooks may override this with special import code.

_file_magic_filter(\LONG_TEXT $filename, string $path, array $properties) : array

Parameters

$filename

\LONG_TEXT

Filename OR Resource label

$path

string

The path (blank: root / not applicable)

$properties

array

Properties

Returns

arrayA pair: the resource label, Properties (may be empty, properties given are open to interpretation by the hook but generally correspond to database fields)

Reinterpret the input of a folder, into a way we can understand it to add/edit. Hooks may override this with special import code.

_folder_magic_filter(\LONG_TEXT $filename, string $path, array $properties) : array

Parameters

$filename

\LONG_TEXT

Filename OR Resource label

$path

string

The path (blank: root / not applicable)

$properties

array

Properties

Returns

arrayA pair: the resource label, Properties (may be empty, properties given are open to interpretation by the hook but generally correspond to database fields)

Get the file resource info for this Commandr-fs resource hook.

_get_cma_info(\ID_TEXT $resource_type) : object

Parameters

$resource_type

\ID_TEXT

The resource type

Returns

objectThe object

Find all translated strings for a language ID. This is used as an intermediate step in creating multi-language serialisations.

_get_translated_text(\AUTO_LINK $lang_id, object $db) : array

Parameters

$lang_id

\AUTO_LINK

Language ID

$db

object

Database connection to look up from

Returns

arrayA map of language to the text in that language

Find whether a kind of resource handled by this hook (folder or file) can be under a particular kind of folder.

_has_parent_child_relationship(\?ID_TEXT $above, \ID_TEXT $under) : \?array

Parameters

$above

\?ID_TEXT

Folder resource type (null: root)

$under

\ID_TEXT

Resource type (may be file or folder)

Returns

\?arrayA map: The parent referencing field, the table it is in, and the ID field of that table (null: cannot be under)

Convert a category to an integer, defaulting to NULL if it is blank.

_integer_category(\?ID_TEXT $category) : \?integer

Parameters

$category

\?ID_TEXT

The category value (blank: root) (null: root)

Returns

\?integerThe category (null: root)

Whether the filesystem hook is active.

_is_active() : boolean

Returns

booleanWhether it is

Helper function: detect if a resource did not save all the properties it was given.

_log_if_save_matchup(\?ID_TEXT $resource_type, \~ID_TEXT $resource_id, string $path, array $properties) 

Parameters

$resource_type

\?ID_TEXT

The resource type (null: unknown)

$resource_id

\~ID_TEXT

The resource ID (false: was not added/edited)

$path

string

The path (blank: root / not applicable)

$properties

array

Properties

 Properties

 

$_cma_object

$_cma_object 

Default

array()
 

$file_resource_type

$file_resource_type 

Default

null
 

$folder_resource_type

$folder_resource_type 

Default

null