CMS  Version 3.9
Breadcrumbs Class Reference

Public Member Functions

 __construct ()
 
 getTrail ()
 Gather the breadcrumb trail. More...
 
 findPage ()
 Get the server's url and query the SiteMap table for a match. More...
 
 walkUpTree ($currentSiteMapPage)
 Traverse up the tree through each parent url to find the root. More...
 
 walkDownTree ($upTreePages)
 No need to show breadcrumbs if there is just one single node in the tree path. More...
 
 getLink ($identifier=null)
 

Public Attributes

 $breadcrumbs
 
 $qs
 
 $url
 

Static Public Attributes

static $overrideCurrentPage = null
 

Detailed Description

Definition at line 62 of file breadcrumbs_manager.inc.

Constructor & Destructor Documentation

◆ __construct()

Breadcrumbs::__construct ( )

Definition at line 69 of file breadcrumbs_manager.inc.

70  {
71  $qs = getCleanQueryString();
72  $this->url = $this->getLink();
73 
74  trace("Breadcrumb url $this->url", 3);
75  $this->qs = preg_replace("/_style=\\w+&*/", "", $qs);
76 
77  $this->breadcrumbs = $this->getTrail();
78  }
getLink($identifier=null)
getTrail()
Gather the breadcrumb trail.

Member Function Documentation

◆ findPage()

Breadcrumbs::findPage ( )

Get the server's url and query the SiteMap table for a match.

Returns
instance of SiteMap or null

Definition at line 111 of file breadcrumbs_manager.inc.

112  {
114 
115  $pages = Query::create(SiteMap, "WHERE url =:url")
116  ->bind(":url", $url)
117  ->execute();
118 
119  return (count($pages)) ? $pages[0] : null;
120  }
static $overrideCurrentPage
$pages
Definition: export.inc:38

◆ getLink()

Breadcrumbs::getLink (   $identifier = null)

Definition at line 184 of file breadcrumbs_manager.inc.

185  {
186  global $section;
187 
188  if (!$identifier) $identifier = $_REQUEST["identifier"];
189 
190  if ($section->section == "/")
191  $url = "/$identifier";
192  else
193  $url = "/{$section->section}/$identifier";
194 
195  return $url;
196  }
$section
Definition: event_form.inc:44
$identifier
Definition: rss.inc:37

◆ getTrail()

Breadcrumbs::getTrail ( )

Gather the breadcrumb trail.

1) Find the page the user is on in the SiteMap table 2) Traverse the site map tree to find the root node 3) Walk down the tree to format the trail from the root to the current page for display.

Definition at line 87 of file breadcrumbs_manager.inc.

88  {
89  $currentSiteMapPage = $this->findPage();
90  trace("Breadcrumbs:: currentSiteMapPage id {$currentSiteMapPage->url}", 3);
91 
92  if(!$currentSiteMapPage)
93  {
94  return "";
95  }
96 
97  $upTreePages = $this->walkUpTree($currentSiteMapPage);
98 
99  $breadcrumbs = $this->walkDownTree($upTreePages);
100 
101  return $breadcrumbs;
102  }
walkUpTree($currentSiteMapPage)
Traverse up the tree through each parent url to find the root.
findPage()
Get the server's url and query the SiteMap table for a match.
walkDownTree($upTreePages)
No need to show breadcrumbs if there is just one single node in the tree path.

◆ walkDownTree()

Breadcrumbs::walkDownTree (   $upTreePages)

No need to show breadcrumbs if there is just one single node in the tree path.

Parameters
array$upTreePagesarray of SiteMap objects
Returns
String breadcrumbs

Definition at line 152 of file breadcrumbs_manager.inc.

153  {
154  $breadcrumbs = "";
155 
156  if(count($upTreePages) < 2) return $breadcrumbs;
157 
158  $downTreePages = array_reverse($upTreePages);
159 
160  $idx = 0;
161  $last = count($downTreePages) - 1;
162 
163  foreach($downTreePages as $downTreePage)
164  {
165  // Only need qs if this is not the first page
166  // and not the last. Last page is just title, not link
167  if($idx < $last)
168  {
169  $link = ($idx > 0 AND $this->qs) ? "$downTreePage->url?{$this->qs}" : $downTreePage->url;
170  $title = $downTreePage->page_title;
171  $breadcrumbs .= "<a href=\"{$link}\">{$title}</a> &raquo;\n";
172  }
173  else
174  {
175  $breadcrumbs .= $downTreePage->page_title . "\n";
176  }
177 
178  $idx++;
179  }
180 
181  return $breadcrumbs;
182  }

◆ walkUpTree()

Breadcrumbs::walkUpTree (   $currentSiteMapPage)

Traverse up the tree through each parent url to find the root.

Parameters
obj$currentSiteMapPageinstance of SiteMap
Returns
array of SiteMap objects

Definition at line 129 of file breadcrumbs_manager.inc.

130  {
131  $upTreePages = array();
132  if(!$currentSiteMapPage) return $upTreePages;
133 
134  $currPage = clone $currentSiteMapPage;
135  // walk up the tree to get all parents of the page
136  while(isset($currPage))
137  {
138  array_push($upTreePages, $currPage);
139  $currPage = $currPage->Parent();
140  }
141 
142  return $upTreePages;
143  }

Member Data Documentation

◆ $breadcrumbs

Breadcrumbs::$breadcrumbs

Definition at line 64 of file breadcrumbs_manager.inc.

◆ $overrideCurrentPage

Breadcrumbs::$overrideCurrentPage = null
static

Definition at line 68 of file breadcrumbs_manager.inc.

◆ $qs

Breadcrumbs::$qs

Definition at line 65 of file breadcrumbs_manager.inc.

◆ $url

Breadcrumbs::$url

Definition at line 66 of file breadcrumbs_manager.inc.


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