Index: project_issue.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/project_issue/project_issue.module,v
retrieving revision 1.65
diff -u -r1.65 project_issue.module
--- project_issue.module	22 Oct 2007 18:59:06 -0000	1.65
+++ project_issue.module	24 Oct 2007 21:29:55 -0000
@@ -357,7 +357,11 @@
       }
     }
 
-    drupal_add_css(drupal_get_path('module', 'project_issue') .'/project_issue.css');
+    $project_issue_path = drupal_get_path('module', 'project_issue');
+    if (module_exists('views')) {
+      require './'. $project_issue_path .'/project_issue_views.inc';
+    }
+    drupal_add_css($project_issue_path .'/project_issue.css');
   }
   return $items;
 }
Index: project_issue/project_issue_views.inc
===================================================================
RCS file: project_issue/project_issue_views.inc
diff -N project_issue/project_issue_views.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ project_issue/project_issue_views.inc	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,401 @@
+<?php
+
+/**
+ * @file
+ * Provides support for Views integration.
+ *
+ * Currently, this only exposes project_issue-related data, but does
+ * not define any default views.
+ */
+
+/**
+ * Implementation of hook_views_tables
+ */
+function project_issue_views_tables() {
+  $tables['project_issues'] = array(
+    'name' => 'project_issues',
+    'join' => array(
+      'type' => 'inner',
+      'left' => array(
+        'table' => 'node',
+        'field' => 'nid'
+      ),
+      'right' => array(
+        'field' => 'nid'
+      ),
+    ),
+    'fields' => array(
+      // To be useful, 'pid' requires another JOIN on {node}, so see
+      // the project_issue_project_node definition below.
+      'category' => array(
+        'name' => t('Project Issue: Category'),
+        'sortable' => true,
+        'help' => t('The issue\'s category (bug, task, feature, etc).'),
+      ),
+      'component' => array(
+        'name' => t('Project Issue: Component'),
+        'sortable' => true,
+        'help' => t('The issue\'s component (the options are controlled per-project).'),
+      ),
+      'priority' => array(
+        'name' => t('Project Issue: Priority'),
+        'handler' => 'views_handler_field_project_issue_priority',
+        'sortable' => true,
+        'help' => t('The issue\'s priority (critical, normal, minor).'),
+      ),
+/*
+      'rid' => array(
+        'name' => t('Project Issue: Version'),
+        'query_handler' => 'views_query_handler_field_project_issue_version',
+        'handler' => 'views_handler_field_project_issue_version',
+        'addlfields' => array('version'),
+        'sortable' => true,
+        'help' => t('The version associated with the issue (depends on project_release.module)');
+      ),
+*/
+      'sid' => array(
+        'name' => t('Project Issue: Status'),
+        'help' => t('The status of each issue.'),
+        'sortable' => true,
+        'handler' => 'views_handler_field_project_issue_status',
+      ),
+    ),
+    'filters' => array(
+      'category' => array(
+        'name' => t('Project Issue: Category'),
+        'operator' => array('=' => t('Equals')),
+        'list' => 'views_handler_filter_project_issue_category',
+        'list-type' => 'select',
+        'help' => t('Filter by issue category'),
+      ),
+      'priority' => array(
+        'name' => t('Project Issue: Priority'),
+        'operator' => array('=' => t('Equals')),
+        'list' => 'views_handler_filter_project_issue_priority',
+        'list-type' => 'select',
+        'help' => t('Filter by issue priority'),
+      ),
+      'sid' => array(
+        'name' => t('Project Issue: Status'),
+        'operator' => array('=' => t('Equals')),
+        'list' => 'views_handler_filter_project_issue_status',
+        'list-type' => 'select',
+        'help' => t('Filter by issue status'),
+      ),
+    ),
+  );
+
+  // Add data from the project module
+  $tables['project_issue_project_node'] = array(
+    'name' => 'node',
+    'join' => array(
+      'type' => 'inner',
+      'left' => array(
+        'table' => 'project_issues',
+        'field' => 'pid'
+      ),
+      'right' => array(
+        'field' => 'nid'
+      ),
+    ),
+    'fields' => array(
+      'title' => array(
+        'name' => t('Project Issue Project Node: Title'),
+        /*
+        'handler' => array(
+          'views_handler_field_nodelink'           => t('Normal'),
+          'views_handler_field_nodelink_with_mark' => t('With updated mark')
+        ),
+*/
+        'sortable' => true,
+      ),
+    ),
+    'filters' => array(
+      'nid' => array(
+        'name' => t('Project Issue Project Node: Project'),
+        'operator' => array('=' => t('Equals')),
+        'list' => 'views_handler_filter_project_issue_project',
+        'list-type' => 'select',
+        'help' => t('Filter by project'),
+      ),
+    ),
+  );
+  
+  // Add data from the users module
+  $tables['users'] = array(
+    'name' => 'users',
+    'join' => array(
+      'type' => 'inner',
+      'left' => array(
+        'table' => 'project_issues',
+        'field' => 'assigned'
+      ),
+      'right' => array(
+        'field' => 'uid'
+      ),
+    ),
+    'fields' => array(
+ 	  // TODO: handlers
+      'name' => array(
+        'name' => t('Project Issue: Assigned'),
+        'help' => t('The user a given issue is assigned to.'),
+        'sortable' => true,
+        'addlfields' => array('uid', 'name'),
+        'handler' => 'views_handler_field_project_issue_assigned',
+      ),
+    ),
+  );
+
+  return $tables;
+}
+
+/**
+ * Displays a field indicating the status of an issue.
+ */
+function views_handler_field_project_issue_status($fieldinfo, $fielddata, $value, $data) {
+  return project_issue_state($value);
+}
+
+/**
+ * Displays a field indicating the priority of an issue.
+ */
+function views_handler_field_project_issue_priority($fieldinfo, $fielddata, $value, $data) {
+  return project_issue_priority($value);
+}
+
+/**
+ * Modifies the query for views that include a field for the issue's
+ * version, and JOIN's against {node} and {project_release_nodes} to
+ * find the version string of a given release id (rid).
+ *
+ * @todo Need to figure out how to make this really work.
+ */
+function views_query_handler_field_project_issue_version($fielddata, $fieldinfo, &$query) {
+/*
+  $joininfo = array(
+    'type' => 'LEFT',
+    'left' => array(
+      'table' => 'project_issues',
+      'field' => 'rid'
+    ),
+    'right' => array(
+      'field' => 'nid'
+    ),
+  );
+  $num = $query->add_table('node', false, 1, $joininfo);
+  $query->add_field('version', $query->get_table_name('node', $num), $field['tablename'] . '_name');
+*/
+}
+
+/**
+ * Format the assigned field as a username. 
+ * Loosely based on views_handler_field_username, but doesn't return
+ * "Anonymous" when there is no one assigned.
+ */
+function views_handler_field_project_issue_assigned($fieldinfo, $fielddata, $value, $data) {
+  $name = '';
+  $obj = new stdClass();
+  $uidfield = $fielddata['tablename'] . "_"  . $fieldinfo['uid'];
+  if (is_numeric($data->users_uid) && $data->users_uid != 0) {
+    // Loading each user seems expensive here, considering we already ahve the data
+    // but we loose theme_username functionality
+    //$obj = user_load(array('uid' => $data->$uidfield));
+    //$name = theme('username', $obj);
+    $name = l($data->users_name, 'user/'.$data->users_uid);
+  }
+  else {
+    $name = '';
+  }
+  return $name;
+}
+
+function views_handler_field_project_issue_version($fieldinfo, $fielddata, $value, $data) {
+  /// @todo
+}
+
+/**
+ * Filter the list of projects by category
+ */
+function views_handler_filter_project_issue_category() {
+  return project_issue_category();
+}
+
+/**
+ * Filter the list of projects by priority
+ * HELP: Is project_issue_priority()supposed to be in the form of
+ * array(1 => 'critical', 'normal', 'minor');
+ */
+function views_handler_filter_project_issue_priority() {
+  //$priorities = project_issue_priority();
+  $priorities = array(1 => 'critical', 2 => 'normal', 3 => 'minor');
+  return $priorities;
+}
+
+
+/**
+ * Filter the list of status options to filter by status
+ */
+function views_handler_filter_project_issue_status() {
+  return project_issue_state();
+}
+
+/**
+ * Filter the list of projects to filter by project
+ */
+function views_handler_filter_project_issue_project() {
+  $project_urls = array();
+  $projects = project_projects_select_options($project_urls);
+  return $projects;
+}
+
+
+/**
+ * Implementations of hook_views_default_views
+ */
+function project_issue_views_default_views() {
+
+  $view = new stdClass();
+  $view->name = 'project_issues2';
+  $view->description = '';
+  $view->access = array (
+  );
+  $view->view_args_php = '';
+  $view->page = TRUE;
+  $view->page_title = 'Issues';
+  $view->page_header = '';
+  $view->page_header_format = '1';
+  $view->page_footer = '';
+  $view->page_footer_format = '1';
+  $view->page_empty = 'There are currently no issues to display for the criteria selected.';
+  $view->page_empty_format = '1';
+  $view->page_type = 'table';
+  $view->url = 'project_issues';
+  $view->use_pager = TRUE;
+  $view->nodes_per_page = '50';
+  $view->menu = TRUE;
+  $view->menu_title = 'Project Issues';
+  $view->menu_tab = FALSE;
+  $view->menu_tab_default = FALSE;
+  $view->menu_tab_weight = '0';
+  $view->sort = array (
+  );
+  $view->argument = array (
+  );
+  $view->field = array (
+    array (
+      'tablename' => 'project_issue_project_node',
+      'field' => 'title',
+      'label' => 'Project',
+      'sortable' => '1',
+    ),
+    array (
+      'tablename' => 'project_issue_project_node',
+      'field' => 'title',
+      'label' => 'Summary',
+      'sortable' => '1',
+    ),
+    array (
+      'tablename' => 'project_issues',
+      'field' => 'sid',
+      'label' => 'Status',
+      'sortable' => '1',
+    ),
+    array (
+      'tablename' => 'project_issues',
+      'field' => 'priority',
+      'label' => 'Priority',
+      'sortable' => '1',
+    ),
+    array (
+      'tablename' => 'project_issues',
+      'field' => 'category',
+      'label' => 'Category',
+      'sortable' => '1',
+    ),
+    array (
+      'tablename' => 'node',
+      'field' => 'changed',
+      'label' => 'Last updated',
+      'handler' => 'views_handler_field_since',
+      'sortable' => '1',
+      'defaultsort' => 'ASC',
+    ),
+    array (
+      'tablename' => 'users',
+      'field' => 'name',
+      'label' => 'Assigned to',
+      'sortable' => '1',
+    ),
+  );
+  $view->filter = array (
+    array (
+      'tablename' => 'project_issue_project_node',
+      'field' => 'nid',
+      'operator' => '=',
+      'options' => '',
+      'value' => '1166',
+    ),
+    array (
+      'tablename' => 'project_issues',
+      'field' => 'sid',
+      'operator' => '=',
+      'options' => '',
+      'value' => '1',
+    ),
+    array (
+      'tablename' => 'project_issues',
+      'field' => 'category',
+      'operator' => '=',
+      'options' => '',
+      'value' => 'bug',
+    ),
+    array (
+      'tablename' => 'project_issues',
+      'field' => 'priority',
+      'operator' => '=',
+      'options' => '',
+      'value' => '1',
+    ),
+  );
+  $view->exposed_filter = array (
+    array (
+      'tablename' => 'project_issue_project_node',
+      'field' => 'nid',
+      'label' => 'Project',
+      'optional' => '1',
+      'is_default' => '0',
+      'operator' => '1',
+      'single' => '1',
+    ),
+    array (
+      'tablename' => 'project_issues',
+      'field' => 'sid',
+      'label' => 'Status',
+      'optional' => '1',
+      'is_default' => '0',
+      'operator' => '1',
+      'single' => '1',
+    ),
+    array (
+      'tablename' => 'project_issues',
+      'field' => 'category',
+      'label' => 'Category',
+      'optional' => '1',
+      'is_default' => '0',
+      'operator' => '1',
+      'single' => '1',
+    ),
+    array (
+      'tablename' => 'project_issues',
+      'field' => 'priority',
+      'label' => 'Priority',
+      'optional' => '1',
+      'is_default' => '0',
+      'operator' => '1',
+      'single' => '1',
+    ),
+  );
+  $view->requires = array(project_issue_project_node, project_issues, node, users);
+  $views[$view->name] = $view;
+  return $views;
+}
