You are here

额外例子:添加一个“待定用户”区块

老葛的Drupal培训班 Think in Drupal

如果你想扩展approval.module,你可以添加另一个区块,以显示等待管理员批准的用户帐号列表。这将作为作业留给读者,自己动手将其放到approval.module模块中去。这里给出了一个在假定的userapproval.module模块中的区块:

 
function userapproval_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
$blocks[0]['info'] = t('Pending users');
return $blocks;
case 'view':
if (user_access('administer users')) {
 $result = db_query_range('SELECT uid, name, created FROM {users}
 WHERE uid != 0 AND status = 0 ORDER BY created DESC', 0, 5);
 $destination = drupal_get_destination();
 // Defensive coding: we use $u instead of $user to avoid potential namespace
 // collision with global $user variable should this code be added to later.
 while ($u = db_fetch_object($result)) {
    $items[] = theme('username', $u). ' '.
    l('[edit]', 'user/'. $u->uid. '/edit', array(), $destination);
 }
 $block['subject'] = t('Pending users');
 $block['content'] = theme('item_list', $items);
}
return $block;
}
}

Drupal版本: