Download & Extend

Integration with Content Profile

Project:Award
Version:6.x-1.0
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

Awards are typically something that should be associated with a user profile. It would be great to integrate this with the Content Profile module.

Comments

#1

Hi,

I have implemented this module with content profile.
Due to possible differences in versions and the fact that I have made several modifications to the award.module file i can't supply the line numbers.
But here is a basic awards content_profile implementation.

file: award.module

/**
* Implementation of hook_nodeapi()
*/
function award_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch ($op) {
    case 'delete':
      if (in_array($node->type, award_get_award_content_types())) {
        // An award node has been deleted, so delete any of its grants
        db_query("DELETE FROM {award_grants} WHERE nid=%d", $node->nid);
      }
      break;
    case 'view':
      if (is_content_profile($node) && $node->uid && arg(0) != 'admin') {
        $node->content['grant_awards_text'] = array(
          '#prefix' => '<br />',
          '#title' => '',
          '#value' => drupal_get_form('award_grant_form', $node),
          '#class' => 'grant_award',
          '#weight' => -4.6,
        );
        $node->content['view_awards_text'] = array(
          '#title' => 'Recieved Awards',
          '#value' => theme('awards_display', $node),
          '#class' => 'awards',
          '#weight' => -4.5,
          '#suffix' => '<br />',
        );
      }
      break;
  }
}

Step 2,
If you wish to remove the awards from the user account view edit this function
file: award.module

/**
* Implementation of hook_user()
*/
function award_user($op, &$edit, &$account, $category = NULL) {

  switch ($op) {
    case 'load':
      $r = db_query("SELECT * FROM {award_grants} WHERE uid=%d ORDER BY granted_time", $account->uid);
      $account->awards = array();
      while ($a = db_fetch_object($r)) {
        $a->award = node_load($a->nid);
        $account->awards[] = $a;
      }
      break;
    case 'view':
      // Remove from here
      $account->content[] = array(
        '#title' => '',
        '#value' => theme('awards_display', $account),
        '#class' => 'awards',
      );

      $account->content[] = array(
        '#title' => '',
        '#value' => drupal_get_form('award_grant_form', $account),
        '#class' => 'grant_award',
      );
      // To here
      break;
  }
}

The function should look like this after the amends

/**
* Implementation of hook_user()
*/
function award_user($op, &$edit, &$account, $category = NULL) {

  switch ($op) {
    case 'load':
      $r = db_query("SELECT * FROM {award_grants} WHERE uid=%d ORDER BY granted_time", $account->uid);
      $account->awards = array();
      while ($a = db_fetch_object($r)) {
        $a->award = node_load($a->nid);
        $account->awards[] = $a;
      }
      break;
    case 'view':
      break;
  }
}

Please send me some feedback.
contact me at http://www.facebook.com/stuart.eske