summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--modules/og_views/includes/og_views_handler_field_og_uid_groups.inc47
-rw-r--r--modules/og_views/og_views.views.inc13
2 files changed, 60 insertions, 0 deletions
diff --git a/modules/og_views/includes/og_views_handler_field_og_uid_groups.inc b/modules/og_views/includes/og_views_handler_field_og_uid_groups.inc
new file mode 100644
index 0000000..04947f4
--- /dev/null
+++ b/modules/og_views/includes/og_views_handler_field_og_uid_groups.inc
@@ -0,0 +1,47 @@
+<?php
+/**
+ * Field handler for displaying a list of groups for a user.
+ */
+class og_views_handler_field_og_uid_groups extends views_handler_field_prerender_list {
+ /**
+ * Fake the field alias -- we don't want to actually join.
+ */
+ function init(&$view, $options) {
+ parent::init($view, $options);
+ switch ($view->base_table) {
+ case 'node':
+ $this->additional_fields['users_uid'] = array('table' => 'users', 'field' => 'uid');
+ $this->field_alias = 'users_uid';
+ break;
+ case 'users':
+ $this->field_alias = 'uid';
+ break;
+ }
+ }
+
+ /**
+ * Add this term to the query
+ */
+ function query() {
+ $this->add_additional_fields();
+ }
+
+ /**
+ * Query in pre_render to grab what we need.
+ */
+ function pre_render($values) {
+ $uids = array();
+ foreach ($values as $row) {
+ if (!empty($row->{$this->field_alias})) {
+ $uids[] = $row->{$this->field_alias};
+ }
+ }
+ if (!empty($uids)) {
+ $placeholders = db_placeholders($uids, 'int');
+ $result = db_query(db_rewrite_sql("SELECT n.nid, n.title, ogu.uid FROM {node} n JOIN {og_uid} ogu ON ogu.nid = n.nid WHERE ogu.uid IN ($placeholders) AND n.status = 1"), $uids);
+ while ($row = db_fetch_object($result)) {
+ $this->items[$row->uid][$row->nid] = l($row->title, "node/{$row->nid}");
+ }
+ }
+ }
+}
diff --git a/modules/og_views/og_views.views.inc b/modules/og_views/og_views.views.inc
index 73c7efb..b008e05 100644
--- a/modules/og_views/og_views.views.inc
+++ b/modules/og_views/og_views.views.inc
@@ -66,6 +66,9 @@ function og_views_views_handlers() {
'og_views_handler_field_og_managelinkmy' => array(
'parent' => 'views_handler_field',
),
+ 'og_views_handler_field_og_uid_groups' => array(
+ 'parent' => 'views_handler_field_prerender_list',
+ ),
// argument
'og_views_handler_argument_og_group_nid' => array(
'parent' => 'views_handler_argument_numeric',
@@ -264,6 +267,7 @@ function og_views_data_og_ancestry() {
'field' => 'nid',
),
);
+
$data['og_ancestry']['group_nid'] = array(
'title' => t('Groups'),
'help' => t('The groups for a post.'),
@@ -356,6 +360,15 @@ function og_views_data_og_uid() {
'help' => t('<strong>Members</strong> are filtered for a specific group.'),
),
);
+ $data['og_uid']['groups'] = array(
+ 'title' => t('User\'s groups'),
+ 'help' => t('Groups that a member belongs to.'),
+ 'field' => array(
+ 'field' => 'uid',
+ 'handler' => 'og_views_handler_field_og_uid_groups',
+ 'help' => t("OG: List of user's groups"),
+ ),
+ );
$data['og_uid']['uid'] = array(
'title' => t('Group member'),
// 'help' => t('foo')