Hi. I have tried in Views but realized it is impossible anyway. I tried to custom-code it, but failed (miserably) and have browsed the net for hours trying to find a solution. Here's my issue...

I want to create a block (Views or PHP, I dont care which) that will display the "latest 10" logged in users. I don't know if this is possible, though surely it is, I meen, how hard can it be? I believe this is a "must have" script for a community website.

I notice the DrupalSN.com website has EXACTLY what I need, but with it being PHP, I cannot view their query code.

Any help would be deeply appreciated.

Comments

michelle’s picture

You can sort a view by the user's last access time.

Michelle

darklight’s picture

Yes, I tried this. A few times, actually. The remaining problem is that the Distinct function does not work. I am now given 10 user pictures all from the same user... "ME!"

If it was that easy I'd have never posted here in the first place.

Thanks for replying.

michelle’s picture

I did it before I answered you. I didn't use the distinct function. Didn't need it. Sounds like you're doing something strange with your view but you haven't given enough details to guess what.

Michelle

darklight’s picture

Hey, it's all OK, I wrote a custom code to do this. Thanks for replying ;)

michelle’s picture

Well, whatever works. I needed to do it anyway because it's part of Advanced Profile Kit that hasn't been ported, yet.

Michelle

darklight’s picture

Do you need the source code for the script I wrote?

michelle’s picture

I already made the view to do it.

Michelle

darklight’s picture

Hmm, I am getting some really strange errors here. Is there any chance of seeing your Views Export for this thing? It would help out tons if I see I am missing something.

michelle’s picture

It won't work for you if you don't have Content Profile installed but here it is:

$view = new view;
$view->name = 'apk_user_list';
$view->description = 'List of users';
$view->tag = 'APK';
$view->view_php = '';
$view->base_table = 'users';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('relationships', array(
  'content_profile_rel' => array(
    'label' => 'Content Profile',
    'required' => 0,
    'type' => 'uprofile',
    'id' => 'content_profile_rel',
    'table' => 'users',
    'field' => 'content_profile_rel',
    'relationship' => 'none',
  ),
));
$handler->override_option('fields', array(
  'uid' => array(
    'label' => 'Uid',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'link_to_user' => 0,
    'exclude' => 1,
    'id' => 'uid',
    'table' => 'users',
    'field' => 'uid',
    'relationship' => 'none',
  ),
  'picture' => array(
    'label' => 'Picture',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'exclude' => 0,
    'id' => 'picture',
    'table' => 'users',
    'field' => 'picture',
    'relationship' => 'none',
  ),
  'name' => array(
    'label' => 'Name',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'link_to_user' => 1,
    'overwrite_anonymous' => 0,
    'anonymous_text' => '',
    'exclude' => 0,
    'id' => 'name',
    'table' => 'users',
    'field' => 'name',
    'relationship' => 'none',
  ),
  'field_about_me_value' => array(
    'label' => 'About',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'link_to_node' => 0,
    'label_type' => 'custom',
    'format' => 'default',
    'multiple' => array(
      'group' => TRUE,
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_reversed' => FALSE,
    ),
    'exclude' => 0,
    'id' => 'field_about_me_value',
    'table' => 'node_data_field_about_me',
    'field' => 'field_about_me_value',
    'relationship' => 'content_profile_rel',
  ),
  'field_interests_value' => array(
    'label' => 'Interests',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'link_to_node' => 0,
    'label_type' => 'widget',
    'format' => 'default',
    'multiple' => array(
      'group' => TRUE,
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_reversed' => FALSE,
    ),
    'exclude' => 0,
    'id' => 'field_interests_value',
    'table' => 'node_data_field_interests',
    'field' => 'field_interests_value',
    'relationship' => 'content_profile_rel',
  ),
  'access' => array(
    'label' => 'Last seen',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'date_format' => 'time ago',
    'custom_date_format' => '',
    'exclude' => 0,
    'id' => 'access',
    'table' => 'users',
    'field' => 'access',
    'relationship' => 'none',
  ),
));
$handler->override_option('sorts', array(
  'access' => array(
    'order' => 'DESC',
    'granularity' => 'second',
    'id' => 'access',
    'table' => 'users',
    'field' => 'access',
    'relationship' => 'none',
  ),
));
$handler->override_option('filters', array(
  'status' => array(
    'operator' => '=',
    'value' => '1',
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'status',
    'table' => 'users',
    'field' => 'status',
    'relationship' => 'none',
  ),
));
$handler->override_option('access', array(
  'type' => 'perm',
  'perm' => 'access user profiles',
));
$handler->override_option('title', 'User List');
$handler->override_option('items_per_page', 15);
$handler->override_option('use_pager', '1');
$handler->override_option('style_plugin', 'table');
$handler->override_option('exposed_block', TRUE);
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'users/list');
$handler->override_option('menu', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
  'name' => 'navigation',
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
));