Moodle APIs 4.3
Moodle 4.3.6 (Build: 20240812)
mod_data\template Class Reference

Class template for database activity. More...

Public Member Functions

 __construct (manager $manager, string $templatecontent, array $options=[], array $fields=null)
 Class contructor.
 
 add_options (array $options=[])
 Add extra display options.
 
 get_template_content ()
 Return the raw template content.
 
 get_template_name ()
 Return the current template name.
 
 has_tag (string $tagname)
 Check if a tag is present in the template.
 
 parse_add_entry (?stdClass $processeddata=null, ?int $entryid=null, ?stdClass $entrydata=null)
 Parse the template as if it was for add entry.
 
 parse_entries (array $entries)
 Return the parsed entry using a template.
 

Static Public Member Functions

static create_default_template (manager $manager, string $templatename, bool $form=false)
 Create a template class with the default template content.
 
static get_default_display_options (string $templatename)
 Get default options for templates.
 

Protected Member Functions

 get_icons ()
 Generate the list of action icons.
 
 get_tag_actionsmenu_replacement (stdClass $entry, bool $canmanageentry)
 Returns the ##actionsmenu## tag replacement for an entry.
 
 get_tag_approvalstatus_replacement (stdClass $entry, bool $canmanageentry)
 Returns the ##approvalstatus## tag replacement for an entry.
 
 get_tag_approvalstatusclass_replacement (stdClass $entry, bool $canmanageentry)
 Returns the ##approvalstatusclass## tag replacement for an entry.
 
 get_tag_approve_replacement (stdClass $entry, bool $canmanageentry)
 Returns the ##approve## tag replacement for an entry.
 
 get_tag_comments_replacement (stdClass $entry, bool $canmanageentry)
 Returns the ##comments## tag replacement for an entry.
 
 get_tag_delcheck_replacement (stdClass $entry, bool $canmanageentry)
 Returns the ##delcheck## tag replacement for an entry.
 
 get_tag_delete_replacement (stdClass $entry, bool $canmanageentry)
 Returns the ##delete## tag replacement for an entry.
 
 get_tag_disapprove_replacement (stdClass $entry, bool $canmanageentry)
 Returns the ##disapprove## tag replacement for an entry.
 
 get_tag_edit_replacement (stdClass $entry, bool $canmanageentry)
 Returns the ##edit## tag replacement for an entry.
 
 get_tag_export_replacement (stdClass $entry, bool $canmanageentry)
 Returns the ##export## tag replacement for an entry.
 
 get_tag_id_replacement (stdClass $entry, bool $canmanageentry)
 Returns the #id## tag replacement for an entry.
 
 get_tag_more_replacement (stdClass $entry, bool $canmanageentry)
 Returns the ##more## tag replacement for an entry.
 
 get_tag_moreurl_replacement (stdClass $entry, bool $canmanageentry)
 Returns the ##moreurl## tag replacement for an entry.
 
 get_tag_otherfields_replacement (stdClass $entry, bool $canmanageentry)
 Returns the ##otherfields## tag replacement for an entry.
 
 get_tag_tags_replacement (stdClass $entry, bool $canmanageentry)
 Returns the ##tags## tag replacement for an entry.
 
 get_tag_timeadded_replacement (stdClass $entry, bool $canmanageentry)
 Returns the ##timeadded## tag replacement for an entry.
 
 get_tag_timemodified_replacement (stdClass $entry, bool $canmanageentry)
 Returns the ##timemodified## tag replacement for an entry.
 
 get_tag_user_replacement (stdClass $entry, bool $canmanageentry)
 Returns the ##user## tag replacement for an entry.
 
 get_tag_userpicture_replacement (stdClass $entry, bool $canmanageentry)
 Returns the ##userpicture## tag replacement for an entry.
 
 load_template_tags (string $templatecontent)
 Scan the template tags.
 
 preprocess_tag_otherfields (string $templatecontent)
 Prepare otherfield tag scanning the present template fields.
 

Protected Attributes

array $fields = []
 The mod_data fields.
 
array $otherfields = []
 All fields that are not present in the template content.
 
array $tags = []
 All template tags (calculated in load_template_tags).
 

Detailed Description

Class template for database activity.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

mod_data\template::__construct ( manager $manager,
string $templatecontent,
array $options = [],
array $fields = null )

Class contructor.

See the add_options method for the available display options.

Parameters
manager$managerthe current instance manager
string$templatecontentthe template string to use
array$optionsan array of extra diplay options
array$fieldsalternative array of fields (for preview presets)

Member Function Documentation

◆ add_options()

mod_data\template::add_options ( array $options = [])

