1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the jquery-datatables-bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) 2018 WEBEWEB |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace WBW\Bundle\JQuery\DataTablesBundle\Helper; |
13
|
|
|
|
14
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\API\DataTablesColumnInterface; |
15
|
|
|
use WBW\Bundle\JQuery\DataTablesBundle\API\DataTablesMappingInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* DataTables mapping helper. |
19
|
|
|
* |
20
|
|
|
* @author webeweb <https://github.com/webeweb/> |
21
|
|
|
* @package WBW\Bundle\JQuery\DataTablesBundle\Helper |
22
|
|
|
*/ |
23
|
|
|
class DataTablesMappingHelper { |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Get an alias. |
27
|
|
|
* |
28
|
|
|
* @param DataTablesMappingInterface $mapping The mapping. |
29
|
|
|
* @return string Returns the alias. |
30
|
|
|
*/ |
31
|
|
|
public static function getAlias(DataTablesMappingInterface $mapping) { |
32
|
|
|
if (null === $mapping->getColumn()) { |
33
|
|
|
return null; |
34
|
|
|
} |
35
|
|
|
if (null === $mapping->getPrefix()) { |
36
|
|
|
return $mapping->getColumn(); |
37
|
|
|
} |
38
|
|
|
return implode(".", [$mapping->getPrefix(), $mapping->getColumn()]); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Get a comparator. |
43
|
|
|
* |
44
|
|
|
* @param DataTablesMappingInterface $mapping The mapping. |
45
|
|
|
* @return string Returns the comparator. |
46
|
|
|
*/ |
47
|
|
|
public static function getComparator(DataTablesMappingInterface $mapping) { |
48
|
|
|
|
49
|
|
|
if (null === $mapping->getParent()) { |
50
|
|
|
return "LIKE"; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
switch ($mapping->getParent()->getType()) { |
54
|
|
|
|
55
|
|
|
case DataTablesColumnInterface::DATATABLES_TYPE_DATE: |
56
|
|
|
case DataTablesColumnInterface::DATATABLES_TYPE_HTML_NUM: |
57
|
|
|
case DataTablesColumnInterface::DATATABLES_TYPE_NUM: |
58
|
|
|
case DataTablesColumnInterface::DATATABLES_TYPE_NUM_FMT: |
59
|
|
|
return "="; |
60
|
|
|
|
61
|
|
|
case DataTablesColumnInterface::DATATABLES_TYPE_HTML: |
62
|
|
|
case DataTablesColumnInterface::DATATABLES_TYPE_STRING: |
63
|
|
|
default: |
64
|
|
|
return "LIKE"; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Get a param. |
70
|
|
|
* |
71
|
|
|
* @param DataTablesMappingInterface $mapping The mapping. |
72
|
|
|
* @return string Returns the param. |
73
|
|
|
*/ |
74
|
|
|
public static function getParam(DataTablesMappingInterface $mapping) { |
75
|
|
|
|
76
|
|
|
$param = [ |
77
|
|
|
":", |
78
|
|
|
$mapping->getPrefix(), |
79
|
|
|
$mapping->getColumn(), |
80
|
|
|
]; |
81
|
|
|
|
82
|
|
|
return implode("", $param); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Get a where. |
87
|
|
|
* |
88
|
|
|
* @param DataTablesMappingInterface $mapping The mapping. |
89
|
|
|
* @return string Returns the where. |
90
|
|
|
*/ |
91
|
|
|
public static function getWhere(DataTablesMappingInterface $mapping) { |
92
|
|
|
|
93
|
|
|
$where = [ |
94
|
|
|
static::getAlias($mapping), |
95
|
|
|
static::getComparator($mapping), |
96
|
|
|
static::getParam($mapping), |
97
|
|
|
]; |
98
|
|
|
|
99
|
|
|
return implode(" ", $where); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|