You are here

function pcp_block_view in Profile Complete Percent 7

Implements hook_block_view().

File

./pcp.module, line 102
Allows users with valid permissions to tag profile fields (core fields or Profile2 fields) for a users profile to be considered complete.

Code

function pcp_block_view($delta = '') {
  global $user;
  $block = array();

  // No need to render a block for anonymous users.
  if (user_is_anonymous()) {
    return;
  }

  //The $delta parameter tells us which block is being requested.
  switch ($delta) {
    case 'pcp_profile_percent_complete':
      $out = pcp_get_complete_percentage_data('user', 'user', $user);
      $hide = variable_get('pcp_hide_block_on_complete', 0);
      $out['field_link_option'] = array(
        'attributes' => array(
          'target' => variable_get('pcp_fields_open_option', '_self'),
        ),
      );
      if ($hide && $out['incomplete'] == 0 || empty($out)) {
        $subject = '';
        $content = '';
      }
      else {
        drupal_add_css(drupal_get_path('module', 'pcp') . '/css/pcp.theme.css');
        $subject = t('Profile Complete');
        $content = theme('pcp_template', $out);
      }
      $block['subject'] = $subject;
      $block['content'] = $content;
      break;

    // Generate content for each profile2 profile type's pcp block.
    default:
      if ($profile2_entity = entity_get_info('profile2')) {
        foreach ($profile2_entity['bundles'] as $bundle => $values) {
          if ($delta == _pcp_block_identifier($bundle)) {
            $out = pcp_get_complete_percentage_data('profile2', $bundle, $user);
            $hide = variable_get('pcp_profile2_' . $bundle . '_hide_block_on_complete', 0);
            $out['field_link_option'] = array(
              'attributes' => array(
                'target' => variable_get('pcp_fields_open_option', '_self'),
              ),
            );

            // If the block should be hidden, hide it.
            if ($hide && $out['incomplete'] == 0 || empty($out)) {
              $content = '';
            }
            else {
              drupal_add_css(drupal_get_path('module', 'pcp') . '/css/pcp.theme.css');
              $content = theme('pcp_template', $out);
            }
            $block['subject'] = t('Profile Complete Percentage - @label', array(
              '@label' => $values['label'],
            ));
            $block['content'] = $content;
          }
        }
      }
      break;
  }
  return $block;
}