I have enabled the setting to provide a link in the user's account page to their content_profile form when it has not been completed, but I am looking for another way to remind users to create their profiles because many are not doing so.
Could this be achieved with a block? If so, can anyone suggest how please?

CommentFileSizeAuthor
#16 block-by-role-profile-picture.png26.69 KBdmetzcher
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Matt B’s picture

I've worked out some PHP for the block body:

<?php
global $user;
$type="profile";
$text= t("Create your @profile_node.", array('@profile_node' => node_get_types('name', $type)));
print l($text,  "user/" . $user->uid . "/profile/profile");
?>

Just change '$type="profile";' to be the name of your profile content type. I guess someone more familiar with the module could refine the above, but it works for me! - the last line might need to be 'print l($text, "user/" . $user->uid . "/profile/" . $type);'

Now I just need to work out what to put in the "Page specific visibility settings" (with "Show if the following PHP code returns TRUE" selected) to only display the block if the user has not created their profile yet....

Matt B’s picture

I'm currently working on:

<?php
global $user;
if (arg(0) == 'user' && $user->uid == arg(1)){
  return FALSE;
}
else if (arg(0) == 'admin') {
  return FALSE;
}
else {
/* now return TRUE if $user has not created their profile (FALSE if not).... */
  return TRUE;
}
?>

