Passed
Push — develop ( 319bd8...330c7a )
by Neill
16:41 queued 15s
created

DateTimeRange::getComponentDetails()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
rs 10
1
<?php
2
/**
3
 * @link http://www.newicon.net/neon
4
 * @copyright Copyright (c) 21/09/2016 Newicon Ltd
5
 * @license http://www.newicon.net/neon/license/
6
 */
7
8
namespace neon\core\form\fields\el;
9
10
use neon\core\grid\query\IQuery;
11
use neon\core\form\fields\Field;
12
use neon\core\form\fields\el\assets\ElAsset;
13
use neon\core\helpers\Html;
14
use neon\core\helpers\Arr;
15
16
class DateTimeRange extends Field
17
{
18
	/**
19
	 * The DDS data type to store the value of the field
20
	 * @var string
21
	 */
22
	public $ddsDataType = 'json';
23
24
	/**
25
	 * @inheritdoc
26
	 */
27
	public function getFieldHtml()
28
	{
29
		return Html::tag('neon-core-form-fields-el-datetimerange', '', [
30
			'id' => $this->id,
31
			'name' => $this->getInputName(),
32
		]);
33
	}
34
35
	/**
36
	 * Get the picker format
37
	 * @return string
38
	 */
39
	public function getFormat()
40
	{
41
		return neon()->formatter->datetimeFormat;
42
	}
43
44
	/**
45
	 * @inheritdoc
46
	 */
47
	public function getProperties()
48
	{
49
		return array_merge(parent::getProperties(), ['format']);
50
	}
51
52
	/**
53
	 * @inheritDoc
54
	 */
55
	public function setValueFromDb($value)
56
	{
57
		$this->_value = json_decode($value);
58
	}
59
60
	/**
61
	 * @inheritdoc
62
	 */
63
	public function processAsFilter(IQuery $query, $searchData=null)
64
	{
65
		$searchData = ($searchData === null) ? $this->getValue() : $searchData;
66
		if ($searchData !== '') {
67
			$dateFrom = Arr::get($searchData, 'from');
68
			$dateTo   = Arr::get($searchData, 'to');
69
			if ($dateFrom)
70
				$query->where($this->getDataKey(), '>=', $dateFrom);
71
			if ($dateTo)
72
				$query->where($this->getDataKey(), '<=', $dateTo);
73
		}
74
	}
75
76
	/**
77
	 * @inheritdoc
78
	 */
79
	public function registerScripts($view)
80
	{
81
		ElAsset::register($view);
82
	}
83
84
	/**
85
	 * @inheritdoc
86
	 */
87
	public function getValue()
88
	{
89
		$value = parent::getValue();
90
		if (is_array($value))
91
			return $value;
92
		return ['from' => '', 'to' => ''];
93
	}
94
95
	/**
96
	 * @inheritdoc
97
	 */
98
	public function getComponentDetails()
99
	{
100
		return [
101
			'label' => 'El Range', 'group' => 'Date & Time', 'icon' => 'fa fa-calendar-o', 'order' => 370,
102
		];
103
	}
104
}