Add extra display options.

The extra options are:

  • page: the current pagination page
  • search: the current search text
  • baseurl: an alternative entry url (moodle_url)
  • comments: if comments must be added if not present
  • ratings: if ratings must be added
Parameters
array$optionsthe array of options.

◆ create_default_template()

static mod_data\template::create_default_template ( manager $manager,
string $templatename,
bool $form = false )
static

Create a template class with the default template content.

Parameters
manager$managerthe current instance manager.
string$templatenamethe template name.
bool$formwhether the fields should be displayed as form instead of data.
Return values
selfThe template with the default content (to be displayed when no template is defined).

◆ get_default_display_options()

static mod_data\template::get_default_display_options ( string $templatename)
static

Get default options for templates.

For instance, the list template supports the show more button.

Parameters
string$templatenamethe template name.
Return values
arrayan array of extra diplay options.

◆ get_icons()

mod_data\template::get_icons ( )
protected

Generate the list of action icons.

Return values
pix_icon[]icon name => pix_icon

◆ get_tag_actionsmenu_replacement()

mod_data\template::get_tag_actionsmenu_replacement ( stdClass $entry,
bool $canmanageentry )
protected

Returns the ##actionsmenu## tag replacement for an entry.

Parameters
stdClass$entrythe entry object
bool$canmanageentryif the current user can manage this entry
Return values
stringthe tag replacement

◆ get_tag_approvalstatus_replacement()

mod_data\template::get_tag_approvalstatus_replacement ( stdClass $entry,
bool $canmanageentry )
protected

Returns the ##approvalstatus## tag replacement for an entry.

Parameters
stdClass$entrythe entry object
bool$canmanageentryif the current user can manage this entry
Return values
stringthe tag replacement

◆ get_tag_approvalstatusclass_replacement()

mod_data\template::get_tag_approvalstatusclass_replacement ( stdClass $entry,
bool $canmanageentry )
protected

Returns the ##approvalstatusclass## tag replacement for an entry.

Parameters
stdClass$entrythe entry object
bool$canmanageentryif the current user can manage this entry
Return values
stringthe tag replacement

◆ get_tag_approve_replacement()

mod_data\template::get_tag_approve_replacement ( stdClass $entry,
bool $canmanageentry )
protected

Returns the ##approve## tag replacement for an entry.

Parameters
stdClass$entrythe entry object
bool$canmanageentryif the current user can manage this entry
Return values
stringthe tag replacement

◆ get_tag_comments_replacement()

mod_data\template::get_tag_comments_replacement ( stdClass $entry,
bool $canmanageentry )
protected

Returns the ##comments## tag replacement for an entry.

Parameters
stdClass$entrythe entry object
bool$canmanageentryif the current user can manage this entry
Return values
stringthe tag replacement

◆ get_tag_delcheck_replacement()

mod_data\template::get_tag_delcheck_replacement ( stdClass $entry,
bool $canmanageentry )
protected

Returns the ##delcheck## tag replacement for an entry.

Parameters
stdClass$entrythe entry object
bool$canmanageentryif the current user can manage this entry
Return values
stringthe tag replacement

◆ get_tag_delete_replacement()

mod_data\template::get_tag_delete_replacement ( stdClass $entry,
bool $canmanageentry )
protected

Returns the ##delete## tag replacement for an entry.

Parameters
stdClass$entrythe entry object
bool$canmanageentryif the current user can manage this entry
Return values
stringthe tag replacement

◆ get_tag_disapprove_replacement()

mod_data\template::get_tag_disapprove_replacement ( stdClass $entry,
bool $canmanageentry )
protected

Returns the ##disapprove## tag replacement for an entry.

Parameters
stdClass$entrythe entry object
bool$canmanageentryif the current user can manage this entry
Return values
stringthe tag replacement

◆ get_tag_edit_replacement()

mod_data\template::get_tag_edit_replacement ( stdClass $entry,
bool $canmanageentry )
protected

Returns the ##edit## tag replacement for an entry.

Parameters
stdClass$entrythe entry object
bool$canmanageentryif the current user can manage this entry
Return values
stringthe tag replacement

◆ get_tag_export_replacement()

mod_data\template::get_tag_export_replacement ( stdClass $entry,
bool $canmanageentry )
protected

Returns the ##export## tag replacement for an entry.

Parameters
stdClass$entrythe entry object
bool$canmanageentryif the current user can manage this entry
Return values
stringthe tag replacement

◆ get_tag_id_replacement()

mod_data\template::get_tag_id_replacement ( stdClass $entry,
bool $canmanageentry )
protected

