Moodle PHP Documentation 4.3
Moodle 4.3.5 (Build: 20240610) (7dcfaa79f78)
core_portfolio

Namespaces

namespace  core_portfolio\privacy
  
 

Classes

interface  core_portfolio\privacy\portfolio_provider
 Provider for the portfolio API. More...
 
class  core_portfolio\privacy\provider
 Provider for the portfolio API. More...
 
class  portfolio_add_button
 Use this to add a portfolio button or icon or form to a page. More...
 
class  portfolio_admin_form
 Admin config form. More...
 
class  portfolio_button_exception
 Exception for interacting with the button class. More...
 
class  portfolio_caller_base
 Base class for callers. More...
 
class  portfolio_caller_exception
 Exception for callers to throw when they have a problem. More...
 
class  portfolio_exception
 Top level portfolio exception. More...
 
class  portfolio_export_exception
 Exception to throw during an export - will clean up session and tempdata. More...
 
class  portfolio_export_form
 During-export config form. More...
 
class  portfolio_exporter
 The class that handles the various stages of the actual export and the communication between the caller and the portfolio plugin. More...
 
class  portfolio_format
 Base class to inherit from. More...
 
class  portfolio_format_document
 'Document format', subtype of file. More...
 
class  portfolio_format_file
 The most basic type - pretty much everything is a subtype. More...
 
class  portfolio_format_image
 Image format, subtype of file. More...
 
class  portfolio_format_leap2a
 Class used for leap2a format. More...
 
class  portfolio_format_leap2a_entry
 This class represents a single leap2a entry. More...
 
class  portfolio_format_leap2a_exception
 Leap2a exception - for invalid api calls. More...
 
class  portfolio_format_leap2a_file
 Subclass of entry, purely for dealing with files. More...
 
class  portfolio_format_leap2a_writer
 Object to encapsulate the writing of leap2a. More...
 
class  portfolio_format_pdf
 'PDF format', subtype of file. More...
 
class  portfolio_format_plainhtml
 HTML format. More...
 
class  portfolio_format_presentation
 'Presentation format', subtype of file. More...
 
class  portfolio_format_rich
 Base class for rich formats. More...
 
class  portfolio_format_richhtml
 Richhtml - html with attachments. More...
 
class  portfolio_format_spreadsheet
 'Spreadsheet format', subtype of file. More...
 
class  portfolio_format_text
 Class for plain text format. More...
 
class  portfolio_format_video
 Video format. More...
 
class  portfolio_instance_select
 Form that just contains the dropdown menu of available instances. More...
 
class  portfolio_module_caller_base
 Base class for module callers. More...
 
class  portfolio_plugin_base
 The base class for portfolio plugins. More...
 
class  portfolio_plugin_exception
 Exception for portfolio plugins to throw when they have a problem. More...
 
class  portfolio_plugin_pull_base
 Class to inherit from for 'pull' type plugins. More...
 
class  portfolio_plugin_push_base
 Class to inherit from for 'push' type plugins. More...
 
class  portfolio_user_form
 User config form. More...
 

