Moodle APIs  3.8
Moodle 3.8.6 (Build: 20201109)
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
settings_navigation_ajax Class Reference
Inheritance diagram for settings_navigation_ajax:
settings_navigation navigation_node renderable

Public Member Functions

 __construct (moodle_page &$page)
 Constructs the navigation for use in an AJAX request. More...
 
 __wakeup ()
 Resets the page specific information on this node if it is being unserialised.
 
 action ()
 Get the action url for this navigation node. More...
 
 add ($text, $url=null, $type=null, $shorttext=null, $key=null, pix_icon $icon=null)
 Override the parent function so that we can add preceeding hr's and set a root node class against all first level element. More...
 
 add_class ($class)
 Adds a CSS class to this node. More...
 
 add_node (navigation_node $childnode, $beforekey=null)
 Adds a navigation node as a child of this one, given a $node object created using the create function. More...
 
 build_flat_navigation_list (flat_navigation $nodes, $showdivider=false, $label='')
 Walk the tree building up a list of all the flat navigation nodes. More...
 
 can_view_user_preferences ($userid)
 Checks to see if there are child nodes available in the specific user's preference node. More...
 
 check_if_active ($strength=URL_MATCH_EXACT)
 Checks if this node is the active node. More...
 
 clear_cache ()
 This function marks the cache as volatile so it is cleared during shutdown.
 
 contains_active_node ()
 Checks if this node or any of its children contain the active node. More...
 
 extend_for_user ($userid)
 Extends the settings navigation for the given user. More...
 
 find ($key, $type)
 Searches for a node of the given type with the given key. More...
 
 find_active_node ()
 Finds the active node. More...
 
 find_all_of_type ($type)
 Finds all nodes of a given type (recursive) More...
 
 find_expandable (array &$expandable)
 Finds all nodes that are expandable by AJAX. More...
 
 force_open ()
 Forces this node to be open and at the same time forces open all parents until the root node. More...
 
 get ($key, $type=null)
 Get the child of this node that has the given key + (optional) type. More...
 
 get_children_key_list ()
 Return a list of all the keys of all the child nodes. More...
 
 get_content ($shorttext=false)
 Gets the content for this node. More...
 
 get_css_type ()
 Gets the CSS class to add to this node to describe its type. More...
 
 get_siblings ()
 Get a list of sibling navigation nodes at the same level as this one. More...
 
 get_tabs_array (array $inactive=array(), $return=false)
 Creates a tab representation of this nodes children that can be used with print_tabs to produce the tabs on a page. More...
 
 get_title ()
 Gets the title to use for this node. More...
 
 has_action ()
 Used to easily determine if this link in the breadcrumbs has a valid action/url. More...
 
 has_children ()
 Checks if this node has or could have any children. More...
 
 has_siblings ()
 True if this nav node has siblings in the tree. More...
 
 hide (array $typestohide=null)
 Hides the node and any children it has. More...
 
 initialise ()
 Initialise the site admin navigation. More...
 
 is_hidden ()
 Used to easily determine if this link in the breadcrumbs is hidden. More...
 
 is_short_branch ()
 To better balance the admin tree, we want to group all the short top branches together. More...
 
 make_active ()
 Marks this node as active and forces it open. More...
 
 make_inactive ()
 Marks a node as inactive and recusised back to the base of the tree doing the same to all parents.
 
 prepend ($text, $url=null, $type=null, $shorttext=null, $key=null, pix_icon $icon=null)
 This function allows the user to add something to the start of the settings navigation, which means it will be at the top of the settings navigation block. More...
 
 remove ()
 Removes this node. More...
 
 remove_class ($class)
 Removes a CSS class from this node. More...
 
 search_for_active_node ()
 Searches all children for the best matching active node. More...
 
 set_parent (navigation_node $parent)
 Sets the parent for this node and if this node is active ensures that the tree is properly adjusted as well. More...
 
 title ($title)
 Sets the title for this node and forces Moodle to utilise it. More...
 
 trim_if_empty ()
 Removes this node if it is empty.
 

Static Public Member Functions

