Hi great flag people,
I was inspired by the tut here http://drupal.org/node/405754, to create latest visitors to a viewed profile page.

The steps are basically the same: creating flag last_visitor, adding a rule with actions Flag viewed user, under "Last Visitors" (and then interchanged with Flag acting user, under "Last Visitors" when failed), and a views block.

With the views, I pulled out picture, username and flagged time fields into a block. The relationship is Flags: last_visitor by any user and left the argument empty since I had no luck to any of the argument there. The block shows only the profile pages a user visited, not visitors of the user. The tut works:) But that's not what I want.

So, my silly question is if it's possible with the current flag and how. And please don't tell me to use user_visits.module, it's ok already, but this time I just want to try the flag to any possible extent.

Here is the views:

$view = new view;
$view->name = 'flag_last_visitors';
$view->description = 'custom last visitors with rules and flag dong';
$view->tag = 'visitors';
$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(
  'flag_content_rel' => array(
    'label' => 'flag',
    'required' => 1,
    'flag' => 'last_visitor',
    'user_scope' => 'any',
    'id' => 'flag_content_rel',
    'table' => 'users',
    'field' => 'flag_content_rel',
    'relationship' => 'none',
    'override' => array(
      'button' => 'Override',
    ),
  ),
  'uid' => array(
    'label' => 'Flag user',
    'required' => 0,
    'id' => 'uid',
    'table' => 'flag_content',
    'field' => 'uid',
    'relationship' => 'flag_content_rel',
    'override' => array(
      'button' => 'Override',
    ),
  ),
));
$handler->override_option('fields', array(
  'picture' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
    ),
    'exclude' => 0,
    'id' => 'picture',
    'table' => 'users',
    'field' => 'picture',
    'relationship' => 'none',
  ),
  'name' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
    ),
    'link_to_user' => 1,
    'overwrite_anonymous' => 0,
    'anonymous_text' => '',
    'exclude' => 0,
    'id' => 'name',
    'table' => 'users',
    'field' => 'name',
    'relationship' => 'none',
  ),
  'timestamp' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
    ),
    'date_format' => 'time ago',
    'custom_date_format' => '1',
    'exclude' => 0,
    'id' => 'timestamp',
    'table' => 'flag_content',
    'field' => 'timestamp',
    'relationship' => 'flag_content_rel',
    'override' => array(
      'button' => 'Override',
    ),
  ),
));
$handler->override_option('sorts', array(
  'timestamp' => array(
    'order' => 'DESC',
    'granularity' => 'minute',
    'id' => 'timestamp',
    'table' => 'flag_content',
    'field' => 'timestamp',
    'relationship' => 'flag_content_rel',
  ),
));
$handler->override_option('access', array(
  'type' => 'role',
  'role' => array(
    '3' => 3,
    '2' => 2,
    '5' => 5,
    '6' => 6,
    '7' => 7,
  ),
));
$handler->override_option('title', 'Latest Visitors');
$handler->override_option('empty', 'Tidak ada pengunjung hari ini.');
$handler->override_option('empty_format', '1');
$handler->override_option('items_per_page', 9);
$handler->override_option('distinct', 1);
$handler->override_option('style_plugin', 'list');
$handler->override_option('style_options', array(
  'type' => 'ul',
));
$handler = $view->new_display('block', 'Block', 'block_1');
$handler->override_option('block_description', 'Tamu Terakhir');
$handler->override_option('block_caching', -1);

And the rules:

