summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--buddylist_views.inc105
1 files changed, 104 insertions, 1 deletions
diff --git a/buddylist_views.inc b/buddylist_views.inc
index d49022c..51715bf 100644
--- a/buddylist_views.inc
+++ b/buddylist_views.inc
@@ -1,6 +1,6 @@
<?php
-
// $Id$
+
/**
* This include file implements views functionality on behalf of the
* buddylist.module
@@ -286,3 +286,106 @@ function buddylist_views_default_views() {
return($views);
}
+
+
+/**
+ * Implementation of hook_views_arguments
+ */
+function buddylist_views_arguments() {
+ if (module_exists('usernode')) {
+ $arguments = array(
+ 'buddylist_buddies' => array(
+ 'name' => t('Buddylist: Usernode is buddy of UID'),
+ 'handler' => 'buddylist_views_handler_arg_buddies',
+ 'help' => t('This will filter usernodes from users, which are buddies of the user with the ID passed to the view as argument.'),
+ ),
+ 'buddylist_buddies_buddyof' => array(
+ 'name' => t('Buddylist: UID is buddy of Usernode'),
+ 'handler' => 'buddylist_views_handler_arg_buddies_buddyof',
+ 'help' => t('This will filter usernodes from users, of which the user with the ID passed to the view as argument is a buddy of.'),
+ ),
+ );
+ return $arguments;
+ }
+}
+
+/**
+ * Callback for buddylist_views_arguments
+ */
+function buddylist_views_handler_arg_buddies($op, &$query, $argtype, $arg = '') {
+ switch($op) {
+ case 'summary':
+ $table_data = _views_get_tables();
+ $joininfo = $table_data['usernode_buddylist_buddyof']['join'];
+ $joininfo['type'] = 'inner';
+ $query->add_table("usernode_buddylist_buddyof", true, 1, $joininfo);
+
+ $query->add_table('users', true);
+ $query->add_field('name', 'users');
+ $query->add_field('uid', 'users');
+ $fieldinfo['field'] = "users.name";
+ return $fieldinfo;
+ break;
+ case 'sort':
+ $query->add_orderby('users', 'name', $argtype);
+ break;
+ case 'filter':
+ $uid = intval($arg);
+ $table_data = _views_get_tables();
+ $joininfo = $table_data['usernode_buddylist']['join'];
+ $joininfo['type'] = 'inner';
+ $joininfo['extra'] = array('uid' => $uid);
+ $query->add_table("usernode_buddylist", true, 1, $joininfo);
+ break;
+ case 'link':
+ $name = ($query->name ? $query->name : variable_get('anonymous', 'Anonymous'));
+ return l($name, "$arg/" . intval($query->uid));
+ case 'title':
+ if (!$query) {
+ return variable_get('anonymous', 'Anonymous');
+ }
+ $user = db_fetch_object(db_query("SELECT name FROM {users} WHERE uid = '%d'", $query));
+ return check_plain($user->name);
+ }
+}
+
+
+/**
+ * Callback for buddylist_views_arguments
+ */
+function buddylist_views_handler_arg_buddies_buddyof($op, &$query, $argtype, $arg = '') {
+ switch($op) {
+ case 'summary':
+ $table_data = _views_get_tables();
+ $joininfo = $table_data['usernode_buddylist']['join'];
+ $joininfo['type'] = 'inner';
+ $query->add_table("usernode_buddylist", true, 1, $joininfo);
+
+ $query->add_table('users', true);
+ $query->add_field('name', 'users');
+ $query->add_field('uid', 'users');
+ $fieldinfo['field'] = "users.name";
+ return $fieldinfo;
+ break;
+ case 'sort':
+ $query->add_orderby('users', 'name', $argtype);
+ break;
+ case 'filter':
+ $uid = intval($arg);
+ $table_data = _views_get_tables();
+ $joininfo = $table_data['usernode_buddylist_buddyof']['join'];
+ $joininfo['type'] = 'inner';
+ $joininfo['extra'] = array('buddy' => $uid);
+ $query->add_table("usernode_buddylist_buddyof", true, 1, $joininfo);
+ break;
+ case 'link':
+ $name = ($query->name ? $query->name : variable_get('anonymous', 'Anonymous'));
+ return l($name, "$arg/" . intval($query->uid));
+ case 'title':
+ if (!$query) {
+ return variable_get('anonymous', 'Anonymous');
+ }
+ $user = db_fetch_object(db_query("SELECT name FROM {users} WHERE uid = '%d'", $query));
+ return check_plain($user->name);
+ }
+}