for the block visibility - just need to fix the "/* now return TRUE if $user has not created their profile (FALSE if not).... */" comment! At the moment this stops the block from being displayed on the users account pages (content profile provides a link here) and on the admin pages (although you'd hope a user with admin rights will have created a profile) as it just gets in the way.

Matt B’s picture

Ok, figured out the block visibility:

<?php
global $user;
$type="profile";

if (arg(0) == 'user' && $user->uid == arg(1)){
/* don't display on user pages (content profile does this for us) */
  return FALSE;
}
else if (arg(0) == 'admin') {
/* don't display on admin pages, gets in the way */
  return FALSE;
}
else {
/* now return TRUE if $user has not created their profile (FALSE if not).... */
$result = db_query("SELECT count(node.nid) as count FROM node WHERE node.type = '" . $type . "' AND node.uid =" . $user->uid);
$row= db_fetch_object($result);
return ($row->count==0);
}
?>

It's a bit of a hack and could possibly be written better - so suggestions are welcome. It'd be better if the Content Profile provided a block that did this....

Patroclas’s picture

Thanks for this Matt, will give it a try later.

Patroclas’s picture

I could not get this to work on my site.
The block appears even for unregistered users and includes a '1' under the title. If I restrict visibility by role of the block itself, it shows even if the cp profile has been created.

Just another idea - If CP module can place a line of text on the user page if no profile has been created, is there not a way to place the same text on other pages via templates maybe?

Matt B’s picture

Sorry you couldn't get it to work - mine's still working fine. Perhaps this should be a feature request for CP, to provide a block?

Patroclas’s picture

I have achieved what I need with the Rules module. Users with no CP are redirected to the appropriate form and a message is displayed. It is possible to display a block but this depends on switching roles around - I didn't want to do that because I am using LM PayPal to set subscription roles.

CP is exposed to Rules - it opens up a range of useful possibilities. Thanks to the module author for providing that!

lias’s picture

This is exactly the approach I took, Rules rules! http://drupal.org/project/rules

dmetzcher’s picture

I did the following. Note that the code below will check four things. You can modify sections of the code below (or remove them) to suit your own needs. The site I'm working on it rather complex in terms of features and I needed a way to let new users know what they had and had not done yet. The effect is a numbered list with each item crossed off as it is completed. The block is no longer displayed when all items have been completed.

  1. Is the user in a role called "administrator"?
    If so, short-circuit everything and do not display the block. I create the administrator role and explicitly assign it all permissions when I set up a Drupal site. This makes it easy to grant full admin status to multiple accounts and I rarely have to log into the super-admin account that Drupal creates (database updates after installing modules is really the only time it's necessary). I also assign this role to the super-admin account for consistency.
  2. Is the user in a role called "verified user"?
    If not, display the block. This is a role I created for the site I'm working on right now. It's a site that ties into Second Life and allows accounts on my site to be linked to their avatars (automatically, using the SlUser module). Once linked, they are considered "verified" and SlUser assigns the "verified user" role to them.
  3. Has the user uploaded a profile picture?
    If not, display the block.
  4. Has the user created their profile (the node managed by the Content Profile module)?
    If not, display the block.

This code goes into the block itself:

<?php

global $user;
$verified_role = array('verified user');
$user_profile_content_type='uprofile';  // The name of the Content Profile content type.
$verify_text = '<span style="font-weight: bold;"><a href="/verification" title="Verify your avatar">Verify your avatar.</a></span>';
$picture_text = '<span style="font-weight: bold;"><a href="/user/' . $user->uid . '/edit" title="Upload your picture">Upload your account picture.</a></span>';
$profile_text = '<span style="font-weight: bold;"><a href="/user/' . $user->uid . '/edit/uprofile" title="Create your profile">Create your profile.</a></span>';

/* Verify Avatar */
if (count(array_intersect($user->roles, $verified_role)) > 0) {  // User is assigned to the verified role.
  $verify_text = '<span style="text-decoration: line-through;">Verify your avatar.</span>';
}

/* Upload Picture */
if ($user->picture) {  // User has an account picture.
  $picture_text = '<span style="text-decoration: line-through;">Upload your account picture.</span>';
}

/* Create Profile */
$result = db_query("SELECT count(node.nid) as count FROM node WHERE node.type = '" . $user_profile_content_type . "' AND node.uid =" . $user->uid);
$row= db_fetch_object($result);
$count_profile_node = ($row->count);  // Get the count of rows (if the user has a profile node, it will be 1).
if ($count_profile_node > 0) {  // User has a profile node.
  $profile_text = '<span style="text-decoration: line-through;">Create your profile.</span>';
}

?>

<ol style="padding-left: 16px; font-family: 'marker felt', 'comic sans ms', fantasy;">
<li><span style="text-decoration: line-through;">Register for an account.</span></li>
<li><span style="text-decoration: line-through;">Verify your email address.</span></li>
<li><?php echo $verify_text; ?></li>
<li><?php echo $picture_text; ?></li>
<li><?php echo $profile_text; ?></li>
</ol>

This code goes into the block's "Page specific visibility settings" -- be sure to select the radio button labeled "Show if the following PHP code returns TRUE (PHP-mode, experts only).":
(Note that the checkbox labeled "authenticated user" under "Show block for specific roles" must be checked on the block's configuration page in order to hide this block from anonymous users -- you don't want them seeing this because it they haven't signed up yet.)

<?php

global $user;
$verified_role = array('verified user');  // Do not display for these roles. Note that anonymous users are not included. Check the option to display only to "authenticated user" under the "Show block for specific roles" section of the block's configuration page.
$roles_never_display = array('administrator');  // We never want to display this block for users in the "administrator" role.
$user_profile_content_type="uprofile";  // The name of the Content Profile content type.

$display_block = FALSE;  // By default, this block should not be displayed.

if (count(array_intersect($user->roles, $roles_never_display)) > 0) {  // User is in a special role that will NEVER see this block.
  return FALSE;  // Return FALSE immediately. Stop processing and do not display this block.
}

/* None of this applies to the users in certain roles ("verified user" is really the only role we care about, but more could be added). */
if (count(array_intersect($user->roles, $verified_role)) == 0) {  // User is NOT in one of the excluded roles.
  $display_block = TRUE;  // Display the block.
} else if ($user->picture == "") {  // Does the user have an account picture uploaded? If it is blank, then no.
  $display_block = TRUE;  // Display the block.
} else {
/* Store the value TRUE (to display the block) if $user has not created their profile. */
$result = db_query("SELECT count(node.nid) as count FROM node WHERE node.type = '" . $user_profile_content_type . "' AND node.uid =" . $user->uid);
$row= db_fetch_object($result);
$count_profile_node = ($row->count);  // Get the count of rows (if the user has a profile node, it will be 1).
if ($count_profile_node == 0) {  // User has no profile node.
      $display_block = TRUE;  // Display the block.
    }
}

return $display_block;

?>
dmetzcher’s picture

Attached is a screenshot of what the block I outlined in comment 15 looks like.