array (
  'rules' => 
  array (
    'rules_3' => 
    array (
      '#type' => 'rule',
      '#set' => 'event_user_view',
      '#label' => 'Last Visitors',
      '#active' => 1,
      '#weight' => '0',
      '#categories' => 
      array (
        0 => '',
      ),
      '#status' => 'custom',
      '#conditions' => 
      array (
        0 => 
        array (
          '#weight' => 0,
          '#info' => 
          array (
            'label' => 'Check a truth value',
            'arguments' => 
            array (
              'boolean' => 
              array (
                'type' => 'boolean',
                'label' => 'Truth value',
              ),
            ),
            'module' => 'Rules',
          ),
          '#name' => 'rules_condition_check_boolean',
          '#settings' => 
          array (
            'boolean' => '1',
          ),
          '#type' => 'condition',
        ),
      ),
      '#actions' => 
      array (
        0 => 
        array (
          '#weight' => -1,
          '#info' => 
          array (
            'label' => 'Flag acting user, under "Last Visitors"',
            'base' => 'flag_rules_action_flag',
            'label callback' => 'flag_rules_action_flag_label',
            'arguments' => 
            array (
              'flag' => 
              array (
                'type' => 'flag',
                'label' => 'Flag',
                'flag_type' => 'user',
              ),
              'object' => 
              array (
                'type' => 'user',
                'label' => 'Flagged user',
              ),
              'flagging_user' => 
              array (
                'type' => 'user',
                'label' => 'User on whose behalf to flag',
                'description' => 'For non-global flags, this is the user on whose behalf to flag the object. In addition, if checked below, the access permissions to the flag are checked against this user.',
              ),
            ),
            'module' => 'Flag',
          ),
          '#name' => 'flag_rules_action_flag_user',
          '#settings' => 
          array (
            'flag' => 'last_visitor',
            'permission_check' => 0,
            '#argument map' => 
            array (
              'object' => 'user',
              'flagging_user' => 'account',
            ),
          ),
          '#type' => 'action',
        ),
        1 => 
        array (
          '#type' => 'action',
          '#settings' => 
          array (
            'flag' => 'last_visitor',
            'cutoff_size' => '9',
            '#argument map' => 
            array (
              'flagging_user' => 'user',
            ),
          ),
          '#name' => 'flag_rules_action_trim',
          '#info' => 
          array (
            'label' => 'Trim "Last visitors" at 5',
            'label callback' => false,
            'arguments' => 
            array (
              'flag' => 
              array (
                'type' => 'flag',
                'label' => 'Flag',
              ),
              'flagging_user' => 
              array (
                'type' => 'user',
                'label' => 'User whose flag to trim',
                'description' => 'For non-global flags, this is the user whose flag to trim. (For global flags, this argument is ignored.)',
              ),
              'cutoff_size' => 
              array (
                'type' => 'number',
                'label' => 'Flag queue size',
                'description' => 'The maximum number of objects to keep in the queue. Newly flagged objects will be kept; older ones will be removed. Tip: by typing "1" here you implement a <a href="http://en.wikipedia.org/wiki/Singleton_pattern">singleton</a>.',
              ),
            ),
            'module' => 'Flag',
          ),
          '#weight' => 0,
        ),
      ),
    ),
  ),
)

Thank you very much for any hint.

Comments

gausarts’s picture

Oh, forgot to mention the flag type is user. Thanks

mooffie’s picture

'label' => 'Flag acting user, under "Last Visitors"',

First, it's important that you (and we, the readers) undersatand who flags who. You elected to have the "profiled" user flag his visitors. That's ok. (It's possible to do this the other way around.)

So you want to have a view that shows, for a given "profiled" user, the users he has flagged.

This module already comes with a view that shows (at the user/123/bookmarks URL) for a given user the nodes he has flagged. You want to build a similar view: one that shows, for a given user, the users he has flagged.

How to do this? Options:

  • Examine the user/%/bookmarks view we provide to learn how things work; or
  • Read the nice handbook page explaining how to build this view. Most unfotunately, problems with Drupal.Org sent this page into oblivion so I can't provide a URL at the moment; or
  • Read our Views Tutorial page. Same problem.

I'll try to come up with the URLs.

mooffie’s picture

Here it is! The fine handbook page:

How to setup a "bookmarks" tab on each user's profile page

Don't worry: the instructions here are suitable for displaying flagged users, not just flagged nodes.

Put this tab, for example, on the user/%/visitors URL. And name that tab "visitors", or anything other than "bookmarks" (because you don't want to confuse yourself (and us!)).

If, and only if, that tab works, continue and turn it into a block.

gausarts’s picture

Thanks for kind reply. Gotta try it today and report soon here. Again thank you very much.

mooffie’s picture

I was inspired by the tut here http://drupal.org/node/405754,

BTW, I've just commented on that page. The recipe there has a tiny glitch.

gausarts’s picture

Hi,

It works. Thank you thank you thank you. Thanks for saving me another headache:)

Additional info: the only thing I missed last time was the relationship for argument.

gausarts’s picture

Hi,

I think I have another problem how to exclude the profile owner from appearing apart from the glitch you mentioned. Any hint? Thanks

mooffie’s picture

Status: Active » Fixed

It works.

Great. So I'll mark this "Fixed". Feel free to re-open.

how to exclude the profile owner from appearing

The preferable way to solve this is to prevent a "profiled" user from flagging himself.

Rules has the notion of "conditions". You have to add to your rule-set a condition that says "If the viewed user isn't equal to the acting user". I can't give you exact instructions (I'm not running Drupal), but IIRC there's a condition that compares two objects (and there's a checkbox that negates the result); You should pick it. Let me know how it's going.

gausarts’s picture

Status: Fixed » Closed (fixed)

You are my hero. The new condition applied only after emptying cache_rules through phpmyadmin. Flushing cache through drupal and admin menu interface seemed to fail. Ok, fixed and closed now. Again thank you very much for great support.

dummas_324324_32’s picture

Component: Code » Miscellaneous
Status: Closed (fixed) » Active

Hi,

I have still a question to this topic..

I have imported the view and rule, what kind of argument do I have to add, that it will work?
or have someone the corrent views and rules?

thx
mathias

quicksketch’s picture

Status: Active » Closed (fixed)

I don't support any requests regarding Rules module, considering this hasn't been updated in a few months, I'm reclosing since it doesn't look like this will be answered.

funature’s picture

is there a D7 edition for this?