You are here

function commons_reputation_set_point_thresholds in Drupal Commons 6.2

Set userpoint thresholds for badges

1 call to commons_reputation_set_point_thresholds()
commons_reputation_install in modules/features/commons_reputation/commons_reputation.install
Implementation of hook_install()

File

modules/features/commons_reputation/commons_reputation.install, line 53

Code

function commons_reputation_set_point_thresholds($badges) {

  // Insert SQL
  $sql = "INSERT INTO {userpoints_badges} (bid, userpoints_goal) VALUES (%d, %d)";

  // Set the point values
  foreach ($badges as $key => $badge) {

    // Determine the bid
    $bid = db_result(db_query("SELECT bid FROM {user_badges_badges} WHERE name = '%s'", $badge->name));

    // Determine the point value
    switch ($key) {
      case 'super_contributor':
        $points = 1500;
        break;
      case 'frequent_contributor':
        $points = 1000;
        break;
      case 'regular_contributor':
        $points = 1000;
        break;
      case 'contributor':
        $points = 50;
        break;
      case 'member':
        $points = 2;
        break;
      default:
        $points = 0;
        break;
    }
    if ($bid && $points) {

      // drupal_write_record() is not working here
      db_query($sql, $bid, $points);
    }
  }
}