Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Tag / Cloud / Decorator / HtmlTag.php
blob2993560358983d780c2e1045781e1d6a3245959d
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Tag\Cloud\Decorator;
12 use Zend\Tag\Cloud\Decorator\Exception\InvalidArgumentException;
13 use Zend\Tag\ItemList;
15 /**
16 * Simple HTML decorator for tags
18 class HtmlTag extends AbstractTag
20 /**
21 * List of tags which get assigned to the inner element instead of
22 * font-sizes.
24 * @var array
26 protected $classList = null;
28 /**
29 * Unit for the fontsize
31 * @var string
33 protected $fontSizeUnit = 'px';
35 /**
36 * Allowed fontsize units
38 * @var array
40 protected $allowedFontSizeUnits = array('em', 'ex', 'px', 'in', 'cm', 'mm', 'pt', 'pc', '%');
42 /**
43 * List of HTML tags
45 * @var array
47 protected $htmlTags = array(
48 'li'
51 /**
52 * Maximum fontsize
54 * @var int
56 protected $maxFontSize = 20;
58 /**
59 * Minimum fontsize
61 * @var int
63 protected $minFontSize = 10;
65 /**
66 * Set a list of classes to use instead of fontsizes
68 * @param array $classList
69 * @throws InvalidArgumentException When the classlist is empty
70 * @throws InvalidArgumentException When the classlist contains an invalid classname
71 * @return HTMLTag
73 public function setClassList(array $classList = null)
75 if (is_array($classList)) {
76 if (count($classList) === 0) {
77 throw new InvalidArgumentException('Classlist is empty');
80 foreach ($classList as $class) {
81 if (!is_string($class)) {
82 throw new InvalidArgumentException('Classlist contains an invalid classname');
87 $this->classList = $classList;
88 return $this;
91 /**
92 * Get class list
94 * @return array
96 public function getClassList()
98 return $this->classList;
102 * Set the font size unit
104 * Possible values are: em, ex, px, in, cm, mm, pt, pc and %
106 * @param string $fontSizeUnit
107 * @throws InvalidArgumentException When an invalid fontsize unit is specified
108 * @return HTMLTag
110 public function setFontSizeUnit($fontSizeUnit)
112 if (!in_array($fontSizeUnit, $this->allowedFontSizeUnits)) {
113 throw new InvalidArgumentException('Invalid fontsize unit specified');
116 $this->fontSizeUnit = (string) $fontSizeUnit;
117 $this->setClassList(null);
118 return $this;
122 * Retrieve font size unit
124 * @return string
126 public function getFontSizeUnit()
128 return $this->fontSizeUnit;
131 * Set the HTML tags surrounding the <a> element
133 * @param array $htmlTags
134 * @return HTMLTag
136 public function setHTMLTags(array $htmlTags)
138 $this->htmlTags = $htmlTags;
139 return $this;
143 * Get HTML tags map
145 * @return array
147 public function getHTMLTags()
149 return $this->htmlTags;
153 * Set maximum font size
155 * @param int $maxFontSize
156 * @throws InvalidArgumentException When fontsize is not numeric
157 * @return HTMLTag
159 public function setMaxFontSize($maxFontSize)
161 if (!is_numeric($maxFontSize)) {
162 throw new InvalidArgumentException('Fontsize must be numeric');
165 $this->maxFontSize = (int) $maxFontSize;
166 $this->setClassList(null);
167 return $this;
171 * Retrieve maximum font size
173 * @return int
175 public function getMaxFontSize()
177 return $this->maxFontSize;
181 * Set minimum font size
183 * @param int $minFontSize
184 * @throws InvalidArgumentException When fontsize is not numeric
185 * @return HTMLTag
187 public function setMinFontSize($minFontSize)
189 if (!is_numeric($minFontSize)) {
190 throw new InvalidArgumentException('Fontsize must be numeric');
193 $this->minFontSize = (int) $minFontSize;
194 $this->setClassList(null);
195 return $this;
199 * Retrieve minimum font size
201 * @return int
203 public function getMinFontSize()
205 return $this->minFontSize;
209 * Defined by Tag
211 * @param ItemList $tags
212 * @throws InvalidArgumentException
213 * @return array
215 public function render($tags)
217 if (!$tags instanceof ItemList) {
218 throw new InvalidArgumentException(sprintf(
219 'HtmlTag::render() expects a Zend\Tag\ItemList argument; received "%s"',
220 (is_object($tags) ? get_class($tags) : gettype($tags))
223 if (null === ($weightValues = $this->getClassList())) {
224 $weightValues = range($this->getMinFontSize(), $this->getMaxFontSize());
227 $tags->spreadWeightValues($weightValues);
229 $result = array();
231 $escaper = $this->getEscaper();
232 foreach ($tags as $tag) {
233 if (null === ($classList = $this->getClassList())) {
234 $attribute = sprintf('style="font-size: %d%s;"', $tag->getParam('weightValue'), $this->getFontSizeUnit());
235 } else {
236 $attribute = sprintf('class="%s"', $escaper->escapeHtmlAttr($tag->getParam('weightValue')));
239 $tagHTML = sprintf('<a href="%s" %s>%s</a>', $escaper->escapeHtml($tag->getParam('url')), $attribute, $escaper->escapeHtml($tag->getTitle()));
240 $tagHTML = $this->wrapTag($tagHTML);
241 $result[] = $tagHTML;
244 return $result;