-
Notifications
You must be signed in to change notification settings - Fork 1
/
MetaModelsFilterSettingDlhCheckbox.php
95 lines (80 loc) · 2.25 KB
/
MetaModelsFilterSettingDlhCheckbox.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
<?php if (!defined('TL_ROOT')) die('You can not access this file directly!');
/**
* Frontend filter for Contao MetaModels
*
* @copyright 2013 de la Haye Kommunikationsdesign <http://www.delahaye.de>
* @author Christian de la Haye <service@delahaye.de>
* @package metamodels_dlh_frontendfilter
* @license LGPL
* @filesource
*/
/**
* Class MetaModelsFilterSettingDlhCheckbox
*
* Filter "checkbox" for FE-filtering, based on filters by the meta models team.
* @author Christian de la Haye <service@delahaye.de>
*/
class MetaModelsFilterSettingDlhCheckbox extends MetaModelFilterSetting
{
/**
* {@inheritdoc}
*/
protected function getParamName()
{
if ($this->get('urlparam'))
{
return $this->get('urlparam');
}
$objAttribute = $this->getMetaModel()->getAttributeById($this->get('attr_id'));
if ($objAttribute)
{
return $objAttribute->getColName();
}
}
/**
* {@inheritdoc}
*/
public function prepareRules(IMetaModelFilter $objFilter, $arrFilterUrl)
{
$objMetaModel = $this->getMetaModel();
$objAttribute = $objMetaModel->getAttributeById($this->get('attr_id'));
$strParamName = $this->getParamName();
$strParamValue = $arrFilterUrl[$strParamName];
if ($objAttribute && $strParamName && $strParamValue)
{
$objQuery = Database::getInstance()->prepare(sprintf(
'SELECT id FROM %s WHERE %s=? ',
$this->getMetaModel()->getTableName(),
$objAttribute->getColName()
))
->execute($strParamValue);
$arrIds = $objQuery->fetchEach('id');
$objFilter->addFilterRule(new MetaModelFilterRuleStaticIdList($arrIds));
return;
}
$objFilter->addFilterRule(new MetaModelFilterRuleStaticIdList(NULL));
}
/**
* {@inheritdoc}
*/
public function getParameters()
{
return ($strParamName = $this->getParamName()) ? array($strParamName) : array();
}
/**
* {@inheritdoc}
*/
public function getParameterDCA()
{
$objAttribute = $this->getMetaModel()->getAttributeById($this->get('attr_id'));
$strLabel = ($this->get('label') ? $this->get('label') : $objAttribute->getName());
return array(
$this->getParamName() => array
(
'label' => ($this->get('yesfield') ? array($strLabel,$GLOBALS['TL_LANG']['MSC']['yes']):array('',$strLabel)),
'inputType' => 'checkbox'
)
);
}
}
?>