Functions

 portfolio_existing_exports ($userid, $type=null)
 Return a list of current exports for the given user.
 
 portfolio_existing_exports_by_plugin ($userid)
 Return an array of existing exports by type for a given user.
 
 portfolio_expected_time_db ($recordcount)
 Try and determine expected_time for purely database based exports or exports that might include large parts of a database.
 
 portfolio_expected_time_file ($totest)
 Try and determine expected_time for purely file based exports or exports that might include large file attachments.
 
 portfolio_export_pagesetup ($PAGE, $caller)
 Setup page export.
 
 portfolio_export_rethrow_exception ($exporter, $exception)
 Helper function to rethrow a caught portfolio_exception as an export exception.
 
 portfolio_export_type_to_id ($type, $userid)
 Get export type id.
 
 portfolio_filesize_info ()
 The default filesizes and threshold information for file based transfers.
 
 portfolio_format_from_mimetype ($mimetype)
 Deduce export format from file mimetype This function returns the revelant portfolio export format which is used to determine which portfolio plugins can be used for exporting this content according to the given mime type this only works when exporting exactly one file, or generating a new one (like a pdf or csv export)
 
 portfolio_format_is_abstract ($format)
 Tiny helper to figure out whether a portfolio format is abstract.
 
 portfolio_format_object ($name)
 Helper function to return a format object from the constant.
 
 portfolio_format_text_options ()
 Return default common options for format_text() when preparing a content to be exported.
 
 portfolio_has_visible_instances ()
 Return whether there are visible instances in portfolio.
 
 portfolio_include_callback_file ($component, $class=null)
 Function to require any potential callback files, throwing exceptions if an issue occurs.
 
 portfolio_insane_notify_admins ($insane, $instances=false)
 Function to send portfolio report to admins.
 
 portfolio_instance ($instanceid, $record=null)
 Helper function to return an instance of a plugin (with config loaded)
 
 portfolio_instance_sanity_check ($instances=null)
 Helper function to check all the instances for sanity and set any insane ones to invisible.
 
 portfolio_instance_select ($instances, $callerformats, $callbackclass, $mimetype=null, $selectname='instance', $return=false, $returnarray=false)
 Returns a drop menu with a list of available instances.
 
 portfolio_instances ($visibleonly=true, $useronly=true)
 Return all portfolio instances.
 
 portfolio_most_specific_formats ($specificformats, $generalformats)
 Return the combination of the two arrays of formats with duplicates in terms of specificity removed and also removes conflicting formats.
 
 portfolio_plugin_sanity_check ($plugins=null)
 Helper function to check all the plugins for sanity and set any insane ones to invisible.
 
 portfolio_report_insane ($insane, $instances=false, $return=false)
 Helper function to display a table of plugins (or instances) and reasons for disabling.
 
 portfolio_rewrite_pluginfile_url_callback ($contextid, $component, $filearea, $itemid, $format, $options, $matches)
 callback function from portfolio_rewrite_pluginfile_urls looks through preg_replace matches and replaces content with whatever the active portfolio export format says
 
 portfolio_rewrite_pluginfile_urls ($text, $contextid, $component, $filearea, $itemid, $format, $options=null)
 Go through all the @PLUGINFILE@ matches in some text, extract the file information and pass it back to the portfolio export format to regenerate the html to output.
 
 portfolio_static_function ($plugin, $function)
 Helper function to call a static function on a portfolio plugin class.
 
 portfolio_supported_formats ()
 Supported formats currently in use.
 
 portfolio_supported_formats_intersect ($callerformats, $pluginformats)
 Intersection of plugin formats and caller formats.
 

Variables

const PORTFOLIO_ADD_FAKE_URL 5
 PORTFOLIO_ADD_FAKE_URL - hacky way to turn the button class into a url to redirect to this replaces the old portfolio_fake_add_url function.
 
const PORTFOLIO_ADD_FULL_FORM 1
 PORTFOLIO_ADD_FULL_FORM - a whole form, containing a drop down menu (where necessary) and a submit button.
 
const PORTFOLIO_ADD_ICON_FORM 2
 PORTFOLIO_ADD_ICON_FORM - a whole form, containing a drop down menu (where necessary) but has an icon instead of a button to submit.
 
const PORTFOLIO_ADD_ICON_LINK 3
 PORTFOLIO_ADD_ICON_LINK - just an icon with a link around it (yuk, as will result in a long url only use where necessary)
 
const PORTFOLIO_ADD_MOODLE_URL 6
 PORTFOLIO_ADD_MOODULE_URL - hacky way to turn the button class into a moodle_url to redirect to this replaces the old portfolio_fake_add_url function.
 
const PORTFOLIO_ADD_TEXT_LINK 4
 PORTFOLIO_ADD_TEXT_LINK - just some text with a link around it (yuk, as will result in a long url only use where necessary)
 
const PORTFOLIO_FORMAT_DOCUMENT 'document'
 PORTFOLIO_FORMAT_DOCUMENT - subtype of file.
 
const PORTFOLIO_FORMAT_FILE 'file'
 PORTFOLIO_FORMAT_FILE - the most basic fallback format.
 
const PORTFOLIO_FORMAT_IMAGE 'image'
 PORTFOLIO_FORMAT_IMAGE - subtype of file.
 
