summaryrefslogtreecommitdiff
path: root/manager/application/views/helpers/TopNav.php
blob: 151b03f779228ac95297562e735fc735b5717234 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_View
 * @subpackage Helper
 * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
 * @version    $Id: TopNav.php 20 2009-12-01 14:26:22Z markus $
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */

/** Zend_View_Helper_Placeholder_Container_Standalone */
require_once 'Zend/View/Helper/Placeholder/Container/Standalone.php';

/**
 * Helper for building an applications top navigation bar
 *
 * @uses       Zend_View_Helper_Placeholder_Container_Standalone
 * @package    Zend_View
 * @subpackage Helper
 * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_View_Helper_TopNav extends Zend_View_Helper_Placeholder_Container_Standalone
{
    /**
     * Registry key for placeholder
     * @var string
     */
    protected $_regKey = 'Zend_View_Helper_TopNav';

    protected $items = array();

    /**
     * Retrieve placeholder for navigation element and optionally set state
     *
     * Single Link elements to be made with $this->url(array('controller'=>'<controller>'), 'default', true);
     *
     * @param  string $link
     * @param  string $setType
     * @param  string $setPos
     * @return Zend_View_Helper_TopNav
     */
    public function topNav($link = null, $setType = Zend_View_Helper_Placeholder_Container_Abstract::APPEND, $setPos = 0)
    {
    	$link = (string) $link;
        if ($link !== '') {
            if ($setType == Zend_View_Helper_Placeholder_Container_Abstract::SET) {
                if ($setPos != 0)
                	$this->items[$setPos] = $link;
                else
                	$this->items[] = $link;
            } elseif ($setType == Zend_View_Helper_Placeholder_Container_Abstract::PREPEND) {
                $this->items = array_merge(array($link), $this->items);
            } else {
                $this->items[] = $link;
            }
        }

        return $this;
    }

    /**
     * Turn helper into string
     *
     * @param  string|null $indent
     * @param  string|null $locale
     * @return string
     */
    public function toString($indent = null, $locale = null)
    {
		$output = '';
    	$indent = (null !== $indent)
                ? $this->getWhitespace($indent)
                : $this->getIndent();

        ksort($this->items);

        $output .= $indent . "<ul>\n";

        foreach ($this->items as $item) {
                $output .= $indent . "<li>" . $item . "</li>\n";
 		}
		$output .= $indent . "</ul>\n";

        return $output;
    }
}