Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * XListMenu and XListMenuItem class file
4
 *
5
 * @author Qiang Xue <qiang.xue@gmail.com>
6
 * @link http://www.pradosoft.com/
7
 * @copyright Copyright &copy; 2006 PradoSoft
8
 * @license http://www.pradosoft.com/license/
9
 * @version $Id: XListMenu.php 1398 2006-09-08 19:31:03Z xue $
10
 */
11
 
12
Prado::using('System.Web.UI.WebControls.TListControl');
13
 
14
/**
15
 * XListMenu class
16
 *
17
 * XListMenu displays a list of hyperlinks that can be used for page menus.
18
 * Menu items adjust their css class automatically according to the current
19
 * page displayed. In particular, a menu item is considered as active if
20
 * the URL it represents is for the page currently displayed.
21
 *
22
 * Usage of XListMenu is similar to PRADO list controls. Each list item has
23
 * two extra properties: {@link XListMenuItem::setPagePath PagePath} and
24
 * {@link XListMenuItem::setNavigateUrl NavigateUrl}. The former is used to
25
 * determine if the item is active or not, while the latter specifies the
26
 * URL for the item. If the latter is not specified, a URL to the page is
27
 * generated automatically.
28
 *
29
 * In template, you may use the following tags to specify a menu:
30
 * <code>
31
 *   <com:XListMenu ActiveCssClass="class1" InactiveCssClass="class2">
32
 *      <com:XListMenuItem Text="Menu 1" PagePath="Page1" />
33
 *      <com:XListMenuItem Text="Menu 2" PagePath="Page2" NavigateUrl="/page2" />
34
 *   </com:XListMenu>
35
 * </code>
36
 *
37
 * @author Qiang Xue <qiang.xue@gmail.com>
38
 * @link http://www.pradosoft.com/
39
 * @copyright Copyright &copy; 2006 PradoSoft
40
 * @license http://www.pradosoft.com/license/
41
 */
42
class XListMenu extends TListControl
43
{
44
	public function addParsedObject($object)
45
	{
46
		if($object instanceof XListMenuItem)
47
			parent::addParsedObject($object);
48
	}
49
 
50
	public function getActiveCssClass()
51
	{
52
		return $this->getViewState('ActiveCssClass','');
53
	}
54
 
55
	public function setActiveCssClass($value)
56
	{
57
		$this->setViewState('ActiveCssClass',$value,'');
58
	}
59
 
60
	public function getInactiveCssClass()
61
	{
62
		return $this->getViewState('InactiveCssClass','');
63
	}
64
 
65
	public function setInactiveCssClass($value)
66
	{
67
		$this->setViewState('InactiveCssClass',$value,'');
68
	}
69
 
70
	public function render($writer)
71
	{
72
		if(($activeClass=$this->getActiveCssClass())!=='')
73
			$activeClass=' class="'.$activeClass.'"';
74
		if(($inactiveClass=$this->getInactiveCssClass())!=='')
75
			$inactiveClass=' class="'.$inactiveClass.'"';
76
		$currentPagePath=$this->getPage()->getPagePath();
77
		$writer->write("<ul>\n");
78
		foreach($this->getItems() as $item)
79
		{
80
			$pagePath=$item->getPagePath();
81
			//if(strpos($currentPagePath.'.',$pagePath.'.')===0)
82
			if($pagePath[strlen($pagePath)-1]==='*')
83
			{
84
				if(strpos($currentPagePath.'.',rtrim($pagePath,'*'))===0)
85
					$cssClass=$activeClass;
86
				else
87
					$cssClass=$inactiveClass;
88
			}
89
			else
90
			{
91
				if($pagePath===$currentPagePath)
92
					$cssClass=$activeClass;
93
				else
94
					$cssClass=$inactiveClass;
95
			}
96
			if(($url=$item->getNavigateUrl())==='')
97
				$url=$this->getService()->constructUrl($pagePath);
98
			$writer->write("<li><a href=\"$url\"$cssClass>".$item->getText()."</a></li>\n");
99
		}
100
		$writer->write("</ul>");
101
	}
102
}
103
 
104
class XListMenuItem extends TListItem
105
{
106
	public function getPagePath()
107
	{
108
		return $this->getValue();
109
	}
110
 
111
	public function setPagePath($value)
112
	{
113
		$this->setValue($value);
114
	}
115
 
116
	public function getNavigateUrl()
117
	{
118
		return $this->hasAttribute('NavigateUrl')?$this->getAttribute('NavigateUrl'):'';
119
	}
120
 
121
	public function setNavigateUrl($value)
122
	{
123
		$this->setAttribute('NavigateUrl',$value);
124
	}
125
}
126
 
127
?>