00001 <?php
00026 require_once 'Zend/View/Helper/Navigation/HelperAbstract.php';
00027
00037 class Zend_View_Helper_Navigation_Breadcrumbs
00038 extends Zend_View_Helper_Navigation_HelperAbstract
00039 {
00045 protected $_separator = ' > ';
00046
00052 protected $_minDepth = 1;
00053
00059 protected $_linkLast = false;
00060
00066 protected $_partial;
00067
00077 public function breadcrumbs(Zend_Navigation_Container $container = null)
00078 {
00079 if (null !== $container) {
00080 $this->setContainer($container);
00081 }
00082
00083 return $this;
00084 }
00085
00086
00087
00095 public function setSeparator($separator)
00096 {
00097 if (is_string($separator)) {
00098 $this->_separator = $separator;
00099 }
00100
00101 return $this;
00102 }
00103
00109 public function getSeparator()
00110 {
00111 return $this->_separator;
00112 }
00113
00122 public function setLinkLast($linkLast)
00123 {
00124 $this->_linkLast = (bool) $linkLast;
00125 return $this;
00126 }
00127
00133 public function getLinkLast()
00134 {
00135 return $this->_linkLast;
00136 }
00137
00152 public function setPartial($partial)
00153 {
00154 if (null === $partial || is_string($partial) || is_array($partial)) {
00155 $this->_partial = $partial;
00156 }
00157
00158 return $this;
00159 }
00160
00166 public function getPartial()
00167 {
00168 return $this->_partial;
00169 }
00170
00171
00172
00183 public function renderStraight(Zend_Navigation_Container $container = null)
00184 {
00185 if (null === $container) {
00186 $container = $this->getContainer();
00187 }
00188
00189
00190 if (!$active = $this->findActive($container)) {
00191 return '';
00192 }
00193
00194 $active = $active['page'];
00195
00196
00197 if ($this->getLinkLast()) {
00198 $html = $this->htmlify($active);
00199 } else {
00200 $html = $active->getLabel();
00201 if ($this->getUseTranslator() && $t = $this->getTranslator()) {
00202 $html = $t->translate($html);
00203 }
00204 $html = $this->view->escape($html);
00205 }
00206
00207
00208 while ($parent = $active->getParent()) {
00209 if ($parent instanceof Zend_Navigation_Page) {
00210
00211 $html = $this->htmlify($parent)
00212 . $this->getSeparator()
00213 . $html;
00214 }
00215
00216 if ($parent === $container) {
00217
00218 break;
00219 }
00220
00221 $active = $parent;
00222 }
00223
00224 return strlen($html) ? $this->getIndent() . $html : '';
00225 }
00226
00250 public function renderPartial(Zend_Navigation_Container $container = null,
00251 $partial = null)
00252 {
00253 if (null === $container) {
00254 $container = $this->getContainer();
00255 }
00256
00257 if (null === $partial) {
00258 $partial = $this->getPartial();
00259 }
00260
00261 if (empty($partial)) {
00262 require_once 'Zend/View/Exception.php';
00263 throw new Zend_View_Exception(
00264 'Unable to render menu: No partial view script provided');
00265 }
00266
00267
00268 $model = array('pages' => array());
00269 if ($active = $this->findActive($container)) {
00270 $active = $active['page'];
00271 $model['pages'][] = $active;
00272 while ($parent = $active->getParent()) {
00273 if ($parent instanceof Zend_Navigation_Page) {
00274 $model['pages'][] = $parent;
00275 } else {
00276 break;
00277 }
00278
00279 if ($parent === $container) {
00280
00281 break;
00282 }
00283
00284 $active = $parent;
00285 }
00286 $model['pages'] = array_reverse($model['pages']);
00287 }
00288
00289 if (is_array($partial)) {
00290 if (count($partial) != 2) {
00291 require_once 'Zend/View/Exception.php';
00292 throw new Zend_View_Exception(
00293 'Unable to render menu: A view partial supplied as ' .
00294 'an array must contain two values: partial view ' .
00295 'script and module where script can be found');
00296 }
00297
00298 return $this->view->partial($partial[0], $partial[1], $model);
00299 }
00300
00301 return $this->view->partial($partial, null, $model);
00302 }
00303
00304
00305
00317 public function render(Zend_Navigation_Container $container = null)
00318 {
00319 if ($partial = $this->getPartial()) {
00320 return $this->renderPartial($container, $partial);
00321 } else {
00322 return $this->renderStraight($container);
00323 }
00324 }
00325 }