12 * obtain it through the world-wide-web, please send an email |
12 * obtain it through the world-wide-web, please send an email |
13 * to license@zend.com so we can send you a copy immediately. |
13 * to license@zend.com so we can send you a copy immediately. |
14 * |
14 * |
15 * @category Zend |
15 * @category Zend |
16 * @package Zend_Navigation |
16 * @package Zend_Navigation |
17 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
17 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
18 * @license http://framework.zend.com/license/new-bsd New BSD License |
18 * @license http://framework.zend.com/license/new-bsd New BSD License |
19 * @version $Id: Page.php 22882 2010-08-22 14:00:16Z freak $ |
19 * @version $Id: Page.php 25125 2012-11-16 15:12:06Z rob $ |
20 */ |
20 */ |
21 |
21 |
22 /** |
22 /** |
23 * @see Zend_Navigation_Container |
23 * @see Zend_Navigation_Container |
24 */ |
24 */ |
189 if (isset($options['type'])) { |
222 if (isset($options['type'])) { |
190 $type = $options['type']; |
223 $type = $options['type']; |
191 } elseif(self::getDefaultPageType()!= null) { |
224 } elseif(self::getDefaultPageType()!= null) { |
192 $type = self::getDefaultPageType(); |
225 $type = self::getDefaultPageType(); |
193 } |
226 } |
194 |
227 |
195 if(isset($type)) { |
228 if(isset($type)) { |
196 if (is_string($type) && !empty($type)) { |
229 if (is_string($type) && !empty($type)) { |
197 switch (strtolower($type)) { |
230 switch (strtolower($type)) { |
198 case 'mvc': |
231 case 'mvc': |
199 $type = 'Zend_Navigation_Page_Mvc'; |
232 $type = 'Zend_Navigation_Page_Mvc'; |
220 } |
253 } |
221 } |
254 } |
222 |
255 |
223 $hasUri = isset($options['uri']); |
256 $hasUri = isset($options['uri']); |
224 $hasMvc = isset($options['action']) || isset($options['controller']) || |
257 $hasMvc = isset($options['action']) || isset($options['controller']) || |
225 isset($options['module']) || isset($options['route']); |
258 isset($options['module']) || isset($options['route']) || |
|
259 isset($options['params']); |
226 |
260 |
227 if ($hasMvc) { |
261 if ($hasMvc) { |
228 require_once 'Zend/Navigation/Page/Mvc.php'; |
262 require_once 'Zend/Navigation/Page/Mvc.php'; |
229 return new Zend_Navigation_Page_Mvc($options); |
263 return new Zend_Navigation_Page_Mvc($options); |
230 } elseif ($hasUri) { |
264 } elseif ($hasUri) { |
231 require_once 'Zend/Navigation/Page/Uri.php'; |
265 require_once 'Zend/Navigation/Page/Uri.php'; |
232 return new Zend_Navigation_Page_Uri($options); |
266 return new Zend_Navigation_Page_Uri($options); |
233 } else { |
267 } else { |
234 require_once 'Zend/Navigation/Exception.php'; |
268 require_once 'Zend/Navigation/Exception.php'; |
235 throw new Zend_Navigation_Exception( |
269 |
236 'Invalid argument: Unable to determine class to instantiate'); |
270 $message = 'Invalid argument: Unable to determine class to instantiate'; |
237 } |
271 if (isset($options['label'])) { |
|
272 $message .= ' (Page label: ' . $options['label'] . ')'; |
|
273 } |
|
274 |
|
275 throw new Zend_Navigation_Exception($message); |
|
276 } |
238 } |
277 } |
239 |
278 |
240 /** |
279 /** |
241 * Page constructor |
280 * Page constructor |
242 * |
281 * |
328 { |
367 { |
329 return $this->_label; |
368 return $this->_label; |
330 } |
369 } |
331 |
370 |
332 /** |
371 /** |
|
372 * Sets a fragment identifier |
|
373 * |
|
374 * @param string $fragment new fragment identifier |
|
375 * @return Zend_Navigation_Page fluent interface, returns self |
|
376 * @throws Zend_Navigation_Exception if empty/no string is given |
|
377 */ |
|
378 public function setFragment($fragment) |
|
379 { |
|
380 if (null !== $fragment && !is_string($fragment)) { |
|
381 require_once 'Zend/Navigation/Exception.php'; |
|
382 throw new Zend_Navigation_Exception( |
|
383 'Invalid argument: $fragment must be a string or null'); |
|
384 } |
|
385 |
|
386 $this->_fragment = $fragment; |
|
387 return $this; |
|
388 } |
|
389 |
|
390 /** |
|
391 * Returns fragment identifier |
|
392 * |
|
393 * @return string|null fragment identifier |
|
394 */ |
|
395 public function getFragment() |
|
396 { |
|
397 return $this->_fragment; |
|
398 } |
|
399 |
|
400 /** |
333 * Sets page id |
401 * Sets page id |
334 * |
402 * |
335 * @param string|null $id [optional] id to set. Default is null, |
403 * @param string|null $id [optional] id to set. Default is null, |
336 * which sets no id. |
404 * which sets no id. |
337 * @return Zend_Navigation_Page fluent interface, returns self |
405 * @return Zend_Navigation_Page fluent interface, returns self |
446 * @return string|null page target or null |
514 * @return string|null page target or null |
447 */ |
515 */ |
448 public function getTarget() |
516 public function getTarget() |
449 { |
517 { |
450 return $this->_target; |
518 return $this->_target; |
|
519 } |
|
520 |
|
521 /** |
|
522 * Sets access key for this page |
|
523 * |
|
524 * @param string|null $character [optional] access key to set. Default |
|
525 * is null, which sets no access key. |
|
526 * @return Zend_Navigation_Page fluent interface, returns self |
|
527 * @throws Zend_Navigation_Exception if access key is not string or null or |
|
528 * if the string length not equal to one |
|
529 */ |
|
530 public function setAccesskey($character = null) |
|
531 { |
|
532 if (null !== $character |
|
533 && (!is_string($character) || 1 != strlen($character))) |
|
534 { |
|
535 require_once 'Zend/Navigation/Exception.php'; |
|
536 throw new Zend_Navigation_Exception( |
|
537 'Invalid argument: $character must be a single character or null' |
|
538 ); |
|
539 } |
|
540 |
|
541 $this->_accesskey = $character; |
|
542 return $this; |
|
543 } |
|
544 |
|
545 /** |
|
546 * Returns page access key |
|
547 * |
|
548 * @return string|null page access key or null |
|
549 */ |
|
550 public function getAccesskey() |
|
551 { |
|
552 return $this->_accesskey; |
451 } |
553 } |
452 |
554 |
453 /** |
555 /** |
454 * Sets the page's forward links to other pages |
556 * Sets the page's forward links to other pages |
455 * |
557 * |
572 $this->_rev[$relation] : |
674 $this->_rev[$relation] : |
573 null; |
675 null; |
574 } |
676 } |
575 |
677 |
576 return $this->_rev; |
678 return $this->_rev; |
|
679 } |
|
680 |
|
681 /** |
|
682 * Sets a single custom HTML attribute |
|
683 * |
|
684 * @param string $name name of the HTML attribute |
|
685 * @param string|null $value value for the HTML attribute |
|
686 * @return Zend_Navigation_Page fluent interface, returns self |
|
687 * @throws Zend_Navigation_Exception if name is not string or value is |
|
688 * not null or a string |
|
689 */ |
|
690 public function setCustomHtmlAttrib($name, $value) |
|
691 { |
|
692 if (!is_string($name)) { |
|
693 require_once 'Zend/Navigation/Exception.php'; |
|
694 throw new Zend_Navigation_Exception( |
|
695 'Invalid argument: $name must be a string' |
|
696 ); |
|
697 } |
|
698 |
|
699 if (null !== $value && !is_string($value)) { |
|
700 require_once 'Zend/Navigation/Exception.php'; |
|
701 throw new Zend_Navigation_Exception( |
|
702 'Invalid argument: $value must be a string or null' |
|
703 ); |
|
704 } |
|
705 |
|
706 if (null === $value && isset($this->_customHtmlAttribs[$name])) { |
|
707 unset($this->_customHtmlAttribs[$name]); |
|
708 } else { |
|
709 $this->_customHtmlAttribs[$name] = $value; |
|
710 } |
|
711 |
|
712 return $this; |
|
713 } |
|
714 |
|
715 /** |
|
716 * Returns a single custom HTML attributes by name |
|
717 * |
|
718 * @param string $name name of the HTML attribute |
|
719 * @return string|null value for the HTML attribute or null |
|
720 * @throws Zend_Navigation_Exception if name is not string |
|
721 */ |
|
722 public function getCustomHtmlAttrib($name) |
|
723 { |
|
724 if (!is_string($name)) { |
|
725 require_once 'Zend/Navigation/Exception.php'; |
|
726 throw new Zend_Navigation_Exception( |
|
727 'Invalid argument: $name must be a string' |
|
728 ); |
|
729 } |
|
730 |
|
731 if (isset($this->_customHtmlAttribs[$name])) { |
|
732 return $this->_customHtmlAttribs[$name]; |
|
733 } |
|
734 |
|
735 return null; |
|
736 } |
|
737 |
|
738 /** |
|
739 * Sets multiple custom HTML attributes at once |
|
740 * |
|
741 * @param array $attribs an associative array of html attributes |
|
742 * @return Zend_Navigation_Page fluent interface, returns self |
|
743 */ |
|
744 public function setCustomHtmlAttribs(array $attribs) |
|
745 { |
|
746 foreach ($attribs as $key => $value) { |
|
747 $this->setCustomHtmlAttrib($key, $value); |
|
748 } |
|
749 return $this; |
|
750 } |
|
751 |
|
752 /** |
|
753 * Returns all custom HTML attributes as an array |
|
754 * |
|
755 * @return array an array containing custom HTML attributes |
|
756 */ |
|
757 public function getCustomHtmlAttribs() |
|
758 { |
|
759 return $this->_customHtmlAttribs; |
|
760 } |
|
761 |
|
762 /** |
|
763 * Removes a custom HTML attribute from the page |
|
764 * |
|
765 * @param string $name name of the custom HTML attribute |
|
766 * @return Zend_Navigation_Page fluent interface, returns self |
|
767 */ |
|
768 public function removeCustomHtmlAttrib($name) |
|
769 { |
|
770 if (!is_string($name)) { |
|
771 require_once 'Zend/Navigation/Exception.php'; |
|
772 throw new Zend_Navigation_Exception( |
|
773 'Invalid argument: $name must be a string' |
|
774 ); |
|
775 } |
|
776 |
|
777 if (isset($this->_customHtmlAttribs[$name])) { |
|
778 unset($this->_customHtmlAttribs[$name]); |
|
779 } |
|
780 } |
|
781 |
|
782 /** |
|
783 * Clear all custom HTML attributes |
|
784 * |
|
785 * @return Zend_Navigation_Page fluent interface, returns self |
|
786 */ |
|
787 public function clearCustomHtmlAttribs() |
|
788 { |
|
789 $this->_customHtmlAttribs = array(); |
|
790 |
|
791 return $this; |
577 } |
792 } |
578 |
793 |
579 /** |
794 /** |
580 * Sets page order to use in parent container |
795 * Sets page order to use in parent container |
581 * |
796 * |
1088 public function toArray() |
1306 public function toArray() |
1089 { |
1307 { |
1090 return array_merge( |
1308 return array_merge( |
1091 $this->getCustomProperties(), |
1309 $this->getCustomProperties(), |
1092 array( |
1310 array( |
1093 'label' => $this->getlabel(), |
1311 'label' => $this->getlabel(), |
1094 'id' => $this->getId(), |
1312 'fragment' => $this->getFragment(), |
1095 'class' => $this->getClass(), |
1313 'id' => $this->getId(), |
1096 'title' => $this->getTitle(), |
1314 'class' => $this->getClass(), |
1097 'target' => $this->getTarget(), |
1315 'title' => $this->getTitle(), |
1098 'rel' => $this->getRel(), |
1316 'target' => $this->getTarget(), |
1099 'rev' => $this->getRev(), |
1317 'accesskey' => $this->getAccesskey(), |
1100 'order' => $this->getOrder(), |
1318 'rel' => $this->getRel(), |
1101 'resource' => $this->getResource(), |
1319 'rev' => $this->getRev(), |
1102 'privilege' => $this->getPrivilege(), |
1320 'customHtmlAttribs' => $this->getCustomHtmlAttribs(), |
1103 'active' => $this->isActive(), |
1321 'order' => $this->getOrder(), |
1104 'visible' => $this->isVisible(), |
1322 'resource' => $this->getResource(), |
1105 'type' => get_class($this), |
1323 'privilege' => $this->getPrivilege(), |
1106 'pages' => parent::toArray() |
1324 'active' => $this->isActive(), |
1107 )); |
1325 'visible' => $this->isVisible(), |
|
1326 'type' => get_class($this), |
|
1327 'pages' => parent::toArray() |
|
1328 ) |
|
1329 ); |
1108 } |
1330 } |
1109 |
1331 |
1110 // Internal methods: |
1332 // Internal methods: |
1111 |
1333 |
1112 /** |
1334 /** |
1117 */ |
1339 */ |
1118 protected static function _normalizePropertyName($property) |
1340 protected static function _normalizePropertyName($property) |
1119 { |
1341 { |
1120 return str_replace(' ', '', ucwords(str_replace('_', ' ', $property))); |
1342 return str_replace(' ', '', ucwords(str_replace('_', ' ', $property))); |
1121 } |
1343 } |
1122 |
1344 |
1123 public static function setDefaultPageType($type = null) { |
1345 public static function setDefaultPageType($type = null) { |
1124 if($type !== null && !is_string($type)) { |
1346 if($type !== null && !is_string($type)) { |
1125 throw new Zend_Navigation_Exception( |
1347 throw new Zend_Navigation_Exception( |
1126 'Cannot set default page type: type is no string but should be' |
1348 'Cannot set default page type: type is no string but should be' |
1127 ); |
1349 ); |
1128 } |
1350 } |
1129 |
1351 |
1130 self::$_defaultPageType = $type; |
1352 self::$_defaultPageType = $type; |
1131 } |
1353 } |
1132 |
1354 |
1133 public static function getDefaultPageType() { |
1355 public static function getDefaultPageType() { |
1134 return self::$_defaultPageType; |
1356 return self::$_defaultPageType; |
1135 } |
1357 } |
1136 |
1358 |
1137 // Abstract methods: |
1359 // Abstract methods: |