.

WidgetBreadcrumb Class Reference
[View]

Print a breadcrumb. More...

Inheritance diagram for WidgetBreadcrumb:
IWidget IRenderer

List of all members.

Public Member Functions

  __construct ($source)
  render ($policy=self::NONE)
  Renders what should be rendered.

Static Public Member Functions

static  output ($source, $policy=self::NONE)

Public Attributes

  $action = 'view'
  $action_params = null
  $glue = ' > '
  $prefix = '> '
  $source
  $url_home
const  BLOCK = 512
const  LINK_LAST = 128
  Link Last Element.
const  UNLINK_LAST = 1024
const  USE_PREFIX = 256

Protected Member Functions

  instance2string ($instance, $action)
  Turn a data obejct into a (link) string.
  to_array ($item, $key=false)
  Transform given source into an array.

Detailed Description

Print a breadcrumb.

The breadcrumb is passed an array that may contain different types of content, namely:

  • a string, which is printed as is (that is: it is not escaped, so you can pass HTML)
  • a data object which is translated to the path to the VIEW action. The object must implement the ISelfDescribing interface. If it implements the IHierarchic interface, too, its parent will be added to the crumb, also (and its parent's parent, and so on)
  • the name of an action as key and a data object as value. This is treated like the object above except the VIEW action is replaced by the given one

As usual, you may substitute the array by a single element.

Author:
Gerd Riesselmann

Definition at line 20 of file breadcrumb.widget.php.


Constructor & Destructor Documentation

WidgetBreadcrumb::__construct ( source  ) 

Definition at line 42 of file breadcrumb.widget.php.

00042                                              {
00043                 $this->url_home = Config::get_value(Config::URL_BASEDIR);
00044                 $this->source = $source;
00045         }

Member Function Documentation

WidgetBreadcrumb::instance2string ( instance,
action  
) [protected]

Turn a data obejct into a (link) string.

Definition at line 96 of file breadcrumb.widget.php.

00096                                                                {
00097                 if (empty($action) || is_numeric($action)) {
00098                         $action = $this->action;
00099                 }
00100                 return WidgetActionLink::output($instance, $action, $instance);
00101         }
static WidgetBreadcrumb::output ( source,
policy = self::NONE  
) [static]

Definition at line 37 of file breadcrumb.widget.php.

00037                                                                    {
00038                 $w = new WidgetBreadcrumb($source);
00039                 return $w->render($policy);
00040         }
WidgetBreadcrumb::render ( policy = self::NONE  ) 

Renders what should be rendered.

Parameters:
int  $policy Defines how to render, meaning depends on implementation
Returns:
string The rendered content

Implements IRenderer.

Definition at line 47 of file breadcrumb.widget.php.

00047                                                    {
00048                 $src = $this->to_array($this->source);
00049                 $crumb = array();
00050                 $unlink_this = !Common::flag_is_set($policy, self::LINK_LAST);
00051                 foreach($src as $item) {
00052                         $link = ($unlink_this) ? preg_replace('|<a.*?>(.*?)</a>|', '$1', $item) : $item;
00053                         array_unshift($crumb, $link);
00054                         $unlink_this = false;
00055                 }
00056                 $home = html::a(Config::get_value(Config::TITLE), $this->url_home, tr('Go to home page', 'app'));
00057                 array_unshift($crumb, $home);
00058         
00059                 $view = ViewFactory::create_view(IViewFactory::MESSAGE, 'core::widgets/breadcrumb');
00060                 $view->assign('breadcrumb_prefix', Common::flag_is_set($policy, self::USE_PREFIX) ? $this->prefix : '');
00061                 $view->assign('breadcrumb_glue', $this->glue);
00062                 $view->assign('breadcrumb_items', $crumb);
00063                 
00064                 return $view->render();
00065         }
WidgetBreadcrumb::to_array ( item,
key = false  
) [protected]

Transform given source into an array.

The array has the last item in breadcrumb as first element

Parameters:
mixed  $source
Returns:
array

Definition at line 73 of file breadcrumb.widget.php.

00073                                                          {
00074                 $arr_ret = array();
00075                 if ($item instanceof IHierarchic) {
00076                         $arr_ret[] = $this->instance2string($item, $key);
00077                         $arr_ret = array_merge($arr_ret, $this->to_array($item->get_parent(), $key));
00078                 }
00079                 else if ($item instanceof ISelfDescribing) {
00080                         $arr_ret[] = $this->instance2string($item, $key);
00081                 }
00082                 else if (is_array($item)) {
00083                         foreach($item as $subkey => $subitem) {
00084                                 $arr_ret = array_merge($this->to_array($subitem, $subkey), $arr_ret);                   
00085                         }
00086                 }
00087                 else if (!empty($item)) {
00088                         $arr_ret[] = @strval($item);
00089                 }
00090                 return $arr_ret;        
00091         }

Member Data Documentation

WidgetBreadcrumb::$action = 'view'

Definition at line 31 of file breadcrumb.widget.php.

WidgetBreadcrumb::$action_params = null

Definition at line 32 of file breadcrumb.widget.php.

WidgetBreadcrumb::$glue = ' &gt; '

Definition at line 34 of file breadcrumb.widget.php.

WidgetBreadcrumb::$prefix = '&gt; '

Definition at line 33 of file breadcrumb.widget.php.

WidgetBreadcrumb::$source

Definition at line 30 of file breadcrumb.widget.php.

WidgetBreadcrumb::$url_home

Definition at line 35 of file breadcrumb.widget.php.

Definition at line 26 of file breadcrumb.widget.php.

Link Last Element.

If not set (default), the last element will be unlinked

Definition at line 24 of file breadcrumb.widget.php.

Deprecated:

Definition at line 28 of file breadcrumb.widget.php.

Definition at line 25 of file breadcrumb.widget.php.


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