Commit 2e3c785c authored by merlinofchaos's avatar merlinofchaos

#241391: (by John Morahan) Allow "distinct" setting on the display.

parent ad2ba848
......@@ -229,6 +229,7 @@ class views_plugin_display extends views_object {
'use_pager' => array('items_per_page', 'offset', 'use_pager', 'pager_element'),
'use_more' => array('use_more'),
'link_display' => array('link_display'),
'distinct' => array('distinct'),
// @todo
'php_arg_code' => array('php_arg_code'),
......@@ -283,6 +284,7 @@ class views_plugin_display extends views_object {
'use_pager' => TRUE,
'pager_element' => TRUE,
'use_more' => TRUE,
'distinct' => TRUE,
'link_display' => TRUE,
'php_arg_code' => TRUE,
......@@ -514,6 +516,13 @@ class views_plugin_display extends views_object {
);
}
$options['distinct'] = array(
'category' => 'basic',
'title' => t('Distinct'),
'value' => $this->get_option('distinct') ? t('Yes') : t('No'),
'desc' => t('Display only distinct items, without duplicates.'),
);
$access = $this->get_option('access');
if (!is_array($access)) {
$access = array('type' => 'none');
......@@ -687,6 +696,15 @@ class views_plugin_display extends views_object {
'#default_value' => $this->get_option('use_more'),
);
break;
case 'distinct':
$form['#title'] .= t('Display only distinct items, without duplicates.');
$form['distinct'] = array(
'#type' => 'checkbox',
'#title' => t('Distinct'),
'#description' => t('This will make the view display only distinct items. If there are multiple identical items, each will be displayed only once. You can use this to try and remove duplicates from a view, though it does not always work. Note that this can slow queries down, so use it with caution.'),
'#default_value' => $this->get_option('distinct'),
);
break;
case 'access':
$form['#title'] .= t('Access restrictions');
$form['access'] = array(
......@@ -888,6 +906,7 @@ class views_plugin_display extends views_object {
$this->set_option('offset', intval($form_state['values']['offset']));
break;
case 'use_more':
case 'distinct':
$this->set_option($section, $form_state['values'][$section]);
break;
case 'row_plugin':
......@@ -1003,6 +1022,16 @@ class views_plugin_display extends views_object {
}
}
/**
* Inject anything into the query that the display handler needs.
*/
function query() {
// Make the query distinct if the option was set.
if ($this->get_option('distinct')) {
$this->view->query->set_distinct();
}
}
/**
* Not all display plugins will support filtering
*/
......
......@@ -468,8 +468,10 @@ class view extends views_db_object {
}
}
// Allow style handler to affect the query:
// Allow display handler to affect the query:
$this->display_handler->query();
// Allow style handler to affect the query:
$this->style_handler->query();
if (variable_get('views_sql_signature', FALSE)) {
......
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