static create ($text, $action=null, $type=self::TYPE_CUSTOM, $shorttext=null, $key=null, pix_icon $icon=null)
 Creates a navigation node, ready to add it as a child using add_node function. More...
 
static override_active_url (moodle_url $url, $loadadmintree=false)
 This sets the URL that the URL of new nodes get compared to when locating the active node. More...
 
static require_admin_tree ()
 Use when page is linked from the admin tree, if not used navigation could not find the page using current URL because the tree is not fully loaded.
 

Public Attributes

moodle_url action_link null $action = null
 An action for the node (link)
 
navigation_node_collection $children = array()
 An array of child nodes.
 
array $classes = array()
 An array of CSS classes for the node.
 
bool $collapse = false
 If set to true the node will be collapsed by default.
 
bool $display = true
 If set to false the node will not be displayed.
 
bool $forceopen = false
 If set to true the node will be expanded by default.
 
bool $forcetitle = false
 If set to true a title will be added to the action no matter what.
 
string $helpbutton = null
 A string that can be used to build a help button.
 
bool $hidden = false
 If set to true the node will be dimmed.
 
bool $hideicon = false
 Override to not display the icon even if one is provided.
 
pix_icon $icon = null
 The path to an icon to use for this node.
 
int $id = null
 Parameter to aid the coder in tracking [optional].
 
mixed $includesectionnum = false
 If set to an int, that section will be included even if it has no activities.
 
bool $isactive = false
 If set to true the node will be recognised as active.
 
bool $isexpandable = false
 Set to true if we KNOW that this node can be expanded. More...
 
string int $key = null
 The identifier for the node, used to retrieve the node.
 
bool $mainnavonly = false
 If set to true the the navigation bar should ignore this node.
 
int $nodetype = self::NODETYPE_LEAF
 See NODETYPE_* constants defined for this class.
 
navigation_node $parent = null
 A reference to the node parent, you should never set this directly you should always call set_parent.
 
bool $preceedwithhr = false
 If set to true then an HR will be printed before the node.
 
bool $requiresajaxloading = false
 does the node need to be loaded via ajax
 
string $shorttext = null
 Short text to use if requested [optional].
 
bool $showinflatnavigation = false
 If set to true this node will be added to the "flat" navigation.
 
string $text = null
 The text to use for the node.
 
string $title = null
 The title attribute for an action if one is defined.
 
int $type = self::TYPE_UNKNOWN
 See TYPE_* constants defined for this class.
 
const COURSE_CURRENT = 2
 var int Course the current user is currently viewing
 
const COURSE_INDEX_PAGE = 'courseindexpage'
 var string The course index page navigation node
 
const COURSE_MY = 1
 var int Course the current user is enrolled in but not viewing
 
const COURSE_OTHER = 0
 var int Course the current user is not enrolled in
 
int const NODETYPE_BRANCH = 1
 Used to identify this node a branch, happens with children 1.
 
int const NODETYPE_LEAF = 0
 Used to identify this node a leaf (default) 0.
 
int const TYPE_ACTIVITY = 40
 Activity node type, e.g. More...
 
int const TYPE_CATEGORY = 10
 Category node type 10.
 
int const TYPE_CONTAINER = 90
 Setting node type, used for containers of no importance 90.
 
int const TYPE_COURSE = 20
 Course node type 20.
 
int const TYPE_CUSTOM = 60
 A custom node type, default when adding without specifing type 60.
 
const TYPE_MY_CATEGORY = 11
 var int Category displayed in MyHome navigation node
 
int const TYPE_RESOURCE = 50
 Resource node type, e.g. More...
 
int const TYPE_ROOTNODE = 0
 System node type 0.
 
int const TYPE_SECTION = 30
 Course Structure node type 30.
 
int const TYPE_SETTING = 70
 Setting node type, used only within settings nav 70.
 
int const TYPE_SITE_ADMIN = 71
 site admin branch node type, used only within settings nav 71
 
int const TYPE_SYSTEM = 1
 System node type 1.
 
null const TYPE_UNKNOWN = null
 Unknown node type null.
 
int const TYPE_USER = 80
 Setting node type, used only within settings nav 80.
 

Static Public Attributes

