summaryrefslogtreecommitdiff
path: root/demos/site/protected/Common/SimpleMenu.php
blob: bcbc94cfc0e4bfc3dc587b8db7b3217c8a571bac (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
<?php

class SimpleMenu extends TControl
{
	public function addParsedObject($object)
	{
		if ($object instanceof SimpleMenuItem)
			parent::addParsedObject($object);
	}

	public function render($writer)
	{
		$writer->renderBeginTag("ul");
		parent::renderChildren($writer);
		$writer->renderEndTag();
	}

}

class SimpleMenuItem extends TControl
{

	public function getPath()
	{
		return $this->getControlState("Path", null);
	}

	public function setPath($value)
	{
		$this->setControlState("Path", TPropertyValue::ensureString($value));
	}

	public function getUrl()
	{
		return $this->getControlState("Url", null);
	}

	public function setUrl($value)
	{
		$this->setControlState("Url", TPropertyValue::ensureString($value));
	}
	
	public function getTarget()
	{
		return $this->getControlState("Target", null);
	}

	public function setTarget($value)
	{
		$this->setControlState("Target", TPropertyValue::ensureString($value));
	}
	
	public function getText()
	{
		return $this->getControlState("Text", $this->getID());
	}

	public function setText($value) {
		$this->setControlState("Text", TPropertyValue::ensureString($value));
	}

	public function render($writer)
	{
		$writer->renderBeginTag("li");

		if(null !== $path = $this->getPath())
		{
			$writer->addAttribute('href', $this->Service->constructUrl($path));

			if($path == $this->Page->getPagePath())
				$writer->addAttribute('class', 'active');
		} elseif(null !== $url = $this->getUrl()) {
			$writer->addAttribute('href', $url);
		}

		if($this->getTarget() !== null)
			$writer->addAttribute('target', $this->getTarget());

		$writer->renderBeginTag("a");

		$writer->write(THttpUtility::htmlEncode($this->getText()));

		$writer->renderEndTag();
		$writer->renderEndTag();
	}
}