I was trying to create a dashboard for every user that lets sumarize the open issues for this user, to avoid to many levels for a user to find how many issues has.
Trying to get the filter and the argument "assigned" I have only found that there's a patch (thank's to Sean B Fuller [http://drupal.org/node/396670]) that acts as a boolean (assigned or not), and that lists the issues that are asssigned to the logged user.
I have hacked a little to get a filter that lets you choose the user which this issue is assigned, and also the argument to refer to list user's assigned issues via path.
I have copied and modified the argument and filter handler from user views submodule, I hope that you found it useful.
To activate this:
these are the differences in project_issue.views.inc :
me@nowhere.noplace [~/www/drupal/sites/all/modules/project_issue/views]# diff -u -r project_issue.views.inc /tmp/project_issue/views/project_issue.views.inc
--- project_issue.views.inc 2010-07-22 06:32:42.000000000 -0600
+++ /tmp/project_issue/views/project_issue.views.inc 2009-06-17 21:48:53.000000000 -0600
@@ -158,25 +158,6 @@
'label' => t('Assigned user'),
),
);
-//PATCH per llistar els issues assignats per lusuari.
- $data['project_issues']['assigned_user'] = array(
- 'real field' => 'assigned',
- 'title' => t('Assigned to this user'),
- 'help' => t('The issue is assigned to this user.'),
- 'argument' => array(
- 'handler' => 'project_issue_handler_argument_assigned_user',
- 'name field' => 'assigned user',// display this field in the summary
- ),
- 'filter' => array(
- 'handler' => 'project_issue_handler_filter_user_assigned',
- 'title' => t('Assigned User'),
- ),
- 'sort' => array(
- 'handler' => 'views_handler_sort',
- ),
- );
-//Fi PATCH
-
$data['project_issues']['sid'] = array(
'title' => t('Status'),
@@ -239,15 +220,6 @@
'project_issue_handler_filter_issue_version' => array(
'parent' => 'views_handler_filter_in_operator',
),
- //PATCH PER LLISTAR SEGONS ASSIGNATS A USUARI
- 'project_issue_handler_filter_user_assigned' => array(
- 'parent' => 'views_handler_filter_in_operator',
- ),
- 'project_issue_handler_argument_assigned_user' => array(
- 'parent' => 'views_handler_argument_numeric',
- ),
- //FI PATCH
-
),
);
}
And you have to include these two files in handlers directory:
me@nowhere.noplace [~/www/drupal/sites/all/modules/project_issue/views]# cat handlers/project_issue_handler_filter_user_assigned.inc
<?php
// $Id: views_handler_filter_user_name.inc,v 1.2 2008/09/22 23:41:14 merlinofchaos Exp $
/**
* Filter handler for usernames
*/
class project_issue_handler_filter_user_assigned extends views_handler_filter_in_operator {
var $no_single = TRUE;
function value_form(&$form, &$form_state) {
$values = array();
if ($this->value) {
$result = db_query("SELECT * FROM {users} u WHERE uid IN (" . implode(', ', $this->value) . ")");
while ($account = db_fetch_object($result)) {
if ($account->uid) {
$values[] = $account->name;
}
else {
$values[] = 'Anonymous'; // Intentionally NOT translated.
}
}
}
sort($values);
$default_value = implode(', ', $values);
$form['value'] = array(
'#type' => 'textfield',
'#title' => t('Usernames'),
'#description' => t('Enter a comma separated list of user names.'),
'#default_value' => $default_value,
'#autocomplete_path' => 'admin/views/ajax/autocomplete/user',
);
if (!empty($form_state['exposed']) && !isset($form_state['input'][$this->options['expose']['identifier']])) {
$form_state['input'][$this->options['expose']['identifier']] = $default_value;
}
}
function value_validate(&$form, &$form_state) {
$values = drupal_explode_tags($form_state['values']['options']['value']);
$uids = $this->validate_user_strings($form['value'], $values);
if ($uids) {
$form_state['values']['options']['value'] = $uids;
}
}
function accept_exposed_input($input) {
$rc = parent::accept_exposed_input($input);
if ($rc) {
// If we have previously validated input, override.
if (isset($this->validated_exposed_input)) {
$this->value = $this->validated_exposed_input;
}
}
return $rc;
}
function exposed_validate(&$form, &$form_state) {
if (empty($this->options['exposed'])) {
return;
}
if (empty($this->options['expose']['identifier'])) {
return;
}
$identifier = $this->options['expose']['identifier'];
$values = drupal_explode_tags($form_state['values'][$identifier]);
$uids = $this->validate_user_strings($form[$identifier], $values);
if ($uids) {
$this->validated_exposed_input = $uids;
}
}
/**
* Validate the user string. Since this can come from either the form
* or the exposed filter, this is abstracted out a bit so it can
* handle the multiple input sources.
*/
function validate_user_strings(&$form, $values) {
$uids = array();
$placeholders = array();
$args = array();
$results = array();
foreach ($values as $value) {
if (strtolower($value) == 'anonymous') {
$uids[] = 0;
}
else {
$missing[strtolower($value)] = TRUE;
$args[] = $value;
$placeholders[] = "'%s'";
}
}
if (!$args) {
return $uids;
}
$result = db_query("SELECT * FROM {users} WHERE name IN (" . implode(', ', $placeholders) . ")", $args);
while ($account = db_fetch_object($result)) {
unset($missing[strtolower($account->name)]);
$uids[] = $account->uid;
}
if ($missing) {
form_error($form, format_plural(count($missing), 'Unable to find user: @users', 'Unable to find users: @users', array('@users' => implode(', ', array_keys($missing)))));
}
return $uids;
}
function value_submit() {
// prevent array filter from removing our anonymous user.
}
// Override to do nothing.
function get_value_options() { }
function admin_summary() {
// set up $this->value_options for the parent summary
$this->value_options = array();
if ($this->value) {
$result = db_query("SELECT * FROM {users} u WHERE uid IN (" . implode(', ', $this->value) . ")");
while ($account = db_fetch_object($result)) {
if ($account->uid) {
$this->value_options[$account->uid] = $account->name;
}
else {
$this->value_options[$account->uid] = 'Anonymous'; // Intentionally NOT translated.
}
}
}
return parent::admin_summary();
}
}
me@nowhere.noplace [~/www/drupal/sites/all/modules/project_issue/views]# cat handlers/project_issue_handler_argument_assigned_user.inc
<?php
// $Id: views_handler_argument_user_uid.inc,v 1.1 2008/09/03 19:21:30 merlinofchaos Exp $
/**
* @file
* Provide user uid argument handler.
*/
/**
* Argument handler to accept a user id.
*/
class project_issue_handler_argument_assigned_user extends views_handler_argument_numeric {
/**
* Override the behavior of title(). Get the name of the user.
*/
function title_query() {
if (!$this->argument) {
return array(variable_get('anonymous', t('Anonymous')));
}
$titles = array();
$placeholders = implode(', ', array_fill(0, sizeof($this->value), '%d'));
$result = db_query("SELECT u.name FROM {users} u WHERE u.uid IN ($placeholders)", $this->value);
while ($term = db_fetch_object($result)) {
$titles[] = check_plain($term->name);
}
return $titles;
}
}
Once you do this it's important to sure that ALWAYS the first argument in issues per user view is "Node: User posted or commented" as it comes by default(it's bypassed including "all") in first path argument when you visit the page, for example ttp://communia.info/communia/project/issues/user/all/5, where all argument means all users, and second mean assigned to user 5.
If you remove this argument you will get an error refering to
$arg_uid = $view->argument[$argument_name]->get_value(); in project_issue.module, line 1690.
If you get this error comment this line and put:
$arg_uid = 18;
repair what I've said about arguments and uncomment line 1690 again and remove $arg_uid = 18;
I have no time to fix this annoying bug in the patch...
Hope you enjoy