Pages

Friday, February 25, 2011

Drupal Module - User View V1

<?php
/**
 * This module provide as viewer for drupal user in a block
 *
 * @type     : drupal module - block, db
 * @author   : irfanudin ridho
 * @email    : irfan.ub@gmail.com
 * @version  : 1.0
 * @date     : February 26, 2011
 */
 
/**
 * Implements hook_block_info()
 */
function user_view_block_info(){
    $block['view_user'] = array(
        'info' => t('User View'),
        'cache' => DRUPAL_CACHE_PER_ROLE,
        'region' => 'sidebar_first',
        'visibility' => 1,
        'pages' => '*',
        'status' => NULL,
    );
   
    return $block;
}




/**
 * Implements hook_block_view()
 */
function user_view_block_view($delta=''){
    switch($delta){
        case 'view_user':
            $block['subject'] = t('User View');
            $block['content'] = get_user($delta);
            break;
    }
   
    return $block;
}

/**
 * What displaying at the block
 */
function get_user($delta_switch){
    $render = get_content();
    switch($delta_switch){
        case 'view_user':
            return $render;
    }
}

/**
 * Querying users table
 */
function get_content(){
    $query = db_select('users')->fields('users')
            ->execute()->fetchAll();
    $output = '<ol>';
    $i = 1;
    foreach($query as $key){
        if($i!=1){
            $output .= '<li>'.$key->name.' - '.$key->mail.'</li>';           
        }
        $i++;
    }
   
    $output .= '</ol>';
   
    return $output;
}

No comments:

Post a Comment