-
Notifications
You must be signed in to change notification settings - Fork 451
/
AttributedItemList.php
66 lines (61 loc) · 2.15 KB
/
AttributedItemList.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
<?php
namespace Concrete\Core\Search\ItemList\Database;
use Concrete\Core\Search\StickyRequest;
use Database;
abstract class AttributedItemList extends ItemList
{
abstract protected function getAttributeKeyClassName();
/**
* Filters by a attribute.
*/
public function filterByAttribute($handle, $value, $comparison = '=')
{
$ak = call_user_func_array(array($this->getAttributeKeyClassName(), 'getByHandle'), array($handle));
if (!is_object($ak)) {
throw new \Exception(t('Unable to find attribute %s', $handle));
}
$ak->getController()->filterByAttribute($this, $value, $comparison);
}
/**
* Magic method for setting up additional filtering by attributes.
* @param $nm
* @param $a
* @throws \Exception
*/
public function __call($nm, $a)
{
if (substr($nm, 0, 8) == 'filterBy') {
$handle = uncamelcase(substr($nm, 8));
if (count($a) == 2) {
$this->filterByAttribute($handle, $a[0], $a[1]);
} else {
$this->filterByAttribute($handle, $a[0]);
}
} else {
if (substr($nm, 0, 6) == 'sortBy') {
$handle = uncamelcase(substr($nm, 6));
if (count($a) == 1) {
$this->sanitizedSortBy('ak_' . $handle, $a[0]);
} else {
$this->sanitizedSortBy('ak_' . $handle);
}
} else {
throw new \Exception(t('%s method does not exist for the %s class', $nm, get_called_class()));
}
}
}
/**
* @param StickyRequest $request
*/
public function setupAutomaticSorting(StickyRequest $request = null)
{
// First, we check to see if there are any sortable attributes we can add to the
// auto sort columns.
if (is_callable(array($this->getAttributeKeyClassName(), 'getList'))) {
$l = call_user_func(array($this->getAttributeKeyClassName(), 'getList'));
foreach($l as $ak) {
$this->autoSortColumns[] = 'ak_' . $ak->getAttributeKeyHandle();
}
}
}
}