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

ImageCompare   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 19
dl 0
loc 50
rs 10
c 1
b 0
f 0
ccs 0
cts 31
cp 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A registerScripts() 0 6 1
A getFilterField() 0 3 1
A getComponentDetails() 0 4 1
A getValueDisplay() 0 14 4
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
}