Individual User activities block

dropchew - March 10, 2009 - 06:57
Project:Activity
Version:6.x-1.1
Component:User interface
Category:feature request
Priority:normal
Assigned:jaydub
Status:patch (to be ported)
Description

Hi,

We are aware that there's a 'All' activities and a 'My' activities block for logged in users. But is there a block that shows individual user's activities? Sorry if this is a duplicate post, I can't find another post with this request. Thanks.

#1

sirkitree - March 10, 2009 - 15:24

We don't currently have a block for this, but there is a way you can do this easily if you look at the code implemented within hook_user()

<?php
...
   
// View activity on user profile page.
   
case 'view':
      if (
user_access('view public activity') && variable_get('activity_user_profile_records', 5) != 0) {
       
drupal_add_css(drupal_get_path('module', 'activity') .'/activity.css');
       
$activities = activity_get_activity($account->uid, NULL, variable_get('activity_user_profile_records', 5));
       
       
$account->content['activity'] = array(
         
'#type' => 'user_profile_category',
         
'#title' => t('Activity'),
         
'#weight' => 6,
        );
       
$account->content['activity'][] = array(
         
'#type' => 'user_profile_item',
         
'#value' => theme('activity_user_profile_activity', $activities),
        );
      }
      break;
...
?>

This basically retrieve's all activity for the current user whose profile you are viewing and shows it. You could just as easily put this in a hook_block() and in the line $activities = activity_get_activity($account->uid, NULL, variable_get('activity_user_profile_records', 5)); you would use $user->uid instead of $account->uid after declaring global $user

So in short you can paste something like this into your site's custom module: (not tested)

<?php
function MYMODULE_block($op = 'list', $delta = 0, $edit = array()) {
  global
$user;
  switch (
$op) {
    case
'list':
     
$blocks[] = array('info' => t("Activity - Current User Activity"));
      return
$blocks;
      break;
    case
'view':
       
drupal_add_css(drupal_get_path('module', 'activity') .'/activity.css');
       
$activities = activity_get_activity($user->uid, NULL, variable_get('activity_user_profile_records', 5));
       
     if (
count($activity)) {
        return array(
         
'subject' => t('My !name\' activity', array('!name' => $type->plural_name)),
         
'content' => theme('activity_block', $activities, $more_link)
        );
      }
   break;
}
?>

#2

bflora - March 11, 2009 - 08:26

How can I do this by just adding some code to my profile page template? I don't want to create another module or mess around with drupal hooks.

I'm currently trying to use this code:

$activities = activity_get_activity(arg(1), NULL, variable_get('activity_user_profile_records', 5));
  print_r(theme('activity_user_profile_activity', $activities));

Where arg(1) is the current profile page's UID.

But this isn't working. What am I doing wrong? All it shows me is "Array" instead of the activity feed. Thanks.

#3

sirkitree - March 11, 2009 - 16:07
Status:active» postponed (maintainer needs more info)

In a core profile system (no mods to the profile) it should already show up. that is what hook_user(), case view does.

Have you modified your user profiles with another module?

As for your code above, if you print_r($activities), that should work. But you don't want to print_r the theme function that you're passing $activities into as the theme function does not return an array.

#4

SocialNicheGuru - March 14, 2009 - 16:31

could this be an option as part of the Activity module?

Facebook status gives you a similar capability to see the status of the person you are viewing. That makes a lot of sense.

#5

bflora - March 14, 2009 - 21:43

I've got a production site with 1000 registered users. The user profiles were written by hand to make sure they do what they need to do.

So I need to find a way to get the activity for a profile to appear on them using custom code.

Good point about the print_r. I only had that in there to see if I could see what was wrong.

The problem with that code I posted above is that all it returns is "array()"

How do I get it ot return the actual activity?

Is there different code I should use?

#6

jaydub - March 20, 2009 - 00:51
Category:support request» feature request
Assigned to:Anonymous» jaydub
Status:postponed (maintainer needs more info)» active

related issue: #373480: My activity block: Can it also display activity of person whose profile i am viewing

#7

jaydub - March 20, 2009 - 02:43
Status:active» needs review

Ok how about someone try this patch which adds a new block for viewing activity for the user you are currently viewing.

this is for the 6.1 branch against the latest -dev snapshot.

AttachmentSize
activity.module.396960.patch 2.22 KB

#8

dropchew - March 21, 2009 - 13:36

With the above patch,

1)eg, if visitor comments on a node, its will be recorded as 'you' commented on the node and not 'visitor' when viewing as a visitor
2)eg, if a member change his status (facebook style status module), when viewing as a visitor, it will be recorded as 'you' and not the member's name.

