/
Set.php
122 lines (106 loc) · 2.95 KB
/
Set.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
115
116
117
118
119
120
121
122
<?php
namespace Concrete\Core\Search\Column;
class Set
{
protected $columns = array();
protected $defaultSortColumn;
public function addColumn($col)
{
$this->columns[] = $col;
}
public function removeColumnByKey($key)
{
foreach($this->columns as $i => $column) {
if ($key == $column->getColumnKey()) {
unset($this->columns[$i]);
}
}
}
public function __sleep()
{
return array('columns', 'defaultSortColumn');
}
public function __wakeup()
{
$i = 0;
foreach ($this->columns as $col) {
if (!$col) {
unset($this->columns[$i]); // Somehow a null column was saved in the result set.
}
if ($col instanceof AttributeKeyColumn) {
$ak = $this->getAttributeKeyColumn(substr($col->getColumnKey(), 3));
if (!is_object($ak)) {
unset($this->columns[$i]);
}
}
++$i;
}
}
public function getSortableColumns()
{
$tmp = array();
$columns = $this->getColumns();
foreach ($columns as $col) {
if ($col->isColumnSortable()) {
$tmp[] = $col;
}
}
return $tmp;
}
public function setDefaultSortColumn(Column $col, $direction = false)
{
if ($direction != false) {
$col->setColumnDefaultSortDirection($direction);
}
$this->defaultSortColumn = $col;
}
public function getDefaultSortColumn()
{
return $this->defaultSortColumn;
}
/**
* @param string $akHandle
*
* @return AttributeKeyColumn|null
*/
public function getAttributeKeyColumn($akHandle)
{
$result = null;
$ak = call_user_func(array($this->attributeClass, 'getByHandle'), $akHandle);
if ($ak !== null) {
$result = new AttributeKeyColumn($ak);
}
return $result;
}
public function getColumnByKey($key)
{
if (substr($key, 0, 3) == 'ak_') {
return $this->getAttributeKeyColumn(substr($key, 3));
} else {
foreach ($this->columns as $col) {
if ($col->getColumnKey() == $key) {
return $col;
}
}
}
}
public function getColumns()
{
return $this->columns;
}
public function contains($col)
{
foreach ($this->columns as $_col) {
if ($col instanceof ColumnInterface) {
if ($_col->getColumnKey() == $col->getColumnKey()) {
return true;
}
} elseif (is_a($col, '\Concrete\Core\Attribute\AttributeKeyInterface')) {
if ($_col->getColumnKey() == 'ak_' . $col->getAttributeKeyHandle()) {
return true;
}
}
}
return false;
}
}