Passed
Pull Request — master (#1574)
by
unknown
04:47 queued 01:14
created

Hook::assignment()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 6
rs 10
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: User
5
 * Date: 2/13/2019
6
 * Time: 5:43 PM
7
 */
8
9
namespace crocodicstudio\crudbooster\types\datetime;
10
11
use crocodicstudio\crudbooster\types\TypesHook;
12
13
class Hook extends TypesHook
14
{
15
16
    /**
17
     * @param $row
18
     * @param $column DatetimeModel
19
     * @return mixed
20
     */
21
    public function indexRender($row, $column)
22
    {
23
        if($column->getFormat()) {
24
		$datetime = date_create_from_format($column->getFormat(), $value);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $value seems to be never defined.
Loading history...
25
		return $datetime ? $datetime->format('Y-m-d H:i:s') : $value;
26
        }else{
27
            return $row->{$column->getField()};
28
        }
29
    }
30
31
    public function assignment($value, $column)
32
    {
33
		if($column->getFormat()) {
34
			return date_create_from_format($column->getFormat(), $value)->format('Y-m-d H:i:s');
35
		} else {
36
			return $value;
37
		}
38
    }
39
    
40
    public function detailRender($row, $column)
41
    {
42
        return $this->indexRender($row, $column);
43
    }
44
45
    public function filterQuery($query, $column, $value)
46
    {
47
        $start = sanitizeXSS($value['start']);
48
        $end = sanitizeXSS($value['end']);
49
        if($start && $end) {
50
            $start = date("Y-m-d H:i:s", strtotime($start));
51
            $end = date("Y-m-d H:i:s", strtotime($end));
52
            $query->whereBetween($column->getFilterColumn(), [$start, $end]);
53
        }
54
        return $query;
55
    }
56
}
57