So far these are my findings. Thanks.

#9

jaydub - March 23, 2009 - 18:43

#1 - don't see this behaviour. Can you detail exactly what steps you took to get this result?

#2 - fbstatus module is maintained outside of Activity and likely needs to have its support
for Activity updated as there have been a lot of changes on our end.

#10

jaydub - April 21, 2009 - 08:07

The patch from #7 was committed to CVS. Please try a -dev release to try out this block.

#11

pribeh - April 22, 2009 - 13:53

Any update for the 5.4 implementation of this? Thanks so much.

#12

jaydub - April 22, 2009 - 17:15

Right now the 6.x branch has a lot more users than 5.x so we're looking to make sure that features are working in the 6.x branch before considering porting to 5.4. I highly encourage you to play with a 6.1-dev snapshot as 6.1.x and on into the future 6.2.x will be the primary focus of development.

#13

pribeh - April 23, 2009 - 16:44

Thanks jaydub. Unfortunately, the site I'm working that heavily uses activity will be in five for awhile until various other modules (panels and APK in particular) become stable for 6.

#14

pribeh - April 23, 2009 - 19:26

OK, so I went ahead and just inserted the following

$block['user']['info'] = t("Activity (User): show activity of the user being viewed");

and

case 'user':
            if (user_access('view public activity') && arg(0) == "user" && is_numeric(arg(1))) {
              $uid = arg(1);
              $author = activity_user_load($uid);
              $activity =  activity_get_activity($uid, NULL, variable_get('activity_block_'. $delta, 5) + 1);
              if ($count = count($activity)) {
                drupal_add_css(drupal_get_path('module', 'activity') .'/activity.css');
                if ($count > variable_get('activity_block_'. $delta, 5)) {
                  $more_link = theme('activity_more_link', 'activity');
                  array_pop($activity);
                }
                $activities = array();
                foreach ($activity as $item) {
                  $item['delete-link'] = activity_delete_link($item);
                  $activities[] = theme('activity', activity_token_replace($item), $item);
                }
                return array(
                  'subject' => t("@username's activity", array('@username' => $author->name)),
                  'content' => theme('activity_block', $activities)
                );
              }
            }
            break;

in 5.x-4.x under hook_block() the same way it appears in the 6 dev version.

Everything works pretty much. The only issue I have, which is a half blessing, is that, having put this block in my APK (user) panel (with bio), it shows comments made on the profile [edit: or any node made by displayed user] by other users as well as every activity made by the user - and nothing else. Since I'm not using core do comments made by other users on nodes by the user (who's profile is being viewed) get shown? I like it even if it's not supposed to happen. The only thing is that simply displays "user commented on user" without the other tokens I've setup for comments like "saying [comment...". All other comments display properly except the one shown in this block made on the node profile by other users.

#15

pribeh - April 23, 2009 - 20:11

