I have a use case where I want to allow administrators to edit user profiles and to be able to see the percentage complete for the individual profiles. At the moment, the percentage complete is only worked out for the currently logged on user. I added a bit of code so that the percentage complete would be worked out for a user profile, no matter who was looking at the profile:

  if (arg(0) == 'user' && is_numeric(arg(1))) {
	$user = user_load(arg(1));
  } else {
        global $user;
 }

This replaces the global $user; line of code at line 109 in the pcp.module file. I'm sure there may be a better way of writing this piece of code, but it works for me.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Sylense’s picture

This works but it had adverse effects in that it would mix up the login sessions. When logged in as user 1 viewing another profile it would attempt to change my session to the viewed user. This is most likely due to the fact the OP code is changing the $user variable.

Instead, I have changed the code to

if (arg(0) == 'user' && is_numeric(arg(1))) {
	$account = user_load(arg(1));
  } else {
    $account = $user;
  }

And you must then change $user to $account on the default and profile2 outputs
$out = pcp_get_complete_percentage_data('user', 'user', $user);
$out = pcp_get_complete_percentage_data('profile2', $bundle, $user);

Patch attached. Not sure if this is necessarily should be committed since this may not be the intended behavior for everyone's usage but it works in my particular use case.

EDIT:
I've noticed the other flaw in this is that anyone would be able to see other user's progress. In my particular use case I am programmatically printing the PCP block in my template so I can simply do this:

global $user;
$pcp = module_invoke('pcp', 'block_view', 'pcp_profile_percent_complete');
if(in_array('administrator', $user->roles) || $user->uid == arg(1)) {
print render($pcp['content']);
}