function pcp_get_complete_percentage_data in Profile Complete Percent 6
Same name and namespace in other branches
- 8 pcp.inc \pcp_get_complete_percentage_data()
- 5 pcp.module \pcp_get_complete_percentage_data()
- 6.2 pcp.module \pcp_get_complete_percentage_data()
- 7 pcp.module \pcp_get_complete_percentage_data()
Get the profile complete percentage data for a given user.
Parameters
obj $user :
- The user object to get data for.
Return value
assoc array of all values needed at the theme layer.
- Refer to comments in theme_pcp_profile_percent_complete() for specific values.
1 call to pcp_get_complete_percentage_data()
- pcp_block in ./
pcp.module - Implementation of hook_block()
File
- ./
pcp.module, line 208 - Allows users with valid permissions to tag profile fields created from the profile module as required fields for a users profile to be considered complete.
Code
function pcp_get_complete_percentage_data($user) {
$fields = pcp_get_tagged_profile_fields();
$user_values = pcp_get_user_profile_values($user->uid);
$percent = 0;
$complete = 0;
$nextfield_set = FALSE;
if (is_array($fields) && !empty($fields)) {
foreach ($fields as $key => $value) {
if ($user_values[$value['fid']] == '') {
if ($nextfield_set === FALSE) {
$nextfield_set = TRUE;
$fid = $value['fid'];
$nextdata = db_fetch_array(db_query("SELECT title, name, category FROM {profile_fields} WHERE fid = %d", $fid));
$nextfield = $nextdata['title'];
$nextcategory = $nextdata['category'];
$nextname = $nextdata['name'];
}
continue;
}
$complete++;
}
$dec = number_format($complete / count($fields), 2);
$percent = $dec * 100;
if ($nextfield_set) {
$next = number_format(($complete + 1) / count($fields), 2);
$nextpercent = $next * 100;
}
}
$complete_data['uid'] = $user->uid;
$complete_data['percent'] = $percent;
$complete_data['completed'] = $complete;
$complete_data['incomplete'] = count($fields) - $complete;
$complete_data['total'] = count($fields);
$complete_data['nextfield'] = $nextfield;
$complete_data['nextpercent'] = $nextpercent;
$complete_data['nextcategory'] = $nextcategory;
$complete_data['nextname'] = $nextname;
return $complete_data;
}