Moodle APIs  3.8
Moodle 3.8.6 (Build: 20201109)
Files | Namespaces | Classes | Functions | Variables
core_portfolio

Files

file  caller.php
 This file contains the base classes that are extended to create portfolio export functionality.
 
file  constants.php
 This file contains all the defined constants to do with portfolios.
 
file  exceptions.php
 This file contains all the portfolio exception classes.
 
file  exporter.php
 This file contains the class definition for the exporter object.
 
file  formats.php
 This file contains all the class definitions of the export formats.
 
file  forms.php
 This file contains all the form definitions used by the portfolio code.
 
file  legacy_polyfill.php
 This file contains the polyfill to allow a plugin to operate with Moodle 3.3 up.
 
file  lib.php
 This file contains the LEAP2a writer used by portfolio_format_leap2a.
 
file  plugin.php
 This file contains the base classes for portfolio plugins to inherit from:
 
file  portfolio_provider.php
 Privacy class for requesting user data.
 
file  portfoliolib.php
 This file contains all global functions to do with manipulating portfolios.
 
file  provider.php
 Privacy class for requesting user data.
 

Namespaces

 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
 
class  portfolio_admin_form
 
class  portfolio_button_exception
 
class  portfolio_caller_base
 
class  portfolio_caller_exception
 
class  portfolio_exception
 
class  portfolio_export_exception
 
class  portfolio_export_form
 
class  portfolio_exporter
 
class  portfolio_format
 
class  portfolio_format_document
 
class  portfolio_format_file
 
class  portfolio_format_image
 
class  portfolio_format_leap2a
 
class  portfolio_format_leap2a_entry
 
class  portfolio_format_leap2a_exception
 
class  portfolio_format_leap2a_file
 
class  portfolio_format_leap2a_writer
 
class  portfolio_format_pdf
 
class  portfolio_format_plainhtml
 
class  portfolio_format_presentation
 
class  portfolio_format_rich
 
class  portfolio_format_richhtml
 
class  portfolio_format_spreadsheet
 
class  portfolio_format_text
 
class  portfolio_format_video
 
class  portfolio_instance_select
 
class  portfolio_module_caller_base
 
class  portfolio_plugin_base
 
class  portfolio_plugin_exception
 
class  portfolio_plugin_pull_base
 
class  portfolio_plugin_push_base
 
class  portfolio_user_form
 

Functions

 portfolio_existing_exports ($userid, $type=null)
 Return a list of current exports for the given user. More...
 
 portfolio_existing_exports_by_plugin ($userid)
 Return an array of existing exports by type for a given user. More...
 
 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. More...
 
 portfolio_expected_time_file ($totest)
 Try and determine expected_time for purely file based exports or exports that might include large file attachments. More...
 
 portfolio_export_pagesetup ($PAGE, $caller)
 Setup page export. More...
 
 portfolio_export_rethrow_exception ($exporter, $exception)
 Helper function to rethrow a caught portfolio_exception as an export exception. More...
 
 portfolio_export_type_to_id ($type, $userid)
 Get export type id. More...
 
 portfolio_filesize_info ()
 The default filesizes and threshold information for file based transfers. More...
 
 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) More...
 
 portfolio_format_is_abstract ($format)
 Tiny helper to figure out whether a portfolio format is abstract. More...
 
 portfolio_format_object ($name)
 Helper function to return a format object from the constant. More...
 
 portfolio_format_text_options ()
 Return default common options for format_text() when preparing a content to be exported. More...
 
 portfolio_has_visible_instances ()
 Return whether there are visible instances in portfolio. More...
 
 portfolio_include_callback_file ($component, $class=null)
 Function to require any potential callback files, throwing exceptions if an issue occurs. More...
 
 portfolio_insane_notify_admins ($insane, $instances=false)
 Function to send portfolio report to admins. More...
 
 portfolio_instance ($instanceid, $record=null)
 Helper function to return an instance of a plugin (with config loaded) More...
 
 portfolio_instance_sanity_check ($instances=null)
 Helper function to check all the instances for sanity and set any insane ones to invisible. More...
 
 portfolio_instance_select ($instances, $callerformats, $callbackclass, $mimetype=null, $selectname='instance', $return=false, $returnarray=false)
 Returns a drop menu with a list of available instances. More...
 
 portfolio_instances ($visibleonly=true, $useronly=true)
 Return all portfolio instances. More...
 
 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. More...
 
 portfolio_plugin_sanity_check ($plugins=null)
 Helper function to check all the plugins for sanity and set any insane ones to invisible. More...
 
 portfolio_report_insane ($insane, $instances=false, $return=false)
 Helper function to display a table of plugins (or instances) and reasons for disabling. More...
 
 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 More...
 
 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. More...
 
 portfolio_static_function ($plugin, $function)
 Helper function to call a static function on a portfolio plugin class. More...
 
 portfolio_supported_formats ()
 Supported formats currently in use. More...
 
 portfolio_supported_formats_intersect ($callerformats, $pluginformats)
 Intersection of plugin formats and caller formats. More...
 

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. More...
 
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. More...
 
const PORTFOLIO_TIME_LOW 'low'
 PORTFOLIO_TIME_LOW - no delay. More...
 
const PORTFOLIO_TIME_MODERATE 'moderate'
 PORTFOLIO_TIME_MODERATE - a small delay. More...
 

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_assignment)
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.