1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace ICanBoogie\Modules\Thumbnailer;
13
14 use Brickrouge\Element;
15
16 class PopThumbnailVersion extends \Brickrouge\Widget
17 {
18 static protected function add_assets(\Brickrouge\Document $document)
19 {
20 parent::add_assets($document);
21
22 $document->js->add(DIR . 'public/module.js');
23 }
24
25 public function __construct(array $attributes=array())
26 {
27 parent::__construct
28 (
29 'a', $attributes + array
30 (
31 'class' => 'spinner'
32 )
33 );
34 }
35
36 public function offsetSet($offset, $value)
37 {
38 if (($offset == 'value' || $offset == self::DEFAULT_VALUE) && is_array($value))
39 {
40 $value = json_encode($value);
41 }
42
43 parent::offsetSet($offset, $value);
44 }
45
46 protected function render_class(array $class_names)
47 {
48 if (!$this['value'])
49 {
50 $class_names['placeholder'] = true;
51 }
52
53 return parent::render_class($class_names);
54 }
55
56 protected function render_inner_html()
57 {
58 $html = parent::render_inner_html();
59
60 $value = $this['value'] ?: $this[self::DEFAULT_VALUE];
61 $decoded_value = json_decode($value, true);
62
63 $input = new Element
64 (
65 'input', array
66 (
67 'name' => $this['name'],
68 'type' => 'hidden',
69 'value' => $value
70 )
71 );
72
73 $content = '';
74
75 if ($decoded_value)
76 {
77 $version = new Version($decoded_value);
78
79 $w = $version->width ?: '<em>auto</em>';
80 $h = $version->height ?: '<em>auto</em>';
81 $method = $version->method;
82 $format = '.' . ($version->format ?: '<em>auto</em>');
83
84 $content = "{$w}×{$h} {$method} $format";
85 }
86
87 $placeholder = 'Version non définie';
88
89 return <<<EOT
90 $input <span class="spinner-content">$content</span> <em class="spinner-placeholder">$placeholder</em> $html
91 EOT;
92 }
93 }
94
95 namespace Brickrouge\Widget;
96
97 class PopThumbnailVersion extends \ICanBoogie\Modules\Thumbnailer\PopThumbnailVersion
98 {
99
100 }