const PORTFOLIO_FORMAT_LEAP2A 'leap2a'
 PORTFOLIO_FORMAT_LEAP2A - supported by mahara and and others {http://wiki.cetis.ac.uk/LEAP_2.0}.
 
const PORTFOLIO_FORMAT_MBKP 'mbkp'
 PORTFOLIO_FORMAT_MBKP - the plugin needs to be able to write a complete backup the caller need to be able to export the particular XML bits to insert into moodle.xml (?and the file bits if necessary)
 
const PORTFOLIO_FORMAT_PDF 'pdf'
 PORTFOLIO_FORMAT_PDF - subtype of file.
 
const PORTFOLIO_FORMAT_PLAINHTML 'plainhtml'
 PORTFOLIO_FORMAT_PLAINHTML - a single html representation - no attachments.
 
const PORTFOLIO_FORMAT_PRESENTATION 'presentation'
 PORTFOLIO_FORMAT_PRESENTATION - subtype of file.
 
const PORTFOLIO_FORMAT_RICH 'rich'
 PORTFOLIO_FORMAT_RICH - just used to say, "we support all these".
 
const PORTFOLIO_FORMAT_RICHHTML 'richhtml'
 PORTFOLIO_FORMAT_RICHHTML - like html but with attachments.
 
const PORTFOLIO_FORMAT_SPREADSHEET 'spreadsheet'
 PORTFOLIO_FORMAT_SPREADSHEET - subtype of file.
 
const PORTFOLIO_FORMAT_TEXT 'text'
 PORTFOLIO_FORMAT_TEXT - subtype of file.
 
const PORTFOLIO_FORMAT_VIDEO 'video'
 PORTFOLIO_FORMAT_VIDEO - subtype of file.
 
const PORTFOLIO_STAGE_CLEANUP 6
 PORTFOLIO_STAGE_CLEANUP - cleanup the temporary area.
 
const PORTFOLIO_STAGE_CONFIG 1
 PORTFOLIO_STAGE_CONFIG - display a form to the user this one might not be used if neither the plugin, or the caller has any config.
 
const PORTFOLIO_STAGE_CONFIRM 2
 PORTFOLIO_STAGE_CONFIRM - summarise the form and ask for confirmation if we skipped PORTFOLIO_STAGE_CONFIG, just confirm the send.
 
const PORTFOLIO_STAGE_FINISHED 7
 PORTFOLIO_STAGE_FINISHED - display the "finished notification".
 
const PORTFOLIO_STAGE_PACKAGE 4
 PORTFOLIO_STAGE_PACKAGE - package up the various bits during this stage both the caller and the plugin get their package methods called.
 
const PORTFOLIO_STAGE_QUEUEORWAIT 3
 PORTFOLIO_STAGE_QUEUEORWAIT - either queue the event and skip to PORTFOLIO_STAGE_FINISHED.
 
const PORTFOLIO_STAGE_SEND 5
 PORTFOLIO_STAGE_SEND - the portfolio plugin must send the file.
 
const PORTFOLIO_TIME_FORCEQUEUE 'queue'
 PORTFOLIO_TIME_FORCEQUEUE - very slow, or immediate transfers not supported.
 
const PORTFOLIO_TIME_HIGH 'high'
 PORTFOLIO_TIME_HIGH - slow.
 
const PORTFOLIO_TIME_LOW 'low'
 PORTFOLIO_TIME_LOW - no delay.
 
const PORTFOLIO_TIME_MODERATE 'moderate'
 PORTFOLIO_TIME_MODERATE - a small delay.
 

Detailed Description

Function Documentation

◆ portfolio_existing_exports()

portfolio_existing_exports ( $userid,
$type = null )

Return a list of current exports for the given user.

This will not go through and call rewaken_object, because it's heavy. It's really just used to figure out what exports are currently happening. This is useful for plugins that don't support multiple exports per session

Parameters
int$useridthe user to check for
string$type(optional) the portfolio plugin to filter by
Return values
array

◆ portfolio_existing_exports_by_plugin()

portfolio_existing_exports_by_plugin ( $userid)

Return an array of existing exports by type for a given user.

This is much more lightweight than existing_exports because it only returns the types, rather than the whole serialised data so can be used for checking availability of multiple plugins at the same time.

See also
existing_exports
Parameters
int$useridthe user to check for
Return values
array

◆ portfolio_expected_time_db()

portfolio_expected_time_db ( $recordcount)

Try and determine expected_time for purely database based exports or exports that might include large parts of a database.

Parameters
int$recordcountnumber of records trying to export
Return values
stringPORTFOLIO_TIME_XXX

◆ portfolio_expected_time_file()

portfolio_expected_time_file ( $totest)

Try and determine expected_time for purely file based exports or exports that might include large file attachments.

Parameters
stored_file | array$totest- either an array of stored_file objects or a single stored_file object
Return values
stringPORTFOLIO_TIME_XXX

◆ portfolio_export_pagesetup()

portfolio_export_pagesetup ( $PAGE,
$caller )

Setup page export.

Parameters
moodle_page$PAGEglobal variable from page object
portfolio_caller_base$callerplugin type caller

◆ portfolio_export_rethrow_exception()

portfolio_export_rethrow_exception ( $exporter,
$exception )

Helper function to rethrow a caught portfolio_exception as an export exception.

Used because when a portfolio_export exception is thrown the export is cancelled throws portfolio_export_exceptiog

Parameters
portfolio_exporter$exportercurrent exporter object
object$exceptionexception to rethrow

◆ portfolio_export_type_to_id()

portfolio_export_type_to_id ( $type,
$userid )

Get export type id.

Parameters
string$typeplugin type
int$useridthe user to check for
Return values
mixed|bool

◆ portfolio_filesize_info()

portfolio_filesize_info ( )

The default filesizes and threshold information for file based transfers.

This shouldn't need to be used outside the admin pages and the portfolio code

Return values
array

◆ portfolio_format_from_mimetype()

portfolio_format_from_mimetype ( $mimetype)

Deduce export format from file mimetype This function returns the revelant portfolio export format which is used to determine which portfolio plugins can be used for exporting this content according to the given mime type this only works when exporting exactly one file, or generating a new one (like a pdf or csv export)

Parameters
string$mimetype(usually $file->get_mimetype())
Return values
stringthe format constant (see PORTFOLIO_FORMAT_XXX constants)

◆ portfolio_format_is_abstract()

portfolio_format_is_abstract ( $format)

Tiny helper to figure out whether a portfolio format is abstract.

Parameters
string$formatthe format to test
Return values
bool

◆ portfolio_format_object()

portfolio_format_object ( $name)

Helper function to return a format object from the constant.

Parameters
string$namethe constant PORTFOLIO_FORMAT_XXX
Return values
portfolio_format

◆ portfolio_format_text_options()

portfolio_format_text_options ( )

Return default common options for format_text() when preparing a content to be exported.

It is important not to apply filters and not to clean the HTML in format_text()

Return values
stdClass

◆ portfolio_has_visible_instances()

portfolio_has_visible_instances ( )

Return whether there are visible instances in portfolio.

Return values
booltrue when there are some visible instances.

◆ portfolio_include_callback_file()

portfolio_include_callback_file ( $component,
$class = null )

Function to require any potential callback files, throwing exceptions if an issue occurs.

Parameters
string$componentThis is the name of the component in Moodle, eg 'mod_forum'
string$className of the class containing the callback functions activity components should ALWAYS use their name_portfolio_caller other locations must use something unique

◆ portfolio_insane_notify_admins()

portfolio_insane_notify_admins ( $insane,
$instances = false )

Function to send portfolio report to admins.

Parameters
array$insanearray of insane plugins
array$instances(optional) if reporting instances rather than whole plugins

◆ portfolio_instance()

portfolio_instance ( $instanceid,
$record = null )

Helper function to return an instance of a plugin (with config loaded)

Parameters
int$instanceidid of instance
object$recorddatabase row that corresponds to this instance this is passed to avoid unnecessary lookups Optional, and the record will be retrieved if null.
Return values
objectof portfolio_plugin_XXX

◆ portfolio_instance_sanity_check()

portfolio_instance_sanity_check ( $instances = null)

Helper function to check all the instances for sanity and set any insane ones to invisible.

Parameters
array$instancesarray of plugin instances
Return values
arrayarray of insane instances (keys= id, values = reasons (keys for plugin lang)

◆ portfolio_instance_select()

portfolio_instance_select ( $instances,
$callerformats,
$callbackclass,
$mimetype = null,
$selectname = 'instance',
$return = false,
$returnarray = false )

Returns a drop menu with a list of available instances.

Parameters
array$instancesarray of portfolio plugin instance objects - the instances to put in the menu
array$callerformatsarray of PORTFOLIO_FORMAT_XXX constants - the formats the caller supports (this is used to filter plugins)
string$callbackclassthe callback class name - used for debugging only for when there are no common formats
string$mimetypeif we already know we have exactly one file, or are going to write one, pass it here to do mime filtering.
string$selectnamethe name of the select element. Optional, defaults to instance.
bool$returnwhether to print or return the output. Optional, defaults to print.
bool$returnarrayif returning, whether to return the HTML or the array of options. Optional, defaults to HTML.
Return values
void|array|stringthe html, from <select> to </select> inclusive.

◆ portfolio_instances()

portfolio_instances ( $visibleonly = true,
$useronly = true )

Return all portfolio instances.

Todo
MDL-15768 - check capabilities here
Parameters
bool$visibleonlyDon't include hidden instances. Defaults to true and will be overridden to true if the next parameter is true
bool$useronlyCheck the visibility preferences and permissions of the logged in user. Defaults to true.
Return values
arrayof portfolio instances (full objects, not just database records)

◆ portfolio_most_specific_formats()

portfolio_most_specific_formats ( $specificformats,
$generalformats )

Return the combination of the two arrays of formats with duplicates in terms of specificity removed and also removes conflicting formats.

Use case: a module is exporting a single file, so the general formats would be FILE and MBKP while the specific formats would be the specific subclass of FILE based on mime (say IMAGE) and this function would return IMAGE and MBKP

Parameters
array$specificformatsarray of more specific formats (eg based on mime detection)
array$generalformatsarray of more general formats (usually more supported)
Return values
arraymerged formats with dups removed

◆ portfolio_plugin_sanity_check()

portfolio_plugin_sanity_check ( $plugins = null)

Helper function to check all the plugins for sanity and set any insane ones to invisible.

Parameters
array$pluginsarray of supported plugin types
Return values
arrayarray of insane instances (keys= id, values = reasons (keys for plugin lang)

◆ portfolio_report_insane()

portfolio_report_insane ( $insane,
$instances = false,
$return = false )

Helper function to display a table of plugins (or instances) and reasons for disabling.

Parameters
array$insanearray of portfolio plugin
array$instancesif reporting instances rather than whole plugins, pass the array (key = id, value = object) here
bool$returnoption to deliver the report in html format or print it out directly to the page.
Return values
void|stringof portfolio report in html table format

◆ portfolio_rewrite_pluginfile_url_callback()

portfolio_rewrite_pluginfile_url_callback ( $contextid,
$component,
$filearea,
$itemid,
$format,
$options,
$matches )

callback function from portfolio_rewrite_pluginfile_urls looks through preg_replace matches and replaces content with whatever the active portfolio export format says

Parameters
int$contextidmodule context id
string$componentmodule name (eg:mod_assign)
string$fileareanormal file_area arguments
int$itemidcomponent item id
portfolio_format$formatexporter format type
array$optionsextra options to pass through to the file_output function in the format (optional)
array$matchesinternal matching
Return values
object|array|string

◆ portfolio_rewrite_pluginfile_urls()

portfolio_rewrite_pluginfile_urls ( $text,
$contextid,
$component,
$filearea,
$itemid,
$format,
$options = null )

Go through all the @PLUGINFILE@ matches in some text, extract the file information and pass it back to the portfolio export format to regenerate the html to output.

Parameters
string$textthe text to search through
int$contextidnormal file_area arguments
string$componentmodule name
string$fileareanormal file_area arguments
int$itemidnormal file_area arguments
portfolio_format$formatthe portfolio export format
array$optionsadditional options to be included in the plugin file url (optional)
Return values
mixed

◆ portfolio_static_function()

portfolio_static_function ( $plugin,
$function )

Helper function to call a static function on a portfolio plugin class.

This will figure out the classname and require the right file and call the function. You can send a variable number of arguments to this function after the first two and they will be passed on to the function you wish to call.

Parameters
string$pluginname of plugin
string$functionfunction to call
Return values
mixed

◆ portfolio_supported_formats()

portfolio_supported_formats ( )

Supported formats currently in use.

Canonical place for a list of all formats that portfolio plugins and callers can use for exporting content

Return values
arraykeyed array of all the available export formats (constant => classname)

◆ portfolio_supported_formats_intersect()

portfolio_supported_formats_intersect ( $callerformats,
$pluginformats )

Intersection of plugin formats and caller formats.

Walks both the caller formats and portfolio plugin formats and looks for matches (walking the hierarchy as well) and returns the intersection

Parameters
array$callerformatsformats the caller supports
array$pluginformatsformats the portfolio plugin supports
Return values
array

Variable Documentation

◆ PORTFOLIO_FORMAT_FILE

const PORTFOLIO_FORMAT_FILE 'file'

PORTFOLIO_FORMAT_FILE - the most basic fallback format.

this should always be supported in remote system.s

◆ PORTFOLIO_TIME_HIGH

const PORTFOLIO_TIME_HIGH 'high'

PORTFOLIO_TIME_HIGH - slow.

the user really should not be given the option to choose this.

◆ PORTFOLIO_TIME_LOW

const PORTFOLIO_TIME_LOW 'low'

PORTFOLIO_TIME_LOW - no delay.

don't even offer the user the option of not waiting for the transfer

◆ PORTFOLIO_TIME_MODERATE

const PORTFOLIO_TIME_MODERATE 'moderate'

PORTFOLIO_TIME_MODERATE - a small delay.

user can still easily opt to watch this transfer and wait.