Returns the #id## tag replacement for an entry.

Parameters
stdClass$entrythe entry object
bool$canmanageentryif the current user can manage this entry
Return values
stringthe tag replacement

◆ get_tag_more_replacement()

mod_data\template::get_tag_more_replacement ( stdClass $entry,
bool $canmanageentry )
protected

Returns the ##more## tag replacement for an entry.

Parameters
stdClass$entrythe entry object
bool$canmanageentryif the current user can manage this entry
Return values
stringthe tag replacement

◆ get_tag_moreurl_replacement()

mod_data\template::get_tag_moreurl_replacement ( stdClass $entry,
bool $canmanageentry )
protected

Returns the ##moreurl## tag replacement for an entry.

Parameters
stdClass$entrythe entry object
bool$canmanageentryif the current user can manage this entry
Return values
stringthe tag replacement

◆ get_tag_otherfields_replacement()

mod_data\template::get_tag_otherfields_replacement ( stdClass $entry,
bool $canmanageentry )
protected

Returns the ##otherfields## tag replacement for an entry.

Parameters
stdClass$entrythe entry object
bool$canmanageentryif the current user can manage this entry
Return values
stringthe tag replacement

◆ get_tag_tags_replacement()

mod_data\template::get_tag_tags_replacement ( stdClass $entry,
bool $canmanageentry )
protected

Returns the ##tags## tag replacement for an entry.

Parameters
stdClass$entrythe entry object
bool$canmanageentryif the current user can manage this entry
Return values
stringthe tag replacement

◆ get_tag_timeadded_replacement()

mod_data\template::get_tag_timeadded_replacement ( stdClass $entry,
bool $canmanageentry )
protected

Returns the ##timeadded## tag replacement for an entry.

Parameters
stdClass$entrythe entry object
bool$canmanageentryif the current user can manage this entry
Return values
stringthe tag replacement

◆ get_tag_timemodified_replacement()

mod_data\template::get_tag_timemodified_replacement ( stdClass $entry,
bool $canmanageentry )
protected

Returns the ##timemodified## tag replacement for an entry.

Parameters
stdClass$entrythe entry object
bool$canmanageentryif the current user can manage this entry
Return values
stringthe tag replacement

◆ get_tag_user_replacement()

mod_data\template::get_tag_user_replacement ( stdClass $entry,
bool $canmanageentry )
protected

Returns the ##user## tag replacement for an entry.

Parameters
stdClass$entrythe entry object
bool$canmanageentryif the current user can manage this entry
Return values
stringthe tag replacement

◆ get_tag_userpicture_replacement()

mod_data\template::get_tag_userpicture_replacement ( stdClass $entry,
bool $canmanageentry )
protected

Returns the ##userpicture## tag replacement for an entry.

Parameters
stdClass$entrythe entry object
bool$canmanageentryif the current user can manage this entry
Return values
stringthe tag replacement

◆ get_template_content()

mod_data\template::get_template_content ( )

Return the raw template content.

Return values
stringthe template content before parsing

◆ get_template_name()

mod_data\template::get_template_name ( )

Return the current template name.

Return values
stringthe template name

◆ has_tag()

mod_data\template::has_tag ( string $tagname)

Check if a tag is present in the template.

Parameters
bool$tagnamethe tag to check (without ##)
Return values
boolif the tag is present

◆ load_template_tags()

mod_data\template::load_template_tags ( string $templatecontent)
protected

Scan the template tags.

This method detects which tags are used in this template and store them in the $this->tags attribute. This attribute will be used to determine which replacements needs to be calculated.

Parameters
string$templatecontentthe current template

◆ parse_add_entry()

mod_data\template::parse_add_entry ( ?stdClass $processeddata = null,
?int $entryid = null,
?stdClass $entrydata = null )

Parse the template as if it was for add entry.

This method is similar to the parse_entry but it uses the display_add_field method instead of the display_browse_field.

Parameters
stdClass | null$processeddatathe previous process data information.
int | null$entryidthe possible entry id
stdClass | null$entrydatathe entry data from a previous form or from a real entry
Return values
stringthe add entry HTML content

◆ parse_entries()

mod_data\template::parse_entries ( array $entries)

Return the parsed entry using a template.

This method apply a template replacing all necessary tags.

Parameters
array$entriesof entres to parse
Return values
stringthe entries outputs using the template

◆ preprocess_tag_otherfields()

mod_data\template::preprocess_tag_otherfields ( string $templatecontent)
protected

Prepare otherfield tag scanning the present template fields.

Parameters
string$templatecontentthe template content

The documentation for this class was generated from the following file: