Class midcom_helper_nav

Description

Main Navigation interface class.

Basically, this class proxies all requests to a midcom_helper__basicnav class. See the interface definition of it for further details.

Additionally this class implements a couple of helper functions to make common NAP tasks easier.

Important note: Whenever you add new code to this class, or extend it through inheritance, never call the proxy-functions of basicnav directly, this is strictly forbidden.

  • see: midcom_helper__basicnav
  • todo: End-User documentation of node and leaf data, as the one in basicnav is incomplete too.

Located in /midcom/helper/nav.php (line 27)


	
			
Variable Summary
Method Summary
 midcom_helper_nav midcom_helper_nav ([int $contextid = -1])
 string edit_current_page_url (string $baseurl)
 string get_breadcrumb_line ([string $separator = " > "], [string $class = null], int $skip_levels, [string $current_class = null])
 midcom_helper_toolbar get_combined_toolbar (string $baseurl, [mixed $leaf = null])
 Array get_leaf (string $leaf_id)
 midcom_helper_toolbar get_leaf_toolbar (string $baseurl, [mixed $leaf = null])
 int get_leaf_uplink (string $leaf_id)
 Array get_node (int $node_id)
 midcom_helper_toolbar get_node_toolbar (string $baseurl, [mixed $node = null])
 int get_node_uplink (int $node_id)
 int get_root_node ()
 Array get_toolbar_definition (Array $nap_object)
 bool is_node_in_tree (int $node_id, mixed $root_id, int $root_node)
 Array list_child_elements (int $parent_node_id)
 Array list_leaves (mixed $parent_leaf, [bool $show_noentry = false], int $parent_node)
 Array list_nodes (int $parent_node, [bool $show_noentry = false])
 string render_combined_toolbar (string $baseurl, [mixed $leaf = null])
 string render_leaf_toolbar (string $baseurl, [mixed $leaf = null])
 string render_node_toolbar (string $baseurl, [mixed $node = null])
 mixed resolve_guid (string $guid)
 void show_combined_nav (Array $config)
 void show_simple_nav (Array $config)
 string view_current_page_url (string $baseurl)
 void _check_toolbar_permissions (int $topic_id)
Variables
midcom_helper__basicnav $_basicnav (line 35)

A reference to the basicnav instance in use.

  • access: private
int $_contextid (line 43)

The context ID we're accociated with.

  • access: private
Methods
Constructor midcom_helper_nav (line 52)

Create a NAP instance for the given context. If unspecified, it uses the currently active context which should be sufficient in most cases.

midcom_helper_nav midcom_helper_nav ([int $contextid = -1])
  • int $contextid: The id of the context you want to navigate.
edit_current_page_url (line 469)

This function provides an interface to construct links like "Edit this page".

It takes the currently displayed content element (either a leaf or node) and constructs the respective URL relative to the root of the AIS instance as passed to the function.

  • return: The full URL to the AIS element in question, null if there is no on-site representation, false on failure
string edit_current_page_url (string $baseurl)
  • string $baseurl: The base url that leads to the root AIS page of the MidCOM site (without any /$id/data additions).
get_breadcrumb_line (line 862)

Construct a breadcrumb line.

Gives you a line like "Start > Topic1 > Topic2 > Article" using NAP to traverse upwards till the root node. $separator is inserted between the pairs, $class, if non-null, will be used as CSS-class for the A-Tags.

The parameter skip_levels indicates how much nodes should be skipped at the beginning of the current path. Default is to show the complete path. A value of 1 will skip the home link, 2 will skip the home link and the first subtopic and so on. If a leaf or node is selected, that normally would be hidden, only its name will be shown.

  • return: The computed breadrumb line.
string get_breadcrumb_line ([string $separator = " > "], [string $class = null], int $skip_levels, [string $current_class = null])
  • string $separator: The separator to use between the elements.
  • string $class: If not-null, it will be assigned to all A tags.
  • int $skip_levels: The number of topic levels to skip before starting to work (use this to skip "Home" links etc.).
  • string $current_class: The class that should be assigned to the currently active topic.
get_combined_toolbar (line 713)

Compute a toolbar out of the NAP information for a given leaf and its node. Merges both toolbars into one. Always based on a leaf.

You can either pass a leaf structure, a leaf id or null. I the last case the current leaf is used. If the current leaf is undefined, the class will return the current node toolbar instead.

The information from the component will be post-processed so that the URLs point to the right location in NAP.

It uses _check_toolbar_permission to ascertain if the user can edit the leaf/node.

  • return: The created toolbar.
  • see: midcom_helper_nav::_check_toolbar_permission()
midcom_helper_toolbar get_combined_toolbar (string $baseurl, [mixed $leaf = null])
  • string $baseurl: The base url that leads to the root AIS page of the MidCOM site (without any /$id/data additions).
  • mixed $leaf: The node to be processed, either a fetched leaf array, a leaf id or null for the current leaf.
get_current_leaf (line 85)

