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 402] [Versions 311 and 403]

This file contains the LEAP2a writer used by portfolio_format_leap2a

Copyright: 2009 Penny Leach (penny@liip.ch), Martin Dougiamas
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 533 lines (22 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 3 classes

portfolio_format_leap2a_writer:: (6 methods):
  __construct()
  add_entry()
  make_selection()
  link_files()
  validate()
  to_xml()

portfolio_format_leap2a_entry:: (8 methods):
  __construct()
  __set()
  validate()
  add_link()
  add_category()
  to_dom()
  create_xhtmlish_element()
  add_extra_links()

portfolio_format_leap2a_file:: (2 methods):
  __construct()
  add_extra_links()


Class: portfolio_format_leap2a_writer  - X-Ref

Object to encapsulate the writing of leap2a.

Should be used like:
$writer = portfolio_format_leap2a::leap2a_writer($USER);
$entry = new portfolio_format_leap2a_entry('forumpost6', $title, 'leap2', 'somecontent')
$entry->add_link('something', 'has_part')->add_link('somethingelse', 'has_part');
.. etc
$writer->add_entry($entry);
$xmlstr = $writer->to_xml();

__construct(stdclass $user)   X-Ref
Constructor - usually generated from portfolio_format_leap2a::leap2a_writer($USER);

param: stdclass $user the user exporting (almost always $USER)

add_entry(portfolio_format_leap2a_entry $entry)   X-Ref
Adds a entry to the feed ready to be exported

param: portfolio_format_leap2a_entry $entry new feed entry to add
return: portfolio_format_leap2a_entry

make_selection($selectionentry, $ids, $selectiontype)   X-Ref
Select an entry that has previously been added into the feed

param: portfolio_format_leap2a_entry|string $selectionentry the entry to make a selection (id or entry object)
param: array $ids array of ids this selection includes
param: string $selectiontype for selection type, see: http://wiki.cetis.ac.uk/2009-03/LEAP2A_categories/selection_type

link_files($entry, $files)   X-Ref
Helper function to link some stored_files into the feed and link them to a particular entry

param: portfolio_format_leap2a_entry $entry feed object
param: array $files array of stored_files to link

validate()   X-Ref
Validate the feed and all entries


to_xml()   X-Ref
Return the entire feed as a string.
Then, it calls for validation

return: string feeds' content in xml

Class: portfolio_format_leap2a_entry  - X-Ref

This class represents a single leap2a entry.

You can create these directly and then add them to the main leap feed object

__construct($id, $title, $type, $content=null)   X-Ref
Constructor.  All arguments are required (and will be validated)
http://wiki.cetis.ac.uk/2009-03/LEAP2A_types

param: string $id unique id of this entry.
param: string $title title of the entry. This is pure atom.
param: string $type the leap type of this entry.
param: mixed $content the content of the entry. string (xhtml/html/text)

__set($field, $value)   X-Ref
Override __set to do proper dispatching for different things.
Only allows the optional and required leap2a entry fields to be set

param: string $field property's name
param: mixed $value property's value
return: mixed

validate()   X-Ref
Validate this entry.
At the moment this just makes sure required fields exist
but it could also check things against a list, for example


add_link($otherentry, $reltype, $displayorder=null)   X-Ref
Add a link from this entry to another one.
These will be collated at the end of the export (during to_xml)
and validated at that point. This function does no validation
{@link http://wiki.cetis.ac.uk/2009-03/LEAP2A_relationships}

param: portfolio_format_leap2a_entry|string $otherentry portfolio_format_leap2a_entry or its id
param: string $reltype (no leap2: ns required)
param: string $displayorder (optional)
return: portfolio_format_leap2a_entry the current entry object. This is so that these calls can be chained

add_category($term, $scheme=null, $label=null)   X-Ref
Add a category to this entry
{@link http://wiki.cetis.ac.uk/2009-03/LEAP2A_categories}
"tags" should just pass a term here and no scheme or label.
They will be automatically normalised if they have spaces.

param: string $term eg 'Offline'
param: string $scheme (optional) eg resource_type
param: string $label (optional) eg File

to_dom(DomDocument $dom, $feedauthor)   X-Ref
Create an entry element and append all the children
And return it rather than adding it to the dom.
This is handled by the main writer object.

param: DomDocument $dom use this to create elements
param: stdClass $feedauthor object of author(user) info
return: DOMDocument

create_xhtmlish_element(DomDocument $dom, $tagname, $content)   X-Ref
Try to load whatever is in $content into xhtml and add it to the dom.
Failing that, load the html, escape it, and set it as the body of the tag.
Either way it sets the type attribute of the top level element.
Moodle should always provide xhtml content, but user-defined content can't be trusted

param: DomDocument $dom the dom doc to use
param: string $tagname usually 'content' or 'summary'
param: string $content the content to use, either xhtml or html.
return: DomDocument

add_extra_links($dom, $entry)   X-Ref
Hook function for subclasses to add extra links (like for files)

param: DomDocument $dom feed object
param: DomDocument $entry feed added link

Class: portfolio_format_leap2a_file  - X-Ref

Subclass of entry, purely for dealing with files

__construct($title, stored_file $file)   X-Ref
Overridden constructor to set up the file.

param: string $title title of the entry
param: stored_file $file file storage instance

add_extra_links($dom, $entry)   X-Ref
Implement the hook to add extra links to attach the file in an enclosure

param: DomDocument $dom feed object
param: DomDocument $entry feed added link