/
Column.php
114 lines (92 loc) · 2.59 KB
/
Column.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
namespace Concrete\Core\Search\Column;
use Concrete\Core\Search\Result\Result;
class Column implements ColumnInterface
{
/** These properties are to be treated as protected. Use the set and get methods instead */
/** @deprecated */
public $columnKey;
/** @deprecated */
public $columnName;
/** @deprecated */
public $sortDirection = 'asc';
/** @deprecated */
public $isSortable;
/** @deprecated */
public $callback;
public function getColumnValue($obj)
{
if (is_array($this->getColumnCallback())) {
return call_user_func($this->getColumnCallback(), $obj);
}
return call_user_func([$obj, $this->getColumnCallback()]);
}
public function getColumnKey()
{
return $this->columnKey;
}
public function getColumnName()
{
return $this->columnName;
}
/**
* @deprecated
*/
public function getColumnDefaultSortDirection()
{
return $this->sortDirection;
}
public function isColumnSortable()
{
return $this->isSortable;
}
public function getColumnCallback()
{
return $this->callback;
}
/**
* @deprecated
*/
public function setColumnDefaultSortDirection($dir)
{
$this->setColumnSortDirection($dir);
}
public function getSortClassName(Result $result)
{
$il = $result->getItemListObject();
return $il->getSortClassName($this->getColumnKey());
}
public function getColumnSortDirection()
{
return $this->sanitizeSortDirection($this->sortDirection);
}
public function setColumnSortDirection($sortDirection)
{
return $this->sortDirection = $this->sanitizeSortDirection($sortDirection);
}
/**
* Normalize a sort direction to "asc" or "desc".
*
* @param $direction
*
* @return string
*/
private function sanitizeSortDirection($direction)
{
return strtolower(trim($direction)) === 'asc' ? 'asc' : 'desc';
}
public function getSortURL(Result $result)
{
$il = $result->getItemListObject();
$dir = $this->getColumnSortDirection();
return $il->getSortURL($this->getColumnKey(), $dir, $result->getBaseURL());
}
public function __construct($key = null, $name = null, $callback = null, $isSortable = true, $sort = 'asc')
{
$this->columnKey = $key;
$this->columnName = $name;
$this->isSortable = $isSortable;
$this->callback = $callback;
$this->sortDirection = $this->sanitizeSortDirection($sort);
}
}