Another bug I have is that when using block refresh (http://drupal.org/project/block_refresh) the block refreshes a blank slate unlike the rest of the activity blocks which seem to pull in fresh data fine.

#16

jaydub - April 23, 2009 - 21:09

That module doesn't exist for Drupal 6 so I'm afraid I can't really assess why the feature in this issue doesn't work for you. I encourage you to delve into block_refresh and see how it works and post your results here.

#17

pribeh - April 23, 2009 - 21:48

Yup will do.

#18

jaydub - April 27, 2009 - 00:45
Status:needs review» patch (to be ported)

The original issue request is in CVS now. For the poster in #15 you can open a new issue although keep in mind that there is no d5 implementation of this yet and since your problem with block_refresh is on a d5 module it might not get addressed.

#19

patchak - May 1, 2009 - 11:40

I saw that activity module now has views integration, so is there a way that I can actually reproduce this kind of functionnality using the views integration??

Not sure this is possible tho...
Patchak

#20

sirkitree - May 1, 2009 - 17:00

It should be possible now, yes. The basic idea would be to give your Activity view a uid argument, or filter.

If anyone tries this out please report back and give us a recipe - I'd like to start a handbook page of different Views that people can plug into their sites. Thanks!

#21

nitram079 - November 4, 2009 - 20:11

here is the view I have created (6.x-2.x-dev on drupal 6.14 with latest dev of views). It does the job and can be included e.g. in panels on user profiles

$view = new view;
$view->name = 'user_activity';
$view->description = 'All activity of a user';
$view->tag = 'activity';
$view->view_php = '';
$view->base_table = 'activity';
$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(
  'uid' => array(
    'label' => 'User',
    'required' => 1,
    'id' => 'uid',
    'table' => 'activity',
    'field' => 'uid',
    'relationship' => 'none',
  ),
));
$handler->override_option('fields', array(
  'created' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'date_format' => 'raw time ago',
    'custom_date_format' => '',
    'exclude' => 0,
    'id' => 'created',
    'table' => 'activity',
    'field' => 'created',
    'relationship' => 'none',
  ),
  'message' => 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' => 'message',
    'table' => 'activity_messages',
    'field' => 'message',
    'relationship' => 'none',
  ),
  'delete_activity' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'text' => '',
    'exclude' => 0,
    'id' => 'delete_activity',
    'table' => 'activity',
    'field' => 'delete_activity',
    'relationship' => 'none',
  ),
));
$handler->override_option('sorts', array(
  'aid' => array(
    'order' => 'DESC',
    'id' => 'aid',
    'table' => 'activity',
    'field' => 'aid',
    'relationship' => 'none',
  ),
));
$handler->override_option('arguments', array(
  'uid' => array(
    'default_action' => 'default',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '',
    'breadcrumb' => '',
    'default_argument_type' => 'user',
    'default_argument' => '',
    'validate_type' => 'none',
    'validate_fail' => 'not found',
    'break_phrase' => 0,
    'not' => 0,
    'id' => 'uid',
    'table' => 'users',
    'field' => 'uid',
    'relationship' => 'uid',
    'validate_user_argument_type' => 'uid',
    'validate_user_roles' => array(
      '2' => 0,
    ),
    'override' => array(
      'button' => 'Override',
    ),
    'default_options_div_prefix' => '',
    'default_argument_user' => 0,
    'default_argument_fixed' => '',
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'panel' => 0,
      'profile' => 0,
      'story' => 0,
      'uprofile' => 0,
      'video' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '1' => 0,
      '6' => 0,
      '2' => 0,
      '3' => 0,
      '4' => 0,
      '5' => 0,
    ),
    'validate_argument_type' => 'tid',
    'validate_argument_transform' => 0,
    'validate_user_restrict_roles' => 0,
    'validate_argument_node_flag_name' => '*relationship*',
    'validate_argument_node_flag_test' => 'flaggable',
    'validate_argument_node_flag_id_type' => 'id',
    'validate_argument_user_flag_name' => '*relationship*',
    'validate_argument_user_flag_test' => 'flaggable',
    'validate_argument_user_flag_id_type' => 'id',
    'validate_argument_php' => '',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler->override_option('title', 'user activity');
$handler->override_option('use_ajax', TRUE);
$handler->override_option('items_per_page', 25);
$handler->override_option('use_pager', '1');
$handler->override_option('row_options', array(
  'inline' => array(
    'created' => 'created',
    'message' => 'message',
    'delete_activity' => 'delete_activity',
  ),
  'separator' => '-',
  'hide_empty' => 0,
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'user/%/activity');
$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,
));
$handler = $view->new_display('panel_pane', 'Content pane', 'panel_pane_1');
$handler->override_option('arguments', array(
  'uid' => array(
    'default_action' => 'ignore',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '',
    'breadcrumb' => '',
    'default_argument_type' => 'fixed',
    'default_argument' => '',
    'validate_type' => 'none',
    'validate_fail' => 'not found',
    'break_phrase' => 0,
    'not' => 0,
    'id' => 'uid',
    'table' => 'users',
    'field' => 'uid',
    'relationship' => 'uid',
    'validate_user_argument_type' => 'uid',
    'validate_user_roles' => array(
      '2' => 0,
    ),
    'override' => array(
      'button' => 'Override',
    ),
    'default_options_div_prefix' => '',
    'default_argument_user' => 0,
    'default_argument_fixed' => '',
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'panel' => 0,
      'profile' => 0,
      'story' => 0,
      'uprofile' => 0,
      'video' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '1' => 0,
      '6' => 0,
      '2' => 0,
      '3' => 0,
      '4' => 0,
      '5' => 0,
    ),
    'validate_argument_type' => 'tid',
    'validate_argument_transform' => 0,
    'validate_user_restrict_roles' => 0,
    'validate_argument_node_flag_name' => '*relationship*',
    'validate_argument_node_flag_test' => 'flaggable',
    'validate_argument_node_flag_id_type' => 'id',
    'validate_argument_user_flag_name' => '*relationship*',
    'validate_argument_user_flag_test' => 'flaggable',
    'validate_argument_user_flag_id_type' => 'id',
    'validate_argument_php' => '',
  ),
  'uid_1' => array(
    'default_action' => 'ignore',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '',
    'breadcrumb' => '',
    'default_argument_type' => 'fixed',
    'default_argument' => '',
    'validate_type' => 'none',
    'validate_fail' => 'not found',
    'break_phrase' => 0,
    'not' => 0,
    'id' => 'uid_1',
    'table' => 'activity',
    'field' => 'uid',
    'validate_user_argument_type' => 'uid',
    'validate_user_roles' => array(
      '2' => 0,
    ),
    'override' => array(
      'button' => 'Use default',
    ),
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_argument_user' => 0,
    'default_argument_fixed' => '',
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'panel' => 0,
      'profile' => 0,
      'story' => 0,
      'uprofile' => 0,
      'video' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '1' => 0,
      '6' => 0,
      '2' => 0,
      '3' => 0,
      '4' => 0,
      '5' => 0,
    ),
    'validate_argument_type' => 'tid',
    'validate_argument_transform' => 0,
    'validate_user_restrict_roles' => 0,
    'validate_argument_node_flag_name' => '*relationship*',
    'validate_argument_node_flag_test' => 'flaggable',
    'validate_argument_node_flag_id_type' => 'id',
    'validate_argument_user_flag_name' => '*relationship*',
    'validate_argument_user_flag_test' => 'flaggable',
    'validate_argument_user_flag_id_type' => 'id',
    'validate_argument_php' => '',
  ),
));
$handler->override_option('pane_title', '');
$handler->override_option('pane_description', '');
$handler->override_option('pane_category', array(
  'name' => 'View panes',
  'weight' => 0,
));
$handler->override_option('allow', array(
  'use_pager' => 0,
  'items_per_page' => 0,
  'offset' => 0,
  'link_to_view' => 'link_to_view',
  'more_link' => 0,
  'path_override' => 0,
  'title_override' => 'title_override',
  'exposed_form' => FALSE,
));
$handler->override_option('argument_input', array(
  'uid' => array(
    'type' => 'context',
    'context' => 'node.uid',
    'context_optional' => 0,
    'panel' => '0',
    'fixed' => '',
    'label' => 'User: Uid',
  ),
  'uid_1' => array(
    'type' => 'user',
    'context' => 'node.uid',
    'context_optional' => 0,
    'panel' => '0',
    'fixed' => '',
    'label' => 'User: Uid',
  ),
));
$handler->override_option('link_to_view', 0);
$handler->override_option('inherit_panels_path', 0);
$handler = $view->new_display('block', 'Block', 'block_1');
$handler->override_option('block_description', '');
$handler->override_option('block_caching', -1);

 
 

Drupal is a registered trademark of Dries Buytaert.