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\DataTablesMapping; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* DataTables mapping helper. |
18
|
|
|
* |
19
|
|
|
* @author webeweb <https://github.com/webeweb/> |
20
|
|
|
* @package WBW\Bundle\JQuery\DataTablesBundle\Helper |
21
|
|
|
*/ |
22
|
|
|
class DataTablesMappingHelper { |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Get an alias. |
26
|
|
|
* |
27
|
|
|
* @param DataTablesMapping $mapping The mapping. |
28
|
|
|
* @return string Returns the alias. |
29
|
|
|
*/ |
30
|
|
|
public static function getAlias(DataTablesMapping $mapping) { |
31
|
|
|
if (null === $mapping->getColumn()) { |
32
|
|
|
return null; |
33
|
|
|
} |
34
|
|
|
if (null === $mapping->getPrefix()) { |
35
|
|
|
return $mapping->getColumn(); |
36
|
|
|
} |
37
|
|
|
return implode(".", [$mapping->getPrefix(), $mapping->getColumn()]); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Get a param. |
42
|
|
|
* |
43
|
|
|
* @param DataTablesMapping $mapping The mapping. |
44
|
|
|
* @return string Returns the param. |
45
|
|
|
*/ |
46
|
|
|
public static function getParam(DataTablesMapping $mapping) { |
47
|
|
|
|
48
|
|
|
// Initialize the param. |
49
|
|
|
$param = ":"; |
50
|
|
|
$param .= $mapping->getPrefix(); |
51
|
|
|
$param .= $mapping->getColumn(); |
52
|
|
|
|
53
|
|
|
// Return the param. |
54
|
|
|
return $param; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Get a mapping where. |
59
|
|
|
* |
60
|
|
|
* @param DataTablesMapping $mapping The mapping. |
61
|
|
|
* @return string Returns the where. |
62
|
|
|
*/ |
63
|
|
|
public static function getWhere(DataTablesMapping $mapping) { |
64
|
|
|
|
65
|
|
|
// Initialize the where. |
66
|
|
|
$where = self::getAlias($mapping); |
67
|
|
|
$where .= " LIKE "; |
68
|
|
|
$where .= self::getParam($mapping); |
69
|
|
|
|
70
|
|
|
// Return the where. |
71
|
|
|
return $where; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
} |
75
|
|
|
|