Commit b57c309a authored by merlinofchaos's avatar merlinofchaos

#240102: (Largely by neclimdul) -- Initial pass at profile field handlers....

#240102: (Largely by neclimdul) -- Initial pass at profile field handlers. Still 3 @todo items remain but they are not hard.
parent 9a10f2b1
......@@ -85,8 +85,8 @@
border: #ccc 1px solid;
border-top: 0;
margin-left: 117px; /* 118 -1 causes borders to overlap */
min-height: 302px;
_height: 300px; /*stupid IE hack */
// min-height: 302px;
// _height: 300px; /*stupid IE hack */
}
* html .views-tabset .views-display {
......@@ -189,8 +189,6 @@ div.views-display-deleted div.tab-section {
#views-ajax-pad {
background: transparent;
margin-top: 0px;
min-height: 200px;
_height: 200px; /* stupid IE */
}
#views-ajax-title {
......@@ -207,7 +205,7 @@ div.views-display-deleted div.tab-section {
margin-left: 117px;
border: #ADB7BE 1px solid;
border-top: 0;
padding: 3em 0em;
/* padding: 3em 0em; */
text-align: center;
background: transparent;
font-style: italic;
......
......@@ -810,6 +810,58 @@ class views_handler_field_url extends views_handler_field {
}
}
/**
* Field handler to provide a list of items.
*
* The items are expected to be loaded by a child object during pre_render,
* and 'my field' is expected to be the pointer to the items in the list.
*
* Items to render should be in a list in $this->items
*
* @ingroup views_field_handlers
*/
class views_handler_field_prerender_list extends views_handler_field {
function options(&$options) {
parent::options($options);
$options['type'] = 'separator';
$options['separator'] = ', ';
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['type'] = array(
'#type' => 'radios',
'#title' => t('Display type'),
'#options' => array(
'ul' => t('Unordered list'),
'ol' => t('Ordered list'),
'separator' => t('Simple separator'),
),
'#default_value' => $this->options['type'],
);
$form['separator'] = array(
'#type' => 'textfield',
'#title' => 'separator',
'#default_value' => $this->options['separator'],
'#process' => array('views_process_dependency'),
'#dependency' => array('radio:options[type]' => array('separator')),
);
}
function render($value) {
$field = $value->{$this->field_alias};
if (!empty($this->items[$field])) {
if ($this->options['type'] == 'separator') {
return implode(check_plain($this->options['separator']), $this->items[$field]);
}
else {
return theme('item_list', $this->items[$field], NULL, $this->options['type']);
}
}
}
}
/**
* @}
*/
......
......@@ -590,7 +590,9 @@ class view extends views_db_object {
// Give field handlers the opportunity to perform additional queries
// using the entire resultset prior to rendering.
foreach ($this->field as $id => $field) {
$this->field[$id]['handler']->pre_render($this->result);
if (!empty($this->field[$id]['handler'])) {
$this->field[$id]['handler']->pre_render($this->result);
}
}
return $this->display_handler->render();
......
......@@ -322,7 +322,7 @@ function node_views_data() {
'field' => 'vid',
),
// Links to user table through node table.
'user' => array(
'users' => array(
// Since it doesn't link to the user table, we must specify
'left_table' => 'node',
'left_field' => 'vid',
......
......@@ -190,6 +190,22 @@ function user_views_data() {
),
);
$data['users']['edit_node'] = array(
'field' => array(
'title' => t('Edit link'),
'help' => t('Provide a simple link to edit the user.'),
'handler' => 'views_handler_field_user_link_edit',
),
);
$data['users']['delete_node'] = array(
'field' => array(
'title' => t('Delete link'),
'help' => t('Provide a simple link to delete the user.'),
'handler' => 'views_handler_field_user_link_delete',
),
);
// ----------------------------------------------------------------------
// Roles table
......@@ -297,6 +313,84 @@ class views_handler_field_user_name extends views_handler_field_user {
}
}
/**
* Field handler to present a link to the user.
*
* @ingroup views_field_handlers
*/
class views_handler_field_user_link extends views_handler_field {
function construct() {
parent::construct();
$this->additional_fields['uid'] = 'uid';
}
function options(&$options) {
parent::options($options);
$options['text'] = '';
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['text'] = array(
'#type' => 'textfield',
'#title' => t('Text to display'),
'#default_value' => $this->options['text'],
);
}
// An example of field level access control.
function access() {
return user_access('access user profiles');
}
function query() {
$this->ensure_my_table();
$this->add_additional_fields();
}
function render($values) {
$text = !empty($this->options['text']) ? $this->options['text'] : t('view');
$uid = $values->{$this->aliases['uid']};
return l($text, "user/$uid");
}
}
/**
* Field handler to present a link to user edit.
*
* @ingroup views_field_handlers
*/
class views_handler_field_user_link_edit extends views_handler_field_user_link {
// An example of field level access control.
function access() {
return user_access('administer users');
}
function render($values) {
$text = !empty($this->options['text']) ? $this->options['text'] : t('edit');
$uid = $values->{$this->aliases['uid']};
return l($text, "user/$uid/edit", array('query' => drupal_get_destination()));
}
}
/**
* Field handler to present a link to user delete.
*
* @ingroup views_field_handlers
*/
class views_handler_field_user_link_delete extends views_handler_field_user_link {
// An example of field level access control.
function access() {
return user_access('administer users');
}
function render($values) {
$text = !empty($this->options['text']) ? $this->options['text'] : t('delete');
$uid = $values->{$this->aliases['uid']};
return l($text, "user/$uid/delete", array('query' => drupal_get_destination()));
}
}
/**
* Field handler to provide acess control for the email field
*
......@@ -363,42 +457,15 @@ class views_handler_field_user_picture extends views_handler_field {
*
* @ingroup views_field_handlers
*/
class views_handler_field_user_roles extends views_handler_field {
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 options(&$options) {
parent::options($options);
$options['type'] = 'separator';
$options['separator'] = ', ';
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['type'] = array(
'#type' => 'radios',
'#title' => t('Display type'),
'#options' => array(
'ul' => t('Unordered list'),
'ol' => t('Ordered list'),
'separator' => t('Simple separator'),
),
'#default_value' => $this->options['type'],
);
$form['separator'] = array(
'#type' => 'textfield',
'#title' => 'separator',
'#default_value' => $this->options['separator'],
'#process' => array('views_process_dependency'),
'#dependency' => array('radio:options[type]' => array('separator')),
);
}
function query() {
$this->add_additional_fields();
$this->field_alias = $this->aliases['uid'];
}
function pre_render($results) {
......@@ -413,19 +480,7 @@ class views_handler_field_user_roles extends views_handler_field {
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->roles[$role->uid][$role->rid] = check_plain($role->name);
}
}
}
function render($value) {
$uid = $value->{$this->aliases['uid']};
if (!empty($this->roles[$uid])) {
if ($this->options['type'] == 'separator') {
return implode(check_plain($this->options['separator']), $this->roles[$uid]);
}
else {
return theme('item_list', $this->roles[$uid], NULL, $this->options['type']);
$this->items[$role->uid][$role->rid] = check_plain($role->name);
}
}
}
......
......@@ -152,8 +152,9 @@ function template_preprocess_views_view_table(&$vars) {
foreach ($columns as $field => $column) {
// render the header labels
if ($field == $column) {
$label = check_plain(!empty($fields[$field]['handler']) ? $fields[$field]['handler']->label() : '');
if (empty($options['info'][$field]['sortable'])) {
$vars['header'][$field] = check_plain($fields[$field]['handler']->label());
$vars['header'][$field] = $label;
}
else {
// @todo -- make this a setting
......@@ -163,7 +164,6 @@ function template_preprocess_views_view_table(&$vars) {
$initial = 'desc';
}
$label = check_plain($fields[$field]['handler']->label());
$image = theme('tablesort_indicator', $initial);
$title = t('sort by @s', array('@s' => $label));
$link_options = array(
......
......@@ -5,7 +5,7 @@
* Template for the primary view editing window.
*/
?>
<div class="views-display views-display-<?php print $display->id; if (!empty($display->deleted)) { print ' views-display-deleted'; }; ?>">
<div class="clear-block views-display views-display-<?php print $display->id; if (!empty($display->deleted)) { print ' views-display-deleted'; }; ?>">
<?php // top section ?>
<div class="top">
<div class="inside">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment