My profile API: Difference between revisions
(my profile node information) |
m (Minor changes to the introduction.) |
||
Line 1: | Line 1: | ||
== Introduction == | == Introduction == | ||
The My Profile API is a set of methods that allows user related information to be displayed on the | The My Profile API is a set of methods that allows user related information to be displayed on the my profile page. The API is similar to the navigation API as the page is made up of a tree of nodes. | ||
== Categories == | == Categories == | ||
The category class requires the following properties be filled out when creating a new object: | The category class requires the following properties be filled out when creating a new object: |
Revision as of 01:58, 4 May 2015
Introduction
The My Profile API is a set of methods that allows user related information to be displayed on the my profile page. The API is similar to the navigation API as the page is made up of a tree of nodes.
Categories
The category class requires the following properties be filled out when creating a new object:
- $name
- The name of category. Used as a key for child nodes to attach to, or for other categories to use in $after.
- $title
- The text being displayed. This needs to be a localised string (get_string());
- $after
- The name for the category that this category comes after. Optional
- $classes
- HTML class attributes for this category. Classes should be separated by a space, e.g. 'class1 class2'. Optional
Adding a category
$category = new core_user\output\myprofile\category('badges', get_string('badges', 'badges'), null);
$tree->add_category($category);
Nodes
Nodes contain most of the information for the user profile page. The node class requires the following properties be filled out when creating a new object:
- $parentcat
- The parent category. Use the name of the category.
- $name
- The name of this node. Used as a key for other nodes.
- $title
- A localised string for the node. Please use get_string().
- $after
- By using the name of another node you can position this after that one. Optional
- $url
- A url that this node links to. It is recommended that you use a moodle_url. Optional
- $content
- Additional content to display under this node. Optional
- $icon
- An icon to be displayed next to the node. May be a pix_icon. Optional
- $classes
- HTML class attributes for this node. Classes should be separated by a space, e.g. 'class1 class2'. Optional
Adding a node
$url = new moodle_url('/mod/forum/user.php', array('id' => $user->id, 'mode' => 'discussions'));
$string = get_string('myprofileowndis', 'mod_forum');
$node = new core_user\output\myprofile\node('miscellaneous', 'forumdiscussions', $string, null, $url);
$tree->add_node($node);
Adding information to the User's profile page
To add the category and node information into the my profile page, you need to create a function in the lib.php file.
The function needs to start with the component name followed by '_myprofile_navigation()'
mod/forum/lib.php
public function mod_forum_myprofile_navigation(core_user\output\myprofile\tree $tree, $user, $iscurrentuser, $course) {
...
}