Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
|
Use this to add a portfolio button or icon or form to a page. More...
Public Member Functions | |
__construct ($options=null) | |
Constructor. | |
get_callbackargs () | |
Getter for $callbackargs property. | |
get_callbackclass () | |
Getter for $callbackclass property. | |
get_callbackcomponent () | |
Getter for $callbackcomponent property. | |
get_formats () | |
Getter for $format property. | |
render ($format=null, $addstr=null) | |
Echo the form/button/icon/text link to the page. | |
reset_formats () | |
Reset formats to the default, which is usually what base_supported_formats returns. | |
set_callback_options ($class, array $argarray, $component) | |
Function to set the callback options. | |
set_format_by_file (stored_file $file, $extraformats=null) | |
If we already know we have exactly one file, bypass set_formats and just pass the file so we can detect the formats by mimetype. | |
set_format_by_intended_file ($extn, $extraformats=null) | |
Correllary this is use to set_format_by_file, but it is also used when there is no stored_file and when we're writing out a new type of file (like csv or pdf) | |
set_formats ($formats=null) | |
Sets the available export formats for this content. | |
to_html ($format=null, $addstr=null) | |
Returns the form/button/icon/text link as html. | |
Use this to add a portfolio button or icon or form to a page.
These class methods do not check permissions. the caller must check permissions first. Later, during the export process, the caller class is instantiated and the check_permissions method is called If you are exporting a single file, you should always call set_format_by_file($file) This class can be used like this: $button = new portfolio_add_button(); $button->set_callback_options('name_of_caller_class', array('id' => 6), 'yourcomponent'); eg. mod_forum $button->render(PORTFOLIO_ADD_FULL_FORM, get_string('addeverythingtoportfolio', 'yourcomponent'));
or like this: $button = new portfolio_add_button(array('callbackclass' => 'name_of_caller_class', 'callbackargs' => array('id' => 6), 'callbackcomponent' => 'yourcomponent')); eg. mod_forum $somehtml .= $button->to_html(PORTFOLIO_ADD_TEXT_LINK);
portfolio_add_button::__construct | ( | $options = null | ) |
Constructor.
Either pass the options here or set them using the helper methods. Generally the code will be clearer if you use the helper methods.
array | $options | keyed array of options: key 'callbackclass': name of the caller class (eg forum_portfolio_caller') key 'callbackargs': the array of callback arguments your caller class wants passed to it in the constructor key 'callbackcomponent': the file containing the class definition of your caller class. See set_callback_options for more information on these three. key 'formats': an array of PORTFOLIO_FORMATS this caller will support See set_formats or set_format_by_file for more information on this. |
portfolio_add_button::get_callbackargs | ( | ) |
Getter for $callbackargs property.
array |
portfolio_add_button::get_callbackclass | ( | ) |
Getter for $callbackclass property.
string |
portfolio_add_button::get_callbackcomponent | ( | ) |
Getter for $callbackcomponent property.
string |
portfolio_add_button::get_formats | ( | ) |
Getter for $format property.
array |
portfolio_add_button::render | ( | $format = null, | |
$addstr = null ) |
Echo the form/button/icon/text link to the page.
int | $format | format to display the button or form or icon or link. See constants PORTFOLIO_ADD_XXX for more info. optional, defaults to PORTFOLIO_ADD_FULL_FORM |
string | $addstr | string to use for the button or icon alt text or link text. this is whole string, not key. optional, defaults to 'Export to portfolio'; |
portfolio_add_button::set_callback_options | ( | $class, | |
array | $argarray, | ||
$component ) |
Function to set the callback options.
string | $class | Name of the class containing the callback functions activity components should ALWAYS use their name_portfolio_caller other locations must use something unique |
array | $argarray | This can be an array or hash of arguments to pass back to the callback functions (passed by reference) these MUST be primatives to be added as hidden form fields. and the values get cleaned to PARAM_ALPHAEXT or PARAM_FLOAT or PARAM_PATH |
string | $component | This is the name of the component in Moodle, eg 'mod_forum' |
portfolio_add_button::set_format_by_file | ( | stored_file | $file, |
$extraformats = null ) |
If we already know we have exactly one file, bypass set_formats and just pass the file so we can detect the formats by mimetype.
stored_file | $file | file to set the format from |
array | $extraformats | any additional formats other than by mimetype eg leap2a etc |
portfolio_add_button::set_format_by_intended_file | ( | $extn, | |
$extraformats = null ) |
Correllary this is use to set_format_by_file, but it is also used when there is no stored_file and when we're writing out a new type of file (like csv or pdf)
string | $extn | the file extension we intend to generate |
array | $extraformats | any additional formats other than by mimetype eg leap2a etc |
portfolio_add_button::set_formats | ( | $formats = null | ) |
Sets the available export formats for this content.
This function will also poll the static function in the caller class and make sure we're not overriding a format that has nothing to do with mimetypes. Eg: if you pass IMAGE here but the caller can export LEAP2A it will keep LEAP2A as well.
array | $formats | if the calling code knows better than the static method on the calling class (base_supported_formats). Eg: if it's going to be a single file, or if you know it's HTML, you can pass it here instead. This is almost always the case so it should be use all the times portfolio_format_from_mimetype for how to get the appropriate formats to pass here for uploaded files. or just call set_format_by_file instead |
portfolio_add_button::to_html | ( | $format = null, | |
$addstr = null ) |
Returns the form/button/icon/text link as html.
int | $format | format to display the button or form or icon or link. See constants PORTFOLIO_ADD_XXX for more info. Optional, defaults to PORTFOLIO_ADD_FULL_FORM |
string | $addstr | string to use for the button or icon alt text or link text. This is whole string, not key. optional, defaults to 'Add to portfolio'; |
void|string|moodle_url |