Passed
Push — 2.3.0 ( ...813ccf )
by steve
17:15
created

ImageMultiple::setValue()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 3
nc 4
nop 1
ccs 0
cts 6
cp 0
crap 12
1
<?php
2
3
4
namespace neon\core\form\fields;
5
6
7
use neon\core\helpers\Html;
8
9
class ImageMultiple extends Field
10
{
11
	/**
12
	 * @inheritdoc
13
	 */
14
	public $ddsDataType = 'json';
15
16
	/**
17
	 * @inheritdoc
18
	 */
19
	public function getFilterField()
20
	{
21
		return ['class' => 'neon\\core\\form\\fields\\Text'];
22
	}
23
24
	public function setValue($value)
25
	{
26
		if (is_array($value))
27
			$this->_value = $value;
28
		if (is_string($value))
29
			$this->_value = json_decode($value);
30
	}
31
32
	public function getData()
33
	{
34
		if (is_string($this->_value)) {
35
			return json_decode($this->_value);
36
		}
37
		return $this->_value;
38
	}
39
40
	/**
41
	 * @inheritdoc
42
	 */
43
	public function getComponentDetails()
44
	{
45
		return [
46
			'icon' => 'fa fa-image', 'group' => 'Media', 'order' => 80
47
		];
48
	}
49
50
	public function getValueDisplay($context='')
51
	{
52
		$json = $this->getValue();
53
		if (empty($json))
54
			return neon()->formatter->asJson($this->getValue());
55
		if ($context==='grid') {
56
			$out = '';
57
			foreach($json as $image) {
58
				$url = neon()->firefly->getImage($image);
59
				$out .= "<img src='$url' />";
60
			}
61
			return $out;
62
		}
63
		return neon()->formatter->asJson($this->getValue());
64
	}
65
}
66