Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / View / Helper / Navigation / Breadcrumbs.php
bloba52350ee90ffca1c92b5a1ca4a144f4e4361877b
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\View\Helper\Navigation;
12 use Zend\Navigation\AbstractContainer;
13 use Zend\Navigation\Page\AbstractPage;
14 use Zend\View;
15 use Zend\View\Exception;
17 /**
18 * Helper for printing breadcrumbs
20 class Breadcrumbs extends AbstractHelper
22 /**
23 * Whether last page in breadcrumb should be hyperlinked
25 * @var bool
27 protected $linkLast = false;
29 /**
30 * The minimum depth a page must have to be included when rendering
32 * @var int
34 protected $minDepth = 1;
36 /**
37 * Partial view script to use for rendering menu
39 * @var string|array
41 protected $partial;
43 /**
44 * Breadcrumbs separator string
46 * @var string
48 protected $separator = ' &gt; ';
50 /**
51 * Helper entry point
53 * @param string|AbstractContainer $container container to operate on
54 * @return Breadcrumbs
56 public function __invoke($container = null)
58 if (null !== $container) {
59 $this->setContainer($container);
62 return $this;
65 /**
66 * Renders helper
68 * Implements {@link HelperInterface::render()}.
70 * @param AbstractContainer $container [optional] container to render. Default is
71 * to render the container registered in the helper.
72 * @return string
74 public function render($container = null)
76 $partial = $this->getPartial();
77 if ($partial) {
78 return $this->renderPartial($container, $partial);
81 return $this->renderStraight($container);
84 /**
85 * Renders breadcrumbs by chaining 'a' elements with the separator
86 * registered in the helper
88 * @param AbstractContainer $container [optional] container to render. Default is
89 * to render the container registered in the helper.
90 * @return string
92 public function renderStraight($container = null)
94 $this->parseContainer($container);
95 if (null === $container) {
96 $container = $this->getContainer();
99 // find deepest active
100 if (!$active = $this->findActive($container)) {
101 return '';
104 $active = $active['page'];
106 // put the deepest active page last in breadcrumbs
107 if ($this->getLinkLast()) {
108 $html = $this->htmlify($active);
109 } else {
110 $html = $active->getLabel();
111 if (null !== ($translator = $this->getTranslator())) {
112 $html = $translator->translate($html, $this->getTranslatorTextDomain());
114 $escaper = $this->view->plugin('escapeHtml');
115 $html = $escaper($html);
118 // walk back to root
119 while ($parent = $active->getParent()) {
120 if ($parent instanceof AbstractPage) {
121 // prepend crumb to html
122 $html = $this->htmlify($parent)
123 . $this->getSeparator()
124 . $html;
127 if ($parent === $container) {
128 // at the root of the given container
129 break;
132 $active = $parent;
135 return strlen($html) ? $this->getIndent() . $html : '';
139 * Renders the given $container by invoking the partial view helper
141 * The container will simply be passed on as a model to the view script,
142 * so in the script it will be available in <code>$this->container</code>.
144 * @param AbstractContainer $container [optional] container to pass to view script.
145 * Default is to use the container registered
146 * in the helper.
147 * @param string|array $partial [optional] partial view script to use.
148 * Default is to use the partial registered
149 * in the helper. If an array is given, it
150 * is expected to contain two values; the
151 * partial view script to use, and the module
152 * where the script can be found.
153 * @throws Exception\RuntimeException if no partial provided
154 * @throws Exception\InvalidArgumentException if partial is invalid array
155 * @return string helper output
157 public function renderPartial($container = null, $partial = null)
159 $this->parseContainer($container);
160 if (null === $container) {
161 $container = $this->getContainer();
164 if (null === $partial) {
165 $partial = $this->getPartial();
168 if (empty($partial)) {
169 throw new Exception\RuntimeException(
170 'Unable to render menu: No partial view script provided'
174 // put breadcrumb pages in model
175 $model = array('pages' => array());
176 $active = $this->findActive($container);
177 if ($active) {
178 $active = $active['page'];
179 $model['pages'][] = $active;
180 while ($parent = $active->getParent()) {
181 if ($parent instanceof AbstractPage) {
182 $model['pages'][] = $parent;
183 } else {
184 break;
187 if ($parent === $container) {
188 // break if at the root of the given container
189 break;
192 $active = $parent;
194 $model['pages'] = array_reverse($model['pages']);
197 if (is_array($partial)) {
198 if (count($partial) != 2) {
199 throw new Exception\InvalidArgumentException(
200 'Unable to render menu: A view partial supplied as '
201 . 'an array must contain two values: partial view '
202 . 'script and module where script can be found'
206 $partialHelper = $this->view->plugin('partial');
207 return $partialHelper($partial[0], /*$partial[1], */$model);
210 $partialHelper = $this->view->plugin('partial');
211 return $partialHelper($partial, $model);
215 * Sets whether last page in breadcrumbs should be hyperlinked
217 * @param bool $linkLast whether last page should be hyperlinked
218 * @return Breadcrumbs
220 public function setLinkLast($linkLast)
222 $this->linkLast = (bool) $linkLast;
223 return $this;
227 * Returns whether last page in breadcrumbs should be hyperlinked
229 * @return bool
231 public function getLinkLast()
233 return $this->linkLast;
237 * Sets which partial view script to use for rendering menu
239 * @param string|array $partial partial view script or null. If an array is
240 * given, it is expected to contain two
241 * values; the partial view script to use,
242 * and the module where the script can be
243 * found.
244 * @return Breadcrumbs
246 public function setPartial($partial)
248 if (null === $partial || is_string($partial) || is_array($partial)) {
249 $this->partial = $partial;
252 return $this;
256 * Returns partial view script to use for rendering menu
258 * @return string|array|null
260 public function getPartial()
262 return $this->partial;
266 * Sets breadcrumb separator
268 * @param string $separator separator string
269 * @return Breadcrumbs
271 public function setSeparator($separator)
273 if (is_string($separator)) {
274 $this->separator = $separator;
277 return $this;
281 * Returns breadcrumb separator
283 * @return string breadcrumb separator
285 public function getSeparator()
287 return $this->separator;