From 2c6dfbb9e44071e66b432e40a27223917283ddea Mon Sep 17 00:00:00 2001
From: Mark Schulte <schultetwin@gmail.com>
Date: Sun, 16 Oct 2011 21:06:51 -0400
Subject: [PATCH] Adding feature to user terms module. I hope this won't cause
 any conflicts on the next drupal commons upgrade.

---
 .../contrib/user_terms/user_terms.views.inc        |   16 ++++
 ..._terms_plugin_argument_default_taxonomy_tid.inc |   76 ++++++++++++++++++++
 2 files changed, 92 insertions(+), 0 deletions(-)
 create mode 100644 profiles/drupal_commons/modules/contrib/user_terms/user_terms_plugin_argument_default_taxonomy_tid.inc

diff --git a/profiles/drupal_commons/modules/contrib/user_terms/user_terms.views.inc b/profiles/drupal_commons/modules/contrib/user_terms/user_terms.views.inc
index 7b2b17b..1d1d437 100644
--- a/profiles/drupal_commons/modules/contrib/user_terms/user_terms.views.inc
+++ b/profiles/drupal_commons/modules/contrib/user_terms/user_terms.views.inc
@@ -82,3 +82,19 @@ function user_terms_views_handlers() {
     ),
   );
 }
+
+/**
+ * Implementation of hook_views_plugins
+ */
+function user_terms_views_plugins() {
+  return array(
+    'argument default' => array(
+      'user_terms_tid' => array(
+        'title' => t('Taxonomy Term ID Users Terms'),
+        'handler' => 'user_terms_plugin_argument_default_taxonomy_tid',
+        'path' => drupal_get_path('module', 'user_terms'),
+        'parent' => 'fixed',
+      ),
+    ),
+  );
+}
\ No newline at end of file
diff --git a/profiles/drupal_commons/modules/contrib/user_terms/user_terms_plugin_argument_default_taxonomy_tid.inc b/profiles/drupal_commons/modules/contrib/user_terms/user_terms_plugin_argument_default_taxonomy_tid.inc
new file mode 100644
index 0000000..4f05aaf
--- /dev/null
+++ b/profiles/drupal_commons/modules/contrib/user_terms/user_terms_plugin_argument_default_taxonomy_tid.inc
@@ -0,0 +1,76 @@
+<?php
+// $Id: views_plugin_argument_default_taxonomy_tid.inc,v 1.1.6.2 2010/03/22 22:34:18 merlinofchaos Exp $
+/**
+ * @file
+ *   Taxonomy tid default argument.
+ */
+
+class user_terms_plugin_argument_default_taxonomy_tid extends views_plugin_argument_default {
+  function option_definition() {
+    $options = parent::option_definition();
+
+    $options['limit'] = array('default' => FALSE);
+    $options['vids'] = array('default' => NULL);
+
+    return $options;
+  }
+
+  function options_form(&$form, &$form_state) {
+    $form['limit'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Limit terms by vocabulary'),
+      '#default_value'=> $this->options['limit'],
+      '#process' => array('expand_checkboxes', 'views_process_dependency'),
+      '#dependency' => array(
+        'edit-options-argument-default-taxonomy-tid-node' => array(1),
+      ),
+    );
+
+    $options = array();
+    $vocabularies = taxonomy_get_vocabularies();
+    foreach ($vocabularies as $voc) {
+      $options[$voc->vid] = check_plain($voc->name);
+    }
+
+    $form['vids'] = array(
+      '#prefix' => '<div><div id="edit-options-vids">',
+      '#suffix' => '</div></div>',
+      '#type' => 'checkboxes',
+      '#title' => t('Vocabularies'),
+      '#options' => $options,
+      '#default_value' => $this->options['vids'],
+      '#process' => array('expand_checkboxes', 'views_process_dependency'),
+      '#dependency' => array(
+        //'edit-options-argument-default-taxonomy-tid-limit' => array(1),
+        'edit-options-argument-default-taxonomy-tid-node' => array(1),
+      ),
+    );
+  }
+
+  function options_submit(&$form, &$form_state, &$options) {
+    // Clear checkbox values.
+    $options['vids'] = array_filter($options['vids']);
+  }
+
+  function get_argument() {
+    global $user;
+    $user = user_load($user->uid);
+    if (!empty($user->user_terms)) {
+      if (!empty($this->options['limit'])) {
+        $tids = array();
+        // filter by vid
+        foreach ($user->user_terms as $tid => $term) {
+          if (!empty($this->options['vids'][$term->vid])) {
+            $tids[] = $tid;
+          }
+        }
+        return implode("+", $tids);
+      }
+      // Return all tids.
+      else {
+        return implode("+", array_keys($user->user_terms));
+      }
+    }
+  }
+}
+
-- 
1.7.7