Retrieve the ID of the currently displayed leaf. This is a leaf that is displayed by the handling topic. If no leaf is active, this function returns FALSE. (Remeber to make a type sensitve check, e.g.

nav::get_current_leaf() !== false to distinguish "0" and "false".)

int get_current_leaf ()
get_current_node (line 72)

Retrieve the ID of the currently displayed node. Defined by the topic of the component that declared able to handle the request.

int get_current_node ()
get_leaf (line 156)

This will give you a key-value pair describeing the leaf with the ID $node_id. The defined keys are described above in leaf data interchange format. You will get false if the leaf ID is invalid.

Array get_leaf (string $leaf_id)
  • string $leaf_id: The leaf-id to be retrieved.
get_leaf_toolbar (line 604)

Compute a toolbar out of the NAP information for a given leaf.

You can either pass a leaf structure, a leaf id or null. I the last case the current leaf is used. If the current leaf is undefined, the class will return null.

The information from the component will be post-processed so that the URLs point to the right location in NAP.

It uses _check_toolbar_permission to ascertain if the user can edit a leaf.

  • return: The created toolbar or null if no current leaf toolbar is available.
  • see: midcom_helper_nav::_check_toolbar_permission()
midcom_helper_toolbar get_leaf_toolbar (string $baseurl, [mixed $leaf = null])
  • string $baseurl: The base url that leads to the root AIS page of the MidCOM site (without any /$id/data additions).
  • mixed $leaf: The node to be processed, either a fetched leaf array, a leaf id or null for the current leaf.
get_leaf_uplink (line 168)

Returns the ID of the node to which $leaf_id is accociated to, false on failure.

int get_leaf_uplink (string $leaf_id)
  • string $leaf_id: The Leaf-ID to search an uplink for.
get_node (line 143)

This will give you a key-value pair describeing the node with the ID $node_id. The defined keys are described above in Node data interchange format. You will get false if the node ID is invalid.

Array get_node (int $node_id)
  • int $node_id: The node-id to be retrieved.
get_node_toolbar (line 508)

Compute a toolbar out of the NAP information for a given node.

You can either pass a node structure, a node id or null. I the last case the current node is used.

The information from the component will be post-processed so that the URLs point to the right location in NAP.

It uses _check_toolbar_permission to ascertain if the user can edit a node.

  • return: The created toolbar.
  • see: midcom_helper_nav::_check_toolbar_permission()
midcom_helper_toolbar get_node_toolbar (string $baseurl, [mixed $node = null])
  • string $baseurl: The base url that leads to the root AIS page of the MidCOM site (without any /$id/data additions).
  • mixed $node: The node to be processed, either a fetched node array, a node id or null for the current node.
get_node_uplink (line 180)

Returns the ID of the node to which $node_id is accociated to, false on failure. The root node's uplink is -1.

int get_node_uplink (int $node_id)
  • int $node_id: The Leaf-ID to search an uplink for.
get_root_node (line 98)

Retrieve the ID of the root node. Note that this ID is dependent from the ID of the MidCOM Root topic and therefore will change as easily as the root topic ID might. The MIDCOM_NAV_URL entry of the root node's data will always be empty.

int get_root_node ()
get_toolbar_definition (line 209)

This function returns the toolbar definition for the NAP object passed. This must superseed all calls to $nap_object[MIDCOM_NAV_TOOLBAR] as this information is not usable directly - it would result from the MidCOM cache and thus be out of date always (and especially not adapted to the current user).

Implementation note: This is a hotfix, that works around the current problem. It is not very performant if you query large numbers of NAP toolbars at this time. We have some basic caching in this function, but nevertheless we need a better solution here.

  • return: Toolbar definition array as originally stored in the MIDCOM_NAV_TOOLBAR key (so this can be null as well).
Array get_toolbar_definition (Array $nap_object)
  • Array $nap_object: The NAP data structure of the object for which a toolbar should be retrieved.
is_node_in_tree (line 191)

Checks if the given node is within the tree of another node.

  • return: True, if the node is a subnode of the root node, false otherwise.
bool is_node_in_tree (int $node_id, mixed $root_id, int $root_node)
  • int $node_id: The node in question.
  • int $root_node: The root node to use.
list_child_elements (line 229)

List all child elements, nodes and leaves alike, of the node with ID $parent_node_id. For every child element, an array of ID and type (node/leaf) is given as

  • MIDCOM_NAV_ID => 0,
  • MIDCOM_NAV_TYPE => "node"
If there are no child elements at all the method will return an empty array, in case of an error FALSE. NOTE: This method should be quite slow, there's room for improvement... :-)

  • return: A list of found elements, or false on failure.
Array list_child_elements (int $parent_node_id)
  • int $parent_node_id: The ID of the parent node.
list_leaves (line 129)

Lists all leaves of $parent_node. If there are no leaves you will get an empty array, if there was an error (for instance an unknown parent node ID) you will get FALSE.

Array list_leaves (mixed $parent_leaf, [bool $show_noentry = false], int $parent_node)
  • int $parent_node: The ID of the node of which the leaves are searched.
  • bool $show_noentry: Show all objects on-site which have the noentry flag set. This parameter has no effect in AIS. This defaults to false.