static bool $autofindactive = true
 toogles auto matching of active node
 

Protected Member Functions

 add_context_locking_node (\navigation_node $node, context $context)
 Add the menu item to handle locking and unlocking of a conext. More...
 
 generate_user_settings ($courseid, $userid, $gstitle='usercurrentsettings')
 This function gets called by settings_navigation::load_user_settings() and actually works out what can be shown/done. More...
 
 get_by_path (array $path)
 Gets a navigation node given an array of keys that represent the path to the desired node. More...
 
 in_alternative_role ()
 Determine whether the user is assuming another role. More...
 
 is_admin_tree_needed ()
 Does this page require loading of full admin tree or is it enough rely on AJAX? More...
 
 load_administration_settings (navigation_node $referencebranch=null, part_of_admin_tree $adminbranch=null)
 Load the site administration tree. More...
 
 load_block_settings ()
 Loads block specific settings in the navigation. More...
 
 load_category_settings ()
 Loads category specific settings in the navigation. More...
 
 load_course_settings ($forceopen=false)
 This function loads the course settings that are available for the user. More...
 
 load_front_page_settings ($forceopen=false)
 This function loads all of the front page settings into the settings navigation. More...
 
 load_local_plugin_settings ()
 This function gives local plugins an opportunity to modify the settings navigation.
 
 load_module_settings ()
 This function calls the module function to inject module settings into the settings navigation tree. More...
 
 load_user_settings ($courseid=SITEID)
 Loads the user settings block of the settings nav. More...
 
 scan_for_active_node (navigation_node $node)
 This function recursivily scans nodes until it finds the active node or there are no more nodes. More...
 

Protected Attributes

string $adminsection
 contains administration section navigation_nodes
 
navigation_cache $cache
 
stdClass $context
 the current context
 
bool $initialised = false
 A switch to see if the navigation node is initialised.
 
array $namedtypes
 
moodle_page $page
 the moodle page that the navigation belongs to
 
array $userstoextendfor = array()
 An array of users that the nodes can extend for.
 

Static Protected Attributes

static moodle_url $fullmeurl = null
 
static bool $loadadmintree = false
 should we load full admin tree or rely on AJAX for performance reasons
 

Constructor & Destructor Documentation

◆ __construct()

settings_navigation_ajax::__construct ( moodle_page $page)

Constructs the navigation for use in an AJAX request.

Parameters
moodle_page$page

Reimplemented from settings_navigation.

Member Function Documentation

◆ action()

navigation_node::action ( )
inherited

Get the action url for this navigation node.

Called from templates.

Since
Moodle 3.2

◆ add()

settings_navigation::add (   $text,
  $url = null,
  $type = null,
  $shorttext = null,
  $key = null,
pix_icon  $icon = null 
)
inherited

Override the parent function so that we can add preceeding hr's and set a root node class against all first level element.

It does this by first calling the parent's add method navigation_node::add() and then proceeds to use the key to set class and hr

Parameters
string$texttext to be used for the link.
string | moodle_url$urlurl for the new node
int$typethe type of node navigation_node::TYPE_*
string$shorttext
string | int$keya key to access the node by.
pix_icon$iconAn icon that appears next to the node.
Return values
navigation_nodewith the new node added to it.

Reimplemented from navigation_node.

◆ add_class()

navigation_node::add_class (   $class)
inherited

Adds a CSS class to this node.

Parameters
string$class
Return values
bool

◆ add_context_locking_node()

navigation_node::add_context_locking_node ( \navigation_node  $node,
context  $context 
)
protectedinherited

Add the menu item to handle locking and unlocking of a conext.

Parameters
navigation_node$nodeNode to add
context$contextThe context to be locked

◆ add_node()

navigation_node::add_node ( navigation_node  $childnode,
  $beforekey = null 
)
inherited

Adds a navigation node as a child of this one, given a $node object created using the create function.

Parameters
navigation_node$childnodeNode to add
string$beforekey
Return values
navigation_nodeThe added node

◆ build_flat_navigation_list()

navigation_node::build_flat_navigation_list ( flat_navigation  $nodes,
  $showdivider = false,
  $label = '' 
)
inherited

