1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: namespace Kotchasan;
12:
13: 14: 15: 16: 17: 18: 19:
20: class Tab
21: {
22: 23: 24:
25: private $datas;
26: 27: 28:
29: private $id;
30: 31: 32:
33: private $select;
34: 35: 36:
37: private $urls;
38:
39: 40: 41: 42: 43: 44: 45:
46: public function __construct($id, $url, $items = array())
47: {
48: $this->id = $id;
49: $this->urls = explode('?', $url);
50: if (count($this->urls) == 1) {
51: $this->urls[1] = '';
52: } else {
53: $this->urls[1] = str_replace(array('&', '&amp;'), '&', $this->urls[1]);
54: }
55: $this->datas = empty($items) ? array() : $items;
56: }
57:
58: 59: 60: 61: 62: 63: 64: 65:
66: public function add($id, $title, $url = '', $target = null)
67: {
68: $this->datas[] = array(
69: 'title' => $title,
70: 'url' => $url,
71: 'id' => $id,
72: 'target' => $target,
73: );
74: }
75:
76: 77: 78: 79: 80:
81: public function getSelect()
82: {
83: return $this->select;
84: }
85:
86: 87: 88: 89: 90: 91: 92:
93: public function render($select = '')
94: {
95: $html = '<div class="inline"><div class="writetab"><ul id="'.$this->id.'">';
96: foreach ($this->datas as $i => $item) {
97: $prop = array();
98: if (empty($item['url'])) {
99: if (isset($item['id'])) {
100: if ($this->urls[1] == '') {
101: $prop[] = 'href="'.$this->urls[0].'?tab='.$item['id'].'"';
102: } else {
103: $prop[] = 'href="'.$this->urls[0].'?'.$this->urls[1].'&tab='.$item['id'].'"';
104: }
105: $prop[] = 'id="tab_'.$item['id'].'"';
106: }
107: } else {
108: $prop[] = 'href="'.$item['url'].'"';
109: }
110: if (!empty($item['target'])) {
111: $prop[] = 'target="'.$item['target'].'"';
112: }
113: if ($select == $item['id'] || ($i == 0 && $select == '')) {
114: $prop[] = 'class="select"';
115: $this->select = $item['id'];
116: }
117: $html .= '<li><a '.implode(' ', $prop).'>'.$item['title'].'</a></li>';
118: }
119:
120: return $html.'</ul></div></div>';
121: }
122: }
123: