From 5c9336a057f2e02aa29203e42b2ce1b667c7e07e Mon Sep 17 00:00:00 2001
From: Marco Villegas <marvil07@gmail.com>
Date: Tue, 7 Dec 2010 19:35:51 -0500
Subject: [PATCH] task #970244: Create a views handler to map operation author/committer to their drupal user

- Add "person" handler for operation author/committer.
- Now author/committer link is autogenerated by the handler, so remove
  link creation on the global text field at the commitlog_global_commits
  view.
---
 commitlog/includes/commitlog.views_default.inc     |    2 +-
 ...rsioncontrol_handler_field_operation_author.inc |   35 --------------------
 ...rsioncontrol_handler_field_operation_person.inc |   21 ++++++++++++
 includes/views/versioncontrol.views.inc            |   14 ++++++--
 4 files changed, 33 insertions(+), 39 deletions(-)
 delete mode 100644 includes/views/handlers/versioncontrol_handler_field_operation_author.inc
 create mode 100644 includes/views/handlers/versioncontrol_handler_field_operation_person.inc

diff --git commitlog/includes/commitlog.views_default.inc commitlog/includes/commitlog.views_default.inc
index cba8900..7bfbc5a 100644
--- commitlog/includes/commitlog.views_default.inc
+++ commitlog/includes/commitlog.views_default.inc
@@ -775,7 +775,7 @@ function commitlog_views_default_views() {
     'nothing' => array(
       'label' => '',
       'alter' => array(
-        'text' => '<div class="commit-global">Commit <strong>[revision]</strong> by <a class="author-link"  href="#"> [author]</a> [date]</div>',
+        'text' => '<div class="commit-global">Commit <strong>[revision]</strong> by [author] [date]</div>',
         'make_link' => 0,
         'path' => '#',
         'link_class' => 'global-author',
diff --git includes/views/handlers/versioncontrol_handler_field_operation_author.inc includes/views/handlers/versioncontrol_handler_field_operation_author.inc
deleted file mode 100644
index 564966c..0000000
--- includes/views/handlers/versioncontrol_handler_field_operation_author.inc
+++ /dev/null
@@ -1,35 +0,0 @@
-<?php
-// $Id: versioncontrol_handler_field_operation_author.inc,v 1.1 2010/12/03 16:31:06 tizzo Exp $
-
-/**
- * Views Field handler to map the author of a commit to their drupal user.
- */
-class versioncontrol_handler_field_operation_author extends views_handler_field {
-
-  /**
-   * Called to add the field to a query.
-   */
-  function query() {
-    $this->ensure_my_table();
-    $this->field_alias = $this->query->add_field($this->table_alias, $this->real_field);
-    // Force views to load the repo_id field when this field is added so that
-    // we can appropriately build our links.
-    $this->author_uid_alias = $this->query->add_field($this->table_alias, 'author_uid');
-    $this->add_additional_fields();
-  }
-
-  function render($values) {
-    $sanitized_author = $values->{$this->field_alias};
-    // Strip out a email addresses wrapped in brackets
-    $sanitized_author = preg_replace('/\<.*@.*\>/', '', $sanitized_author);
-    // Protect against having only the email address not wrapped in <>
-    $sanitized_author = preg_replace('/@.*\..*/', '', $sanitized_author);
-    if ($values->{$this->author_uid_alias} != 0) {
-      $output = l($sanitized_author, 'user/' . $author_uid);
-    }
-    else {
-      $output = $sanitized_author; 
-    }
-    return $output;
-  }
-}
diff --git includes/views/handlers/versioncontrol_handler_field_operation_person.inc includes/views/handlers/versioncontrol_handler_field_operation_person.inc
new file mode 100644
index 0000000..fb9b4f3
--- /dev/null
+++ includes/views/handlers/versioncontrol_handler_field_operation_person.inc
@@ -0,0 +1,21 @@
+<?php
+// $Id$
+
+/**
+ * Views Field handler to show an author or committer, mapped to a
+ * drupal user if possible.
+ */
+class versioncontrol_handler_field_operation_person extends views_handler_field {
+
+  function render($values) {
+    $account->uid = $values->{$this->aliases['person_uid']};
+    if ($account->uid == 0) {
+      return $values->{$this->field_alias};
+    }
+    else {
+      $account->name = $values->{$this->field_alias};
+      return theme('username', $account);
+    }
+  }
+
+}
diff --git includes/views/versioncontrol.views.inc includes/views/versioncontrol.views.inc
index c5f1004..f1f92c2 100755
--- includes/views/versioncontrol.views.inc
+++ includes/views/versioncontrol.views.inc
@@ -206,7 +206,11 @@ function versioncontrol_views_data() {
     'title'    => t('Author'),
     'help'     => t('The Operation Author'),
     'field'    => array(
-      'handler' => 'versioncontrol_handler_field_operation_author',
+      'handler' => 'versioncontrol_handler_field_operation_person',
+      'click sortable' => TRUE,
+      'additional fields' => array(
+        'person_uid' => array('table' => 'versioncontrol_operations', 'field' => 'author_uid'),
+      ),
     ),
     'sort' => array(
       'handler' => 'views_handler_sort',
@@ -234,7 +238,11 @@ function versioncontrol_views_data() {
     'title'    => t('Commiter'),
     'help'     => t('The Operation Commiter'),
     'field'    => array(
-      'handler' => 'views_handler_field',
+      'handler' => 'versioncontrol_handler_field_operation_person',
+      'click sortable' => TRUE,
+      'additional fields' => array(
+        'person_uid' => array('table' => 'versioncontrol_operations', 'field' => 'committer_uid'),
+      ),
     ),
     'sort' => array(
       'handler' => 'views_handler_sort',
@@ -553,7 +561,7 @@ function versioncontrol_views_handlers() {
       'versioncontrol_handler_field_operation_revision' => array(
         'parent' => 'views_handler_field',
       ),
-      'versioncontrol_handler_field_operation_author' => array(
+      'versioncontrol_handler_field_operation_person' => array(
         'parent' => 'views_handler_field',
       ),
       // filter handlers
-- 
1.7.2.3