Walk the tree building up a list of all the flat navigation nodes.

Parameters
flat_navigation$nodesList of the found flat navigation nodes.
boolean$showdividerShow a divider before the first node.
string$labelA label for the collection of navigation links.

◆ can_view_user_preferences()

settings_navigation::can_view_user_preferences (   $userid)
inherited

Checks to see if there are child nodes available in the specific user's preference node.

If so, then they have the appropriate permissions view this user's preferences.

Since
Moodle 2.9.3
Parameters
int$useridThe user's ID.
Return values
boolTrue if child nodes exist to view, otherwise false.

◆ check_if_active()

navigation_node::check_if_active (   $strength = URL_MATCH_EXACT)
inherited

Checks if this node is the active node.

This is determined by comparing the action for the node against the defined URL for the page. A match will see this node marked as active.

Parameters
int$strengthOne of URL_MATCH_EXACT, URL_MATCH_PARAMS, or URL_MATCH_BASE
Return values
bool

◆ contains_active_node()

navigation_node::contains_active_node ( )
inherited

Checks if this node or any of its children contain the active node.

Recursive.

Return values
bool

◆ create()

static navigation_node::create (   $text,
  $action = null,
  $type = self::TYPE_CUSTOM,
  $shorttext = null,
  $key = null,
pix_icon  $icon = null 
)
staticinherited

Creates a navigation node, ready to add it as a child using add_node function.

(The created node needs to be added before you can use it.)

Parameters
string$text
moodle_url | action_link$action
int$type
string$shorttext
string | int$key
pix_icon$icon
Return values
navigation_node

◆ extend_for_user()

settings_navigation::extend_for_user (   $userid)
inherited

Extends the settings navigation for the given user.

Note: This method gets called automatically if you call $PAGE->navigation->extend_for_user($userid)

Parameters
int$userid

◆ find()

navigation_node::find (   $key,
  $type 
)
inherited

Searches for a node of the given type with the given key.

This searches this node plus all of its children, and their children.... If you know the node you are looking for is a child of this node then please use the get method instead.

Parameters
int | string$keyThe key of the node we are looking for
int$typeOne of navigation_node::TYPE_*
Return values
navigation_node|false

Reimplemented in global_navigation.

◆ find_active_node()

navigation_node::find_active_node ( )
inherited

Finds the active node.

Searches this nodes children plus all of the children for the active node and returns it if found.

Recursive.

Return values
navigation_node|false

◆ find_all_of_type()

navigation_node::find_all_of_type (   $type)
inherited

Finds all nodes of a given type (recursive)

Parameters
int$typeOne of navigation_node::TYPE_*
Return values
array

◆ find_expandable()

navigation_node::find_expandable ( array &  $expandable)
inherited

Finds all nodes that are expandable by AJAX.

Parameters
array$expandableAn array by reference to populate with expandable nodes.

◆ force_open()

navigation_node::force_open ( )
inherited

Forces this node to be open and at the same time forces open all parents until the root node.

Recursive.

◆ generate_user_settings()

settings_navigation::generate_user_settings (   $courseid,
  $userid,
  $gstitle = 'usercurrentsettings' 
)
protectedinherited

This function gets called by settings_navigation::load_user_settings() and actually works out what can be shown/done.

Parameters
int$courseidThe current course' id
int$useridThe user id to load for
string$gstitleThe string to pass to get_string for the branch title
Return values
navigation_node|false

◆ get()

navigation_node::get (   $key,
  $type = null 
)
inherited

Get the child of this node that has the given key + (optional) type.

If you are looking for a node and want to search all children + their children then please use the find method instead.

Parameters
int | string$keyThe key of the node we are looking for
int$typeOne of navigation_node::TYPE_*
Return values
navigation_node|false

Reimplemented in navbar, and global_navigation.

◆ get_by_path()

settings_navigation::get_by_path ( array  $path)
protectedinherited

Gets a navigation node given an array of keys that represent the path to the desired node.

Parameters
array$path
Return values
navigation_node|false

◆ get_children_key_list()

navigation_node::get_children_key_list ( )
inherited

