diff --git a/includes/autocomplete.inc b/includes/autocomplete.inc index a4526d7..020d328 100644 --- a/includes/autocomplete.inc +++ b/includes/autocomplete.inc @@ -86,6 +86,35 @@ function project_issue_autocomplete_project_user($uid, $string = '') { drupal_json_output($matches); } +/** + * Return valid issue-enabled project names based projects a user maintains. + * + * Only returns matches for project titles for projects the user owns. + */ +function project_issue_autocomplete_project_maintainer($uid, $string = '') { + $matches = array(); + + // The user enters a comma-separated list of projects. We only autocomplete + // the last one. + $array = drupal_explode_tags($string); + $last_string = trim(array_pop($array)); + + if ($last_string != '') { + $prefix = count($array) ? implode(', ', $array) .', ' : ''; + $projects = project_issue_get_projects('maintainer', $uid); + + foreach ($projects as $title) { + // Commas and quotes in terms are special cases, so encode 'em. + if (strpos($title, ',') !== FALSE || strpos($title, '"') !== FALSE) { + $title = '"'. str_replace('"', '""', $project->title) .'"'; + } + $matches[$prefix . $title] = check_plain($title); + } + } + + drupal_json_output($matches); +} + /** * Handles the auto-complete callback for the nodereference widget. * diff --git a/project_issue.module b/project_issue.module index bc36373..5173ece 100644 --- a/project_issue.module +++ b/project_issue.module @@ -139,6 +139,17 @@ function project_issue_menu() { 'type' => MENU_CALLBACK, ); + // Autocomplete a comma-separated list of projects a user maintain issues for. + $items['project/autocomplete/issue/maintainer/%'] = array( + 'page callback' => 'project_issue_autocomplete_project_maintainer', + 'page arguments' => array(4, 5), + 'access callback' => 'project_issue_menu_access', + 'access arguments' => array('any'), + 'file' => 'autocomplete.inc', + 'file path' => $includes, + 'type' => MENU_CALLBACK, + ); + // Autocomplete an issue nid from a user entered node ID or issue title. $items['project/autocomplete/issues/nodereference'] = array( 'page callback' => 'project_issue_autocomplete_issues_nodereference', @@ -1694,10 +1705,11 @@ function theme_project_issue_query_result_links($variables) { * Helper function to return an array of projects that meet a given constraint. * * @param $constraint - * Restrict the list of projects. Valid options are 'all' (all projects with - * issue tracking enabled), 'owner' (all projects owned by a given user). + * Restrict the list of projects. Valid options are 'all' (all projects with + * issue tracking enabled), 'owner' (all projects owned by a given user), + * and 'maintainer' (all projects that a user maintains). * @param $uid - * User ID to use for $constraint == 'owner'. + * User ID to use for $constraint == 'owner' or 'maintainer'. * * @return * Array of project titles, keyed by node ID (nid) that match the given @@ -1724,6 +1736,17 @@ function project_issue_get_projects($constraint = 'all', $uid = NULL) { // The given uid must own each project. $query->propertyCondition('uid', $uid); break; + + case 'maintainer': + $subquery = db_select('node', 'n'); + $subquery->innerJoin('project_issue_project_maintainer', 'pipm', 'n.nid = pipm.nid'); + $subquery + ->addTag('node_access') + ->condition('n.status', 1) + ->condition('pipm.uid', $uid) + ->fields('n', array('nid')); + $query->entityCondition('entity_id', $subquery->execute()->fetchCol()); + break; } $result = $query diff --git a/views/handlers/project_issue_handler_filter_issue_project.inc b/views/handlers/project_issue_handler_filter_issue_project.inc index 3d951f0..7057467 100644 --- a/views/handlers/project_issue_handler_filter_issue_project.inc +++ b/views/handlers/project_issue_handler_filter_issue_project.inc @@ -63,6 +63,7 @@ class project_issue_handler_filter_issue_project extends views_handler_filter_in $source_options['all'] = t('All issue-enabled projects'); if (count($arguments) > 1) { $source_options['owner'] = t('Projects owned by a given user'); + $source_options['maintainer'] = t('Projects maintained by a given user'); } else { $description = t('If you add a user argument to this view, you will also be able to restrict the choices here to projects owned by a given user, or projects from issues that a user has participated in.'); @@ -136,6 +137,10 @@ class project_issue_handler_filter_issue_project extends views_handler_filter_in case 'owner': $autocomplete_path = "project/autocomplete/issue/owner/$uid"; break; + + case 'maintainer': + $autocomplete_path = "project/autocomplete/issue/maintainer/$uid"; + break; } $form['value'] = array( @@ -311,6 +316,9 @@ class project_issue_handler_filter_issue_project extends views_handler_filter_in case 'owner': return t('Projects a user owns'); + + case 'maintainer': + return t('Projects a user maintains'); } }