| 330 |
$output .= '</div>'; |
$output .= '</div>'; |
| 331 |
|
|
| 332 |
if ($complete_data['nextfield'] && $complete_data['nextpercent']) { |
if ($complete_data['nextfield'] && $complete_data['nextpercent']) { |
| 333 |
$output .= 'Filling out <i>'. l($complete_data['nextfield'], 'user/'. $complete_data['uid'] .'/edit/'. $complete_data['nextcategory'], array('query' => 'fieldname='. $complete_data['nextname'])) .'</i> will bring your profile to '. t('!complete% Complete', array('!complete' => $complete_data['nextpercent'])); |
$output .= t('Filling out ') . '<i> ' . l($complete_data['nextfield'], 'user/'. $complete_data['uid'] .'/edit/'. $complete_data['nextcategory'], array('query' => 'fieldname='. $complete_data['nextname'])) .'</i> ' . t('will bring your profile to') . ' ' . t('!complete% Complete', array('!complete' => $complete_data['nextpercent'])); |
| 334 |
} |
} |
| 335 |
|
|
| 336 |
return $output; |
return $output; |
| 337 |
|
} |
| 338 |
|
|
| 339 |
|
/** |
| 340 |
|
* Implementation of hook_rules_condition_info(). |
| 341 |
|
* |
| 342 |
|
* @ingroup rules |
| 343 |
|
* @see content_complete_completeness_percentage_form |
| 344 |
|
*/ |
| 345 |
|
function pcp_rules_condition_info() { |
| 346 |
|
return array( |
| 347 |
|
'pcp_condition_check_profile_fields_completeness' => array( |
| 348 |
|
'label' => t('Check profile fields completeness'), |
| 349 |
|
'arguments' => array( |
| 350 |
|
'user' => array('type' => 'user', 'label' => t('User')), |
| 351 |
|
), |
| 352 |
|
'help' => 'Evaluates to TRUE, if all the the selected user profile fields are filled in.', |
| 353 |
|
'module' => 'Profile Complete Percent', |
| 354 |
|
), |
| 355 |
|
); |
| 356 |
|
} |
| 357 |
|
|
| 358 |
|
/** |
| 359 |
|
* Rules Condition form configuration - select the profile fields to check |
| 360 |
|
* |
| 361 |
|
* @see pcp_rules_condition_info |
| 362 |
|
*/ |
| 363 |
|
function pcp_condition_check_profile_fields_completeness_form($settings = array(), &$form) { |
| 364 |
|
|
| 365 |
|
$options = pcp_admin_settings_form_data(); |
| 366 |
|
$form['settings']['profile_fields'] = array( |
| 367 |
|
'#title' => t('Profile Fields'), |
| 368 |
|
'#type' => 'checkboxes', |
| 369 |
|
'#options' => $options['profile_fields_options'], |
| 370 |
|
'#default_value' => isset($settings['profile_fields']) ? $settings['profile_fields'] : array(), |
| 371 |
|
'#description' => t('Check which fields the user has to fill in'), |
| 372 |
|
); |
| 373 |
|
} |
| 374 |
|
|
| 375 |
|
/** |
| 376 |
|
* Rules Condition - Are the selected user profile fields filed in? |
| 377 |
|
* |
| 378 |
|
* @param $user |
| 379 |
|
* The user for which the condition is checked. |
| 380 |
|
* @param $settings |
| 381 |
|
* The configured settings of the rule condition |
| 382 |
|
* |
| 383 |
|
* @see pcp_condition_check_profile_fields_completeness_form |
| 384 |
|
* @see pcp_rules_condition_info |
| 385 |
|
* |
| 386 |
|
* @return TRUE or FALSE |
| 387 |
|
*/ |
| 388 |
|
function pcp_condition_check_profile_fields_completeness($user, $settings) { |
| 389 |
|
|
| 390 |
|
$edit_categories = array(); |
| 391 |
|
profile_load_profile($user); |
| 392 |
|
if ($settings['profile_fields']) { |
| 393 |
|
$result = db_query("SELECT fid, title, name, category FROM {profile_fields} WHERE fid IN (%s)", implode(', ', $settings['profile_fields'])); |
| 394 |
|
while ($field = db_fetch_object($result)) { |
| 395 |
|
if (!$user->{$field->name}) { |
| 396 |
|
return FALSE; |
| 397 |
|
} |
| 398 |
|
} |
| 399 |
|
} |
| 400 |
|
return TRUE; |
| 401 |
|
} |
| 402 |
|
|
| 403 |
|
/** |
| 404 |
|
* Implementation of hook_rules_action_info |
| 405 |
|
*/ |
| 406 |
|
function pcp_rules_action_info() { |
| 407 |
|
return array( |
| 408 |
|
'pcp_action_redirect_user_to_editform' => array( |
| 409 |
|
'label' => t('Redirect the user to his own profile edit page'), |
| 410 |
|
'arguments' => array( |
| 411 |
|
'user' => array('type' => 'user', 'label' => t('User whos profile fields should be filled in')), |
| 412 |
|
), |
| 413 |
|
'module' => 'Profile Complete Percent', |
| 414 |
|
), |
| 415 |
|
); |
| 416 |
|
} |
| 417 |
|
|
| 418 |
|
/** |
| 419 |
|
* Rules Action - Redirect the user to his profile edit page |
| 420 |
|
* |
| 421 |
|
* @param $user |
| 422 |
|
* The user for which the action is performed. |
| 423 |
|
* @param $settings |
| 424 |
|
* The configured settings of the rule action |
| 425 |
|
* |
| 426 |
|
* @see pcp_rules_action_info |
| 427 |
|
* |
| 428 |
|
* @return Perform the redirection |
| 429 |
|
*/ |
| 430 |
|
function pcp_action_redirect_user_to_editform($user, $settings) { |
| 431 |
|
$settings = pcp_get_condition_settings('pcp_condition_check_profile_fields_completeness'); |
| 432 |
|
$edit_categories = array(); |
| 433 |
|
profile_load_profile($user); |
| 434 |
|
if ($settings['profile_fields']) { |
| 435 |
|
$result = db_query("SELECT fid, title, name, category FROM {profile_fields} WHERE fid IN (%s)", implode(', ', $settings['profile_fields'])); |
| 436 |
|
while ($field = db_fetch_object($result)) { |
| 437 |
|
if (!$user->{$field->name}) { |
| 438 |
|
drupal_set_message(t('Please fill in "<i>'.$field->category.'</i>".'), 'warning'); |
| 439 |
|
|
| 440 |
|
// Necessary to avoid redirect loop or malfunctioning |
| 441 |
|
unset($_REQUEST['destination']); |
| 442 |
|
unset($_REQUEST['edit']['destination']); |
| 443 |
|
drupal_goto('user/'.$user->uid.'/edit/'.$field->category); |
| 444 |
|
} |
| 445 |
|
} |
| 446 |
|
} |
| 447 |
|
} |
| 448 |
|
|
| 449 |
|
/** |
| 450 |
|
* Helper function to get the setting of a particular condition |
| 451 |
|
* |
| 452 |
|
* @param Condition name $name |
| 453 |
|
* @return Array settings |
| 454 |
|
*/ |
| 455 |
|
function pcp_get_condition_settings($name) { |
| 456 |
|
$rules = rules_get_configured_items('rules'); |
| 457 |
|
foreach ($rules as $rule) { |
| 458 |
|
if ($rule['#conditions']) { |
| 459 |
|
foreach ($rule['#conditions'] as $condition) { |
| 460 |
|
if ($condition['#name'] == $name) { |
| 461 |
|
return $condition['#settings']; |
| 462 |
|
} |
| 463 |
|
} |
| 464 |
|
} |
| 465 |
|
} |
| 466 |
} |
} |