1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\Modules\Taxonomy\Vocabulary;
13
14 use Brickrouge\Element;
15
16 class CloudElement extends Element
17 {
18 const T_LEVELS = '#cloud-levels';
19
20 protected function render_inner_html()
21 {
22 $options = $this[self::OPTIONS];
23
24 if (!$options)
25 {
26 return;
27 }
28
29 $min = min($options);
30 $max = max($options);
31
32 $range = ($min == $max) ? 1 : $max - $min;
33 $levels = $this[self::T_LEVELS] ?: 8;
34
35 $markup = $this->type == 'ul' ? 'li' : 'span';
36
37 $rc = '';
38
39 foreach ($options as $name => $usage)
40 {
41 $popularity = ($usage - $min) / $range;
42 $level = 1 + ceil($popularity * ($levels - 1));
43
44 $rc .= '<' . $markup . ' class="tag' . $level . '">' . $name . '</' . $markup . '>' . PHP_EOL;
45 }
46
47 return $rc;
48 }
49 }