list_nodes (line 113)

Lists all Sub-nodes of $parent_node. If there are no subnodes you will get an empty array, if there was an error (for instance an unkown parent node ID) you will get FALSE.

Array list_nodes (int $parent_node, [bool $show_noentry = false])
  • int $parent_node: The id of the node of which the subnodes are searched.
  • bool $show_noentry: Show all objects on-site which have the noentry flag set. This parameter has no effect in AIS. This defaults to false.
render_combined_toolbar (line 801)

Shortcut function, which creates a combined leaf/node-toolbar and renders it immediately.

string render_combined_toolbar (string $baseurl, [mixed $leaf = null])
  • string $baseurl: The base url that leads to the root AIS page of the MidCOM site (without any /$id/data additions).
  • mixed $leaf: The node to be processed, either a fetched leaf array, a leaf id or null for the current leaf.
render_leaf_toolbar (line 685)

Shortcut function, which creates a leaf-toolbar and renders it immediately.

string render_leaf_toolbar (string $baseurl, [mixed $leaf = null])
  • string $baseurl: The base url that leads to the root AIS page of the MidCOM site (without any /$id/data additions).
  • mixed $leaf: The node to be processed, either a fetched leaf array, a leaf id or null for the current leaf.
render_node_toolbar (line 581)

Shortcut function, which creates a node-toolbar and renders it immediately.

string render_node_toolbar (string $baseurl, [mixed $node = null])
  • string $baseurl: The base url that leads to the root AIS page of the MidCOM site (without any /$id/data additions).
  • mixed $node: The node to be processed, either a fetched node array, a node id or null for the current node.
resolve_guid (line 293)

This function tries to resolve a guid into an NAP object.

The code is optimized trying to avoid a full-scan if possible. To do this it will treat topic and article guids specially: In both cases the system will translate it using the topic id into a node id and scan only that part of the tree non-recursivly.

A full scan of the NAP data is only done if another MidgardObject is used.

  • return: Eitehr a node or leaf structure, distinguishable by MIDCOM_NAV_TYPE, or false on failure.
mixed resolve_guid (string $guid)
  • string $guid: The GUID of the object to be looked up.
show_combined_nav (line 1176)

Generate a fully automated navigation.

On the same basis of config data, as show_simple_nav, this function builds a navigation that does not make a structural difference between nodes and leaves, only in markup. It uses the list_child_elements() method of NAP and thus honors topic's user-defined NAVORDER settings.

void show_combined_nav (Array $config)
  • Array $config: Configuration data.
show_simple_nav (line 994)

Generate a fully automated navigation.

This method will print a simple navigation tree. It uses CSS both for line formatting and for indentation. This method starts automatically at the root node, the root node's leaves will not be shown.

Here is a configuration example that can be copy&pasted, everything is mandatory:

  1. <?php
  2. // These are CSS-classes, don't set them if you don't have any classes
  3. // no class=... tags will be written out then
  4. $config["css_div_leaf_selected"] = "nav_leaf_selected";
  5. $config["css_div_leaf_unselected"] = "nav_leaf_unselected";
  6. $config["css_div_node_selected"] = "nav_node_selected";
  7. $config["css_div_node_unselected"] = "nav_node_unselected";
  8. $config["css_a_leaf_unselected"] = "nav_leaf_unselected";
  9. $config["css_a_node_unselected"] = "nav_node_unselected";
  10.  
  11. // Prefix automatically prepended to any displayed leaves or nodes,
  12. // leave empty if you don't want them.
  13. // It must include trailing spaces if you want them between prefix and element name!
  14. $config["leaf_prefix"] = "&raquo; ";
  15. $config["node_prefix"] = "";
  16.  
  17. // These are css lenght's used to build up the indentation
  18. $config["indent_size"] = "15";
  19. $config["indent_linewrap"] = "5";
  20. $config["indent_unit"] = "px";
  21.  
  22. // other Miscellaneous configuration parameters
  23. // This one controls wether leaves or subnodes are displayed first
  24. $config["leaves_first"] = true;
  25. ?>

void show_simple_nav (Array $config)
  • Array $config: Configuration as outlined above
view_current_page_url (line 422)

This function provides an interface to construct links like "View this page".

It takes the currently displayed content element (either a leaf or node) and constructs the respective URL relative to the root of the website as passed to the function.

  • return: The full URL to the on-site element in question, null if there is no on-site representation, false on failure
string view_current_page_url (string $baseurl)
  • string $baseurl: The base url that leads to the root page of the MidCOM site.
_check_toolbar_permissions (line 813)

Checks for the toolbar permissions, uses the cache variables $_user and $_admin to cache the data against repeated calls.

void _check_toolbar_permissions (int $topic_id)
  • int $topic_id: The topic id to check against.

Documentation generated on Mon, 21 Nov 2005 18:19:38 +0100 by phpDocumentor 1.3.0RC3