private function views_handler_filter_dynamic_fields::pre_query_multiple in Views Dynamic Fields 7
Handle pre_query processing when checkboxes are enabled.
1 call to views_handler_filter_dynamic_fields::pre_query_multiple()
- views_handler_filter_dynamic_fields::pre_query in handlers/
views_handler_filter_dynamic_fields.inc - Exclude fields from the view before the query is run.
File
- handlers/
views_handler_filter_dynamic_fields.inc, line 567 - Views dynamic fields filter handler.
Class
- views_handler_filter_dynamic_fields
- Simple filter to pick and choose the fields to show in the view.
Code
private function pre_query_multiple($exposed_input, $field_names, $combined_fields) {
$exposed_input_fields = $exposed_input[$this->options['expose']['identifier']];
// Fields displayed in the filter.
$form_field_names = isset($exposed_input['field_names']) ? unserialize($exposed_input['field_names']) : $field_names;
$orig_field_exposed = $order_includes = $order_excludes = array();
foreach ($exposed_input_fields as $id => $info) {
$orig_field_exposed[$info['sort']] = $form_field_names[$id];
// Unset fields that haven't been selected.
if (!isset($info['check']) || $info['check'] != 1) {
unset($exposed_input_fields[$id]);
$order_includes[$info['sort']] = $form_field_names[$id];
}
else {
$order_excludes[$info['sort']] = $form_field_names[$id];
}
}
// Sorted order of fields for display.
ksort($orig_field_exposed);
ksort($order_includes);
ksort($order_excludes);
// If exclusion mode is selected.
if (isset($exposed_input['reverse']) && $exposed_input['reverse']) {
$fields_to_exclude = $order_excludes;
}
else {
$fields_to_exclude = $order_includes;
}
// If only one field is selected, this ensures no issues with array.
// @see http://drupal.org/node/1831858
if (!is_array($fields_to_exclude)) {
$fields_to_exclude = array(
$fields_to_exclude,
);
}
// Also include/exclude the fields combined into any
// of the $exposed_input fields.
foreach ($fields_to_exclude as $key => $efield) {
// Add the combined field to the exclusion array if parent
// is filterable and excluded.
if (isset($combined_fields[$efield]) && $this->options['filterable_fields'][$efield] !== 0) {
$fields_to_exclude[$combined_fields[$efield]] = $combined_fields[$efield];
}
// On the other hand, the combined field should be included
// in the view if the parent is.
if (in_array($efield, $combined_fields)) {
unset($fields_to_exclude[$key]);
}
}
// Mark the fields to be excluded to the view object.
foreach ($fields_to_exclude as $field_to_exclude) {
// Exclude only the fields chosen as excludable in filter options.
if ($this->options['filterable_fields'][$field_to_exclude] !== 0) {
$this->view->field[$field_to_exclude]->options['exclude'] = 1;
}
}
// Reorder the view's fields.
$view_fields = $this->view->field;
$view_fields_ordered = array();
foreach ($orig_field_exposed as $field_title) {
$view_fields_ordered[$field_title] = $view_fields[$field_title];
unset($view_fields[$field_title]);
}
// Check if any still remaning (hidden fields, already excluded fields).
if (!empty($view_fields)) {
foreach ($view_fields as $field_title => $field_info) {
$view_fields_ordered[$field_title] = $field_info;
}
}
$this->view->field = $view_fields_ordered;
}