Return a list of all the keys of all the child nodes.

Return values
arraythe keys.

◆ get_content()

navigation_node::get_content (   $shorttext = false)
inherited

Gets the content for this node.

Parameters
bool$shorttextIf true shorttext is used rather than the normal text
Return values
string

◆ get_css_type()

navigation_node::get_css_type ( )
inherited

Gets the CSS class to add to this node to describe its type.

Return values
string

◆ get_siblings()

navigation_node::get_siblings ( )
inherited

Get a list of sibling navigation nodes at the same level as this one.

Return values
bool|arrayof navigation_node

◆ get_tabs_array()

navigation_node::get_tabs_array ( array  $inactive = array(),
  $return = false 
)
inherited

Creates a tab representation of this nodes children that can be used with print_tabs to produce the tabs on a page.

call_user_func_array('print_tabs', $node->get_tabs_array());

Parameters
array$inactive
bool$return
Return values
arrayArray (tabs, selected, inactive, activated, return)

◆ get_title()

navigation_node::get_title ( )
inherited

Gets the title to use for this node.

Return values
string

◆ has_action()

navigation_node::has_action ( )
inherited

Used to easily determine if this link in the breadcrumbs has a valid action/url.

Return values
boolean

◆ has_children()

navigation_node::has_children ( )
inherited

Checks if this node has or could have any children.

Return values
boolReturns true if it has children or could have (by AJAX expansion)

◆ has_siblings()

navigation_node::has_siblings ( )
inherited

True if this nav node has siblings in the tree.

Return values
bool

◆ hide()

navigation_node::hide ( array  $typestohide = null)
inherited

Hides the node and any children it has.

Since
Moodle 2.5
Parameters
array$typestohideOptional. An array of node types that should be hidden. If null all nodes will be hidden. If an array is given then nodes will only be hidden if their type mtatches an element in the array. e.g. array(navigation_node::TYPE_COURSE) would hide only course nodes.

◆ in_alternative_role()

settings_navigation::in_alternative_role ( )
protectedinherited

Determine whether the user is assuming another role.

This function checks to see if the user is assuming another role by means of role switching. In doing this we compare each RSW key (context path) against the current context path. This ensures that we can provide the switching options against both the course and any page shown under the course.

Return values
bool|intThe role(int) if the user is in another role, false otherwise

◆ initialise()

settings_navigation_ajax::initialise ( )

Initialise the site admin navigation.

Return values
arrayAn array of the expandable nodes

Reimplemented from settings_navigation.

◆ is_admin_tree_needed()

settings_navigation::is_admin_tree_needed ( )
protectedinherited

Does this page require loading of full admin tree or is it enough rely on AJAX?

Return values
bool

◆ is_hidden()

navigation_node::is_hidden ( )
inherited

Used to easily determine if this link in the breadcrumbs is hidden.

Return values
boolean

◆ is_short_branch()

navigation_node::is_short_branch ( )
inherited

To better balance the admin tree, we want to group all the short top branches together.

This means < 8 nodes and no subtrees.

Return values
bool

◆ load_administration_settings()

settings_navigation::load_administration_settings ( navigation_node  $referencebranch = null,
part_of_admin_tree  $adminbranch = null 
)
protectedinherited

Load the site administration tree.

This function loads the site administration tree by using the lib/adminlib library functions

Parameters
navigation_node$referencebranchA reference to a branch in the settings navigation tree
part_of_admin_tree$adminbranchThe branch to add, if null generate the admin tree and start at the beginning
Return values
mixedA key to access the admin tree by

◆ load_block_settings()

settings_navigation::load_block_settings ( )
protectedinherited

Loads block specific settings in the navigation.

Return values
navigation_node

◆ load_category_settings()

settings_navigation::load_category_settings ( )
protectedinherited

Loads category specific settings in the navigation.

Return values
navigation_node

◆ load_course_settings()

settings_navigation::load_course_settings (   $forceopen = false)
protectedinherited

This function loads the course settings that are available for the user.

Parameters
bool$forceopenIf set to true the course node will be forced open
Return values
navigation_node|false

◆ load_front_page_settings()

