function pcp_get_complete_percentage_data in Profile Complete Percent 6.2
Same name and namespace in other branches
- 8 pcp.inc \pcp_get_complete_percentage_data()
- 5 pcp.module \pcp_get_complete_percentage_data()
- 6 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 332 - 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) {
$profile_fields = pcp_get_tagged_profile_fields();
$additional_fields = pcp_get_additional_tagged_fields();
$fields = $profile_fields + $additional_fields;
$user_profile_values = pcp_get_user_profile_values($user->uid);
$user_additional_values = pcp_get_user_additional_values($user->uid);
$user_values = $user_profile_values + $user_additional_values;
$percent = 0;
$complete = 0;
$nextfield_set = FALSE;
if (is_array($fields) && !empty($fields)) {
//Shuffle the fields to display a random field to fill in (issue #708382)
shuffle($fields);
foreach ($fields as $key => $value) {
if (isset($user_values[$value['fid']]) && ($user_values[$value['fid']] == '' || $user_values[$value['fid']] == '0' && $value['type'] == 'selection')) {
if ($nextfield_set === FALSE) {
$nextfield_set = TRUE;
$fid = $value['fid'];
$nextfield_fid = $fid;
if (is_numeric($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'];
}
elseif ($fid == 'user_picture') {
$nextfield = $value['title'];
$nextcategory = 'Default';
$nextname = $value['name'];
}
elseif (substr($fid, 0, 10) == 'user_terms' && variable_get('pcp_enabled_user_terms_vocabs', array())) {
$nextfield = $value['title'];
$nextcategory = $value['category'] == 'account' ? 'Default' : $value['category'];
$nextname = $value['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 = array();
$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['nextfield_fid'] = $nextfield_fid;
$complete_data['nextpercent'] = $nextpercent;
$complete_data['nextcategory'] = $nextcategory;
$complete_data['nextname'] = $nextname;
return $complete_data;
}