1
|
<?php
|
2
|
/**
|
3
|
* Filter by node type
|
4
|
*/
|
5
|
class panelizer_handler_filter_panelizer_status extends views_handler_filter_in_operator {
|
6
|
function get_value_options() {
|
7
|
if (!isset($this->value_options)) {
|
8
|
$this->value_title = t('Panelizer defaults');
|
9
|
$entity_info = entity_get_info($this->definition['entity_type']);
|
10
|
|
11
|
// The normal get_panelizer_default_objects() requires a bundle type
|
12
|
// but in a filter all we know for sure is the entity type. This
|
13
|
// is going to make a bit of an awkward list, unfortunately.
|
14
|
$conditions = array(
|
15
|
'panelizer_type' => $this->definition['entity_type'],
|
16
|
);
|
17
|
|
18
|
ctools_include('export');
|
19
|
$options = array();
|
20
|
$defaults = ctools_export_load_object('panelizer_defaults', 'conditions', $conditions);
|
21
|
|
22
|
foreach ($defaults as $name => $default) {
|
23
|
if (empty($default->title)) {
|
24
|
$default->title = t('Default');
|
25
|
}
|
26
|
$options[$name] = t('@bundle: @title', array('@bundle' => $entity_info['bundles'][$default->panelizer_key]['label'], '@title' => $default->title));
|
27
|
}
|
28
|
natcasesort($options);
|
29
|
$options = array(
|
30
|
'not' => t('Not panelized'),
|
31
|
'custom' => t('Customized'),
|
32
|
) + $options;
|
33
|
|
34
|
$this->value_options = $options;
|
35
|
}
|
36
|
}
|
37
|
|
38
|
function op_simple() {
|
39
|
if (empty($this->value)) {
|
40
|
return;
|
41
|
}
|
42
|
$this->ensure_my_table();
|
43
|
|
44
|
$or = db_or();
|
45
|
$values = $this->value;
|
46
|
|
47
|
// @todo -- see if we need to use in_array() when a select is used.
|
48
|
if (in_array('not', $values)) {
|
49
|
if ($this->operator == 'in') {
|
50
|
$or->condition(
|
51
|
db_and()
|
52
|
->condition("$this->table_alias.$this->real_field", NULL)
|
53
|
->condition("$this->table_alias.did", 0)
|
54
|
);
|
55
|
}
|
56
|
else {
|
57
|
$or->condition(
|
58
|
db_or()
|
59
|
->isNotNull("$this->table_alias.$this->real_field")
|
60
|
->condition(db_and()
|
61
|
->isNull("$this->table_alias.$this->real_field")
|
62
|
->condition("$this->table_alias.did", 0, '!=')
|
63
|
)
|
64
|
);
|
65
|
}
|
66
|
unset($values['not']);
|
67
|
}
|
68
|
|
69
|
if (in_array('custom', $values)) {
|
70
|
if ($this->operator == 'in') {
|
71
|
$or->condition(
|
72
|
db_and()
|
73
|
->condition("$this->table_alias.$this->real_field", NULL)
|
74
|
->condition("$this->table_alias.did", 0, '!=')
|
75
|
);
|
76
|
}
|
77
|
else {
|
78
|
$or->condition(
|
79
|
db_or()
|
80
|
->isNotNull("$this->table_alias.$this->real_field")
|
81
|
->condition(db_and()
|
82
|
->isNull("$this->table_alias.$this->real_field")
|
83
|
->condition("$this->table_alias.did", 0, '=')
|
84
|
)
|
85
|
);
|
86
|
}
|
87
|
unset($values['custom']);
|
88
|
}
|
89
|
|
90
|
if ($values) {
|
91
|
$or->condition("$this->table_alias.$this->real_field", array_values($values), $this->operator);
|
92
|
}
|
93
|
|
94
|
// We use array_values() because the checkboxes keep keys and that can cause
|
95
|
// array addition problems.
|
96
|
$this->query->add_where($this->options['group'], $or);
|
97
|
}
|
98
|
|
99
|
}
|