settings_navigation::load_front_page_settings (   $forceopen = false)
protectedinherited

This function loads all of the front page settings into the settings navigation.

This function is called when the user is on the front page, or $COURSE==$SITE

Parameters
bool$forceopen(optional)
Return values
navigation_node

◆ load_module_settings()

settings_navigation::load_module_settings ( )
protectedinherited

This function calls the module function to inject module settings into the settings navigation tree.

This only gets called if there is a corrosponding function in the modules lib file.

For examples mod/forum/lib.php forum_extend_settings_navigation()

Return values
navigation_node|false

◆ load_user_settings()

settings_navigation::load_user_settings (   $courseid = SITEID)
protectedinherited

Loads the user settings block of the settings nav.

This function is simply works out the userid and whether we need to load just the current users profile settings, or the current user and the user the current user is viewing.

This function has some very ugly code to work out the user, if anyone has any bright ideas please feel free to intervene.

Parameters
int$courseidThe course id of the current course
Return values
navigation_node|false

◆ make_active()

navigation_node::make_active ( )
inherited

Marks this node as active and forces it open.

Important: If you are here because you need to mark a node active to get the navigation to do what you want have you looked at navigation_node::override_active_url()? You can use it to specify a different URL to match the active navigation node on rather than having to locate and manually mark a node active.

◆ override_active_url()

static navigation_node::override_active_url ( moodle_url  $url,
  $loadadmintree = false 
)
staticinherited

This sets the URL that the URL of new nodes get compared to when locating the active node.

The active node is the node that matches the URL set here. By default this is either $PAGE->url or if that hasn't been set $FULLME.

Parameters
moodle_url$urlThe url to use for the fullmeurl.
bool$loadadmintreeuse true if the URL point to administration tree

◆ prepend()

settings_navigation::prepend (   $text,
  $url = null,
  $type = null,
  $shorttext = null,
  $key = null,
pix_icon  $icon = null 
)
inherited

This function allows the user to add something to the start of the settings navigation, which means it will be at the top of the settings navigation block.

Parameters
string$texttext to be used for the link.
string | moodle_url$urlurl for the new node
int$typethe type of node navigation_node::TYPE_*
string$shorttext
string | int$keya key to access the node by.
pix_icon$iconAn icon that appears next to the node.
Return values
navigation_node::$nodewith the new node added to it.

◆ remove()

navigation_node::remove ( )
inherited

Removes this node.

Return values
bool

◆ remove_class()

navigation_node::remove_class (   $class)
inherited

Removes a CSS class from this node.

Parameters
string$class
Return values
boolTrue if the class was successfully removed.

◆ scan_for_active_node()

settings_navigation::scan_for_active_node ( navigation_node  $node)
protectedinherited

This function recursivily scans nodes until it finds the active node or there are no more nodes.

Parameters
navigation_node$node

◆ search_for_active_node()

navigation_node::search_for_active_node ( )
inherited

Searches all children for the best matching active node.

Return values
navigation_node|false

◆ set_parent()

navigation_node::set_parent ( navigation_node  $parent)
inherited

Sets the parent for this node and if this node is active ensures that the tree is properly adjusted as well.

Parameters
navigation_node$parent

◆ title()

navigation_node::title (   $title)
inherited

Sets the title for this node and forces Moodle to utilise it.

Parameters
string$title

Member Data Documentation

◆ $isexpandable

bool navigation_node::$isexpandable = false
inherited

Set to true if we KNOW that this node can be expanded.


◆ $namedtypes

array navigation_node::$namedtypes
protectedinherited
Initial value:
= array(0 => 'system', 10 => 'category', 20 => 'course', 30 => 'structure', 40 => 'activity',
50 => 'resource', 60 => 'custom', 70 => 'setting', 71 => 'siteadmin', 80 => 'user',
90 => 'container')

◆ TYPE_ACTIVITY

int const navigation_node::TYPE_ACTIVITY = 40
inherited

Activity node type, e.g.

Forum, Quiz 40

◆ TYPE_RESOURCE

int const navigation_node::TYPE_RESOURCE = 50
inherited

Resource node type, e.g.

Link to a file, or label 50


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