Passed
Push — 2.4.0 ( ...442824 )
by steve
20:14
created

ImageCompare::getValueDisplay()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 14
rs 9.9332
c 1
b 0
f 0
cc 4
nc 4
nop 1
ccs 0
cts 14
cp 0
crap 20
1
<?php
2
/**
3
 * @link http://www.newicon.net/neon
4
 * @copyright Copyright (c) 2017 Newicon Ltd
5
 * @license http://www.newicon.net/neon/license/
6
 * @author Steve O'Brien <[email protected]> 17/04/2020
7
 * @package neon
8
 */
9
10
namespace neon\cms\form\fields;
11
12
use \neon\core\form\fields\Field;
13
use neon\core\form\fields\ImageMultiple;
14
15
class ImageCompare extends ImageMultiple
16
{
17
    /**
18
	 * @inheritdoc
19
	 */
20
    public $ddsDataType = 'json';
21
22
    /**
23
	 * @inheritdoc
24
	 */
25
	public function registerScripts($view)
26
	{
27
        $view->registerAssetBundle(\neon\cms\assets\CmsFormAsset::class);
28
		$view->registerAssetBundle(\neon\firefly\assets\BrowserAsset::class);
29
		$view->registerJsFile('https://cdn.knightlab.com/libs/juxtapose/latest/js/juxtapose.min.js');
30
        $view->registerCssFile('https://cdn.knightlab.com/libs/juxtapose/latest/css/juxtapose.css');
31
    }
32
    
33
    /**
34
	 * @inheritdoc
35
	 */
36
	public function getFilterField()
37
	{
38
		return ['class' => 'neon\\core\\form\\fields\\Text'];
39
	}
40
    
41
    /**
42
	 * @inheritdoc
43
	 */
44
	public function getComponentDetails()
45
	{
46
		return [
47
			'icon' => 'fa fa-image', 'group' => 'Media', 'order' => 80, 'label' => 'Image Compare'
48
		];
49
    }
50
    
51
    public function getValueDisplay($context='')
52
	{
53
		$json = $this->getValue();
54
		if (empty($json))
55
			return neon()->formatter->asJson($this->getValue());
56
		if ($context==='grid') {
57
			$out = '';
58
			foreach($json as $image) {
59
				$url = neon()->firefly->getImage($image);
60
				$out .= "<img src='$url' />";
61
			}
62
			return $out;
63
		}
64
		return neon()->formatter->asJson($this->getValue());
65
	}
66
67
}