|
|
Drupal example source code file (views_handler_field_user_roles.inc)
The views_handler_field_user_roles.inc Drupal example source code<?php // $Id: views_handler_field_user_roles.inc,v 1.2 2009/07/01 23:07:14 merlinofchaos Exp $ /** * Field handler to provide a list of roles. */ class views_handler_field_user_roles extends views_handler_field_prerender_list { function construct() { parent::construct(); $this->additional_fields['uid'] = array('table' => 'users', 'field' => 'uid'); } function query() { $this->add_additional_fields(); $this->field_alias = $this->aliases['uid']; } function pre_render($values) { $uids = array(); $this->items = array(); foreach ($values as $result) { $uids[] = $result->{$this->aliases['uid']}; } if ($uids) { $result = db_query("SELECT u.uid, u.rid, r.name FROM {role} r INNER JOIN {users_roles} u ON u.rid = r.rid WHERE u.uid IN (" . implode(', ', $uids) . ") ORDER BY r.name"); while ($role = db_fetch_object($result)) { $this->items[$role->uid][$role->rid]['role'] = check_plain($role->name); $this->items[$role->uid][$role->rid]['rid'] = $role->rid; } } } function render_item($count, $item) { return $item['role']; } function document_self_tokens(&$tokens) { $tokens['[' . $this->options['id'] . '-role' . ']'] = t('The name of the role.'); $tokens['[' . $this->options['id'] . '-rid' . ']'] = t('The role ID of the role.'); } function add_self_tokens(&$tokens, $item) { $tokens['[' . $this->options['id'] . '-role' . ']'] = $item['role']; $tokens['[' . $this->options['id'] . '-rid' . ']'] = $item['rid']; } } Other Drupal examples (source code examples)Here is a short list of links related to this Drupal views_handler_field_user_roles.inc source code file: |
"Drupal" is a registered trademark of Dries Buytaert.
my drupal tutorials and examples
Copyright
1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.
Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.