Commit 588d7fd5 authored by merlinofchaos's avatar merlinofchaos

#125973: (mfrederickson) Backport of internal views filter changes to 4.7 version.

parent 22765a73
......@@ -9,6 +9,7 @@ Views 4.7.x-dev
o #138510: Multi-select for taxonomy had disappeared.
o #117365: Comment: Last Changed Time wasn't ensuring node_comment_statistics is in the query.
o #136794: Sort by nid via click-sorting was also broken
o #125973: Backported of internal views filter changes to 4.7 version.
Views 4.7.x-1.6-beta3
o Reverting #130196: The original behavior was correct.
......
......@@ -273,7 +273,7 @@ function _views_sort_arrays($a, $b) {
return ($a['weight'] > $b['weight']) ? -1 : 1;
}
function _views_get_query(&$view, $args) {
function _views_get_query(&$view, $args, $filters) {
if ($view->is_cacheable && ($cached = cache_get('views_query:' . $view->name))) {
$info = unserialize($cached->data);
......@@ -284,7 +284,7 @@ function _views_get_query(&$view, $args) {
}
else {
views_load_query();
$info = _views_build_query($view, $args);
$info = _views_build_query($view, $args, $filters);
if ($view->is_cacheable) {
$data = array(
'query' => _views_replace_args($info['query'], $info['args']),
......@@ -730,13 +730,25 @@ function views_view_block($vid) {
* $use_pager is false, and $limit is !0, $page tells it what page to start
* on, in case for some reason a particular section of view is needed,
* without paging on.
* @param $filters
* An array of exposed filter ops and values to use with the exposed filter system
* Array has the form:
* [0] => array('op' => 'foo', 'value' => 'bar'),
* [1] => array('value' => 'zoo'), // for a locked operator, e.g.
* If no array is passed in, views will look in the $_GET array for potential filters
*/
function views_build_view($type, &$view, $args = array(), $use_pager = false, $limit = 0, $page = 0, $offset = 0) {
function views_build_view($type, &$view, $args = array(), $use_pager = false, $limit = 0, $page = 0, $offset = 0, $filters = NULL) {
// Fix a number of annoying whines when NULL is passed in..
if ($args == NULL) {
$args = array();
}
// if no filter values are passed in, get them from the $_GET array
if ($filters == NULL) {
$filters = _views_get_filter_values();
}
$GLOBALS['current_view'] = &$view;
$view->build_type = $type;
......@@ -762,7 +774,7 @@ function views_build_view($type, &$view, $args = array(), $use_pager = false, $l
$output .= $function($view);
}
$info = _views_get_query($view, $args);
$info = _views_get_query($view, $args, $filters);
if ($info['fail']) {
return FALSE;
......@@ -1532,8 +1544,8 @@ function views_filters_form($view) {
}
if ($expose['single']) {
unset($item['#multiple']);
// On multi-select categories the #size element is in the form by default. We remove it to allow the single-select drop-down filter to work.
unset($item['#multiple']);
// On multi-select categories the #size element is in the form by default. We remove it to allow the single-select drop-down filter to work.
unset($item['#size']);
}
if ($expose['optional'] && is_array($item['#options'])) {
......@@ -2242,3 +2254,19 @@ function views_taxonomy($op, $type, $object = NULL) {
views_invalidate_cache();
}
}
/**
* This function fetches filter values from the $_GET object
*/
function _views_get_filter_values() {
$values = array();
foreach($_GET as $key => $value) {
if(strpos($key, 'op') === 0) { // starts with op
$values[substr($key, 2)]['op'] = $value; // two letters in op
} elseif (strpos($key, 'filter') === 0) { // starts with op
$values[substr($key, 6)]['filter'] = $value; // six letters in filter
}
}
return $values;
}
......@@ -4,11 +4,10 @@
/*
* This builds a query for the view.
*/
function _views_build_query(&$view, $args = array()) {
function _views_build_query(&$view, $args = array(), $filters = array()) {
$query = new _views_query('node', 'nid', !empty($view->use_alias_prefix) ? $view->use_alias_prefix : '');
// Process static filters
_views_view_build_filters($query, $view);
// Process static filters and exposed filters
_views_view_build_filters($query, $view, $filters);
// Process arguments.
$view->args = $args; // we'll need these later.
......@@ -74,7 +73,7 @@ function _views_build_query(&$view, $args = array()) {
/*
* Take all the filters in a view and add them to the query object.
*/
function _views_view_build_filters(&$query, &$view) {
function _views_view_build_filters(&$query, &$view, $exposed_filter_values) {
$filters = _views_get_filters();
$view->used_filters = array();
......@@ -88,39 +87,39 @@ function _views_view_build_filters(&$query, &$view) {
foreach($view->exposed_filter as $count => $expose) {
if ($filter['id'] == $expose['id']) {
$id = $expose['id'];
if ($_GET["$filter$count"] === '') {
unset($_GET["filter$count"]);
if ($exposed_filter_values[$count]['filter'] === '') {
$exposed_filter_values[$count]['filter'];
}
if (isset($view->exposed_filter_offset)) {
$count += $view->exposed_filter_offset;
}
if (!$expose['operator'] && $_GET["op$count"]) {
$filter['operator'] = check_plain($_GET["op$count"]);
$view->used_filters["op$count"] = $_GET["op$count"];
if (!$expose['operator'] && $exposed_filter_values[$count]['op']) {
$filter['operator'] = check_plain($exposed_filter_values[$count]['op']);
$view->used_filters["op$count"] = $exposed_filter_values[$count]['op'];
}
if ($expose['optional']) {
// Test to see if the filter is not given
if ((!isset($_GET["filter$count"]) || $_GET["filter$count"] == '') && !$expose['is_default']) {
if ((!isset($exposed_filter_values[$count]['filter']) || $exposed_filter_values[$count]['filter'] == '') && !$expose['is_default']) {
continue 2; // skip
}
if ($_GET["filter$count"] == '**ALL**' ||
(is_array($_GET["filter$count"]) && in_array('**ALL**', $_GET["filter$count"]))) {
$view->used_filters["filter$count"] = $_GET["filter$count"];
if ($exposed_filter_values[$count]['filter'] == '**ALL**' ||
(is_array($exposed_filter_values[$count]['filter']) && in_array('**ALL**', $exposed_filter_values[$count]['filter']))) {
$view->used_filters["filter$count"] = $exposed_filter_values[$count]['filter'];
continue 2; // skip this filter entirely.
}
}
// note that if we get here and the filter wasn't set, it's because we
// are supposed to leave the default.
if (isset($_GET["filter$count"]) && $_GET["filter$count"] != '') {
$value = $_GET["filter$count"];
if (isset($exposed_filter_values[$count]['filter']) && $exposed_filter_values[$count]['filter'] != '') {
$value = $exposed_filter_values[$count]['filter'];
if ($filterinfo['value-type'] == 'array' && !is_array($value)) {
$value = array($value);
}
$filter['value'] = $value;
$view->used_filters["filter$count"] = $_GET["filter$count"];
$view->used_filters["filter$count"] = $exposed_filter_values[$count]['filter'];
}
break;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment