1: <?php
2: /**
3: * Document for class GeoList
4: *
5: * PHP Version 5.6
6: *
7: * @category Class
8: * @package Geolib
9: * @author Peter Pitchford <peter@geotonics.com>
10: * @license GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
11: * @link http://geotonics.com/#geolib
12: */
13:
14: /**
15: * Geo - Class to create html list (ul or ol) tags
16: *
17: * @category Html_Tag
18: * @package Geolib
19: * @author Peter Pitchford <peter@geotonics.com>
20: * @license GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
21: * @version Release: .1
22: * @link http://geotonics.com/#geolib
23: * @since Class available since Release .1
24: */
25:
26:
27: class GeoList extends GeoTag
28: {
29: private $items;
30: private $cols;
31: private $addLinks;
32: /**
33: * Construcor
34: *
35: * @param array||string $items List item(s)
36: To have ids for each list item, either:
37: Easiest way: make item keys non integer, such as "item_3"
38: Otherwise:feed id array to ->tag()
39: * @param string $class Class Attribute
40: * @param string $id Id Attribute
41: * @param integer $cols Number of columns. Break $items into this many equal (or nearly equal) parts.
42: Each part becomes an HTML list.
43: * @param string $style Style attribute
44: * @param string $listType Type of list (ol or ul)
45: */
46: public function __construct($items = null, $class = null, $id = null, $cols = 1, $style = null, $listType = 'ul')
47: {
48: if (!$listType) {
49: $listType = 'ul';
50: }
51:
52: $this->cols = $cols;
53: $this->init($listType, null, $class, $id, $style);
54: $this->items = Geo::arr($items);
55: }
56:
57: /**
58: * Sets flag to indicate that each item in the list will be a link with the key as text
59: *
60: * @return void
61: */
62: public function addLinks()
63: {
64: $this->addLinks = true;
65: }
66:
67: /**
68: * Create HTML list tag
69: *
70: * @param string|array $classes Class attribute(s)
71: * @param string|array $ids Id attribute(s)
72: * @param string|array $styles Style attribute(s)
73: *
74: * @return void
75: */
76: public function tag($classes = null, $ids = null, $styles = null)
77: {
78: if ($this->cols) {
79: $itemarrs = Geo::arraySplit($this->items, $this->cols);
80: } else {
81: $itemarrs[] = $this->items;
82: }
83:
84: if ($itemarrs) {
85: foreach ($itemarrs as $key => $items) {
86: $this->text[$key] = '';
87:
88: foreach ($items as $key2 => $item) {
89: if (!is_object($item)) {
90: if ($this->addLinks) {
91: $item = geoLink($item, $key2);
92: }
93:
94: if (is_int($key2)) {
95: $id = Geo::ifArr($ids, $key2);
96: } else {
97: $id = $key2;
98: }
99:
100: $item = new GeoTag("li", $item, Geo::ifArr($classes, $key2), $id, Geo::ifArr($styles, $key2));
101: }
102: $this->text[$key] .= $item->baseTag();
103: }
104:
105: }
106:
107: }
108: return parent::baseTag();
109: }
110: }
111: